:root {
    --bg: #0b1020;
    --bg-elev: #131a31;
    --bg-card: #18213d;
    --border: rgba(148, 163, 184, 0.18);
    --text: #f1f5f9;
    --muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #10b981;
    --accent-hover: #059669;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --warning: #f59e0b;
    --radius: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at top right, #1e1b4b 0%, var(--bg) 55%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

h1, h2, h3, .big-letter {
    font-family: 'Outfit', sans-serif;
}

.hidden {
    display: none !important;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: 1120px;
    margin: 0 auto;
    padding: 1rem;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0 1.25rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.brand-badge {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    display: grid;
    place-items: center;
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 1.15rem;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.35);
}

.brand h1 {
    font-size: 1.35rem;
    line-height: 1.15;
}

.subtitle {
    color: var(--muted);
    font-size: 0.82rem;
}

.room-pill {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    font-size: 0.9rem;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.view {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
    gap: 1.25rem;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.card h2 {
    font-size: 1.3rem;
    margin-bottom: 0.35rem;
}

.card h3 {
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
}

.muted {
    color: var(--muted);
    font-size: 0.92rem;
    margin-bottom: 1rem;
}

.muted-sm {
    color: var(--muted);
    font-size: 0.82rem;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
}

.row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.88rem;
    font-weight: 500;
}

input, select, textarea {
    width: 100%;
    background: var(--bg-elev);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.68rem 0.85rem;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.22);
}

.code-input {
    text-transform: uppercase;
    letter-spacing: 0.25em;
    font-weight: 700;
    font-size: 1.1rem;
    text-align: center;
}

button {
    cursor: pointer;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-weight: 600;
    padding: 0.65rem 1rem;
    font-size: 0.95rem;
    transition: transform 0.1s, background-color 0.2s, opacity 0.2s;
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-lg {
    padding: 0.85rem 1.25rem;
    font-size: 1rem;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-accent {
    background: var(--accent);
    color: #042f2e;
}
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); color: #fff; }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-secondary {
    background: rgba(148, 163, 184, 0.15);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: rgba(148, 163, 184, 0.25); }

.btn-ghost-sm {
    background: transparent;
    color: var(--muted);
    padding: 0.25rem 0.55rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 999px;
}
.btn-ghost-sm:hover { color: #fff; border-color: var(--muted); }

.chips-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: rgba(99, 102, 241, 0.16);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: #e0e7ff;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    font-size: 0.82rem;
}

.chip button {
    background: transparent;
    color: #cbd5e1;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1;
}

.add-cat-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.35rem;
}

.rules-box {
    margin-top: 1.25rem;
    padding: 0.95rem;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid var(--border);
    font-size: 0.86rem;
}

.rules-box ul {
    padding-left: 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    color: #cbd5e1;
}

.tag {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #c7d2fe;
    background: rgba(99, 102, 241, 0.22);
    padding: 0.22rem 0.6rem;
    border-radius: 999px;
    margin-bottom: 0.4rem;
}

.lobby-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.lobby-code-title {
    font-size: 1.7rem;
}

.highlight-code {
    color: #34d399;
    letter-spacing: 0.15em;
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 1rem 0;
}

.lobby-players-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.65rem;
}

.players-grid {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}

.player-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.95rem;
    border-radius: 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
}

.lobby-actions {
    margin-top: 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
}

.alert-banner {
    background: rgba(239, 68, 68, 0.18);
    border: 1px solid rgba(239, 68, 68, 0.5);
    color: #fecaca;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    text-align: center;
    animation: pulseBorder 1s infinite alternate;
}

@keyframes pulseBorder {
    from { border-color: rgba(239, 68, 68, 0.45); }
    to { border-color: rgba(239, 68, 68, 0.95); }
}

.play-header-card {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.play-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.timer-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.timer-box strong {
    font-size: 1.2rem;
    color: #fbbf24;
}

.letter-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.letter-label {
    color: var(--muted);
    font-size: 0.95rem;
}

.big-letter {
    width: 72px;
    height: 72px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), #ec4899);
    display: grid;
    place-items: center;
    font-size: 2.5rem;
    font-weight: 800;
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4);
}

.progress-track {
    height: 8px;
    background: var(--bg-elev);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--accent), var(--primary));
    transition: width 0.5s linear;
}

.answers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.85rem;
}

.play-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.35rem;
}

.play-actions .btn-danger {
    flex: 2 1 220px;
}

.play-actions .btn-secondary {
    flex: 1 1 160px;
}

.judge-banner {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.22), rgba(16, 185, 129, 0.14));
}

.judge-comment {
    font-size: 1.05rem;
    color: #e2e8f0;
}

.scoreboard-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0.75rem;
}

.score-pill {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.score-pill strong {
    font-size: 1.15rem;
    color: #34d399;
}

.table-header-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.table-scroll {
    overflow-x: auto;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
}

.results-table th, .results-table td {
    border-bottom: 1px solid var(--border);
    padding: 0.65rem 0.6rem;
    text-align: left;
    vertical-align: top;
    font-size: 0.88rem;
}

.results-table th {
    color: var(--muted);
    font-weight: 600;
}

.cell-word {
    font-weight: 600;
    margin-bottom: 0.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
}

.pts-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
}

.pts-100 { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.pts-50 { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.pts-0 { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }

.cell-reason {
    color: var(--muted);
    font-size: 0.76rem;
    line-height: 1.3;
}

.btn-appeal {
    margin-top: 0.35rem;
    padding: 0.22rem 0.55rem;
    font-size: 0.75rem;
    background: rgba(245, 158, 11, 0.16);
    border: 1px solid rgba(245, 158, 11, 0.45);
    color: #fde68a;
}
.btn-appeal:hover { background: rgba(245, 158, 11, 0.3); }

.results-actions, .podium-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.podium-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin: 1rem 0 1.25rem;
}

.podium-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    font-size: 1.05rem;
}

.podium-item.first {
    border-color: rgba(251, 191, 36, 0.65);
    background: rgba(251, 191, 36, 0.1);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.75);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 460px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.5);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
}

.toast {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 80;
    background: #1e293b;
    border: 1px solid var(--border);
    color: #fff;
    padding: 0.75rem 1.05rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    max-width: 340px;
    font-size: 0.9rem;
}

.app-footer {
    margin-top: 2rem;
    padding: 1rem 0 0.5rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.82rem;
    border-top: 1px solid var(--border);
}
