/*
  Lucy English: shared components (owned by W1; W2 and W3 only use them).
  No colour values here: use the tokens from base.css. No shadows, gradients,
  uppercase or rotation. Radius 4px at most, 50% only for .play.

  Layout
    .page          <main> content column for lists, 760px, left aligned.
    .page-lesson   Same, 680px, for the lesson page. Use together: class="page page-lesson".
    .page-head     Block at the top of a page: links, h1, one .sub line.
    .form          Vertical stack of .field elements and a button (gap 16px).
    .sub           Secondary text, 14px muted. Defined in base.css.

  .bar           App bar. Rendered by main.js; views do not build it.
                 <header class="bar"><a class="bar-brand">Lucy English</a>
                   <nav class="bar-nav"><a href aria-current="page">…</a></nav>
                   <div class="bar-end"><span class="bar-user">…</span><button class="btn-quiet">…</button></div></header>
  .tabs / .tab   <div class="tabs" role="tablist"><button class="tab" role="tab" aria-selected="true">…</button></div>
                 .tab may also be an <a>. Selected = aria-selected="true" or aria-current="page".
                 Scrolls sideways under 640px.
  .btn           Main action: <button class="btn">Nộp bài</button> (also on <a>).
  .btn-quiet     Secondary action, outlined: <button class="btn-quiet">Xem</button>.
  .field         <label class="field"><span>Họ tên</span><input class="input"></label>
                 Optional error under it: <span class="status bad">…</span> inside the label.
  .input         <input>, <select>, <textarea>. Add class="input".
  .table         <table class="table"><thead><tr><th>…</th></tr></thead><tbody>…</tbody></table>
                 Rules between rows only. Wrap in <div class="table-wrap"> to scroll on phones.
  .row           List row: title, secondary line, actions on the right.
                 <div class="row"><div class="row-main"><a class="row-title">…</a><p class="row-sub">…</p></div>
                   <div class="row-end"><span class="status">…</span><a class="btn-quiet">…</a></div></div>
                 A list of rows: <div class="rows">…</div> (rule above the first row).
                 Extra lines under a row (teacher notes): <p class="row-note">…</p> inside .row-main.
  .status        Coloured text, no border: <span class="status">Chưa nộp</span>,
                 .status.ok (green), .status.bad (red). role="status" or role="alert" as needed.
  .en            English learning text, serif 18/1.6. <p class="en">…</p>
  .en.word       Single English word, serif 17px, bold 600. <span class="en word">hello</span>
  .ipa           IPA, 15px muted. <span class="ipa">/həˈloʊ/</span>
  .vi            Vietnamese meaning or translation, 14px muted. <p class="vi">…</p>
  .play          Round 32px listen button with SVG; build it with ui.playButton(url).
                 Playing state: class="play is-playing" (blue fill, square icon).
  .player        Passage player.
                 <div class="player"><button class="play">…</button>
                   <input type="range" class="player-seek" min="0" max="100" value="0">
                   <span class="player-time">0:00 / 0:40</span>
                   <button class="btn-quiet player-slow" aria-pressed="false">Chậm</button></div>
  .q / .opt      Question with options (radio inside each label).
                 <fieldset class="q" id="q1"><legend class="q-prompt">…</legend>
                   <label class="opt"><input type="radio" name="q1" value="0"><span>…</span></label> …
                   <p class="q-result">…</p></fieldset>
                 Selected option is styled through :has(:checked); also add .is-selected for old browsers.
                 A text answer: <input class="input q-input"> inside .q.
  .ok / .bad     Result marks after grading: on .q (coloured margin rule), on .opt (coloured border),
                 or on any text. .fix is red correction text: <p class="fix">Đáp án: …</p>.
  .tiles / .tile Word tiles. <div class="tiles tiles-answer">…</div> (answer line)
                 <div class="tiles">…<button class="tile en">name</button></div> (pool).
                 Used tile in the pool: <button class="tile" disabled>.
  .rec           Recorder: <div class="rec"><button class="btn">Ghi âm</button>
                   <span class="rec-time">00:00 / 01:30</span><button class="btn-quiet">Dừng</button><audio controls></audio></div>
                 Recording state: class="rec is-recording" (time turns red).
  .anchors       Sticky strip of section links at the top of the lesson.
                 <nav class="anchors"><a href="#tu-vung" aria-current="true">Từ vựng</a> …</nav>
                 Use JS scrollIntoView for these: the hash is owned by the router.
  .footbar       Sticky bottom bar: <div class="footbar"><span>Đã làm 12/17</span>
                   <span class="sub">Đã lưu 14:02</span><button class="btn">Nộp bài</button></div>
  .toast         Created by ui.toast(text); do not build it by hand.
  .switch        Toggle: <label class="switch"><input type="checkbox"><span>Ẩn nghĩa</span></label>
  .is-playing    On a dialogue line or any element: highlighter background (--mark).
  .chart         Writing data table: use .table inside <figure class="chart"><figcaption>…</figcaption>.
*/

/* Layout */
.page { max-width: calc(760px + 2 * var(--gutter)); padding: 32px var(--gutter) 48px; }
.page-lesson { max-width: calc(680px + 2 * var(--gutter)); }
.page > * + * { margin-top: 32px; }
.page section > * + * { margin-top: 12px; }
.page-head > * + * { margin-top: 8px; }
.form { display: grid; gap: 16px; max-width: 420px; }
.form .btn { justify-self: start; }

/* Bar */
.bar {
  display: flex; align-items: center; gap: 24px;
  min-height: 56px; padding: 0 var(--gutter);
  border-bottom: 1px solid var(--rule);
}
.bar-brand { font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap; }
.bar-nav { display: flex; gap: 16px; min-width: 0; }
.bar-nav a { display: inline-flex; align-items: center; min-height: 44px; color: var(--ink); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; transition: color 120ms, border-color 120ms; }
.bar-nav a:hover { color: var(--blue); }
.bar-nav a[aria-current="page"] { color: var(--blue); border-bottom-color: var(--blue); }
.bar-end { display: flex; align-items: center; gap: 12px; margin-left: auto; white-space: nowrap; }
.bar-user { color: var(--muted); font-size: 14px; }

/* Tabs */
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--rule); overflow-x: auto; scrollbar-width: none; }
.tab {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0;
  background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  color: var(--muted); text-decoration: none; white-space: nowrap;
  transition: color 120ms, border-color 120ms;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--blue); border-bottom-color: var(--blue); }

/* Buttons */
.btn, .btn-quiet {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; border-radius: 4px;
  font-weight: 600; text-decoration: none; white-space: nowrap;
  transition: background-color 120ms, color 120ms, border-color 120ms;
}
.btn { background: var(--blue); color: var(--paper); border: 1px solid var(--blue); }
.btn:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-quiet { background: var(--paper); color: var(--blue); border: 1px solid var(--rule); }
.btn-quiet:hover { border-color: var(--blue); color: var(--blue); }
.btn-quiet[aria-pressed="true"] { background: var(--blue-weak); border-color: var(--blue); }
.btn:disabled, .btn-quiet:disabled { color: var(--muted); background: var(--paper); border-color: var(--rule); }

/* Fields */
.field { display: grid; gap: 4px; }
.field > span:first-child { font-size: 14px; font-weight: 600; }
.input {
  width: 100%; min-height: 44px; padding: 8px 12px;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 4px;
  transition: border-color 120ms;
}
.input:hover { border-color: var(--muted); }
.input:focus { border-color: var(--blue); outline: none; }
.input:focus-visible { outline: 2px solid var(--blue); outline-offset: 0; }
.input::placeholder { color: var(--muted); }
textarea.input { min-height: 120px; resize: vertical; line-height: 1.5; }
select.input { padding-right: 32px; }
.field .status { font-size: 14px; }

/* Table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px 12px 0; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule); }
.table thead th { font-size: 14px; font-weight: 600; color: var(--muted); }
.table tbody th { font-weight: 600; }

/* Rows */
.rows { border-top: 1px solid var(--rule); }
.row {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--rule);
}
.row-main { flex: 1; min-width: 0; }
.row-main > * + * { margin-top: 4px; }
.row-title { font-weight: 600; color: var(--ink); text-decoration: none; }
a.row-title:hover { color: var(--blue); }
.row-sub { font-size: 14px; line-height: 20px; color: var(--muted); }
.row-note { font-size: 14px; line-height: 20px; }
.row-end { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

/* Status */
.status { color: var(--muted); }
.status.ok, .ok { color: var(--green); }
.status.bad, .bad, .fix { color: var(--red); }

/* Language text */
.en { font-family: var(--serif); font-size: 18px; line-height: 1.6; }
.en.word { font-size: 17px; font-weight: 600; }
.ipa { font-size: 15px; color: var(--muted); }
.vi { font-size: 14px; line-height: 20px; color: var(--muted); }

/* Listen button */
.play {
  position: relative; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  border: 1px solid var(--blue); border-radius: 50%;
  background: var(--paper); color: var(--blue);
  vertical-align: middle;
  transition: background-color 120ms, color 120ms;
}
.play::after { content: ""; position: absolute; inset: -6px; }
.play svg { width: 14px; height: 14px; fill: currentColor; }
.play .i-stop { display: none; }
.play:hover { background: var(--blue-weak); }
.play.is-playing { background: var(--blue); color: var(--paper); }
.play.is-playing .i-play { display: none; }
.play.is-playing .i-stop { display: inline; }
.play:disabled { border-color: var(--rule); color: var(--muted); background: var(--paper); }

/* Player */
.player { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.player-seek { flex: 1; min-width: 120px; min-height: 32px; accent-color: var(--blue); }
.player-time { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.player-slow { min-height: 32px; padding: 0 12px; font-weight: 400; }

/* Questions */
.q { margin: 0; padding: 0 0 0 12px; border: 0; border-left: 2px solid transparent; min-width: 0; }
.q + .q { margin-top: 24px; }
.q-prompt { padding: 0; margin-bottom: 8px; font-weight: 600; }
.q > * + * { margin-top: 8px; }
.opt {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--rule); border-radius: 4px; cursor: pointer;
  transition: border-color 120ms, background-color 120ms;
}
.opt + .opt { margin-top: 8px; }
.opt input { margin: 0; accent-color: var(--blue); }
.opt:hover { border-color: var(--blue); }
.opt:has(input:checked), .opt.is-selected { border-color: var(--blue); background: var(--blue-weak); }
.q.ok, .q.bad { color: var(--ink); }
.q.ok { border-left-color: var(--green); }
.q.bad { border-left-color: var(--red); }
.opt.ok { border-color: var(--green); color: var(--ink); }
.opt.bad { border-color: var(--red); color: var(--ink); }
.q-input { max-width: 320px; }
.q-result { font-size: 14px; line-height: 20px; }

/* Tiles */
.tiles { display: flex; flex-wrap: wrap; gap: 8px; }
.tiles-answer { min-height: 52px; padding: 4px 0; border-bottom: 1px solid var(--ink); }
.tile {
  min-height: 44px; padding: 0 12px;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 4px;
  font-family: var(--serif); font-size: 17px;
  transition: border-color 120ms, color 120ms;
}
.tile:hover { border-color: var(--blue); }
.tile:disabled { color: var(--rule); border-style: dashed; }

/* Recorder */
.rec { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.rec-time { font-variant-numeric: tabular-nums; color: var(--muted); }
.rec.is-recording .rec-time { color: var(--red); }
.rec audio { max-width: 100%; height: 36px; }

/* Anchors */
.anchors {
  position: sticky; top: 0; z-index: 2;
  display: flex; gap: 16px; overflow-x: auto; scrollbar-width: none;
  background: var(--paper); border-bottom: 1px solid var(--rule);
}
.anchors a { display: inline-flex; align-items: center; min-height: 44px; color: var(--muted); text-decoration: none; white-space: nowrap; transition: color 120ms; }
.anchors a:hover { color: var(--ink); }
.anchors a[aria-current="true"] { color: var(--blue); }

/* Foot bar */
.footbar {
  position: sticky; bottom: 0; z-index: 2;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 0; background: var(--paper); border-top: 1px solid var(--rule);
}
.footbar .btn { margin-left: auto; }

/* Toast */
.toast {
  position: fixed; top: 12px; right: var(--gutter); z-index: 10;
  max-width: calc(100% - 2 * var(--gutter));
  padding: 8px 16px; border-radius: 4px;
  background: var(--ink); color: var(--paper); font-size: 14px;
}

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; cursor: pointer; }
.switch input { margin: 0; accent-color: var(--blue); }

/* Highlighter */
.is-playing:not(.play) { background: var(--mark); }

/* Chart */
.chart { margin: 0; }
.chart figcaption { font-weight: 600; margin-bottom: 8px; }

@media (max-width: 639px) {
  .bar { gap: 16px; flex-wrap: wrap; padding-top: 8px; }
  .bar-nav { order: 3; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; }
  .bar-user { display: none; }
  .row { flex-wrap: wrap; }
  .row-end { width: 100%; }
  .form { max-width: none; }
  .play { width: 36px; height: 36px; }
}
