/* ============================================================
   HKB B1 Self-Paced Resource — Design System
   Mobile-first · 40–64 audience · container-aware · themeable
   All colours/sizes are CSS custom properties so HKB can rebrand
   without touching internals (see §10/§11 of the proposal).
   ============================================================ */

:root {
  /* Brand / theme hooks — override these to rebrand */
  --b1-brand:        #b3122e;   /* HKB red */
  --b1-brand-dark:   #7d0c20;
  --b1-accent:       #1f6feb;
  --b1-bg:           #fbfaf7;
  --b1-surface:      #ffffff;
  --b1-ink:          #1c1c1c;
  --b1-ink-soft:     #555;
  --b1-line:         #e4e0d8;
  --b1-ok:           #1a7f4b;
  --b1-warn:         #c47f00;
  --b1-bad:          #c0392b;

  /* Tense colours — meaning is consistent site-wide (proposal C1/C2) */
  --b1-present: #1f6feb;   /* present simple */
  --b1-past:    #8a4fbf;   /* past simple    */
  --b1-perfect: #1a7f4b;   /* present perfect */
  --b1-future:  #c47f00;   /* future forms   */
  --b1-continuous: #be185d; /* continuous aspect (B2) */

  /* Typography — generous base, user-scalable */
  --b1-font: "Noto Sans", "Noto Sans HK", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --b1-scale: 1;                       /* text-size control multiplies this */
  --b1-base: calc(18px * var(--b1-scale));
  --b1-radius: 14px;
  --b1-tap: 48px;                      /* minimum tap target */
  --b1-shadow: 0 2px 10px rgba(0,0,0,.07);
  --b1-maxw: 760px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--b1-font);
  font-size: var(--b1-base);
  line-height: 1.6;
  color: var(--b1-ink);
  background: var(--b1-bg);
}

/* Language visibility — toggled by app.js on <html data-lang> */
html[data-lang="en"] .only-zh { display: none !important; }
html[data-lang="zh"] .only-en { display: none !important; }

/* Anti-flicker: keep the body invisible until app.js has applied the language.
   The early head script sets data-lang from localStorage, so CSS visibility
   rules above are already correct; this only hides the brief moment before
   textContent swap, so users navigating in EN never see a flash of ZH.
   Reveal automatically after a short fallback even if scripts fail to load. */
html:not([data-ready]) body { visibility: hidden; animation: b1Reveal 0s linear 0.6s forwards; }
@keyframes b1Reveal { to { visibility: visible; } }

img { max-width: 100%; height: auto; display: block; }

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

h1,h2,h3 { line-height: 1.25; }
h1 { font-size: 1.7em; }
h2 { font-size: 1.35em; }
h3 { font-size: 1.1em; }

/* ---------- Layout ---------- */
.b1-wrap { max-width: var(--b1-maxw); margin: 0 auto; padding: 0 16px 24px; }
.b1-section { margin: 28px 0; }
.b1-card {
  background: var(--b1-surface);
  border: 1px solid var(--b1-line);
  border-radius: var(--b1-radius);
  padding: 18px;
  box-shadow: var(--b1-shadow);
  margin: 16px 0;
}

/* The four-strip subject template markers */
.strip { margin: 26px 0; }
.strip-label {
  display: inline-block;
  font-size: .8em; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase;
  color: #fff; background: var(--b1-brand);
  padding: 4px 12px; border-radius: 999px; margin-bottom: 10px;
}

/* ---------- Top bar ---------- */
.b1-topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--b1-brand);
  color: #fff;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.b1-topbar a.brand { color:#fff; text-decoration:none; font-weight:700; font-size:1.05em; display: inline-flex; align-items: center; gap: 8px; }
.b1-topbar .brand-logo { height: 28px; width: auto; display: block; }
.b1-topbar .spacer { flex: 1; }
.b1-topbar button {
  min-height: var(--b1-tap); min-width: var(--b1-tap);
  border: 1px solid rgba(255,255,255,.5);
  background: rgba(255,255,255,.12); color:#fff;
  border-radius: 10px; font-size: .9em; cursor: pointer; padding: 6px 12px;
}
.b1-topbar button:hover { background: rgba(255,255,255,.25); }
.b1-topbar button[aria-pressed="true"] { background:#fff; color: var(--b1-brand); font-weight:700; }

/* ---------- Buttons / pills ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content:center; gap: 8px;
  min-height: var(--b1-tap); padding: 10px 18px;
  border-radius: 12px; border: 2px solid var(--b1-brand);
  background: var(--b1-brand); color:#fff; font: inherit; font-weight:600;
  text-decoration: none; cursor: pointer;
}
.btn.secondary { background:#fff; color: var(--b1-brand); }
.btn.ghost { background:transparent; border-color: var(--b1-line); color: var(--b1-ink); }
.btn:disabled { opacity:.5; cursor: default; }

.tile {
  min-height: var(--b1-tap);
  border: 2px solid var(--b1-line); background:#fff; border-radius: 12px;
  padding: 12px 14px; font: inherit; cursor: pointer; text-align:left;
}
.tile:hover { border-color: var(--b1-accent); }
.tile.is-correct { border-color: var(--b1-ok); background:#eafaf0; }
.tile.is-wrong   { border-color: var(--b1-bad); background:#fdecea; }
.tile.is-selected{ border-color: var(--b1-accent); background:#eaf2fe; }

/* ---------- Subject grid (home / library) ---------- */
.subj-grid { display:grid; gap:14px; grid-template-columns: 1fr; }
.subj-grid a {
  display:flex; gap:14px; align-items:center;
  background: var(--b1-surface); border:1px solid var(--b1-line);
  border-radius: var(--b1-radius); padding:16px; text-decoration:none; color:inherit;
  box-shadow: var(--b1-shadow);
}
.subj-grid a:hover { border-color: var(--b1-brand); }
.subj-grid .emoji { font-size: 2.2em; line-height:1; }
.subj-grid .meta small { color: var(--b1-ink-soft); }

/* ---------- Audio speaker button ---------- */
b1-audio { display: inline-flex; vertical-align: middle; }
.b1-spk {
  min-width: 40px; min-height: 40px;
  border-radius: 50%; border:2px solid var(--b1-accent);
  background:#eaf2fe; color: var(--b1-accent);
  cursor:pointer; font-size: 1.05em; display:inline-flex;
  align-items:center; justify-content:center; padding:0;
}
.b1-spk.examiner { border-color:#5a3ea8; color:#5a3ea8; background:#f0ebfb; }
.b1-spk.model    { border-color: var(--b1-ok); color: var(--b1-ok); background:#eafaf0; }
.b1-spk.narrator { border-color: var(--b1-warn); color:#8a5a00; background:#fdf4e3; }
.b1-spk.playing { animation: pulse 1s infinite; }
.b1-spk.missing { opacity:.4; }
@keyframes pulse { 50% { transform: scale(1.12); } }

/* ---------- Flashcards (C11) ---------- */
.flash {
  perspective: 1200px;
}
.flash-card {
  min-height: 150px; cursor:pointer; position:relative;
  border:2px solid var(--b1-line); border-radius: var(--b1-radius);
  background:#fff; padding:22px; display:flex; flex-direction:column;
  justify-content:center; align-items:center; text-align:center; gap:10px;
  transition: border-color .2s;
}
.flash-card:hover { border-color: var(--b1-accent); }
.flash-q { font-size:1.15em; font-weight:600; }
.flash-a { color: var(--b1-ok); font-size:1.1em; }
.flash-hint { color: var(--b1-ink-soft); font-size:.85em; }
.pos { font-size:.7em; font-weight:500; color: var(--b1-ink-soft); margin-left:6px; cursor: help; font-style: italic; }
.flash-nav { display:flex; gap:10px; align-items:center; justify-content:space-between; margin-top:12px; }

/* ---------- Q&A list (opening questions) ---------- */
.qa { padding:14px 16px; }
.qa-q { font-size:1.1em; }
.qa-a { margin-top:10px; padding-top:10px; border-top:1px dashed var(--b1-line); color:var(--b1-ok); font-size:1.05em; }
.qa-reveal {
  margin-top:10px;
  font-size: 1em;
  font-weight: 500;
  border: 1.5px dashed #8a5a00;
  color: #8a5a00;
  background: #fdf4e3;
  padding: 8px 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  animation: qaPulse 2.2s ease-in-out infinite;
}
.qa-reveal:hover { background:#fbe9c4; border-style: solid; }
.qa-reveal .qa-emoji { font-size: 1.55em; vertical-align: -3px; margin-right: 4px; display:inline-block; animation: qaNudge 2.2s ease-in-out infinite; }
@keyframes qaPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(181,137,0,.0); }
  50%     { box-shadow: 0 0 0 6px rgba(181,137,0,.20); }
}
@keyframes qaNudge {
  0%,100% { transform: translateY(-3px) rotate(-6deg); }
  50%     { transform: translateY(-3px) rotate(6deg); }
}

/* verb highlight inside a sentence (universal past-tense marker) */
.verb-hl {
  background:#fff2b8;
  border-radius:5px;
  padding:0 4px;
  font-weight:700;
  cursor: help;
  border-bottom: 2px dotted #b58900;
  box-decoration-break:clone;
  -webkit-box-decoration-break:clone;
  position: relative;
}
.verb-hl.perfect {
  background:#e3eefe;
  border-bottom-color:#1f6feb;
}
.verb-hl.continuous {
  background:#fce7f3;
  border-bottom-color:var(--b1-continuous);
}
.verb-hl:focus { outline: 2px solid var(--b1-accent); outline-offset: 2px; }
.verb-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: #222; color: #fff;
  padding: 6px 10px; border-radius: 8px;
  font-size: .85em; font-weight: 500;
  white-space: nowrap; z-index: 100;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.verb-tip::after {
  content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: #222;
}
.verb-hl:hover .verb-tip,
.verb-hl:focus .verb-tip,
.verb-hl.show-tip .verb-tip { display: block; }

/* ---------- Model answer (C9) ---------- */
.model-line { display:flex; gap:10px; align-items:flex-start; padding:8px 0; border-bottom:1px dashed var(--b1-line); }
.model-line:last-child { border-bottom:none; }
.tag {
  font-size:.72em; font-weight:700; padding:2px 8px; border-radius:999px; color:#fff; white-space:nowrap;
}
.tag.present{background:var(--b1-present);} .tag.past{background:var(--b1-past);}
.tag.perfect{background:var(--b1-perfect);} .tag.future{background:var(--b1-future);}
.tag.continuous{background:var(--b1-continuous);}
.tag.vocab{background:#444;} .tag.phrase{background:#0a7d8c;}
.hl { border-bottom:3px solid transparent; cursor:help; }
.hl.present{border-color:var(--b1-present);} .hl.past{border-color:var(--b1-past);}
.hl.perfect{border-color:var(--b1-perfect);} .hl.future{border-color:var(--b1-future);}
.hl.continuous{border-color:var(--b1-continuous);}

/* Inline Chinese gloss for difficult vocab — stays visible in EN view
   (no data-en/data-zh, so applyLang() never rewrites it). */
.gloss { color: var(--b1-ink-soft); font-size:.85em; font-style:italic; }

/* ---------- B2 typed cloze (b2-cloze) ---------- */
.b2-cloze .cloze-line { font-size:1.1em; line-height:2; margin:6px 0; }
.b2-cloze input { font-size:1em; padding:6px 8px; min-width:120px; border:2px solid var(--b1-line); border-radius:8px; font-family:inherit; }
.b2-cloze input:focus { outline:none; border-color:var(--b1-accent); }
.b2-cloze input.is-correct { border-color:var(--b1-ok); background:#eafaf0; }
.b2-cloze input.is-wrong { border-color:var(--b1-bad); background:#fdece9; }
.b2-cloze .cloze-reveal { font-size:.85em; margin-left:6px; }
.b2-cloze .cloze-hint { color:var(--b1-ink-soft); font-size:.85em; margin-left:4px; }

/* Muted, non-clickable CTA / button (e.g. a feature that is coming soon) */
.cta-link.disabled, .btn.disabled { opacity:.55; pointer-events:none; cursor:default; }

/* Per-point cue label in the topic/answer planner (b1-topicform pointLabels) */
.pt-cue { font-size:.85em; color:var(--b1-ink-soft); margin:2px 0; }

/* ---------- B2 listening player (b2-listen) ---------- */
.b2-listen .listen-bar { display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin:8px 0; }
.b2-listen .play-count { font-size:.85em; color:var(--b1-ink-soft); }

/* ---------- Builder (C8) ---------- */
.builder-frame { font-size:1.15em; line-height:2.2; }
.slot {
  display:inline-block; min-width:90px; min-height:38px;
  border-bottom:3px solid var(--b1-accent); padding:2px 8px; margin:0 4px;
  text-align:center; background:#eaf2fe; border-radius:6px 6px 0 0; cursor:pointer;
}
.slot.filled { background:#eafaf0; border-color: var(--b1-ok); }
.chip {
  display:inline-block; margin:4px; padding:8px 14px; border-radius:999px;
  border:2px solid var(--b1-line); background:#fff; cursor:pointer; font:inherit; min-height:40px;
}
.chip:hover{ border-color: var(--b1-accent); }
.chip.used { opacity:.35; pointer-events:none; }
.chip.is-selected { background:#1f6feb; color:#fff; border-color:#1f6feb; box-shadow:0 0 0 3px rgba(31,111,235,.18); }

/* assembled sentence box (genre wheel etc.) */
.assembled {
  margin-top: 14px;
  background: #eafaf0;
  border: 2px solid var(--b1-ok);
  border-radius: var(--b1-radius);
  padding: 14px 16px;
  font-size: 1.2em;
  font-weight: 600;
}
.assembled.warn { background:#fdf6e7; border-color: var(--b1-warn); }
.assembled .note-line { display:block; font-size:.75em; font-weight:400; color:#8a5a00; margin-top:6px; }

/* ---------- Feedback / notes ---------- */
.feedback { margin-top:10px; font-weight:600; min-height:1.5em; }
.feedback.ok { color: var(--b1-ok); }
.feedback.no { color: var(--b1-bad); }
.note { border-left:5px solid var(--b1-accent); background:#f3f7ff; padding:10px 14px; border-radius:0 10px 10px 0; margin:12px 0; }
.note.warn { border-color: var(--b1-warn); background:#fdf6e7; }
.note.bad  { border-color: var(--b1-bad);  background:#fdece9; }
/* Low-profile B1/B2 cross-link on the landing pages (not a boxy .note). */
.section-switch { text-align:center; font-size:.9em; color:var(--b1-ink-soft); margin:12px 0 4px; }
.section-switch a { color:var(--b1-accent); text-decoration:none; font-weight:600; }
.section-switch a:hover { text-decoration:underline; }

/* usage note card (C12) */
.usage { display:grid; gap:10px; }
.usage .row { display:flex; gap:10px; align-items:center; padding:10px; border-radius:10px; }
.usage .row.no { background:#fdece9; }
.usage .row.ok { background:#eafaf0; }
.usage .mark { font-size:1.3em; }

/* ---------- Timeline (C1) ---------- */
.timeline { position:relative; height:64px; margin:30px 0; }
.timeline .bar { position:absolute; top:50%; left:0; right:0; height:4px; background:var(--b1-line); }
.timeline .pt { position:absolute; top:50%; transform:translate(-50%,-50%); text-align:center; font-size:.8em; color:var(--b1-ink-soft); }
.timeline .pt .dot { width:14px; height:14px; border-radius:50%; background:var(--b1-ink-soft); margin:0 auto 4px; }
.timeline .marker { position:absolute; top:0; transform:translateX(-50%); transition:left .5s ease; font-size:1.6em; }

/* ---------- Sorter / categoriser (C7) ---------- */
.buckets { display:grid; gap:12px; grid-template-columns:1fr; margin-top:12px; }
.bucket { border:2px dashed var(--b1-line); border-radius:12px; padding:10px; min-height:70px; }
.bucket h4 { margin:0 0 8px; }
.bucket.over { border-color: var(--b1-accent); background:#eaf2fe; }
.bucket-items, .pool { display:flex; flex-wrap:wrap; gap:8px; }
.drag-item { padding:8px 14px; border-radius:999px; border:2px solid var(--b1-line); background:#fff; cursor:grab; min-height:40px; }
.drag-item.placed-ok { border-color:var(--b1-ok); background:#eafaf0; }

/* ---------- Help me now (C15) ---------- */
.helpnow { position:relative; }
.helpnow > button { width:100%; }
.helpnow-panel { margin-top:10px; }

/* ---------- Progress / readiness ---------- */
.rating { display:flex; gap:8px; flex-wrap:wrap; margin:8px 0; }
.rating button { flex:1; min-width:120px; }
.progress-done { color: var(--b1-ok); font-weight:700; }

/* ---------- Footer ---------- */
.b1-footer { border-top:1px solid var(--b1-line); margin-top:40px; padding:20px 16px; color:var(--b1-ink-soft); font-size:.85em; text-align:center; }

.b1-cta-strip {
  margin: 12px 0 0; padding: 12px 16px;
  border-top: 1px dashed var(--b1-line);
  border-bottom: 1px dashed var(--b1-line);
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  justify-content: center; align-items: center;
  font-size: .95em;
}
.b1-cta-strip .cta-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--b1-line); border-radius: 999px;
  color: var(--b1-ink-soft); text-decoration: none; background: transparent;
}
.b1-cta-strip .cta-link:hover,
.b1-cta-strip .cta-link:focus {
  border-color: var(--b1-brand); color: var(--b1-brand); background: rgba(0,0,0,.02);
}
.b1-cta-strip .cta-sep { color: var(--b1-line); }
@media (max-width: 420px) { .b1-cta-strip .cta-sep { display: none; } }

.b1-no-audio { position:fixed; left:50%; bottom:16px; transform:translateX(-50%); max-width:min(640px, calc(100vw - 24px)); background:#fff7e0; border:1.5px solid #b58900; color:#5a3d00; padding:10px 14px 10px 16px; border-radius:10px; box-shadow:0 6px 24px rgba(0,0,0,.15); font-size:.95em; line-height:1.4; z-index:9999; display:flex; gap:10px; align-items:flex-start; }
.b1-no-audio button { flex:0 0 auto; background:transparent; border:0; font-size:1.3em; line-height:1; color:#5a3d00; cursor:pointer; padding:0 4px; }
.b1-no-audio button:hover { color:#000; }

/* ---------- Container-aware: wider screens ---------- */
@container (min-width: 560px) { .subj-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 560px) {
  .subj-grid { grid-template-columns: 1fr 1fr; }
  .buckets { grid-template-columns: 1fr 1fr; }
}

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

/* ---------- Print: clean B&W layout for paper revision ---------- */
@media print {
  @page { margin: 1.5cm; }
  html, body { background: #fff !important; color: #000 !important; }
  body { font-size: 11pt; line-height: 1.45; }
  * { animation: none !important; transition: none !important; box-shadow: none !important; }
  /* Hide on-screen-only chrome */
  .b1-topbar,
  .b1-spk, .b1-speed,
  .b1-no-audio,
  .qa-reveal,
  nav.b1-card,
  .flash-hint,
  #b1-cta-strip,
  #b1-print { display: none !important; }
  /* Keep questions, answers, examples, and cards together on one page */
  .b1-card, .strip, .ex, .item, .qa { break-inside: avoid; page-break-inside: avoid; }
  /* Show URLs after every external link (footer / outbound), but not on
     internal buttons rendered as anchors or the brand link itself
     (which is hidden along with the topbar). */
  a[href^="http"]:not(.b1-spk)::after {
    content: " (" attr(href) ")";
    font-size: .85em;
    color: #555;
    word-break: break-all;
  }
  /* Subtler borders on paper than on screen */
  .b1-card { border-color: #ccc !important; }
}
