:root {
    color-scheme: light;
    --bg: #0f172a;
    --bg-alt: #1e293b;
    --panel: #1e293b;
    --panel-soft: #0f172a;
    --panel-border: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

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

body {
    margin: 0;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg-alt) 100%);
    color: var(--text);
    overflow-x: hidden;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select {
    font: inherit;
}

.screen {
    display: none;
    min-height: 100vh;
    padding: 20px;
}

.screen.active {
    display: block;
}

.container {
    max-width: 600px;
    margin: 0 auto;
}

textarea {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--panel-border);
    border-radius: 8px;
    background: var(--panel-soft);
    color: var(--text);
    font: inherit;
    resize: vertical;
}

.hero {
    margin-bottom: 30px;
    text-align: center;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.8rem;
}

.hero h1 {
    margin: 0 0 8px;
    font-size: 2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-copy {
    margin: 0;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.6;
}

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    margin: 0 0 20px;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    background: var(--panel);
    border-bottom: 1px solid var(--panel-border);
    border-radius: 0;
    box-shadow: none;
    padding: 16px 20px;
    display: block;
}

.game-info {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: space-between;
    max-width: 600px;
    margin: 0 auto;
}

.game-code {
    cursor: pointer;
    padding: 8px 12px;
    background: var(--panel-soft);
    color: var(--text);
    border: 0;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.3s;
    white-space: nowrap;
    min-height: 0;
}

.game-code:active,
.game-code:hover {
    background: var(--panel-border);
}

.viewer-badge {
    padding: 6px 12px;
    background: var(--warning);
    color: var(--bg);
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.owner-badge {
    background: var(--success);
    color: var(--bg);
}

.role-badge {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.round-info {
    font-weight: 600;
    color: var(--primary);
    font-size: 1.2rem;
    white-space: nowrap;
}

.layout {
    display: grid;
    gap: 20px;
}

.card,
.panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 24px;
}

.panel-header h2,
.panel-header p {
    margin: 0;
}

.panel-header {
    display: grid;
    gap: 6px;
}

.panel-header h2 {
    font-size: 1.5rem;
    color: var(--text);
}

.stack {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-weight: 600;
}

.form-group {
    margin-bottom: 20px;
}

input,
select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--panel-border);
    border-radius: 12px;
    background: var(--panel-soft);
    color: var(--text);
    transition: border-color 0.3s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary);
}

button {
    border: 0;
    border-radius: 8px;
    padding: 14px 24px;
    cursor: pointer;
    font-weight: 600;
    min-height: 46px;
    transition: all 0.3s;
}

button.primary,
.inline-form button,
#roundForm button[type="submit"] {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff;
}

.btn {
    width: 100%;
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 10px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
}

.btn-secondary {
    background: var(--panel-border);
    color: var(--text);
}

button.primary:hover,
.inline-form button:hover,
#roundForm button[type="submit"]:hover,
button.ghost:hover,
.stepper-button:hover:not(:disabled) {
    transform: translateY(-2px);
}

button.ghost {
    background: var(--panel-soft);
    color: var(--text);
    border: 2px solid var(--panel-border);
}

.inline-form {
    display: grid;
    gap: 12px;
    grid-template-columns: 1fr auto;
}

.resume-card {
    padding: 24px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    border-radius: 16px;
    color: white;
}

.resume-card p {
    color: rgba(255, 255, 255, 0.9);
    margin: 0 0 15px;
}

.resume-card .btn {
    background: white;
    color: var(--primary);
}

.hidden {
    display: none !important;
}

.muted {
    color: var(--muted);
}

.status-banner {
    margin-bottom: 16px;
    padding: 14px 16px;
    border-radius: 8px;
    font-weight: 600;
    background: var(--panel-soft);
    color: var(--text);
}

.player-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

.player-count-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-top: 12px;
}

.player-count-btn {
    padding: 20px;
    font-size: 1.3rem;
    font-weight: 700;
    border: 3px solid var(--panel-border);
    border-radius: 12px;
    background: var(--panel-soft);
    color: var(--text);
    cursor: pointer;
    transition: all 0.3s;
    min-height: 0;
}

.player-count-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: var(--primary);
    color: white;
}

.winner-picker,
.winner-buttons {
    display: grid;
    gap: 12px;
}

.winner-buttons {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
}

.winner-btn {
    width: 100%;
    padding: 16px 12px;
    font-size: 1rem;
    font-weight: 700;
    border: 2px solid var(--panel-border);
    border-radius: 8px;
    background: var(--panel-soft);
    color: var(--text);
    min-height: 0;
}

.winner-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: var(--primary);
    color: white;
}

.winner-summary {
    padding: 16px;
    border-radius: 8px;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--text);
}

.winner-summary strong {
    color: var(--success);
}

.winner-summary-actions {
    margin-top: 14px;
}

.winner-summary-actions .btn {
    margin-top: 0;
}

.round-details-card {
    display: grid;
    gap: 16px;
}

.round-note {
    color: var(--muted);
    font-size: 0.95rem;
}

.player-navigation {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 8px;
}

.nav-btn {
    width: 48px;
    height: 48px;
    border: 2px solid var(--panel-border);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
    min-height: 0;
    padding: 0;
}

.nav-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.player-card {
    border: 2px solid var(--panel-border);
    border-radius: 8px;
    padding: 16px;
    display: grid;
    gap: 12px;
    background: var(--panel-soft);
}

.player-card h3,
.history-item h3,
.round-entry h3 {
    margin: 0;
}

.phase-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(99, 102, 241, 0.14);
    color: #c7d2fe;
    border-radius: 6px;
    padding: 6px 12px;
    width: fit-content;
    font-weight: 700;
}

.phase-finished {
    background: rgba(16, 185, 129, 0.14);
    color: var(--success);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
}

.round-entry {
    border: 2px solid var(--panel-border);
    border-radius: 8px;
    padding: 16px;
    display: grid;
    gap: 14px;
    background: var(--panel-soft);
}

.row-header {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    align-items: center;
}

.row-header > div:first-child {
    min-width: 0;
}

.entry-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.entry-meta span {
    background: var(--panel-soft);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--muted);
    font-size: 0.9rem;
}

.mode-switch {
    display: grid;
    gap: 8px;
}

.mode-switch select {
    max-width: 320px;
}

.entry-fields {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.phase-answer-block {
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: rgba(16, 185, 129, 0.08);
    padding: 14px;
    display: grid;
    gap: 12px;
}

.phase-answer-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.phase-answer-options {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.phase-answer-option {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    background: var(--panel-soft);
    font-weight: 700;
    cursor: pointer;
}

.phase-answer-option.active {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.18);
}

.phase-answer-option input {
    width: 22px;
    height: 22px;
}

.score-preview {
    border-radius: 8px;
    padding: 12px 14px;
    background: var(--panel-soft);
    color: var(--muted);
    border: 1px solid var(--panel-border);
}

.score-preview strong {
    color: var(--text);
}

.helper-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.helper-card {
    border: 2px solid var(--panel-border);
    border-radius: 8px;
    padding: 14px;
    display: grid;
    gap: 12px;
    background: var(--panel-soft);
}

.helper-head {
    display: grid;
    gap: 4px;
}

.helper-head strong {
    font-size: 1rem;
}

.helper-head span {
    color: var(--muted);
    font-size: 0.9rem;
}

.stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.stepper-button {
    min-width: 48px;
    min-height: 48px;
    padding: 10px 12px;
    background: var(--panel);
    color: var(--text);
    font-size: 1.5rem;
    border: 2px solid var(--panel-border);
}

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

.helper-count {
    min-width: 28px;
    text-align: center;
    font-size: 1.15rem;
    font-weight: 800;
}

.helper-summary {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--panel-soft);
    color: var(--muted);
    border: 1px solid var(--panel-border);
}

.history-list {
    display: grid;
    gap: 12px;
}

.final-summary {
    display: grid;
    gap: 16px;
}

.final-summary-card {
    border: 1px solid rgba(16, 185, 129, 0.28);
    border-radius: 16px;
    padding: 18px;
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(99, 102, 241, 0.08));
}

.final-summary-card h3 {
    margin-bottom: 14px;
}

.final-summary-duration {
    margin-bottom: 14px;
    color: var(--text);
}

.final-summary-list {
    display: grid;
    gap: 12px;
}

.final-summary-item {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    padding: 14px;
    border-radius: 12px;
    background: var(--panel-soft);
    border: 1px solid var(--panel-border);
}

.final-summary-item.winner {
    border-color: rgba(16, 185, 129, 0.45);
    box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.2);
}

.final-summary-stats {
    display: grid;
    gap: 4px;
    text-align: right;
}

.confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 2000;
}

.confetti-piece {
    position: absolute;
    top: -10vh;
    width: 10px;
    height: 18px;
    opacity: 0.9;
    animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translate3d(0, 0, 0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translate3d(0, 120vh, 0) rotate(540deg);
        opacity: 0;
    }
}

.history-item {
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 16px;
    display: grid;
    gap: 12px;
    background: var(--panel);
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
}

.history-table th,
.history-table td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--panel-border);
    font-size: 0.95rem;
}

.history-table th {
    background: var(--panel-soft);
    color: var(--primary);
    position: sticky;
    top: 0;
}

.pill {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 4px;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
}

.actions {
    margin-top: 20px;
    padding-bottom: 30px;
}

.sponsor-footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--muted);
    font-size: 0.9rem;
}

.sponsor-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-modal-content {
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    border: none;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--muted);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    min-height: 0;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.game-code-display {
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    padding: 20px;
    background: var(--panel-soft);
    border-radius: 12px;
    margin: 20px 0 12px;
    letter-spacing: 4px;
    color: var(--primary);
}

.share-link-text {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    word-break: break-all;
    margin-bottom: 18px;
}

.game-code-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.game-code-actions .btn {
    flex: 1 1 160px;
    margin-top: 0;
}

.whatsapp-btn {
    background: #25D366;
    color: #fff;
}

.success {
    color: var(--success);
}

.warning {
    color: var(--warning);
}

.danger {
    color: var(--danger);
}

@media (max-width: 720px) {
    .screen {
        padding: 20px 16px 32px;
    }

    .hero {
        margin-bottom: 24px;
    }

    .hero h1 {
        font-size: 1.5rem;
    }

    .hero-copy {
        font-size: 0.95rem;
    }

    .header {
        padding: 16px 20px;
    }

    .game-info {
        justify-content: center;
        text-align: center;
    }

    .inline-form {
        grid-template-columns: 1fr;
    }

    .game-code,
    .viewer-badge,
    .owner-badge,
    .round-info {
        font-size: 0.85rem;
    }

    .row-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .layout {
        gap: 12px;
    }

    .panel {
        padding: 20px;
        border-radius: 16px;
    }

    .player-count-buttons {
        grid-template-columns: repeat(3, 1fr);
    }

    .winner-buttons {
        grid-template-columns: repeat(2, 1fr);
    }

    .status-banner {
        padding: 12px 14px;
        font-size: 0.95rem;
    }

    .player-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .player-card,
    .round-entry,
    .history-item {
        padding: 16px;
    }

    .entry-meta {
        gap: 6px;
    }

    .entry-meta span {
        font-size: 0.82rem;
        padding: 5px 9px;
    }

    .mode-switch select {
        max-width: none;
    }

    .entry-fields {
        grid-template-columns: 1fr;
    }

    .helper-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .helper-card {
        padding: 14px;
    }

    .helper-summary {
        padding: 10px 12px;
        font-size: 0.95rem;
    }

    .final-summary-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .final-summary-stats {
        text-align: left;
    }

    .game-code-display {
        font-size: 1.5rem;
        letter-spacing: 2px;
    }

    .game-code-actions {
        flex-direction: column;
    }

    .history-table th,
    .history-table td {
        padding: 9px 8px;
        font-size: 0.9rem;
    }

    .pill {
        font-size: 0.8rem;
    }
}

@media (max-width: 420px) {
    .topbar-actions {
        width: 100%;
        flex-direction: column;
    }

    .topbar-title-row {
        gap: 8px;
    }

    .phase-badge {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    .stat-row,
    .helper-summary {
        font-size: 0.92rem;
    }

    .player-count-buttons {
        grid-template-columns: repeat(2, 1fr);
    }

    .winner-buttons {
        grid-template-columns: 1fr;
    }
}
