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

:root {
    --bg-primary: #0d1329;
    --bg-secondary: #1a2140;
    --bg-card: #252b4a;
    --accent-teal: #14b8a6;
    --accent-teal-dark: #0d9488;
    --accent-blue: #4a6cf7;
    --accent-purple: #a855f7;
    --text-primary: #ffffff;
    --text-secondary: #8892b0;
    --text-placeholder: #5a6380;
    --success: #4ade80;
    --error: #f87171;
    --warning: #fbbf24;
}

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

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

/* ==================== */
/* Screen System        */
/* ==================== */

.screen {
    display: none;
    height: 100vh;
    height: var(--app-height, 100dvh);
    overflow: hidden;
}

.screen.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

.screen-content {
    padding: 40px 24px;
    padding-top: calc(40px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

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

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ==================== */
/* Typography           */
/* ==================== */

.title {
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 32px;
}

/* ==================== */
/* Buttons              */
/* ==================== */

.btn-play {
    width: 100%;
    padding: 18px;
    background: linear-gradient(135deg, var(--accent-teal) 0%, var(--accent-teal-dark) 100%);
    border: none;
    border-radius: 30px;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(20, 184, 166, 0.3);
}

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

.btn-play:active {
    transform: translateY(0);
}

.btn-play:disabled {
    background: var(--bg-card);
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.6;
}

.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;
    z-index: 10;
    padding: 8px;
}

.btn-join {
    padding: 16px 32px;
    background: transparent;
    border: 2px solid var(--accent-teal);
    border-radius: 30px;
    color: var(--accent-teal);
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

@media (hover: hover) {
    .btn-join:hover {
        background: var(--accent-teal);
        color: var(--text-primary);
    }
}

.btn-join.active {
    background: linear-gradient(135deg, var(--accent-teal) 0%, var(--accent-teal-dark) 100%);
    border-color: transparent;
    color: var(--text-primary);
    box-shadow: 0 4px 20px rgba(20, 184, 166, 0.3);
}

.btn-play.outlined {
    background: transparent;
    border: 2px solid var(--accent-teal);
    color: var(--accent-teal);
    box-shadow: none;
}

.btn-copy {
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

@media (hover: hover) {
    .btn-copy:hover {
        background: var(--bg-secondary);
        color: var(--text-primary);
    }
}

.btn-copy.copied {
    background: var(--success);
    color: #000;
    border-color: var(--success);
}

/* ==================== */
/* Inputs               */
/* ==================== */

.input {
    width: 100%;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 2px solid transparent;
    border-radius: 16px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

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

.input::placeholder {
    color: var(--text-placeholder);
}

.name-input {
    margin-bottom: 20px;
    text-align: center;
}

.code-input {
    width: 100%;
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 8px;
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
}

/* ==================== */
/* Main Screen          */
/* ==================== */

.main-content {
    justify-content: center;
    align-items: center;
}

.game-logo {
    font-size: 80px;
    margin-bottom: 16px;
}

.actions-columns {
    display: flex;
    gap: 16px;
    width: 100%;
    align-items: stretch;
    margin-top: 24px;
}

.action-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    justify-content: center;
    min-width: 0;
}

.col-divider {
    width: 1px;
    background: rgba(255, 255, 255, 0.1);
}

.error-message {
    color: var(--error);
    font-size: 14px;
    text-align: center;
    min-height: 20px;
    margin-top: 16px;
}

/* ==================== */
/* Lobby Screen         */
/* ==================== */

.lobby-content {
    align-items: center;
}

.room-code-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
}

.room-code-display {
    font-size: 48px;
    font-weight: 800;
    letter-spacing: 12px;
    color: var(--accent-teal);
    background: var(--bg-card);
    padding: 16px 32px;
    border-radius: 20px;
    font-family: 'Courier New', monospace;
    user-select: all;
}

.lobby-hint {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

.qr-code-block {
    display: flex;
    justify-content: center;
    margin: 0 0 16px;
}

.qr-code-img {
    width: 160px;
    height: 160px;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    background: #ffffff;
    padding: 8px;
}

.players-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    overflow-y: auto;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-radius: 12px;
    animation: slideIn 0.3s ease;
}

.player-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-teal) 0%, var(--accent-blue) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}

.player-avatar.has-photo {
    padding: 0;
    background: none;
    overflow: visible;
}

.player-avatar.has-photo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scale(1.5);
}

.player-avatar.clickable {
    cursor: pointer;
    position: relative;
}

.player-avatar.clickable::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px dashed rgba(139, 92, 246, 0.5);
    opacity: 0;
    transition: opacity 0.2s;
}

.player-avatar.clickable:not(.has-photo)::after {
    opacity: 1;
}

.player-name {
    flex: 1;
    font-size: 16px;
    font-weight: 500;
}

.player-host {
    font-size: 14px;
    color: var(--accent-teal);
    font-weight: 600;
}

.player-disconnected {
    opacity: 0.4;
}

/* ---- Bottom Section ---- */

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

.lobby-status {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 12px;
}

/* ==================== */
/* Game Screen          */
/* ==================== */

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

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-left: 40px;
}

.round-badge {
    background: var(--bg-card);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.timer-badge {
    width: 48px;
    height: 48px;
    background: var(--accent-teal);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
}

.timer-badge.warning {
    background: var(--error);
    animation: pulse 0.5s ease infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

/* ==================== */
/* Respondent Badge     */
/* ==================== */

.respondent-badge {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-purple);
    margin-bottom: 12px;
    padding: 10px 16px;
    background: rgba(168, 85, 247, 0.12);
    border-radius: 16px;
    border: 1px solid rgba(168, 85, 247, 0.25);
}

.respondent-badge .name {
    font-weight: 700;
    color: #c084fc;
}

/* ==================== */
/* Question             */
/* ==================== */

.question-text {
    font-size: 22px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 24px;
    line-height: 1.3;
}

/* ==================== */
/* Phase Container      */
/* ==================== */

.phase-container {
    animation: fadeIn 0.3s ease;
}

.phase-hint {
    font-size: 16px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 20px;
}

/* ==================== */
/* Options Grid (2x2)   */
/* ==================== */

.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.option-btn {
    padding: 20px 12px;
    background: var(--bg-card);
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    line-height: 1.3;
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (hover: hover) {
    .option-btn:hover:not(:disabled) {
        border-color: var(--accent-teal);
        transform: translateY(-2px);
    }
}

.option-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.option-btn:disabled {
    cursor: default;
    opacity: 0.5;
}

.option-btn.selected {
    background: linear-gradient(135deg, var(--accent-teal) 0%, var(--accent-teal-dark) 100%);
    border-color: var(--accent-teal);
    transform: scale(1.03);
    box-shadow: 0 4px 16px rgba(20, 184, 166, 0.35);
}

.option-btn.selected:disabled {
    opacity: 0.85;
    transform: scale(1.03);
}

/* Reveal states */
.option-btn.correct {
    background: linear-gradient(135deg, rgba(74, 222, 128, 0.25) 0%, rgba(34, 197, 94, 0.15) 100%);
    border-color: var(--success);
    opacity: 1;
}

.option-btn.wrong {
    background: linear-gradient(135deg, rgba(248, 113, 113, 0.2) 0%, rgba(239, 68, 68, 0.1) 100%);
    border-color: var(--error);
    opacity: 0.7;
}

/* Meme option buttons */
.meme-option-btn {
    padding: 4px;
    min-height: auto;
    overflow: hidden;
}

.meme-option-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    pointer-events: none;
    aspect-ratio: 1;
}

.meme-option-btn.selected img {
    opacity: 0.85;
}

/* ==================== */
/* Waiting Phase        */
/* ==================== */

.waiting-animation {
    display: flex;
    justify-content: center;
    margin: 32px 0 16px;
}

.waiting-dots {
    display: flex;
    gap: 8px;
}

.waiting-dots span {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-purple);
    animation: bounce 1.4s infinite ease-in-out both;
}

.waiting-dots span:nth-child(1) { animation-delay: -0.32s; }
.waiting-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.waiting-text {
    font-size: 18px;
    color: var(--text-secondary);
    text-align: center;
    padding: 16px 0;
}

/* ==================== */
/* Round Results Screen */
/* ==================== */

.round-results-content {
    align-items: center;
}

.round-question {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 20px;
}

.correct-answer-block {
    width: 100%;
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(74, 222, 128, 0.15) 0%, rgba(34, 197, 94, 0.08) 100%);
    border: 1px solid var(--success);
    border-radius: 16px;
    text-align: center;
    margin-bottom: 20px;
}

.correct-answer-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.correct-answer-text {
    font-size: 22px;
    font-weight: 700;
    color: var(--success);
}

.respondent-bonus {
    font-size: 13px;
    color: var(--accent-teal);
    margin-top: 6px;
}

/* ==================== */
/* Player Guesses       */
/* ==================== */

.player-guesses {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.guess-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: 12px;
    gap: 12px;
}

.guess-item.correct {
    border: 1px solid var(--success);
    background: rgba(74, 222, 128, 0.1);
}

.guess-item.wrong {
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.guess-item.no-answer {
    opacity: 0.5;
}

.guess-emoji {
    font-size: 22px;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}

.guess-name {
    font-size: 14px;
    font-weight: 600;
    min-width: 60px;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.guess-answer {
    font-size: 13px;
    color: var(--text-secondary);
    flex: 1;
    text-align: center;
}

.guess-result {
    font-size: 14px;
    font-weight: 700;
    min-width: 50px;
    text-align: right;
    color: var(--error);
}

.guess-result.earned {
    color: var(--success);
}

/* ==================== */
/* Scoreboard           */
/* ==================== */

.scoreboard-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    margin-top: 20px;
    color: var(--text-secondary);
}

.scoreboard {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.score-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: 12px;
}

.score-item.leading {
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.2) 0%, rgba(20, 184, 166, 0.1) 100%);
    border: 1px solid var(--accent-teal);
}

.score-position {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    margin-right: 12px;
    background: var(--bg-card);
    flex-shrink: 0;
}

.score-position.gold {
    background: linear-gradient(135deg, #ffd700 0%, #ffb700 100%);
    color: #000;
}

.score-position.silver {
    background: linear-gradient(135deg, #c0c0c0 0%, #a0a0a0 100%);
    color: #000;
}

.score-position.bronze {
    background: linear-gradient(135deg, #cd7f32 0%, #a05a20 100%);
    color: #000;
}

.score-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: contain;
    flex-shrink: 0;
    transform: scale(1.5);
}

.score-name {
    flex: 1;
    font-size: 16px;
    font-weight: 500;
}

.score-value {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-teal);
}

/* ==================== */
/* Results Screen       */
/* ==================== */

.results-content {
    align-items: center;
    justify-content: center;
}

.winner-icon {
    font-size: 80px;
    margin-bottom: 16px;
}

.winner-name {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent-teal);
    margin-bottom: 32px;
}

.final-results {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 32px;
}

/* ==================== */
/* Connection Overlay   */
/* ==================== */

.connection-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 19, 41, 0.9);
    z-index: 100;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 16px;
}

.connection-overlay.visible {
    display: flex;
}

.connection-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-card);
    border-top-color: var(--accent-teal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.connection-text {
    color: var(--text-secondary);
    font-size: 16px;
}

/* ==================== */
/* Yes/No Buttons       */
/* ==================== */

.yesno-buttons {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    margin-bottom: 16px;
}

.yesno-btn {
    flex: 1;
    padding: 32px 16px;
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    font-size: 28px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.yesno-btn.yes-btn {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
}

.yesno-btn.no-btn {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
}

@media (hover: hover) {
    .yesno-btn:hover:not(:disabled) {
        transform: translateY(-3px);
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    }
}

.yesno-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.yesno-btn:disabled {
    cursor: default;
    opacity: 0.5;
}

.yesno-btn.selected {
    transform: scale(1.04);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.yesno-btn.yes-btn.selected {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.3) 0%, rgba(109, 40, 217, 0.2) 100%);
    border-color: rgba(139, 92, 246, 0.7);
    color: #c4b5fd;
}

.yesno-btn.no-btn.selected {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.3) 0%, rgba(109, 40, 217, 0.2) 100%);
    border-color: rgba(139, 92, 246, 0.7);
    color: #c4b5fd;
}

.yesno-btn.selected:disabled {
    opacity: 0.85;
    transform: scale(1.04);
}

/* ==================== */
/* Packs Screen         */
/* ==================== */

.packs-content {
    align-items: stretch;
}

.packs-container {
    flex: 1;
    overflow-y: auto;
    margin: 0 -4px;
    padding: 4px;
    -webkit-overflow-scrolling: touch;
}

.packs-summary {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 12px;
}

.packs-summary strong {
    color: var(--accent-teal);
    font-size: 16px;
}

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

@media (max-width: 480px) {
    .screen-content {
        padding: 24px 16px;
        padding-top: calc(24px + env(safe-area-inset-top, 0px));
    }

    .title {
        font-size: 24px;
    }

    .game-logo {
        font-size: 60px;
    }

    .room-code-display {
        font-size: 36px;
        padding: 12px 24px;
        letter-spacing: 8px;
    }

    .question-text {
        font-size: 18px;
    }

    .option-btn {
        padding: 16px 10px;
        font-size: 14px;
        min-height: 60px;
    }

    .yesno-btn {
        padding: 24px 12px;
        font-size: 24px;
        min-height: 80px;
    }

    .timer-badge {
        width: 42px;
        height: 42px;
        font-size: 18px;
    }
}

@media (min-width: 768px) {
    .screen-content {
        padding: 50px 40px;
    }

    .title {
        font-size: 32px;
    }

    .question-text {
        font-size: 26px;
    }

    .option-btn {
        padding: 24px 16px;
        font-size: 17px;
        min-height: 80px;
    }

    .timer-badge {
        width: 56px;
        height: 56px;
        font-size: 24px;
    }
}
