* {
    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;

    /* Codenames team colors */
    --team-red: #e53935;
    --team-red-dark: #c62828;
    --team-blue: #1e88e5;
    --team-blue-dark: #1565c0;
    --neutral-color: #78909c;
    --neutral-dark: #546e7a;
    --assassin-color: #212121;
    --assassin-dark: #000000;
}

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);
}

.app.full-width {
    max-width: 100%;
}

.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;
}

/* ==================== */
/* Onboarding overrides */
/* ==================== */
.onboarding-container {
    max-width: 360px;
    gap: 30px;
}

.onboarding-slides {
    min-height: 260px;
}

.slide-icon {
    font-size: 64px;
    margin-bottom: 8px;
}

.slide-title {
    margin-bottom: 0;
}

.onboarding-slide {
    padding: 0;
    gap: 16px;
}

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

.onboarding-buttons {
    gap: 12px;
    max-width: none;
}

.onboarding-dots {
    margin-bottom: 0;
}

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

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

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

/* ==================== */
/* Dictionary Selection */
/* ==================== */
#dictionary-screen {
    position: relative;
}

.packs-container {
    width: 100%;
}

/* ==================== */
/* Game Mode Selection   */
/* ==================== */
#gamemode-screen {
    position: relative;
    justify-content: center;
}

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

.gamemode-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) {
    .gamemode-card:hover {
        border-color: var(--accent-pink);
        transform: translateY(-2px);
    }
}

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

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

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

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

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

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

.role-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) {
    .role-card:hover {
        border-color: var(--accent-pink);
        transform: translateY(-2px);
    }
}

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

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

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

.role-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;
}

/* ==================== */
/* Landscape Prompt     */
/* ==================== */
#landscape-screen {
    justify-content: center;
}

.landscape-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 20px;
    padding: 40px 20px;
}

.rotate-icon {
    font-size: 60px;
    animation: rotate-hint 2s ease-in-out infinite;
}

@keyframes rotate-hint {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

.landscape-prompt h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.landscape-prompt p {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.5;
    max-width: 280px;
}

.landscape-prompt .btn-play {
    width: auto;
    padding: 14px 40px;
    margin-top: 10px;
}

/* ==================== */
/* Game Screen          */
/* ==================== */
#game-screen {
    padding: 0;
    min-height: 100vh;
    min-height: var(--app-height, 100dvh);
    justify-content: center;
    position: relative;
}

.game-layout {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100vh;
    height: var(--app-height, 100dvh);
}

.game-sidebar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px 8px;
    flex-shrink: 0;
    width: 80px;
    background: var(--bg-secondary);
}

.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;
}

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

.sidebar-scores {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.score {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.score-red {
    color: var(--team-red);
}

.score-blue {
    color: var(--team-blue);
}

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

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

/* ==================== */
/* Board Grid           */
/* ==================== */
.board-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    min-width: 0;
}

.board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 6px;
    width: 100%;
    height: 100%;
    max-width: 644px;
}

/* ==================== */
/* Cell Styles          */
/* ==================== */
.cell {
    position: relative;
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    perspective: 800px;
    min-height: 0;
    overflow: hidden;
}

.cell-inner {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: transform 0.5s ease;
    transform-style: preserve-3d;
    position: relative;
}

.cell-front,
.cell-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 6px;
}

/* Player mode: unrevealed front */
.player-mode .cell-front {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.cell-back {
    transform: rotateY(180deg);
}

/* Color classes */
.cell-back.red,
.captain-mode .cell-front.red {
    background: linear-gradient(135deg, var(--team-red), var(--team-red-dark));
}

.cell-back.blue,
.captain-mode .cell-front.blue {
    background: linear-gradient(135deg, var(--team-blue), var(--team-blue-dark));
}

.cell-back.neutral,
.captain-mode .cell-front.neutral {
    background: linear-gradient(135deg, var(--neutral-color), var(--neutral-dark));
}

.cell-back.assassin,
.captain-mode .cell-front.assassin {
    background: linear-gradient(135deg, #1a1a1a, #000000);
    border: 2px solid #ff1744;
}

/* Player mode: flip animation */
.player-mode .cell.revealed .cell-inner {
    transform: rotateY(180deg);
}

/* Captain mode: single-sided, always colored */
.captain-mode .cell-front {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 4px;
}

/* Captain mode: toggle effect */
.captain-mode .cell.toggled .cell-front {
    opacity: 0.35;
}

.captain-mode .cell.toggled::after {
    content: '\2713';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: clamp(18px, 4vw, 28px);
    font-weight: 700;
    color: white;
    z-index: 2;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

/* Assassin icon on card back */
.cell-assassin-icon {
    font-size: clamp(20px, 5vw, 36px);
}

/* Word text */
.cell-word {
    font-size: clamp(14px, 4.4vw, 24px);
    font-weight: 600;
    text-align: center;
    color: var(--text-primary);
    word-break: break-word;
    line-height: 1.15;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ==================== */
/* Pictures Mode         */
/* ==================== */
.cell-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    display: block;
    pointer-events: none;
}

.pictures-mode .cell {
    aspect-ratio: 3 / 2;
}

/* Captain mode pictures: colored border frame around image */
.captain-mode.pictures-mode .cell-front {
    padding: 0;
    border-width: 4px;
    border-style: solid;
    border-color: transparent;
}

.captain-mode.pictures-mode .cell-front.red {
    background: none;
    border-color: var(--team-red);
    box-shadow: inset 0 0 0 2px var(--team-red);
}

.captain-mode.pictures-mode .cell-front.blue {
    background: none;
    border-color: var(--team-blue);
    box-shadow: inset 0 0 0 2px var(--team-blue);
}

.captain-mode.pictures-mode .cell-front.neutral {
    background: none;
    border-color: var(--neutral-color);
    box-shadow: inset 0 0 0 2px var(--neutral-color);
}

.captain-mode.pictures-mode .cell-front.assassin {
    background: none;
    border-color: #212121;
    box-shadow: inset 0 0 0 2px #212121;
    position: relative;
}

.captain-mode.pictures-mode .cell-front.assassin::after {
    content: '\1F480';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(16px, 4vw, 28px);
    border-radius: 4px;
    z-index: 1;
}

.captain-mode.pictures-mode .cell-front .cell-image {
    border-radius: 4px;
}

/* Player mode pictures */
.player-mode.pictures-mode .cell-front {
    padding: 0;
}

.player-mode.pictures-mode .cell-front .cell-image {
    border-radius: 8px;
}

/* Player mode back: thick colored border around image */
.player-mode.pictures-mode .cell-back {
    padding: 0;
    border-width: 4px;
    border-style: solid;
    border-color: transparent;
}

.player-mode.pictures-mode .cell-back.red {
    background: none;
    border-color: var(--team-red);
    box-shadow: inset 0 0 0 2px var(--team-red);
}

.player-mode.pictures-mode .cell-back.blue {
    background: none;
    border-color: var(--team-blue);
    box-shadow: inset 0 0 0 2px var(--team-blue);
}

.player-mode.pictures-mode .cell-back.neutral {
    background: none;
    border-color: var(--neutral-color);
    box-shadow: inset 0 0 0 2px var(--neutral-color);
}

.player-mode.pictures-mode .cell-back.assassin {
    background: none;
    border-color: #ff1744;
    box-shadow: inset 0 0 0 2px #ff1744;
}

.player-mode.pictures-mode .cell-back .cell-image {
    border-radius: 4px;
}

/* ==================== */
/* First Team Indicator */
/* ==================== */
.first-team-indicator {
    text-align: center;
    font-size: 10px;
    font-weight: 600;
    padding: 4px 6px;
    border-radius: 8px;
    line-height: 1.3;
}

.first-team-indicator.red {
    color: var(--team-red);
    background: rgba(229, 57, 53, 0.15);
}

.first-team-indicator.blue {
    color: var(--team-blue);
    background: rgba(30, 136, 229, 0.15);
}

/* ==================== */
/* Game Over Overlay     */
/* ==================== */
.game-over-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;
    animation: fadeIn 0.3s ease;
}

.game-over-overlay.active {
    display: flex;
}

.game-over-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
    padding: 40px;
}

.game-over-icon {
    font-size: 72px;
}

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

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

.game-over-content .btn-play {
    width: auto;
    padding: 14px 40px;
    margin-top: 12px;
}

/* ==================== */
/* Picture Lightbox      */
/* ==================== */
.picture-lightbox {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 110;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.picture-lightbox.active {
    display: flex;
}

.picture-lightbox-img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s ease;
    pointer-events: none;
}

/* ==================== */
/* Responsive           */
/* ==================== */

/* Landscape mode: game board optimization */
@media (orientation: landscape) {
    .game-sidebar {
        padding-left: calc(8px + env(safe-area-inset-left, 0px));
        width: calc(80px + env(safe-area-inset-left, 0px));
    }

    .board {
        max-height: calc(100vh - 16px);
        max-width: calc((100vh - 16px) * 1.29);
    }

    .cell {
        min-height: 0;
        overflow: hidden;
    }

    .cell-word {
        font-size: clamp(14px, 3.6vh, 24px);
    }

    .pictures-mode .cell {
        aspect-ratio: 3 / 2;
    }

    .pictures-mode .board {
        max-height: calc(100vh - 16px);
        max-width: calc((100vh - 16px) * 0.85);
    }
}

/* Portrait mode: rotate game screen to landscape */
@media (orientation: portrait) {
    #game-screen {
        min-height: auto;
        height: 100vw;
        width: 100vh;
        transform: rotate(90deg);
        transform-origin: top left;
        position: absolute;
        top: 0;
        left: 100vw;
    }

    #game-screen .game-layout {
        height: 100%;
    }

    #game-screen .game-sidebar {
        padding-left: calc(8px + env(safe-area-inset-top, 0px));
        width: calc(80px + env(safe-area-inset-top, 0px));
    }
}

/* Small mobile */
@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));
    }

    .title {
        font-size: 22px;
    }

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

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

    .role-icon {
        font-size: 40px;
    }

    .role-title {
        font-size: 18px;
    }

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

    .gamemode-icon {
        font-size: 40px;
    }

    .gamemode-title {
        font-size: 18px;
    }

    .pack-card {
        padding: 20px 16px;
    }

    .premium-badge {
        font-size: 14px;
        top: 6px;
        right: 6px;
    }
}

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

/* Tablet and larger */
@media (min-width: 768px) and (orientation: portrait) {
    .board {
        max-width: 515px;
    }
}
