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

:root {
    --bg-primary: #0d1329;
    --bg-secondary: #1a2140;
    --bg-card: #252b4a;
    --accent-primary: #9333ea;
    --accent-primary-dark: #7e22ce;
    --accent-secondary: #c084fc;
    --accent-blue: #4a6cf7;
    --accent-green: #4ade80;
    --accent-yellow: #facc15;
    --text-primary: #ffffff;
    --text-secondary: #8892b0;
    --text-placeholder: #5a6380;
    --success: #4ade80;
    --error: #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;
}

.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-primary) 0%, var(--accent-primary-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(147, 51, 234, 0.3);
}

@media (hover: hover) {
    .btn-play:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 24px rgba(147, 51, 234, 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-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-primary); }
.input::placeholder { color: var(--text-placeholder); }
.name-input { margin-bottom: 20px; text-align: center; }

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

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

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

.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-primary);
    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-primary) 0%, var(--accent-secondary) 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-primary); font-weight: 600; }
.player-disconnected { opacity: 0.4; }

.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 Header          */
/* ==================== */

.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: 0 16px 0 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-primary);
    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); }
}

/* ==================== */
/* Prompt Card          */
/* ==================== */

.prompt-card {
    text-align: center;
    padding: 16px 20px;
    background: var(--bg-card);
    border-radius: 16px;
    margin: 0 16px 12px;
    border: 2px solid rgba(147, 51, 234, 0.3);
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.prompt-card.image-prompt {
    padding: 0;
    overflow: hidden;
    aspect-ratio: auto;
    max-height: 200px;
}

.prompt-card.image-prompt img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    max-height: 200px;
}

.prompt-text {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--accent-secondary);
}

.choosing-subtitle, .voting-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 12px;
    padding: 0 16px;
}

.btn-refresh-hand {
    align-self: center;
    padding: 10px 22px;
    margin: 0 auto 12px;
    background: linear-gradient(135deg, var(--accent-blue) 0%, #2c4fd1 100%);
    color: var(--text-primary);
    border: none;
    border-radius: 22px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 4px 16px rgba(74, 108, 247, 0.35);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

@media (hover: hover) {
    .btn-refresh-hand:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(74, 108, 247, 0.5);
    }
}

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

/* ==================== */
/* Card Grid (Hand)     */
/* ==================== */

.cards-grid {
    width: 100%;
    padding: 0 16px;
    margin-bottom: 12px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.cards-grid-inner {
    column-count: 2;
    column-gap: 0;
}

.card {
    position: relative;
    overflow: hidden;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-card);
    break-inside: avoid;
    margin-bottom: 0;
}

.card.text-card {
    aspect-ratio: 3/4;
}

.card img {
    width: 100%;
    height: auto;
    display: block;
}

/* Situation text card */
.card.text-card {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    text-align: center;
    font-size: 11px;
    line-height: 1.3;
    color: var(--text-primary);
    font-weight: 500;
    word-break: break-word;
}

@media (hover: hover) {
    .card:hover:not(.selected):not(.disabled) {
        border-color: rgba(147, 51, 234, 0.4);
    }
}

.card.selected {
    border-color: var(--accent-primary);
    box-shadow: 0 0 20px rgba(147, 51, 234, 0.5);
}

.card.disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.card-check {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    background: var(--accent-primary);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
}

.card.selected .card-check { display: flex; }

/* ==================== */
/* Table Cards (Voting) */
/* ==================== */

.table-grid {
    width: 100%;
    padding: 0 16px;
    margin-bottom: 12px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.table-grid-inner {
    column-count: 2;
    column-gap: 0;
}

.table-grid.single-column .table-grid-inner {
    column-count: 1;
}

.table-card {
    position: relative;
    overflow: hidden;
    border: 3px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-card);
    break-inside: avoid;
    margin-bottom: 0;
}

.table-card.text-card {
    aspect-ratio: 3/4;
}

.table-card img {
    width: 100%;
    height: auto;
    display: block;
}

.table-card.text-card {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    text-align: center;
    font-size: 13px;
    line-height: 1.3;
    color: var(--text-primary);
    font-weight: 500;
    word-break: break-word;
}

@media (hover: hover) {
    .table-card:hover:not(.voted):not(.disabled):not(.own-card) {
        border-color: rgba(74, 108, 247, 0.4);
    }
}

.table-card.voted {
    border-color: var(--accent-blue);
    box-shadow: 0 0 16px rgba(74, 108, 247, 0.4);
    cursor: default;
}

.table-card.own-card {
    border-color: rgba(255, 255, 255, 0.15);
    cursor: default;
}

.table-card.disabled { cursor: default; }

.table-card-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.7);
    color: var(--text-secondary);
    font-size: 11px;
    text-align: center;
    font-weight: 500;
}

.table-card-letter {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
}

/* ==================== */
/* Submitted Overlay    */
/* ==================== */

.submitted-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(13, 19, 41, 0.85);
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    z-index: 5;
    border-radius: 12px;
}

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

.submitted-icon { font-size: 48px; }
.submitted-text { font-size: 18px; font-weight: 600; color: var(--success); }
.submitted-hint { font-size: 14px; color: var(--text-secondary); }

/* ==================== */
/* Reveal Screen        */
/* ==================== */

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

/* ==================== */
/* 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-primary);
    margin-bottom: 32px;
}

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

.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(147, 51, 234, 0.2) 0%, rgba(147, 51, 234, 0.1) 100%);
    border: 1px solid var(--accent-primary);
}

.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, #ffb700); color: #000; }
.score-position.silver { background: linear-gradient(135deg, #c0c0c0, #a0a0a0); color: #000; }
.score-position.bronze { background: linear-gradient(135deg, #cd7f32, #a05a20); 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-primary); }

/* ==================== */
/* 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-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==================== */
/* Card Preview Overlay */
/* ==================== */

.card-preview-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(13, 19, 41, 0.95);
    z-index: 50;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    padding-top: calc(24px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

.card-preview-overlay.visible {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.card-preview-close {
    position: absolute;
    top: calc(16px + env(safe-area-inset-top, 0px));
    right: 16px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-primary);
    font-size: 28px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.card-preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
}

.card-preview-image {
    width: 100%;
    max-height: 70vh;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.card-preview-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.card-preview-image.text-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: var(--bg-card);
    font-size: 20px;
    line-height: 1.5;
    color: var(--text-primary);
    text-align: center;
    min-height: 200px;
}

.card-preview-actions {
    width: 100%;
    max-width: 400px;
    padding-top: 20px;
}

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

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

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

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

.packs-summary strong { color: var(--accent-primary); }

.btn-settings-link {
    display: block;
    margin: 0 auto 12px;
    background: none;
    border: none;
    color: var(--accent-secondary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
    padding: 4px 8px;
}

/* ==================== */
/* 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;
    }
    .timer-badge { width: 42px; height: 42px; font-size: 18px; }
    .cards-grid { column-gap: 0; }
    .table-grid { column-gap: 0; padding: 0 12px; }
}

@media (min-width: 768px) {
    .screen-content { padding: 50px 40px; }
    .title { font-size: 32px; }
    .timer-badge { width: 56px; height: 56px; font-size: 24px; }
}
