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

:root {
    --bg-primary: #0d1329;
    --bg-secondary: #1a2140;
    --bg-card: #252b4a;
    --accent-pink: #ff3b6f;
    --accent-pink-dark: #cc2f59;
    --text-primary: #ffffff;
    --text-secondary: #8892b0;

    --team-a: #e53935;
    --team-a-dark: #c62828;
    --team-b: #1e88e5;
    --team-b-dark: #1565c0;
    --intercept-green: #4ade80;
    --miscom-red: #f87171;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(180deg, var(--bg-primary) 0%, #0a0f1f 100%);
    min-height: 100vh;
    min-height: var(--app-height, 100dvh);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-user-select: none;
    user-select: none;
}

.app {
    max-width: 430px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: var(--app-height, 100dvh);
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    min-height: var(--app-height, 100dvh);
    padding: 40px 20px;
    padding-top: calc(40px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==================== */
/* Back Button          */
/* ==================== */
.btn-back {
    position: absolute;
    top: calc(16px + env(safe-area-inset-top, 0px));
    left: 16px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    z-index: 10;
    opacity: 0.8;
    transition: opacity 0.2s;
}

@media (hover: hover) {
    .btn-back:hover {
        opacity: 1;
    }
}

/* ==================== */
/* Title                */
/* ==================== */
.title {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 12px;
    color: var(--text-primary);
    animation: fadeIn 0.3s ease;
}

.subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 24px;
    line-height: 1.4;
}

.packs-container {
    width: 100%;
}

/* Onboarding overrides */
.dot.active {
    width: 10px;
    border-radius: 50%;
    transform: scale(1.2);
}

.btn-next-slide {
    flex: 1;
}

.btn-skip {
    border-color: var(--bg-card);
}

@media (hover: hover) {
    .btn-skip:hover {
        border-color: var(--text-secondary);
    }
}

/* ==================== */
/* Team Selection       */
/* ==================== */
#team-screen {
    position: relative;
    justify-content: center;
}

.team-cards {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 360px;
    margin-top: 20px;
}

.team-card {
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: 20px;
    padding: 30px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

@media (hover: hover) {
    .team-card:hover {
        transform: translateY(-2px);
    }
}

.team-card:active {
    transform: scale(0.98);
}

@media (hover: hover) {
    .team-a-card:hover {
        border-color: var(--team-a);
    }
}

@media (hover: hover) {
    .team-b-card:hover {
        border-color: var(--team-b);
    }
}

.team-card-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.team-card-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--accent-pink);
}

.team-a-card .team-card-title {
    color: var(--team-a);
}

.team-b-card .team-card-title {
    color: var(--team-b);
}

.team-card-desc {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ==================== */
/* Code Input           */
/* ==================== */
#code-screen {
    position: relative;
    justify-content: center;
}

.code-input-container {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin: 32px 0;
}

.code-digit {
    width: 64px;
    height: 80px;
    background: var(--bg-card);
    border: 2px solid var(--text-secondary);
    border-radius: 16px;
    color: var(--text-primary);
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    outline: none;
    caret-color: var(--accent-pink);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.code-digit:focus {
    border-color: var(--accent-pink);
    box-shadow: 0 0 20px rgba(255, 59, 111, 0.2);
}

.btn-random-code {
    display: block;
    margin: 0 auto 24px;
    padding: 8px 20px;
    background: transparent;
    border: 1.5px solid var(--bg-card);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
}

@media (hover: hover) {
    .btn-random-code:hover {
        border-color: var(--text-secondary);
        color: var(--text-primary);
    }
}

.btn-random-code:active {
    transform: scale(0.96);
}

.bottom-section {
    width: 100%;
    max-width: 360px;
    margin-top: auto;
    padding-bottom: 20px;
}

.btn-play {
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--accent-pink), var(--accent-pink-dark));
    border: none;
    border-radius: 30px;
    color: white;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(255, 59, 111, 0.3);
}

@media (hover: hover) {
    .btn-play:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(255, 59, 111, 0.4);
    }
}

.btn-play:active {
    transform: scale(0.98);
}

.btn-play:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ==================== */
/* Game Screen          */
/* ==================== */
#game-screen {
    padding: 12px 16px;
    min-height: 100vh;
    min-height: var(--app-height, 100dvh);
    justify-content: flex-start;
    gap: 12px;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0;
}

.btn-back-game {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 6px 10px;
    opacity: 0.8;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

@media (hover: hover) {
    .btn-back-game:hover {
        opacity: 1;
    }
}

.round-indicator {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.btn-history-toggle {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 6px 10px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

@media (hover: hover) {
    .btn-history-toggle:hover {
        opacity: 1;
    }
}

/* ==================== */
/* Scores Bar           */
/* ==================== */
.scores-bar {
    display: flex;
    gap: 8px;
    width: 100%;
}

.score-block {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 8px 12px;
    text-align: center;
}

.score-block.our-score {
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.score-block.enemy-score {
    border: 1px solid rgba(255, 255, 255, 0.05);
    opacity: 0.8;
}

.score-team-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 4px;
}

.score-tokens {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.token {
    font-size: 14px;
    font-weight: 700;
}

.token-intercept {
    color: var(--intercept-green);
}

.token-miscom {
    color: var(--miscom-red);
}

/* ==================== */
/* Words Panel          */
/* ==================== */
.words-panel {
    width: 100%;
}

.words-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 8px;
}

.words-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.word-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 10px 6px;
    text-align: center;
    border: 2px solid transparent;
    transition: all 0.3s;
}

.word-card .word-number {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 4px;
    opacity: 0.6;
}

.word-card .word-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-word;
    line-height: 1.2;
}

.team-A .word-card {
    border-color: rgba(229, 57, 53, 0.3);
}

.team-A .word-card .word-number {
    color: var(--team-a);
}

.team-B .word-card {
    border-color: rgba(30, 136, 229, 0.3);
}

.team-B .word-card .word-number {
    color: var(--team-b);
}

/* ==================== */
/* Code Reveal Button   */
/* ==================== */
.btn-show-code {
    width: 100%;
    padding: 14px 20px;
    background: var(--bg-secondary);
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

@media (hover: hover) {
    .btn-show-code:hover {
        border-color: rgba(255, 255, 255, 0.4);
        background: var(--bg-card);
    }
}

.btn-show-code:active {
    transform: scale(0.98);
}

/* ==================== */
/* Clue Section         */
/* ==================== */
.clue-section {
    width: 100%;
}

.clue-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.opponent-clues .clue-section-title {
    color: var(--text-secondary);
    opacity: 0.7;
}

.clue-inputs {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.clue-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.clue-label {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    width: 22px;
    flex-shrink: 0;
}

.clue-input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
}

.clue-input:focus {
    border-color: var(--accent-pink);
}

.clue-input::placeholder {
    color: rgba(136, 146, 176, 0.5);
}

.clue-input-error {
    border-color: var(--miscom-red) !important;
}

/* ==================== */
/* Action Buttons       */
/* ==================== */
.action-buttons {
    width: 100%;
}

.btn-save-clues {
    width: 100%;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

@media (hover: hover) {
    .btn-save-clues:hover {
        background: var(--bg-secondary);
        border-color: var(--accent-pink);
    }
}

.btn-save-clues:active {
    transform: scale(0.98);
}

/* ==================== */
/* Scoring Trigger      */
/* ==================== */
.btn-open-scoring {
    width: 100%;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

@media (hover: hover) {
    .btn-open-scoring:hover {
        background: var(--bg-secondary);
        border-color: var(--accent-pink);
    }
}

.btn-open-scoring:active {
    transform: scale(0.98);
}

/* ==================== */
/* Scoring Overlay      */
/* ==================== */
.scoring-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.scoring-overlay.active {
    display: flex;
}

.scoring-overlay-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 32px 24px;
    background: var(--bg-card);
    border-radius: 20px;
    width: 90%;
    max-width: 360px;
}

.scoring-overlay-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
}

.scoring-hint {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.4;
    margin: 0;
}

.scoring-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.scoring-label {
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
    min-width: 90px;
}

.btn-score {
    flex: 1;
    padding: 10px 10px;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-intercept {
    background: rgba(74, 222, 128, 0.15);
    color: var(--intercept-green);
}

@media (hover: hover) {
    .btn-intercept:hover {
        background: rgba(74, 222, 128, 0.25);
    }
}

.btn-intercept:active {
    transform: scale(0.95);
}

.btn-miscom {
    background: rgba(248, 113, 113, 0.15);
    color: var(--miscom-red);
}

@media (hover: hover) {
    .btn-miscom:hover {
        background: rgba(248, 113, 113, 0.25);
    }
}

.btn-miscom:active {
    transform: scale(0.95);
}

.btn-close-scoring {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 4px;
}

@media (hover: hover) {
    .btn-close-scoring:hover {
        border-color: var(--accent-pink);
        color: var(--text-primary);
    }
}

.btn-close-scoring:active {
    transform: scale(0.98);
}

/* ==================== */
/* Next Round           */
/* ==================== */
.next-round-section {
    width: 100%;
}

.btn-next-round {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--accent-pink), var(--accent-pink-dark));
    border: none;
    border-radius: 30px;
    color: white;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(255, 59, 111, 0.3);
}

@media (hover: hover) {
    .btn-next-round:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(255, 59, 111, 0.4);
    }
}

.btn-next-round:active {
    transform: scale(0.98);
}

/* ==================== */
/* Code Overlay         */
/* ==================== */
.code-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.code-overlay.active {
    display: flex;
}

.code-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 40px;
    text-align: center;
}

.code-overlay-label {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.code-overlay-digits {
    display: flex;
    gap: 16px;
    align-items: center;
}

.code-digit-display {
    width: 72px;
    height: 90px;
    background: var(--bg-card);
    border: 2px solid var(--accent-pink);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    font-weight: 700;
    color: var(--accent-pink);
    box-shadow: 0 0 20px rgba(255, 59, 111, 0.3);
}

.code-digit-separator {
    font-size: 28px;
    color: var(--text-secondary);
    font-weight: 700;
}

.code-overlay-hint {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 260px;
    line-height: 1.5;
}

.code-overlay .btn-play {
    width: auto;
    padding: 14px 40px;
}

/* ==================== */
/* History Screen       */
/* ==================== */
#history-screen {
    position: relative;
    padding-top: 60px;
}

.history-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-bottom: 20px;
    overflow-y: auto;
}

.history-team-section {
    width: 100%;
}

.history-team-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.history-team-label.team-a {
    color: var(--team-a);
}

.history-team-label.team-b {
    color: var(--team-b);
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 12px;
}

.history-th-round,
.history-td-round {
    width: 28px;
}

.history-table thead tr {
    background: var(--bg-secondary);
}

.history-table th {
    padding: 6px 4px;
    text-align: center;
    vertical-align: bottom;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.history-th-round {
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
}

.kw-num {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.kw-word {
    display: block;
    font-size: 9px;
    color: var(--text-secondary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    margin-top: 2px;
    line-height: 1.2;
}

.history-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.history-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

.history-table tbody tr:last-child {
    border-bottom: none;
}

.history-td-round {
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-secondary);
    padding: 8px 2px;
}

.history-td-clue {
    text-align: center;
    padding: 8px 4px;
    color: var(--text-primary);
    font-size: 12px;
    word-break: break-word;
    line-height: 1.3;
    vertical-align: top;
}

.history-td-empty {
    color: rgba(136, 146, 176, 0.25);
    font-size: 14px;
}

.history-empty {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    padding: 40px 20px;
}

/* ==================== */
/* Game Over Screen     */
/* ==================== */
#gameover-screen {
    justify-content: center;
}

.gameover-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    text-align: center;
    max-width: 360px;
}

.gameover-icon {
    font-size: 72px;
}

.gameover-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.gameover-text {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.gameover-scores {
    display: flex;
    gap: 24px;
    font-size: 15px;
}

.gameover-score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.gameover-score-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.gameover-score-value {
    font-size: 18px;
    font-weight: 700;
}

.gameover-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    margin-top: 12px;
}

.gameover-buttons .btn-skip {
    width: 100%;
}

/* ==================== */
/* Responsive           */
/* ==================== */
@media (max-width: 480px) {
    .app {
        max-width: 100%;
    }

    .screen {
        padding: 24px 12px;
        padding-top: calc(24px + env(safe-area-inset-top, 0px));
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    #game-screen {
        padding: 10px 12px;
        gap: 10px;
    }

    .title {
        font-size: 22px;
    }

    .code-digit {
        width: 56px;
        height: 70px;
        font-size: 28px;
    }

    .team-card {
        padding: 24px 20px;
    }

    .team-card-icon {
        font-size: 40px;
    }

    .team-card-title {
        font-size: 18px;
    }

    .word-card .word-text {
        font-size: 11px;
    }

    .word-card .word-number {
        font-size: 12px;
    }

    .scoring-label {
        min-width: 75px;
        font-size: 12px;
    }

    .btn-score {
        font-size: 12px;
        padding: 7px 8px;
    }
}

@media (max-height: 600px) {
    .screen {
        padding: 16px 12px;
    }
}
