/* Exam-trainer styles. Loaded after assets/style.css, so it inherits the
   same colour tokens and serif body. Everything here is scoped to .ex-*
   classes used by assets/exam-engine.js - nothing overrides lesson pages. */

:root {
  --ex-ok: #4f7d5a;
  --ex-ok-bg: #eef3ee;
  --ex-bad: #a23b2e;
  --ex-bad-bg: #f7e8e5;
  --ex-warn: #8a6a1f;
  --ex-warn-bg: #f7f0dd;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ex-ok: #6ea97b;
    --ex-ok-bg: #1c2a1e;
    --ex-bad: #e0745a;
    --ex-bad-bg: #2e1a16;
    --ex-warn: #cfae5c;
    --ex-warn-bg: #2a2416;
  }
}
:root[data-theme="dark"] {
  --ex-ok: #6ea97b;
  --ex-ok-bg: #1c2a1e;
  --ex-bad: #e0745a;
  --ex-bad-bg: #2e1a16;
  --ex-warn: #cfae5c;
  --ex-warn-bg: #2a2416;
}

/* ---------- setup screen ---------- */

.ex-setup {
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.3rem 1.4rem;
  margin: 1.6rem 0;
  background: var(--code-bg);
}
.ex-setup h2 {
  margin-top: 0;
  border: none;
  padding: 0;
  font-size: 1.1rem;
}
.ex-mode-grid {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  margin: 1rem 0;
}
.ex-mode {
  text-align: left;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  cursor: pointer;
  line-height: 1.45;
}
.ex-mode:hover { border-color: var(--accent); }
.ex-mode strong { display: block; margin-bottom: 0.25rem; }
.ex-mode span { color: var(--muted); font-size: 0.85rem; }
.ex-mode.ex-mode-primary { border-color: var(--accent); }

.ex-facts {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0;
}
.ex-facts li { margin: 0.2rem 0; }

/* ---------- sticky status bar ---------- */

.ex-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  align-items: center;
  margin: 0 -1.5rem 1.6rem;
  padding: 0.6rem 1.5rem;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}
.ex-bar-title { font-weight: 600; }
.ex-bar-sep { color: var(--rule); }
.ex-clock {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  padding: 0.1rem 0.45rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--code-bg);
}
.ex-clock.ex-clock-low { color: var(--ex-bad); border-color: var(--ex-bad); }
.ex-clock.ex-clock-done { color: var(--ex-bad); background: var(--ex-bad-bg); }
.ex-bar-count { color: var(--muted); margin-left: auto; }
.ex-bar button {
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--text);
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 0.3rem 0.65rem;
  cursor: pointer;
}
.ex-bar button:hover { border-color: var(--accent); color: var(--accent); }

.ex-progress {
  height: 3px;
  margin: 0 -1.5rem 1.4rem;
  background: var(--rule);
}
.ex-progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.25s ease;
}

/* ---------- section + part headers ---------- */

.ex-section-head {
  margin: 2.2rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--accent);
}
.ex-section-head h2 {
  margin: 0;
  border: none;
  padding: 0;
  font-size: 1.45rem;
}
.ex-section-head .ex-sub {
  color: var(--muted);
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ex-part {
  margin: 2rem 0;
}
.ex-part-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.ex-part-name {
  font-weight: 600;
  font-size: 1.05rem;
}
.ex-part-pts {
  font-size: 0.78rem;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
}
.ex-instruction {
  font-size: 0.95rem;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 0.7rem 0.9rem;
  margin: 0.5rem 0 1.1rem;
}
.ex-instruction .ex-de { font-style: italic; }
.ex-instruction .ex-en { display: block; color: var(--muted); font-size: 0.87rem; margin-top: 0.3rem; }

/* ---------- reading / listening source blocks ---------- */

.ex-text {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  margin: 1rem 0 1.3rem;
  background: var(--bg);
  font-size: 0.97rem;
  line-height: 1.7;
}
.ex-text-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.ex-text p { margin: 0.6rem 0; }
.ex-text p:first-of-type { margin-top: 0; }
.ex-text p:last-child { margin-bottom: 0; }

.ex-audio {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  border: 1px dashed var(--rule);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin: 0.8rem 0 1.1rem;
  background: var(--code-bg);
}
.ex-play {
  font-family: inherit;
  font-size: 0.9rem;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}
.ex-play:hover { opacity: 0.9; }
.ex-play[disabled] { opacity: 0.45; cursor: not-allowed; }
.ex-play.ex-playing { background: var(--ex-ok); }
.ex-audio-meta { font-size: 0.83rem; color: var(--muted); }
.ex-speed {
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 0.25rem 0.35rem;
}

/* ---------- items ---------- */

.ex-item {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.9rem 1.05rem;
  margin: 0.8rem 0;
  background: var(--bg);
}
.ex-item.ex-graded-ok { border-color: var(--ex-ok); background: var(--ex-ok-bg); }
.ex-item.ex-graded-bad { border-color: var(--ex-bad); background: var(--ex-bad-bg); }
.ex-item.ex-graded-skip { border-color: var(--ex-warn); background: var(--ex-warn-bg); }

.ex-q {
  display: flex;
  gap: 0.55rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
  line-height: 1.45;
}
.ex-num {
  flex: none;
  min-width: 1.6rem;
  height: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--code-bg);
  border-radius: 4px;
}
.ex-q-body { flex: 1; }
.ex-q-de { display: block; }
.ex-q-en { display: block; font-weight: 400; font-size: 0.85rem; color: var(--muted); }

.ex-options { display: grid; gap: 0.4rem; margin: 0.5rem 0 0; }
.ex-opt {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1.45;
  background: var(--bg);
}
.ex-opt:hover { border-color: var(--accent); }
.ex-opt input { margin: 0.32rem 0 0; flex: none; accent-color: var(--accent); }
.ex-opt-key {
  flex: none;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.ex-opt.ex-picked { border-color: var(--accent); background: var(--accent-soft); }
.ex-opt.ex-right { border-color: var(--ex-ok); background: var(--ex-ok-bg); }
.ex-opt.ex-right .ex-opt-key { color: var(--ex-ok); }
.ex-opt.ex-wrong { border-color: var(--ex-bad); background: var(--ex-bad-bg); }
.ex-opt.ex-wrong .ex-opt-key { color: var(--ex-bad); }
.ex-opt.ex-locked { cursor: default; }
.ex-opt.ex-locked:hover { border-color: inherit; }

.ex-options-tf { grid-template-columns: 1fr 1fr; }

.ex-gap-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.ex-gap-row input {
  flex: 1 1 12rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
}
.ex-gap-row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.ex-gap-row input.ex-right { border-color: var(--ex-ok); }
.ex-gap-row input.ex-wrong { border-color: var(--ex-bad); }
.ex-gap-hint { font-size: 0.82rem; color: var(--muted); }

.ex-select {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.45rem 0.5rem;
  min-width: 10rem;
}
.ex-select.ex-right { border-color: var(--ex-ok); }
.ex-select.ex-wrong { border-color: var(--ex-bad); }

.ex-bank {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin: 0.8rem 0 1.2rem;
  background: var(--code-bg);
  font-size: 0.93rem;
}
.ex-bank-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 0.45rem;
}
.ex-bank ul { margin: 0; padding-left: 0; list-style: none; }
.ex-bank li { margin: 0.3rem 0; display: flex; gap: 0.5rem; }
.ex-bank li b { flex: none; font-family: "SF Mono", Menlo, Consolas, monospace; color: var(--accent); }

.ex-feedback {
  margin: 0.65rem 0 0;
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  font-size: 0.89rem;
  line-height: 1.55;
  background: var(--code-bg);
}
.ex-feedback b { color: var(--accent); }
.ex-feedback .ex-verdict-ok { color: var(--ex-ok); font-weight: 600; }
.ex-feedback .ex-verdict-bad { color: var(--ex-bad); font-weight: 600; }
.ex-feedback .ex-script {
  display: block;
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--rule);
  font-style: italic;
  color: var(--muted);
}

/* ---------- open (written / spoken) tasks ---------- */

.ex-open textarea {
  width: 100%;
  min-height: 9rem;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.7rem 0.8rem;
  resize: vertical;
}
.ex-wordcount { font-size: 0.82rem; color: var(--muted); margin: 0.35rem 0 0; }
.ex-wordcount.ex-wc-ok { color: var(--ex-ok); }
.ex-wordcount.ex-wc-bad { color: var(--ex-bad); }

.ex-rubric { margin: 0.9rem 0 0; }
.ex-rubric-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.ex-rubric ul { list-style: none; padding: 0; margin: 0.4rem 0 0; }
.ex-rubric li { margin: 0.25rem 0; font-size: 0.92rem; }
.ex-rubric label { display: flex; gap: 0.5rem; align-items: flex-start; cursor: pointer; }
.ex-rubric input { margin: 0.3rem 0 0; accent-color: var(--ex-ok); }

.ex-model {
  margin-top: 0.9rem;
}
.ex-model > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.9rem;
}
.ex-model[open] > summary { margin-bottom: 0.5rem; }

/* ---------- speaking cards ---------- */

.ex-card-grid {
  display: grid;
  gap: 0.7rem;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  margin: 0.8rem 0;
}
.ex-tcard {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.8rem 0.9rem;
  background: var(--accent-soft);
  text-align: center;
  font-size: 0.95rem;
}
.ex-tcard b { display: block; font-size: 1.05rem; }
.ex-tcard span { color: var(--muted); font-size: 0.82rem; }

/* ---------- nav between sections ---------- */

.ex-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: center;
  margin: 2.2rem 0 1rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
}
.ex-nav button {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 1.1rem;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--code-bg);
  color: var(--text);
  cursor: pointer;
}
.ex-nav button:hover { border-color: var(--accent); color: var(--accent); }
.ex-nav .ex-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.ex-nav .ex-primary:hover { opacity: 0.9; color: #fff; }
.ex-nav-note { font-size: 0.85rem; color: var(--muted); }

/* ---------- results ---------- */

.ex-result {
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.3rem 1.4rem;
  margin: 1.8rem 0;
  background: var(--code-bg);
}
.ex-result h2 { margin-top: 0; border: none; padding: 0; }
.ex-score-big {
  font-size: 2.6rem;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.ex-score-big.ex-pass { color: var(--ex-ok); }
.ex-score-big.ex-fail { color: var(--ex-bad); }
.ex-score-note { color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }

.ex-bars { margin: 1.2rem 0 0; }
.ex-bar-row {
  display: grid;
  grid-template-columns: 7rem 1fr 4.5rem;
  gap: 0.6rem;
  align-items: center;
  margin: 0.45rem 0;
  font-size: 0.9rem;
}
.ex-bar-track {
  height: 0.7rem;
  background: var(--rule);
  border-radius: 999px;
  overflow: hidden;
}
.ex-bar-val { height: 100%; background: var(--ex-ok); border-radius: 999px; }
.ex-bar-val.ex-low { background: var(--ex-bad); }
.ex-bar-val.ex-mid { background: var(--ex-warn); }
.ex-bar-num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

.ex-weak { margin: 1.2rem 0 0; font-size: 0.93rem; }
.ex-weak ul { padding-left: 1.1rem; }

.ex-history { font-size: 0.88rem; color: var(--muted); }
.ex-history table { font-size: 0.88rem; }

/* ---------- misc ---------- */

.ex-hidden { display: none !important; }
.ex-kbd {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8em;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.05em 0.35em;
  background: var(--code-bg);
}
.ex-tip { font-size: 0.88rem; color: var(--muted); font-style: italic; }

/* hub page bits */
.ex-hub-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  margin: 1.2rem 0;
}
.ex-hub-card {
  display: block;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  background: var(--bg);
  text-decoration: none;
  color: var(--text);
}
.ex-hub-card:hover { border-color: var(--accent); }
.ex-hub-card .ex-hub-kick {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.ex-hub-card strong { display: block; font-size: 1.05rem; margin: 0.15rem 0 0.35rem; color: var(--accent); }
.ex-hub-card span.ex-hub-desc { font-size: 0.88rem; color: var(--muted); line-height: 1.5; display: block; }
.ex-hub-card .ex-hub-meta { font-size: 0.78rem; color: var(--muted); margin-top: 0.5rem; display: block; }

.ex-format-table td:first-child { white-space: nowrap; font-weight: 600; }

@media (max-width: 600px) {
  .ex-bar { margin: 0 -1rem 1.2rem; padding: 0.5rem 1rem; }
  .ex-progress { margin: 0 -1rem 1.1rem; }
  .ex-options-tf { grid-template-columns: 1fr; }
  .ex-bar-row { grid-template-columns: 5.5rem 1fr 3.6rem; font-size: 0.84rem; }
  .ex-score-big { font-size: 2.1rem; }

  /* iOS zooms the page when a focused control is under 16px. */
  .ex-select, .ex-speed { font-size: 16px; min-height: 44px; }
  .ex-select { width: 100%; min-width: 0; }

  /* The label wraps the checkbox, so growing it grows the whole tap target. */
  .ex-rubric label { min-height: 44px; align-items: center; }

  /* One mode per row, so each card is a wide, unambiguous tap target. */
  .ex-mode-grid { grid-template-columns: 1fr; }
  .ex-mode { padding: 0.8rem 0.9rem; }
  .ex-setup { padding: 1rem; }

  /* Answer rows need real thumb room. */
  .ex-opt {
    padding: 0.7rem 0.75rem;
    min-height: 44px;
    align-items: center;
  }
  .ex-opt input { width: 1.1rem; height: 1.1rem; margin: 0; }
  .ex-play, .ex-nav button, .ex-ctl-start { min-height: 44px; }
  .ex-bar button { min-height: 36px; padding: 0.4rem 0.7rem; }

  .ex-nav { gap: 0.5rem; }
  .ex-nav button { flex: 1 1 8rem; }
  .ex-ctl-start { width: 100%; }

  /* Gap-fill fields get the full row instead of a cramped 12rem column. */
  .ex-gap-row input { flex: 1 1 100%; }

  .ex-item { padding: 0.8rem 0.85rem; }
  .ex-text { padding: 0.85rem 0.9rem; }
  .ex-instruction { padding: 0.65rem 0.75rem; }
  .ex-section-head h2 { font-size: 1.25rem; }
  .ex-open textarea { min-height: 8rem; }

  /* Keep a question clear of the sticky status bar when scrolled to. */
  .ex-item, .ex-part { scroll-margin-top: 3.5rem; }
}

/* ---------- trainer control strip ---------- */

.ex-ctl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem 1rem;
  align-items: flex-end;
  margin: 1rem 0 0.8rem;
}
.ex-ctl { display: flex; flex-direction: column; gap: 0.25rem; }
.ex-ctl-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.ex-ctl-check {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.92rem;
  padding-bottom: 0.5rem;
  cursor: pointer;
}
.ex-ctl-check input { accent-color: var(--accent); }
.ex-ctl-count { font-size: 0.9rem; color: var(--muted); margin: 0 0 0.9rem; }
.ex-ctl-start {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.6rem 1.3rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.ex-ctl-start:hover { opacity: 0.9; }
.ex-ctl-start[disabled] { opacity: 0.45; cursor: not-allowed; }

@media (max-width: 600px) {
  .ex-ctl-row { gap: 0.6rem; }
  .ex-ctl { flex: 1 1 8rem; }
  .ex-ctl select { min-width: 0; width: 100%; }

  /* The label wraps the checkbox, so growing it grows the whole tap target. */
  .ex-ctl-check { min-height: 44px; padding-bottom: 0; }
  .ex-ctl-check input { width: 1.15rem; height: 1.15rem; }
}
