:root {
    --bg: #121212;
    --surface: #1e1e1e;
    --surface-2: #262626;
    --border: #333333;
    --text: #e0e0e0;
    --muted: #a0a0a0;
    --accent: #4a90e2;
    --accent-text: #ffffff;
    --good: #3fb97a;
    --bad: #e5604f;
    --radius: 10px;
    --ipa-font: 'IPA Trainer Serif', 'Charis SIL', 'Doulos SIL', 'Gentium Plus', 'Noto Sans', 'DejaVu Sans', serif;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f6f7f9;
        --surface: #ffffff;
        --surface-2: #eef0f3;
        --border: #d7dbe0;
        --text: #1d1f23;
        --muted: #5d6470;
        --accent: #2f6fc4;
        --good: #1f8a52;
        --bad: #c23b2b;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, 'Segoe UI', sans-serif;
    line-height: 1.5;
}

/* Served with the site (a Charis SIL subset, see LICENSES.txt): system fonts on macOS, iOS
   and Android lack the IPA combining marks, and a mark taken from a fallback font is drawn
   beside its letter instead of under it (n̩, aɪ̯). Bump ?v= after rebuilding the fonts. */
@font-face {
    font-family: 'IPA Trainer Serif';
    src: url('fonts/ipa-serif-regular.woff2?v=1') format('woff2');
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: 'IPA Trainer Serif';
    src: url('fonts/ipa-serif-semibold.woff2?v=1') format('woff2');
    font-weight: 600;
    font-display: swap;
}

.word, .answer, .key, .slash, .feedback .reveal {
    font-family: var(--ipa-font);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
    max-width: 760px;
    margin: 0 auto;
    padding: 1.5rem 16px 2rem;
}

.top h1 { margin: 0.5rem 0 0.25rem; font-size: 1.8rem; }
.back { font-size: 0.9rem; }
.lede { margin: 0 0 1.25rem; color: var(--muted); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}

.label {
    margin: 0;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.word {
    margin: 0.25rem 0 1rem;
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 600;
    overflow-wrap: anywhere;
}

.answer-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.slash { font-size: 1.8rem; color: var(--muted); }

.answer {
    flex: 1;
    min-height: 3.25rem;
    padding: 0.5rem 0.75rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    font-size: 1.8rem;
    line-height: 1.6;
    overflow-wrap: anywhere;
    transition: border-color 0.15s;
}

.answer:focus-visible { outline: none; border-color: var(--accent); }
.answer.correct { border-color: var(--good); }
.answer.wrong { border-color: var(--bad); animation: shake 0.3s; }

/* Per-symbol mistakes after a wrong check. */
.seg-wrong {
    color: var(--bad);
    background: color-mix(in srgb, var(--bad) 18%, transparent);
    border-radius: 4px;
    text-decoration: underline wavy var(--bad) 1px;
    text-underline-offset: 0.2em;
}
.seg-missing {
    display: inline-block;
    width: 3px;
    height: 1.1em;
    margin: 0 0.12em;
    vertical-align: middle;
    border-radius: 2px;
    background: var(--bad);
}

@keyframes shake {
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.btn-listen { flex: none; width: 44px; padding: 0; font-size: 1.2rem; }
.btn-hear { margin: -0.25rem 0 0.75rem; padding: 0 0.9rem; }

.feedback { min-height: 1.5rem; margin: 0.75rem 0; font-weight: 500; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.btn, .key {
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s, transform 0.05s;
}

.btn:hover, .key:hover { border-color: var(--accent); }
.btn:active, .key:active { transform: scale(0.96); }
.btn:focus-visible, .key:focus-visible, .toggle input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}

.keyboard {
    margin-top: 1.25rem;
    display: grid;
    gap: 0.75rem;
}

.key-group h2 {
    margin: 0 0 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.keys {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 0.4rem;
}

.key { font-family: var(--ipa-font); font-size: 1.3rem; padding: 0 0.25rem; }

.footer-bar {
    margin-top: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}

.toggle { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.toggle input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
.toggle small { color: var(--muted); }
.toggle select {
    min-height: 36px;
    padding: 0 0.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
}
.toggle select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mode-note { margin: -0.5rem 0 1rem; font-size: 0.9rem; color: var(--muted); }

.score { margin: 0; color: var(--muted); font-variant-numeric: tabular-nums; }

.credits {
    margin-top: 2rem;
    font-size: 0.8rem;
    color: var(--muted);
}

@media (max-width: 480px) {
    .card { padding: 1rem; }
    .actions { grid-template-columns: repeat(2, 1fr); }
    .answer { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
    .answer.wrong { animation: none; }
    * { transition: none !important; }
}
