/* ── CUSTOM PROPERTIES ──────────────────────────────────────────────────────── */

:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-alt: #f5f5f7;
    --border: rgba(0, 0, 0, 0.08);
    --border-strong: #d2d2d7;

    --blue: #0071e3;
    --blue-dark: #0064c8;
    --blue-light: rgba(0, 113, 227, 0.08);

    --green: #28cd41;
    --green-light: rgba(40, 205, 65, 0.1);
    --green-border: rgba(40, 205, 65, 0.5);

    --red: #ff3b30;
    --red-light: rgba(255, 59, 48, 0.08);
    --red-border: rgba(255, 59, 48, 0.5);

    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-tertiary: #86868b;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.07), 0 1px 4px rgba(0, 0, 0, 0.04);
    --shadow-hover:
        0 10px 36px rgba(0, 0, 0, 0.1), 0 3px 10px rgba(0, 0, 0, 0.06);

    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;
}

/* ── RESET ──────────────────────────────────────────────────────────────────── */

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

/* ── BASE ───────────────────────────────────────────────────────────────────── */

body {
    background: var(--bg);
    color: var(--text);
    font-family:
        -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Arial,
        sans-serif;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 48px 24px;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── SCREEN SYSTEM ──────────────────────────────────────────────────────────── */

.screen {
    position: relative;
    z-index: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: auto;
    padding-bottom: 24px;
    animation: screenIn 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.screen.hidden {
    display: none;
}

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

/* ── SELECT SCREEN ──────────────────────────────────────────────────────────── */

.select-container {
    width: 100%;
    max-width: 980px;
}

.select-header {
    text-align: center;
    margin-bottom: 56px;
}

.brand-logo {
    font-size: clamp(30px, 6vw, 54px);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.03em;
    line-height: 1.05;
    margin-bottom: 14px;
}

.brand-logo span {
    color: var(--blue);
}

.brand-tagline {
    font-size: clamp(13px, 2vw, 16px);
    color: var(--text-secondary);
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: -0.01em;
}

.select-prompt {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 18px;
}

/* ── TOPICS GRID ────────────────────────────────────────────────────────────── */

.topics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.topic-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    cursor: default;
    text-align: left;
    font-family: inherit;
    box-shadow: var(--shadow-sm);
    transition:
        box-shadow 0.25s ease,
        transform 0.2s ease,
        border-color 0.2s ease;
    position: relative;
    overflow: hidden;
    touch-action: manipulation;
}

.topic-card-inner {
    padding: 22px 22px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
}

.topic-card.available {
    cursor: pointer;
}

.topic-card.available:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-3px);
    border-color: rgba(0, 0, 0, 0.1);
}

.topic-card.available:active {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.topic-card.locked {
    opacity: 0.44;
    cursor: not-allowed;
    box-shadow: none;
}

.topic-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.topic-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.015em;
}

.topic-card.locked .topic-name {
    color: var(--text-secondary);
}

.topic-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--blue);
    opacity: 0.6;
    flex-shrink: 0;
}

.topic-badge {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    background: var(--surface-alt);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    padding: 3px 9px;
}

.topic-desc {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.55;
    flex: 1;
}

.topic-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    padding-top: 13px;
    border-top: 1px solid var(--border);
}

.topic-count {
    font-size: 11px;
    color: var(--text-tertiary);
}

.topic-cta {
    font-size: 12px;
    font-weight: 500;
    color: var(--blue);
    transition: opacity 0.15s;
}

.topic-card.available:hover .topic-cta {
    opacity: 0.7;
}

/* ── GAME SCREEN ────────────────────────────────────────────────────────────── */

.container {
    width: 100%;
    max-width: 780px;
}

/* ── HEADER ─────────────────────────────────────────────────────────────────── */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
    gap: 12px;
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 18px;
    min-width: 0;
}

.back-btn {
    background: none;
    border: none;
    color: var(--blue);
    font-family: inherit;
    font-size: 15px;
    font-weight: 400;
    letter-spacing: -0.01em;
    padding: 4px 0;
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
    touch-action: manipulation;
}

.back-btn:hover {
    opacity: 0.65;
}

.logo {
    font-size: clamp(14px, 3vw, 17px);
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
    white-space: nowrap;
    min-width: 0;
}

.logo span {
    color: var(--blue);
}

.logo-topic {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-tertiary);
    margin-left: 4px;
    letter-spacing: 0;
}

.logo-topic::before {
    content: "/ ";
}

.stats {
    display: flex;
    gap: 28px;
    flex-shrink: 0;
}

.stat {
    text-align: right;
}

.stat-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-tertiary);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.stat-value {
    font-size: clamp(16px, 3.5vw, 21px);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.025em;
    line-height: 1.1;
}

/* ── QUESTION META ──────────────────────────────────────────────────────────── */

.question-meta {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-tertiary);
    letter-spacing: 0.01em;
    margin-bottom: 10px;
}

/* ── QUESTION BOX ───────────────────────────────────────────────────────────── */

.question-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px 28px;
    margin-bottom: 14px;
    font-size: 1.05rem;
    font-weight: 400;
    line-height: 1.65;
    color: var(--text);
    min-height: 90px;
    white-space: pre-wrap;
    box-shadow: var(--shadow-sm);
    letter-spacing: -0.005em;
}

/* ── CHOICES GRID ───────────────────────────────────────────────────────────── */

.choices-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}

.choice-btn {
    background: var(--surface);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 400;
    padding: 14px 16px;
    text-align: left;
    cursor: pointer;
    transition:
        border-color 0.15s,
        background 0.15s,
        box-shadow 0.15s;
    line-height: 1.45;
    letter-spacing: -0.005em;
}

.choice-btn:not(.disabled):hover {
    border-color: var(--blue);
    background: var(--blue-light);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.08);
}

.choice-btn .choice-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-tertiary);
    margin-right: 10px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.choice-btn:not(.disabled):hover .choice-label {
    color: var(--blue);
}

/* Correct answer */
.choice-btn.correct {
    border-color: var(--green-border) !important;
    background: var(--green-light) !important;
    color: var(--text) !important;
}

.choice-btn.correct .choice-label {
    color: var(--green) !important;
}

/* Wrong selection */
.choice-btn.selected-wrong {
    border-color: var(--red-border) !important;
    background: var(--red-light) !important;
    color: var(--text) !important;
}

.choice-btn.selected-wrong .choice-label {
    color: var(--red) !important;
}

/* Unchosen buttons after answer */
.choice-btn.disabled {
    cursor: default;
    opacity: 0.32;
}

.choice-btn.correct.disabled,
.choice-btn.selected-wrong.disabled {
    opacity: 1;
}

/* ── EXPLANATION BOX ────────────────────────────────────────────────────────── */

.explanation-box {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    margin-bottom: 16px;
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.65;
    color: var(--text-secondary);
    white-space: pre-wrap;
    letter-spacing: -0.003em;
    animation: screenIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.explanation-box.hidden {
    display: none;
}

/* ── BOTTOM BAR ─────────────────────────────────────────────────────────────── */

.bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}

.hint {
    font-size: 13px;
    color: var(--text-tertiary);
    letter-spacing: -0.005em;
}

.key-hint {
    opacity: 0.8;
}

.enter-hint {
    color: var(--blue);
    margin-left: 12px;
    font-weight: 500;
    animation: pulse 1.8s ease-in-out infinite;
}

.enter-hint.hidden {
    display: none;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

/* ── NEXT BUTTON ────────────────────────────────────────────────────────────── */

.next-btn {
    background: var(--blue);
    border: none;
    color: #ffffff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: -0.01em;
    padding: 9px 22px;
    cursor: pointer;
    border-radius: 980px;
    transition:
        background 0.15s,
        transform 0.1s;
    touch-action: manipulation;
}

.next-btn:hover {
    background: var(--blue-dark);
}

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

.next-btn.hidden {
    display: none;
}

/* ── FLASH OVERLAY ──────────────────────────────────────────────────────────── */

.flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    opacity: 0;
}

.flash.success {
    background: rgba(40, 205, 65, 0.05);
    animation: flashAnim 0.45s ease-out;
}

.flash.error {
    background: rgba(255, 59, 48, 0.05);
    animation: flashAnim 0.2s ease-out;
}

@keyframes flashAnim {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

/* ── SITE FOOTER ────────────────────────────────────────────────────────────── */

.site-footer {
    width: 100%;
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary);
    padding: 8px 0 max(16px, env(safe-area-inset-bottom));
    margin-top: auto;
}

#gameScreen:not(.hidden) ~ .site-footer {
    display: none;
}

.site-footer a {
    color: var(--blue);
    text-decoration: none;
    transition: opacity 0.15s;
}

.site-footer a:visited {
    color: var(--blue);
}

.site-footer a:hover {
    opacity: 0.65;
}

/* ── RESPONSIVE ─────────────────────────────────────────────────────────────── */

/* lg: wide tablet / small laptop (≤ 960px) */
@media (max-width: 960px) {
    .topics-grid {
        gap: 12px;
    }

    .topic-card-inner {
        padding: 18px 18px 14px;
    }
}

/* md: tablet / large phone (≤ 700px) */
@media (max-width: 700px) {
    body {
        padding: 28px 16px;
    }

    .select-header {
        margin-bottom: 36px;
    }

    .topics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .topic-card-inner {
        padding: 16px 16px 14px;
    }

    .choices-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* sm: phone (≤ 480px) */
@media (max-width: 480px) {
    body {
        padding: 16px 14px;
    }

    .select-header {
        margin-bottom: 24px;
    }

    .select-prompt {
        font-size: 10px;
        letter-spacing: 0.06em;
        margin-bottom: 14px;
    }

    .topics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .topic-card-inner {
        padding: 14px 14px 12px;
        gap: 6px;
    }

    .topic-name {
        font-size: 13px;
    }

    .topic-desc {
        font-size: 11px;
    }

    .topic-count {
        font-size: 10px;
    }

    .topic-cta {
        font-size: 11px;
    }

    .topic-badge {
        font-size: 9px;
        padding: 2px 7px;
    }

    /* keep game screen flush to the top so keyboard doesn't bury it */
    #gameScreen {
        margin-top: 0;
        align-self: flex-start;
    }

    /* back-btn + logo on row 1, stats on row 2 */
    header {
        margin-bottom: 20px;
        row-gap: 10px;
        align-items: center;
    }

    .header-left {
        flex: 1 1 100%;
        justify-content: space-between;
        align-items: center;
    }

    .stats {
        flex: 1 1 100%;
        justify-content: flex-end;
        gap: 20px;
    }

    .logo-topic {
        font-size: 12px;
    }

    .question-box {
        padding: 18px 16px;
        margin-bottom: 12px;
        font-size: 0.95rem;
    }

    .choices-grid {
        grid-template-columns: 1fr;
        gap: 8px;
        margin-bottom: 12px;
    }

    .choice-btn {
        font-size: 0.875rem;
        padding: 13px 14px;
    }

    .explanation-box {
        padding: 14px 16px;
        margin-bottom: 12px;
        font-size: 0.82rem;
    }

    .key-hint {
        display: none;
    }

    .bottom-bar {
        flex-wrap: nowrap;
    }

    .hint {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* xs: very small phone (≤ 360px) */
@media (max-width: 360px) {
    body {
        padding: 12px 10px;
    }

    .topics-grid {
        grid-template-columns: 1fr;
    }

    .stat-label {
        font-size: 9px;
    }

    .back-btn {
        font-size: 14px;
    }

    .next-btn {
        font-size: 13px;
        padding: 8px 18px;
    }
}
