/* ── keysig · monochrome ────────────────────────────────────────────────────
   Forked from reflex's style.css. Colour, type and shape tokens all come from
   theme.css, which is loaded first and owns both light and dark. This file
   defines no palette of its own — state is carried by contrast, weight, fill
   and border style. The piano keyboard is drawn from the same grey ramp. */

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

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

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

body {
    background: var(--bg);
    color: var(--text-primary);
    font-family: var(--sans);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

.screen {
    position: relative;
    z-index: 1;
    width: 100%;
    flex: 1; /* fill available height so content centers inside */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
    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: 1060px;
}

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

/* The home wordmark is now the shared .hero-lockup in theme.css. */

.brand-tagline {
    /* clears the shared .hero-lockup above, matching the hub's spacing */
    margin-top: 12px;
    font-size: clamp(13px, 2vw, 16px);
    color: var(--text-secondary);
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: -0.01em;
}

.brand-sources {
    margin-top: 10px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--mono);
}

/* ── LANGUAGE TABS ──────────────────────────────────────────────────────────── */

.lang-tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 36px;
}

.lang-tab {
    background: var(--bg-subtle);
    border: 1.5px solid var(--border-strong);
    border-radius: 980px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
    padding: 8px 22px;
    cursor: pointer;
    transition:
        border-color 0.15s,
        background 0.15s,
        color 0.15s;
    touch-action: manipulation;
}

.lang-tab:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

.lang-tab.active {
    background: var(--text-primary);
    border-color: var(--text-primary);
    color: var(--text-inverse);
}

.lang-panel.hidden {
    display: none;
}

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

/* ── CARDS GRID ─────────────────────────────────────────────────────────────── */

.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 36px;
}

.card {
    background: var(--bg-subtle);
    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;
}

.card-inner {
    padding: 20px 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    height: 100%;
}

.card.available {
    cursor: pointer;
}

.card.available:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px);
    border-color: var(--border-strong);
}

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

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

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

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

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

.card-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-primary);
    opacity: 0.7;
    flex-shrink: 0;
}

.card-badge {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-muted);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    padding: 3px 8px;
    flex-shrink: 0;
}

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

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

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

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

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

/* ── GAME SCREENS: SHARED FRAME ─────────────────────────────────────────────── */

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

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    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(--text-primary);
    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-primary);
    letter-spacing: -0.02em;
    white-space: nowrap;
    min-width: 0;
}

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

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

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

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

.stat {
    text-align: right;
}

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

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

/* ── DRILL: META ROW ────────────────────────────────────────────────────────── */

.drill-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.drill-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.drill-source {
    font-size: 12px;
    font-family: var(--mono);
    color: var(--text-muted);
}

/* ── DRILL: CODE BOX ────────────────────────────────────────────────────────── */

.code-box {
    position: relative;
    background: var(--bg-subtle);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 26px 30px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    cursor: text;
    transition:
        border-color 0.2s,
        box-shadow 0.2s;
}

.code-box:focus-within {
    border-color: var(--text-primary);
    box-shadow:
        0 0 0 3px var(--fill),
        var(--shadow-sm);
}

.code-box.done {
    border-color: var(--text-primary);
    cursor: pointer;
}

.code-display {
    font-family: var(--mono);
    font-size: 15px;
    line-height: 1.75;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-muted);
}

.char {
    border-radius: 3px;
}

.char.correct {
    color: var(--text-primary);
}

.char.wrong {
    color: var(--text-primary);
    background: var(--fill-strong);
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 2px;
}

.char.current {
    background: var(--fill);
    box-shadow: inset 0 -2px 0 var(--text-primary);
    animation: caretPulse 1.1s ease-in-out infinite;
}

@keyframes caretPulse {
    0%,
    100% {
        background: var(--fill);
    }
    50% {
        background: var(--fill-strong);
    }
}

.char.nl {
    opacity: 0.55;
    font-size: 12px;
}

/* recall mode: a not-yet-typed character hidden behind a mask glyph */
.char.mask {
    color: var(--text-muted);
    opacity: 0.4;
}

.char.mask.current {
    opacity: 0.75;
}

.char.nl.correct {
    color: var(--text-muted);
}

/* invisible input that receives keystrokes (and summons mobile keyboards) */
.drill-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    border: none;
    resize: none;
    padding: 0;
}

/* ── PROGRESS BAR ───────────────────────────────────────────────────────────── */

.progress-bar {
    height: 5px;
    background: var(--bg-muted);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 18px;
}

.progress-fill {
    height: 100%;
    background: var(--text-primary);
    border-radius: 3px;
    transition: width 0.12s ease;
}

/* ── EXPLANATION BOX (shared: drill + quiz) ─────────────────────────────────── */

.explain-box {
    background: var(--bg-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 20px 24px;
    margin-bottom: 18px;
    animation: screenIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

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

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

.subsystem-chip {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-primary);
    background: var(--fill);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    padding: 4px 10px;
}

.explain-ref {
    font-size: 11px;
    font-family: var(--mono);
    color: var(--text-muted);
}

.explain-text {
    font-size: 0.925rem;
    font-weight: 400;
    line-height: 1.65;
    color: var(--text-secondary);
    letter-spacing: -0.003em;
}

/* quiz variant: ref sits under the text */
#quizExplainBox .explain-ref {
    display: block;
    margin-top: 12px;
}

/* ── QUIZ: QUESTION ─────────────────────────────────────────────────────────── */

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

.question-box {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 36px;
    margin-bottom: 18px;
    font-size: 1.15rem;
    font-weight: 400;
    line-height: 1.65;
    color: var(--text-primary);
    min-height: 110px;
    white-space: pre-wrap;
    box-shadow: var(--shadow-sm);
    letter-spacing: -0.005em;
}

/* ── QUIZ: CHOICES ──────────────────────────────────────────────────────────── */

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

.choice-btn {
    background: var(--bg-subtle);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 400;
    padding: 18px 20px;
    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(--text-primary);
    background: var(--fill);
    box-shadow: 0 0 0 3px var(--fill);
}

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

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

/* Correct answer */
.choice-btn.correct {
    border-width: 2px !important;
    border-color: var(--text-primary) !important;
    background: var(--fill) !important;
    color: var(--text-primary) !important;
}

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

/* Wrong selection */
.choice-btn.selected-wrong {
    border-width: 2px !important;
    border-style: dashed !important;
    border-color: var(--border-strong) !important;
    background: none !important;
    color: var(--text-secondary) !important;
}

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

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

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

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

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

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

.key-hint {
    opacity: 0.8;
}

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

.enter-hint {
    color: var(--text-primary);
    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 / SKIP BUTTON ─────────────────────────────────────────────────────── */

.next-btn {
    background: var(--text-primary);
    border: none;
    color: var(--text-inverse);
    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;
    white-space: nowrap;
}

.next-btn:hover {
    opacity: 0.85;
}

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

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

/* ── REPEAT BUTTON (secondary) ──────────────────────────────────────────────── */

.action-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.repeat-btn {
    background: var(--bg-subtle);
    border: 1.5px solid var(--border-strong);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: -0.01em;
    padding: 8px 18px;
    cursor: pointer;
    border-radius: 980px;
    transition:
        border-color 0.15s,
        background 0.15s,
        transform 0.1s;
    touch-action: manipulation;
    white-space: nowrap;
}

.repeat-btn:hover {
    border-color: var(--text-primary);
    background: var(--fill);
}

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

/* the hide toggle lights up whenever any masking is active */
.repeat-btn.on {
    border-color: var(--text-primary);
    background: var(--fill);
    color: var(--text-primary);
}

.hide-btn {
    min-width: 116px;
    text-align: center;
}

.repeat-btn .rep-icon {
    margin-right: 5px;
    font-size: 13px;
}

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

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

.flash.success {
    background: var(--fill-weak);
    animation: flashAnim 0.45s ease-out;
}

.flash.error {
    background: var(--fill-strong);
    animation: flashAnim 0.2s ease-out;
}

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

/* ── CHALLENGE SCREEN ───────────────────────────────────────────────────────── */

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

.prompt-box {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 26px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.prompt-box .subsystem-chip {
    display: inline-block;
    margin-bottom: 12px;
}

.prompt-text {
    font-size: 1.1rem;
    font-weight: 400;
    line-height: 1.55;
    color: var(--text-primary);
    letter-spacing: -0.005em;
    white-space: pre-wrap;
}

.challenge-input {
    width: 100%;
    min-height: 150px;
    resize: vertical;
    background: var(--bg-subtle);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 16px;
    font-family: var(--mono);
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    tab-size: 2;
    box-shadow: var(--shadow-sm);
    transition:
        border-color 0.2s,
        box-shadow 0.2s;
}

.challenge-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.challenge-input:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow:
        0 0 0 3px var(--fill),
        var(--shadow-sm);
}

.challenge-input:read-only {
    opacity: 0.75;
    cursor: default;
}

.challenge-feedback {
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    animation: screenIn 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.challenge-feedback.hidden {
    display: none;
}

.challenge-feedback.correct {
    border-width: 2px;
    border-color: var(--text-primary);
    background: var(--fill);
}

.challenge-feedback.wrong {
    border-style: dashed;
    border-color: var(--border-strong);
    background: none;
}

.challenge-feedback.hint {
    border-style: dotted;
    border-color: var(--border-strong);
    background: none;
}

.feedback-head {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 6px;
}

.challenge-feedback.correct .feedback-head {
    color: var(--text-primary);
}

.challenge-feedback.wrong .feedback-head {
    color: var(--text-secondary);
}

.feedback-msg {
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-secondary);
}

.feedback-msg code {
    font-family: var(--mono);
    font-size: 0.85em;
    background: var(--bg-subtle);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xs);
    padding: 1px 6px;
    color: var(--text-primary);
}

.solution-wrap {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.solution-wrap.hidden {
    display: none;
}

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

.solution-code {
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
    background: var(--bg-subtle);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

.output-wrap {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.output-wrap.hidden {
    display: none;
}

.output-block {
    font-family: var(--mono);
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-muted);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 1.6em;
}

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

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

#drillScreen:not(.hidden) ~ .site-footer,
#earScreen:not(.hidden) ~ .site-footer,
#quizScreen:not(.hidden) ~ .site-footer {
    display: none;
}

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

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

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

/* ── SOUND TOGGLE ───────────────────────────────────────────────────────────── */

.sound-btn {
    align-self: center;
    background: none;
    border: 1.5px dashed var(--border-strong);
    border-radius: 980px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    padding: 5px 12px;
    cursor: pointer;
    white-space: nowrap;
    touch-action: manipulation;
    transition:
        border-color 0.15s,
        color 0.15s;
}

/* on = solid border, full contrast; muted = dashed, faint */
.sound-btn.on {
    border-style: solid;
    color: var(--text-primary);
}

.sound-btn:hover {
    border-color: var(--text-primary);
}

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

/* the drill line is notes, not code — a little larger and airier */
.code-display {
    font-size: 19px;
    word-spacing: 0.25em;
}

/* ── PIANO KEYBOARD ─────────────────────────────────────────────────────────── */

.keyboard {
    position: relative;
    display: flex;
    height: 92px;
    margin-bottom: 18px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg);
    user-select: none;
}

.kb-key {
    position: relative;
    transition: background 0.08s;
}

.kb-key.white {
    height: 100%;
    background: var(--bg);
    border-right: 1px solid var(--border);
}

.kb-key.white:last-child {
    border-right: none;
}

.kb-key.black {
    position: absolute;
    top: 0;
    height: 58%;
    z-index: 2;
    background: var(--text-primary);
    border-radius: 0 0 3px 3px;
}

/* octave marker on each C */
.kb-key[data-c]::before {
    content: attr(data-c);
    position: absolute;
    bottom: 4px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 9px;
    color: var(--text-muted);
    opacity: 0.7;
}

.kb-key.white.on {
    background: var(--bg-muted);
}

.kb-key.black.on {
    background: var(--text-secondary);
}

/* a marked key: a filled dot carrying the spelled note name */
.kb-label {
    display: none;
}

.kb-key.marked .kb-label {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    min-width: 22px;
    height: 22px;
    padding: 0 4px;
    border-radius: 11px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: -0.02em;
    z-index: 3;
}

.kb-key.white.marked .kb-label {
    bottom: 16px;
    background: var(--text-primary);
    color: var(--text-inverse);
}

.kb-key.black.marked .kb-label {
    bottom: 6px;
    background: var(--bg);
    color: var(--text-primary);
    border: 1px solid var(--text-primary);
}

.kb-key.white.marked[data-c]::before {
    display: none;
}

/* Dark mode keeps a piano a piano: the tokens alone would invert it (light
   "black" keys on dark "white" ones), so the keyboard swaps which grey it
   takes from the same ramp. Still no hue. */
:root[data-theme="dark"] .keyboard,
:root[data-theme="dark"] .kb-key.white {
    background: var(--text-secondary);
}

:root[data-theme="dark"] .kb-key.white {
    border-right-color: var(--text-muted);
}

:root[data-theme="dark"] .kb-key.black {
    background: var(--bg);
}

:root[data-theme="dark"] .kb-key.white.on {
    background: var(--text-muted);
}

:root[data-theme="dark"] .kb-key.black.on {
    background: var(--border-strong);
}

:root[data-theme="dark"] .kb-key[data-c]::before {
    color: var(--bg-muted);
}

:root[data-theme="dark"] .kb-key.white.marked .kb-label {
    background: var(--bg);
    color: var(--text-primary);
}

:root[data-theme="dark"] .kb-key.black.marked .kb-label {
    background: var(--text-primary);
    color: var(--text-inverse);
    border-color: var(--bg);
}

/* ── EAR SCREEN ─────────────────────────────────────────────────────────────── */

.ear-box {
    display: flex;
    align-items: center;
    gap: 22px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 26px;
    margin-bottom: 18px;
    box-shadow: var(--shadow-sm);
}

.play-big {
    flex-shrink: 0;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: var(--text-primary);
    color: var(--text-inverse);
    font-size: 20px;
    cursor: pointer;
    touch-action: manipulation;
    transition:
        transform 0.1s,
        opacity 0.15s;
}

.play-big .play-icon {
    display: inline-block;
    transform: translateX(2px);
}

.play-big:hover {
    opacity: 0.85;
}

.play-big:active {
    transform: scale(0.95);
}

.ear-question {
    font-size: 1.15rem;
    line-height: 1.5;
    color: var(--text-primary);
    letter-spacing: -0.005em;
}

.choices-grid.many {
    grid-template-columns: repeat(3, 1fr);
}

/* after answering, the other options stay live for comparison */
.choice-btn.after {
    opacity: 0.6;
}

.choice-btn.after:hover {
    opacity: 1;
}

.choice-btn.comparing {
    opacity: 1;
    border-style: dotted;
    border-color: var(--text-primary);
}

/* ── RECALL INPUT ───────────────────────────────────────────────────────────── */

.quiz-input {
    width: 100%;
    background: var(--bg-subtle);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 16px;
    font-family: var(--mono);
    font-size: 18px;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    transition:
        border-color 0.2s,
        box-shadow 0.2s;
}

.quiz-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.quiz-input:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow:
        0 0 0 3px var(--fill),
        var(--shadow-sm);
}

.quiz-input:read-only {
    opacity: 0.75;
}

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

/* lg: wide tablet / small laptop (≤ 900px) */
@media (max-width: 900px) {
    .cards-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }

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

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

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

    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 28px;
    }

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

    header {
        margin-bottom: 16px;
    }

    .question-box {
        padding: 24px 26px;
    }

    .code-box {
        padding: 20px 22px;
    }

    .code-display {
        font-size: 13px;
    }
}

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

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

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

    .cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        margin-bottom: 24px;
    }

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

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

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

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

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

    .card-badge {
        font-size: 8px;
        padding: 2px 7px;
    }

    /* On mobile the soft keyboard can shrink the viewport mid-session.
       Override the base flex:1 / centering so content is always
       visible near the top rather than floating at mid-screen. */
    #drillScreen,
    #earScreen,
    #quizScreen {
        flex: none;
        align-items: flex-start;
        align-self: flex-start;
    }

    header {
        margin-bottom: 10px;
        row-gap: 6px;
        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: 16px;
    }

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

    .question-box {
        padding: 18px 16px;
        margin-bottom: 10px;
        font-size: 0.95rem;
        min-height: auto;
    }

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

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

    .code-box {
        padding: 14px 14px;
        margin-bottom: 10px;
    }

    .code-display {
        font-size: 12px;
        line-height: 1.7;
    }

    .explain-box {
        padding: 12px 16px;
        margin-bottom: 10px;
    }

    .explain-text {
        font-size: 0.82rem;
    }

    .key-hint {
        display: none;
    }

    .bottom-bar {
        flex-wrap: wrap;
        row-gap: 10px;
    }

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

    /* let the button row wrap under the hint instead of overflowing */
    .action-group {
        flex-wrap: wrap;
        justify-content: flex-end;
        width: 100%;
    }

    .lang-tabs {
        gap: 6px;
        margin-bottom: 20px;
    }

    .lang-tab {
        font-size: 12px;
        padding: 6px 13px;
    }

    .hide-btn {
        min-width: 0;
    }
}

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

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

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

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

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



/* keysig additions at phone widths */
@media (max-width: 680px) {
    .code-display {
        font-size: 16px;
    }

    .keyboard {
        height: 74px;
    }

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

@media (max-width: 480px) {
    .code-display {
        font-size: 15px;
    }

    .keyboard {
        height: 64px;
        margin-bottom: 10px;
    }

    .kb-key.marked .kb-label {
        min-width: 18px;
        height: 18px;
        font-size: 9px;
        padding: 0 2px;
    }

    .kb-key[data-c]::before {
        display: none;
    }

    .ear-box {
        padding: 14px 16px;
        gap: 14px;
        margin-bottom: 10px;
    }

    .play-big {
        width: 46px;
        height: 46px;
        font-size: 16px;
    }

    .ear-question {
        font-size: 0.95rem;
    }

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

    .stats {
        gap: 14px;
    }

    /* keep the track name clear of the fixed theme toggle */
    .header-left {
        padding-right: 44px;
    }
}
