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

:root {
    --bg: #0a0a0a;
    --bg-card: #141414;
    --border: #2a2a2a;
    --border-light: #3a3a3a;
    --text: #ffffff;
    --text-dim: #bbbbbb;
    --accent: #ffffff;
    --accent-glow: rgba(200, 200, 200, 0.15);
    --success: #4ade80;
    --success-glow: rgba(74, 222, 128, 0.3);
    --danger: #f87171;
    --danger-glow: rgba(248, 113, 113, 0.3);
    --radius: 14px;
    --radius-sm: 10px;
    --game-size: 800px;

    --fs-xs: 1rem;
    --fs-sm: 1.2rem;
    --fs-md: 1.5rem;
    --fs-lg: 2.5rem;
    --fs-xl: 5rem;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.screen {
    display: none;
    position: relative;
    min-height: 100vh;
    padding: 2rem 1rem;
}

.screen.active {
    display: flex;
    align-items: safe center;
    justify-content: center;
    overflow-y: auto;
}

.container {
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    text-align: center;
}

/* ── Landing ── */
.logo {
    width: 96px;
    height: 96px;
    margin: 0 auto 1.5rem;
    display: block;
}

.title {
    font-size: var(--fs-xl);
    font-weight: 800;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text);
    font-size: var(--fs-md);
    margin-bottom: 2.5rem;
    line-height: 1.5;
}

.kofi-wrapper {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 10;
}

.kofi-wrapper .btn-container {
    display: inline-block !important;
}

.kofi-wrapper .kofi-button {
    background: #ffffff !important;
    border: 1px solid #ddd !important;
    border-radius: var(--radius-sm) !important;
    padding: 0.6rem 1.2rem !important;
    transition: all 0.2s !important;
}

.kofi-wrapper .kofi-button:hover {
    background: #f0f0f0 !important;
    border-color: #ccc !important;
}

.kofi-wrapper .kofitext {
    color: #000000 !important;
    font-family: inherit !important;
    font-size: var(--fs-xs) !important;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 2rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-primary {
    background: #ffffff;
    color: #0a0a0a;
}

.btn-primary:hover {
    background: #e0e0e0;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border-light);
}

.btn-secondary:hover {
    background: #1e1e1e;
    border-color: #555;
}

.btn-lg {
    padding: 1.1rem 2.75rem;
    font-size: var(--fs-md);
    border-radius: var(--radius);
    display: block;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
}

/* ── Game Layout (3-column) ── */
#screen-game.active {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 1rem;
}

.game-layout {
    display: flex;
    gap: 1.25rem;
    justify-content: center;
    align-items: flex-start;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.game-center {
    flex: 0 0 auto;
    width: var(--game-size);
    max-width: 100%;
}

.side-panel {
    flex: 0 1 260px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    position: sticky;
    top: 1rem;
}


/* ── Info Boxes ── */
.info-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.info-box-title {
    font-size: var(--fs-xs);
    letter-spacing: 0.05em;
    color: var(--text);
    margin-bottom: 0.65rem;
    font-weight: 700;
}

.info-text {
    font-size: var(--fs-xs);
    color: var(--text);
    line-height: 1.5;
}

.info-text.skeleton {
    color: transparent;
    background: linear-gradient(90deg, var(--border) 25%, var(--border-light) 50%, var(--border) 75%);
    background-size: 400px 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 4px;
    min-height: 1.4em;
    user-select: none;
}

@keyframes shimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.35rem 0;
    gap: 0.5rem;
}

.info-row + .info-row {
    border-top: 1px solid var(--border);
}

.info-label {
    font-size: var(--fs-xs);
    color: var(--text-dim);
    flex-shrink: 0;
}

.info-value {
    font-size: var(--fs-xs);
    color: var(--text);
    text-align: right;
    word-break: break-word;
}

/* ── Game HUD ── */
.game-header {
    margin-bottom: 0.75rem;
    max-width: 1400px;
    width: 100%;
    padding: 0 1.25rem;
}

.game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-width: 70px;
}

.hud-title-item {
    flex: 1;
    text-align: center;
}

.hud-label {
    font-size: var(--fs-xs);
    color: var(--text-dim);
}

.hud-value {
    font-size: var(--fs-lg);
    font-weight: 800;
    color: var(--text);
}

.hud-hearts {
    font-size: var(--fs-md);
    letter-spacing: 2px;
    line-height: 1;
}

.heart {
    font-size: 3rem;
    margin-right: 4px;
}

.heart-full {
    color: #f43f5e;
}

.heart-empty {
    color: #444;
}

.icon-win {
    font-size: var(--fs-xl);
    color: var(--success);
}

.icon-lose {
    font-size: var(--fs-xl);
    color: var(--danger);
}

.hud-game-title {
    font-size: var(--fs-sm);
    font-weight: 700;
    color: var(--text);
}

.hud-difficulty {
    font-size: var(--fs-xs);
    color: var(--text-dim);
}

/* ── External Timer ── */


/* ── Game Frame ── */
.game-frame-wrapper {
    position: relative;
    width: var(--game-size);
    max-width: 100%;
    aspect-ratio: 1;
    margin: 0 auto;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
}

.game-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    overflow: hidden;
}

/* ── Game Toolbar (below game frame) ── */
.game-toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 0.75rem;
    padding: 0;
}

.toolbar-spacer {
    flex: 1;
}

.toolbar-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.5rem 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-dim);
    font-size: var(--fs-xs);
    font-family: inherit;
}

.toolbar-btn:hover {
    border-color: var(--border-light);
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
}

.toolbar-btn.voted {
    border-color: rgba(74, 222, 128, 0.4);
    color: var(--text);
}

.toolbar-btn.disabled {
    opacity: 0.3;
    pointer-events: none;
}

.vote-icon {
    font-size: 1rem;
    color: var(--text-dim);
    transition: color 0.2s;
    line-height: 1;
}

.toolbar-btn.voted .vote-icon {
    color: var(--success);
}

#btn-downvote.voted .vote-icon {
    color: var(--danger);
}

#btn-downvote.voted {
    border-color: rgba(248, 113, 113, 0.4);
}

.toolbar-count {
    font-size: var(--fs-xs);
    color: inherit;
    font-weight: 600;
}

.toolbar-icon {
    font-size: 1.1rem;
    line-height: 1;
}

/* ── Report Modal ── */
.report-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

.report-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.report-card h3 {
    font-size: var(--fs-md);
    margin-bottom: 0.5rem;
    color: var(--text);
    font-weight: 700;
}

.report-card p {
    font-size: var(--fs-xs);
    color: var(--text-dim);
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.report-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.report-option {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--fs-xs);
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}

.report-option:hover {
    border-color: var(--border-light);
    background: rgba(255, 255, 255, 0.04);
}

.report-option.reported {
    color: var(--success);
    border-color: rgba(74, 222, 128, 0.3);
    cursor: default;
}

.report-comment {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--fs-xs);
    font-family: inherit;
    resize: vertical;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.report-comment::placeholder {
    color: var(--text-dim);
}

.report-comment:focus {
    outline: none;
    border-color: var(--border-light);
}

.report-cancel {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: var(--fs-xs);
    font-family: inherit;
    cursor: pointer;
    padding: 0.5rem 1rem;
    transition: color 0.15s;
}

.report-cancel:hover {
    color: var(--text);
}

/* ── Loading State ── */
.game-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    z-index: 5;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    justify-content: center;
    max-width: 400px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--text);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1.25rem;
}

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

.loading-text {
    color: var(--text);
    font-weight: 600;
    font-size: var(--fs-md);
    margin-bottom: 0.5rem;
}

.loading-subtext {
    color: var(--text-dim);
    font-size: var(--fs-sm);
    margin-bottom: 1.25rem;
}

.loading-steps {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.step {
    font-size: var(--fs-xs);
    color: var(--border-light);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.3s;
}

.step.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

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

/* ── Loading Bar ── */
.loading-bar-track {
    width: 80%;
    max-width: 320px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin-top: 1.25rem;
    overflow: hidden;
}

.loading-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #666666, #aaaaaa);
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* ── Loading Error Actions ── */
.loading-error-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* ── Ad Placeholder ── */
.ad-placeholder {
    width: 100%;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.ad-label {
    font-size: var(--fs-xs);
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
}

.ad-text {
    font-size: var(--fs-xs);
    color: var(--text-dim);
    font-style: italic;
}

/* ── Pre-game Start Overlay ── */
.game-start-overlay {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 10, 0.95);
    animation: fadeIn 0.3s ease;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.start-card {
    text-align: center;
    padding: 2.5rem;
    max-width: 500px;
    width: 90%;
}

.start-title {
    font-size: var(--fs-lg);
    font-weight: 800;
    color: var(--text);
    margin-bottom: 1.5rem;
}

.start-info {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
    text-align: left;
}

.start-row {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.start-label {
    font-size: var(--fs-xs);
    color: var(--text-dim);
    min-width: 70px;
    flex-shrink: 0;
    padding-top: 0.1em;
}

.start-value {
    font-size: var(--fs-xs);
    color: var(--text);
    line-height: 1.5;
}

.start-countdown {
    font-size: 5rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
    margin-bottom: 0.5rem;
    font-variant-numeric: tabular-nums;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.start-countdown.pulse {
    transform: scale(1.2);
    opacity: 0.7;
}

.start-countdown.go {
    color: var(--success);
    font-size: 4rem;
}

.start-hint {
    font-size: var(--fs-xs);
    color: var(--text-dim);
}

/* ── Result Overlay ── */
.game-result {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 10, 0.88);
    backdrop-filter: blur(6px);
    animation: fadeIn 0.3s ease;
}

.result-card {
    text-align: center;
    padding: 2.5rem;
    max-width: 480px;
}

.result-icon {
    font-size: var(--fs-xl);
    margin-bottom: 0.75rem;
}

.result-title {
    font-size: var(--fs-lg);
    margin-bottom: 0.5rem;
}

.result-title.correct {
    color: var(--success);
    text-shadow: 0 0 30px var(--success-glow);
}

.result-title.wrong {
    color: var(--danger);
    text-shadow: 0 0 30px var(--danger-glow);
}

.result-subtitle {
    color: var(--text);
    margin-bottom: 1.5rem;
    font-size: var(--fs-sm);
}

.result-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ── Game Over Overlay ── */
.game-over-overlay {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 10, 0.92);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.4s ease;
}

.gameover-card {
    text-align: center;
    padding: 2.5rem;
    max-width: 480px;
}

.gameover-title {
    font-size: var(--fs-xl);
    font-weight: 800;
    color: var(--danger);
    margin-bottom: 1.5rem;
}

.final-score {
    margin-bottom: 0.75rem;
}

.score-number {
    display: block;
    font-size: var(--fs-xl);
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.score-label {
    display: block;
    font-size: var(--fs-md);
    color: var(--text);
    margin-top: 0.5rem;
}

.gameover-rounds {
    color: var(--text);
    font-size: var(--fs-sm);
    margin-bottom: 0.5rem;
}

.gameover-subtitle {
    color: var(--text-dim);
    margin-bottom: 2rem;
    font-size: var(--fs-md);
}

/* ── Mobile Controls ── */
.mobile-controls {
    display: none;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding: 0.5rem;
    gap: 1rem;
}

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

.dpad-mid-row {
    display: flex;
    gap: 4px;
}

.dpad-btn {
    width: 52px;
    height: 52px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--fs-xs);
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.dpad-btn:active {
    background: #444444;
    border-color: #666666;
}

.dpad-center {
    opacity: 0;
    pointer-events: none;
}

.action-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--border-light);
    color: var(--text);
    font-size: var(--fs-xs);
    font-weight: 800;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.action-btn:active {
    background: #444444;
}

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

.screen.active {
    animation: fadeIn 0.3s ease;
}

/* ── Touch device detection ── */
@media (hover: none) and (pointer: coarse) {
    .mobile-controls {
        display: flex;
    }
}

/* ── Portrait mode: panels below ── */
@media (orientation: portrait), (max-width: 900px) {
    .game-layout {
        flex-direction: column;
        align-items: center;
        max-width: var(--game-size);
    }

    .side-panel {
        flex: none;
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        position: static;
    }

    .side-panel .info-box {
        flex: 1;
        min-width: 140px;
    }

    .panel-left { order: 1; }
    .game-center { order: 0; }
    .panel-right { order: 2; }
}

@media (max-width: 540px) {
    :root {
        --game-size: 100vw;
        --fs-xs: 0.85rem;
        --fs-sm: 1rem;
        --fs-md: 1.25rem;
        --fs-lg: 2rem;
        --fs-xl: 3.5rem;
    }

    .game-frame-wrapper {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .screen {
        padding: 1rem 0.5rem;
    }
}
