/* =========================================================
   English Listening Practice - styles
   Clean, light, minimal. One accent colour, rounded tiles.
   ========================================================= */

:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-alt: #eef0f4;
    --text: #1c2230;
    --text-muted: #566075;
    --border: #d5d9e2;
    --accent: #2457d6;          /* white text on this has contrast > 6:1 */
    --accent-dark: #1b44ad;
    --accent-soft: #e6edfc;
    --good: #14683a;
    --good-bg: #e7f6ed;
    --bad: #a12a2a;
    --bad-bg: #fdeceb;
    --radius: 14px;
    --radius-small: 10px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1, h2 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.15rem; }
p  { margin: 0 0 1rem; }

a { color: var(--accent); }

/* Visible keyboard focus everywhere */
:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

[hidden] { display: none !important; }

/* Elements focused by script (feedback box, results title) need no outline */
[tabindex="-1"]:focus { outline: none; }

/* ---------- Layout ---------- */

.container {
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.center { text-align: center; }

.hero { text-align: center; padding: 16px 0 24px; }
.hero h1 { font-size: 2.1rem; }
.subtitle { color: var(--text-muted); font-size: 1.1rem; margin: 0; }

.notice {
    padding: 12px 16px;
    border-radius: var(--radius-small);
    margin-bottom: 20px;
}
.notice-error { background: var(--bad-bg); color: var(--bad); border: 1px solid var(--bad); }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    min-height: 48px;               /* easy to tap */
    padding: 10px 24px;
    border: 2px solid transparent;
    border-radius: var(--radius-small);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, opacity .15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn-secondary:hover { background: var(--accent-soft); }

.btn-large { min-height: 56px; width: 100%; font-size: 1.1rem; }

.btn:disabled { opacity: .5; cursor: not-allowed; }

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

/* ---------- Home page: choices ---------- */

.choice-group { border: 0; padding: 0; margin: 0 0 24px; min-width: 0; }

.choice-group legend {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 10px;
    padding: 0;
}

.choices {
    display: grid;
    gap: 10px;
}
.level-choices { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.count-choices { grid-template-columns: repeat(4, 1fr); }

.choice { position: relative; }

/* The real radio stays in the page (keyboard + screen readers) but is visually hidden. */
.choice input {
    position: absolute;
    opacity: 0;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    cursor: pointer;
}

.choice label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 64px;
    padding: 10px;
    text-align: center;
    background: var(--surface-alt);
    border: 2px solid transparent;
    border-radius: var(--radius-small);
    transition: background-color .15s, border-color .15s;
}

.choice-main { font-weight: 700; font-size: 1.1rem; }
.choice-sub  { font-size: .85rem; color: var(--text-muted); }

.choice input:hover + label { background: var(--accent-soft); }

.choice input:checked + label {
    background: var(--accent-soft);
    border-color: var(--accent);
}
/* A check mark so the selection is not shown by colour alone */
.choice input:checked + label .choice-main::before { content: "\2713\00a0"; color: var(--accent); }

.choice input:focus-visible + label {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.how-it-works ol { margin: 0; padding-left: 1.4rem; }
.how-it-works li { margin-bottom: .25rem; }

/* ---------- Exercise page ---------- */

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

.meta {
    margin: 0 0 8px;
    font-size: .85rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.progress {
    height: 10px;
    background: var(--surface-alt);
    border-radius: 999px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0;
    background: var(--accent);
    border-radius: 999px;
    transition: width .3s ease;
}

.exercise-title { font-size: 1.5rem; text-align: center; margin-bottom: 1rem; }

.audio-block { text-align: center; margin-bottom: 8px; }

.btn-audio {
    min-width: 220px;
    min-height: 64px;
    font-size: 1.15rem;
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
}
.btn-audio:hover { background: var(--accent-dark); }
.btn-audio .icon { font-size: 1.1rem; }

.audio-status { min-height: 1.5em; margin: 8px 0 0; font-size: .95rem; color: var(--text-muted); }
.audio-status.is-error { color: var(--bad); font-weight: 600; }

.instruction { text-align: center; color: var(--text-muted); margin-bottom: 20px; }

.area-label {
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 8px;
}

.tile-area {
    display: flex;
    flex-wrap: wrap;                /* tiles wrap naturally on small screens */
    gap: 10px;
    align-content: flex-start;
    min-height: 68px;
    padding: 12px;
    margin-bottom: 20px;
    background: var(--surface-alt);
    border-radius: var(--radius-small);
}

.answer-area {
    background: var(--surface);
    border: 2px dashed var(--border);
}
.answer-area:empty::before {
    content: "Selected words appear here\2026";
    color: var(--text-muted);
    align-self: center;
}

.tile {
    min-height: 44px;
    padding: 8px 16px;
    font: inherit;
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-small);
    cursor: pointer;
    overflow-wrap: anywhere;
    transition: transform .1s, border-color .15s, background-color .15s;
}
.tile:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.tile:active:not(:disabled) { transform: scale(.97); }
.tile:disabled { cursor: default; opacity: .85; }

.answer-area .tile { border-color: var(--accent); background: var(--accent-soft); }

.message { min-height: 1.5em; text-align: center; color: var(--bad); font-weight: 600; margin-bottom: 0; }

/* ---------- Feedback ---------- */

.feedback {
    margin-top: 20px;
    padding: 20px;
    border-radius: var(--radius-small);
    border: 2px solid;
    text-align: center;
}
.feedback:focus { outline: none; }
.feedback-correct   { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.feedback-incorrect { background: var(--bad-bg);  border-color: var(--bad);  color: var(--bad); }

.feedback-title { font-size: 1.4rem; }
.feedback p { color: var(--text); }
.feedback-sentence { font-size: 1.2rem; font-weight: 700; }

/* ---------- Results ---------- */

.score-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 20px 0;
}
.score-box { background: var(--surface-alt); border-radius: var(--radius-small); padding: 16px; }
.score-label { margin: 0; color: var(--text-muted); font-size: .95rem; }
.score-value { margin: 4px 0 0; font-size: 2rem; font-weight: 700; }

.level-results {
    list-style: none;
    margin: 0 auto;
    padding: 0;
    max-width: 320px;
    text-align: left;
}
.level-results li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}
.level-results li:last-child { border-bottom: 0; }
.level-results .lv { font-weight: 700; }

/* ---------- Small screens ---------- */

@media (max-width: 480px) {
    body { font-size: 16px; }
    .card { padding: 18px 14px; }
    .hero h1 { font-size: 1.7rem; }
    .level-choices { grid-template-columns: repeat(2, 1fr); }
    .btn-audio { width: 100%; }
    .actions .btn { flex: 1 1 100%; }
}

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