/* ==========================================================================
   Linguistic Communication — Learning App shell
   Brand: navy #111826 · gold #ffd149 · paper #f6f4ee
   ========================================================================== */

:root {
  --navy: #111826;
  --navy-2: #182232;
  --navy-3: #22304a;
  --paper: #f6f4ee;
  --paper-2: #efece4;
  --white: #ffffff;
  --gold: #ffd149;
  --gold-deep: #d9a92e;
  --gold-graphic: #b07d00;
  --ink: #111826;
  --muted: #4d5665;
  --muted-2: #616a7c;
  --eyebrow: #8a6a05;
  --line: #ddd8cc;
  --line-strong: #c9c3b4;
  --ok: #1f8a54;
  --ok-bg: #e8f5ee;
  --warn: #b9720f;
  --warn-bg: #fdf2e0;
  --bad: #b8382f;
  --bad-bg: #fbeae8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(17, 24, 38, .06), 0 8px 24px -18px rgba(17, 24, 38, .35);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: 96px; }

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0 0 .7em; }
a { color: var(--navy-3); }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--navy);
  color: var(--white);
  border-bottom: 3px solid var(--gold);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { height: 42px; width: auto; display: block; }
.brand-text { min-width: 0; }
.brand-name {
  font-size: .72rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
}
.brand-app {
  font-size: .95rem;
  font-weight: 650;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.timer {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  padding: 6px 14px;
  font-variant-numeric: tabular-nums;
}
.timer-label { font-size: .62rem; text-transform: uppercase; letter-spacing: .12em; color: #cfd6e4; }
.timer-value { font-size: 1.18rem; font-weight: 700; color: var(--white); }
.timer.is-warn { background: rgba(255, 209, 73, .16); border-color: var(--gold); }
.timer.is-warn .timer-value { color: var(--gold); }
.timer.is-critical { background: rgba(184, 56, 47, .28); border-color: #ff8a80; animation: pulse 1.1s infinite; }
.timer.is-critical .timer-value { color: #ffd6d2; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .62; } }

.progress-track { height: 5px; background: rgba(255, 255, 255, .14); }
.progress-fill { height: 100%; width: 0; background: var(--gold); transition: width .28s ease; }

.lang-toggle {
  display: inline-flex;
  align-items: center;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 999px;
  padding: 3px;
  cursor: pointer;
  font: inherit;
}
.lang-toggle .lang-on {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .08em;
  color: #cfd6e4;
  padding: 4px 9px;
  border-radius: 999px;
}
.lang-toggle .lang-on.is-active { background: var(--gold); color: var(--navy); }

/* ---------------------------------------------------------------- layout */
.wrap { max-width: 960px; margin: 0 auto; padding: 22px 16px 40px; }

.screen { display: none; }
.screen.is-active { display: block; }

.eyebrow {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .18em;
  font-weight: 700;
  color: var(--eyebrow);
  margin-bottom: 8px;
}

h1.title { font-size: clamp(1.5rem, 5vw, 2.15rem); font-weight: 750; letter-spacing: -.02em; }
h2.section-title { font-size: 1.3rem; font-weight: 700; }

.lede { color: var(--muted); font-size: 1rem; max-width: 68ch; }

.rule { height: 1px; background: var(--line); border: 0; margin: 22px 0; }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card.tight { padding: 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

.stat {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.stat-label { font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted-2); font-weight: 700; }
.stat-value { font-size: 1.6rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .8rem; color: var(--muted); }

/* --------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 20px;
  font: inherit;
  font-weight: 650;
  font-size: .95rem;
  cursor: pointer;
  background: var(--paper-2);
  color: var(--ink);
  transition: transform .06s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { background: #e6e2d7; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: var(--navy-2); }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { background: #f5c62f; }
.btn-ghost { background: transparent; border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--paper-2); }
.btn-sm { padding: 8px 14px; font-size: .85rem; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- inputs */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .82rem; font-weight: 650; margin-bottom: 6px; }
.field .help { font-size: .76rem; color: var(--muted-2); font-weight: 500; }
.input, select.input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.input:focus, select.input:focus, button:focus-visible, .choice:focus-visible {
  outline: 3px solid rgba(255, 209, 73, .85);
  outline-offset: 1px;
}
.mode-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-option {
  position: relative;
  text-align: left;
  border: 1px solid var(--line-strong);
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: 14px 14px 14px 42px;
  cursor: pointer;
  font: inherit;
}
.mode-option strong { display: block; font-size: .95rem; }
.mode-option span { font-size: .8rem; color: var(--muted); display: block; }
.mode-option::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 16px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: var(--white);
}
.mode-option .mode-flag {
  display: none;
  position: absolute;
  right: 12px;
  top: 10px;
  font-size: .6rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  font-weight: 700;
  background: var(--navy);
  color: var(--gold);
  border-radius: 999px;
  padding: 3px 8px;
}
.mode-option[aria-pressed="true"] { border-color: var(--gold-graphic); background: #fffaf0; box-shadow: inset 0 0 0 2px var(--gold); }
.mode-option[aria-pressed="true"]::before { background: var(--navy); border-color: var(--navy); box-shadow: inset 0 0 0 3px var(--white); }
.mode-option[aria-pressed="true"] .mode-flag { display: inline-block; }

.app-short { display: none; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ------------------------------------------------------------- question */
.qcard {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
  scroll-margin-top: 110px;
}
.qhead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.qnum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  background: var(--navy);
  color: var(--gold);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.chip {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--muted);
}
.chip-module { background: #eef2f9; color: var(--navy-3); }
.chip-points { background: #fff6dd; color: #8a6a05; }

.qtitle { font-size: 1.08rem; font-weight: 700; margin-bottom: 10px; }
.context {
  background: var(--paper-2);
  border-left: 3px solid var(--gold);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  font-size: .92rem;
  color: #2b3240;
  margin-bottom: 12px;
}
.qprompt { font-size: 1rem; font-weight: 600; margin-bottom: 12px; }
.qhint { font-size: .8rem; color: var(--muted-2); margin-bottom: 10px; }

.choices { display: grid; gap: 9px; }
.choice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: var(--white);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.choice:hover { border-color: var(--navy-3); background: #fbfaf7; }
.choice .key {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 750;
  color: var(--muted);
}
.choice[aria-checked="true"] { border-color: var(--gold); background: #fffaf0; box-shadow: inset 0 0 0 1px var(--gold); }
.choice[aria-checked="true"] .key { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.choice.is-correct { border-color: var(--ok); background: var(--ok-bg); }
.choice.is-correct .key { background: var(--ok); border-color: var(--ok); color: #fff; }
.choice.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice.is-wrong .key { background: var(--bad); border-color: var(--bad); color: #fff; }
.choice:disabled { cursor: default; opacity: 1; }

/* match rows */
.matchlist { display: grid; gap: 10px; }
.matchrow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fcfbf8;
}
.matchrow.is-correct { border-color: var(--ok); background: var(--ok-bg); }
.matchrow.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.match-left { font-weight: 650; font-size: .93rem; }
.match-left .tiny { display: block; font-weight: 500; font-size: .78rem; color: var(--muted); }

/* classify rows */
.classlist { display: grid; gap: 10px; }
.classrow {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fcfbf8;
}
.classrow.is-correct { border-color: var(--ok); background: var(--ok-bg); }
.classrow.is-wrong { border-color: var(--bad); background: var(--bad-bg); }
.class-label { font-size: .93rem; font-weight: 600; margin-bottom: 9px; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; background: var(--white); }
.segmented button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 8px 16px;
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--navy); color: var(--white); }
.segmented.is-locked button { cursor: default; }

/* number input */
.number-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.number-row .input { max-width: 180px; font-size: 1.2rem; font-weight: 700; text-align: center; }
.unit { font-weight: 650; color: var(--muted); }

/* tf buttons */
.tf-row { display: flex; gap: 12px; flex-wrap: wrap; }
.tf-btn {
  flex: 1 1 140px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--white);
  padding: 16px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}
.tf-btn[aria-pressed="true"] { border-color: var(--navy); background: var(--navy); color: var(--white); box-shadow: inset 0 0 0 2px var(--navy); }
.tf-btn.is-correct { border-color: var(--ok); background: var(--ok); color: var(--white); }
.tf-btn.is-wrong { border-color: var(--bad); background: var(--bad); color: var(--white); }

/* feedback */
.feedback {
  margin-top: 14px;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: .92rem;
  border-left: 4px solid var(--muted-2);
  background: var(--paper-2);
}
.feedback.is-ok { border-left-color: var(--ok); background: var(--ok-bg); }
.feedback.is-bad { border-left-color: var(--bad); background: var(--bad-bg); }
.feedback.is-partial { border-left-color: var(--warn); background: var(--warn-bg); }
.feedback-head { font-weight: 750; font-size: .82rem; text-transform: uppercase; letter-spacing: .1em; margin-bottom: 6px; }
.feedback.is-ok .feedback-head { color: var(--ok); }
.feedback.is-bad .feedback-head { color: var(--bad); }
.feedback.is-partial .feedback-head { color: var(--warn); }
.steps { margin: 8px 0 0; padding-left: 20px; font-family: var(--mono); font-size: .86rem; }
.steps li { margin-bottom: 4px; }

.qfoot { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.qstatus { font-size: .8rem; color: var(--muted); margin-left: auto; }

/* --------------------------------------------------------------- q index */
.qindex { display: flex; flex-wrap: wrap; gap: 8px; }
.qdot {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--white);
  font: inherit;
  font-weight: 700;
  font-size: .85rem;
  cursor: pointer;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.qdot.is-answered { background: var(--navy); color: var(--white); border-color: var(--navy); }
.qdot.is-wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.qdot.is-right { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.qdot.is-current { box-shadow: 0 0 0 3px var(--gold); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  font-size: .74rem;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  display: inline-block;
  background: var(--white);
}
.sw-answered { background: var(--navy); border-color: var(--navy); }
.sw-right { background: var(--ok-bg); border-color: var(--ok); }
.sw-wrong { background: var(--bad-bg); border-color: var(--bad); }

/* ------------------------------------------------------------ sticky bar */
.actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  background: rgba(17, 24, 38, .97);
  border-top: 3px solid var(--gold);
  color: var(--white);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  backdrop-filter: blur(6px);
}
.actionbar-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.actionbar-info { font-size: .82rem; color: #cfd6e4; min-width: 0; }
.actionbar-info strong { color: var(--white); }
.actionbar .btn { white-space: nowrap; }
.actionbar .spacer { margin-left: auto; }

/* --------------------------------------------------------------- results */
.score-hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 22px;
  align-items: center;
}
.score-ring {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--gold-graphic) calc(var(--pct, 0) * 1%), #e3ded2 0);
  position: relative;
}
.score-ring::after {
  content: "";
  position: absolute;
  inset: 12px;
  background: var(--white);
  border-radius: 50%;
}
.score-ring-inner { position: relative; z-index: 1; text-align: center; }
.score-ring-value { font-size: 2.1rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.score-ring-sub { font-size: .74rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 700; }

.verdict { font-size: 1.25rem; font-weight: 750; margin-bottom: 6px; }
.verdict-sub { color: var(--muted); font-size: .95rem; }

.modbars { display: grid; gap: 10px; margin-top: 6px; }
.modbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: .86rem; }
.modbar-track { height: 8px; background: var(--paper-2); border-radius: 999px; overflow: hidden; margin-top: 5px; }
.modbar-fill { height: 100%; background: var(--gold-graphic); }
.modbar-name { font-weight: 650; }
.modbar-score { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 650; }

.trap {
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold-deep);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--white);
  padding: 14px;
  margin-bottom: 10px;
}
.trap h4 { font-size: .98rem; margin-bottom: 4px; }
.trap p { font-size: .88rem; color: var(--muted); margin: 0; }

/* ---------------------------------------------------------------- admin */
.admin-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
.admin-table th, .admin-table td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); }
.admin-table th { font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted-2); }
.admin-table tbody tr:hover { background: #fbfaf7; }
.admin-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--white); }
.num { font-variant-numeric: tabular-nums; }

.toolbar .eyebrow { margin-bottom: 10px; }
.toolbar-gap { display: inline-block; width: 1px; height: 26px; background: var(--line); margin: 0 4px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 720px) {
  body { font-size: 15px; padding-bottom: 104px; }
  .brand img { height: 34px; }
  .brand-app { font-size: .82rem; }
  .app-long { display: none; }
  .app-short { display: inline; }
  .timer { padding: 5px 10px; }
  .timer-label { font-size: .56rem; }
  .matchrow { grid-template-columns: 1fr; }
  .grid-2, .grid-3, .mode-picker { grid-template-columns: 1fr; }
  .score-hero { grid-template-columns: 1fr; justify-items: start; }
  .score-ring { width: 132px; height: 132px; }
  .score-ring-value { font-size: 1.85rem; }
  .card, .qcard { padding: 16px; }
  .actionbar-info { display: none; }
  .actionbar .btn { flex: 1 1 auto; }
}

/* very narrow phones: give the brand line and the timer room to breathe */
@media (max-width: 520px) {
  .timer-value { font-size: 1rem; }
  .timer-label { display: none; }
  .lang-toggle .lang-on { padding: 4px 7px; }
}

/* --------------------------------------------------------------------------
   In-app confirmation: keeps the countdown running (native confirm() does not)
   -------------------------------------------------------------------------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(17, 24, 38, .74);
}
.confirm-box {
  width: 100%;
  max-width: 430px;
  padding: 22px 20px 18px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .38);
}
.confirm-text {
  margin: 0 0 16px;
  font-size: .98rem;
  line-height: 1.55;
  color: var(--ink, #111826);
  white-space: pre-line;
}
.confirm-box .btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.confirm-box .btn { flex: 1 1 auto; }
