/* Scientific Reading Challenge — restrained, mobile-first, print-quiet.
   Competition feel comes from progress and rank, not from animation. */

:root {
  --bg: #f6f6f2;
  --surface: #ffffff;
  --surface-2: #fbfbf8;
  --ink: #17201b;
  --ink-2: #3c4741;
  --muted: #6d766f;
  --line: #e2e5dd;
  --line-strong: #ccd2c8;
  --accent: #1f4d3d;
  --accent-ink: #ffffff;
  --accent-soft: #e9f0eb;
  --accent-line: #bcd3c5;
  --ok: #2c6b4c;
  --warn: #8a5a17;
  --warn-soft: #fbf1de;
  --danger: #9c3a2e;
  --danger-soft: #fbecea;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(23, 32, 27, .05), 0 8px 24px -18px rgba(23, 32, 27, .35);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC",
          "Microsoft JhengHei", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Noto Serif TC", "Songti TC", serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12160f;
    --surface: #1a1f19;
    --surface-2: #1f2520;
    --ink: #e8eae4;
    --ink-2: #c3c9c0;
    --muted: #8f978d;
    --line: #2b322b;
    --line-strong: #3b443a;
    --accent: #7fc4a3;
    --accent-ink: #10231b;
    --accent-soft: #1e2b24;
    --accent-line: #33513f;
    --ok: #7fc4a3;
    --warn: #d9ab61;
    --warn-soft: #2c2517;
    --danger: #e08a7c;
    --danger-soft: #2e1d1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px -20px rgba(0, 0, 0, .9);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { line-height: 1.3; margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 20;
  background: var(--accent); color: var(--accent-ink); padding: 10px 16px;
}
.skip:focus { left: 8px; top: 8px; border-radius: var(--radius-sm); }

/* ------------------------------------------------------------------ chrome */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px max(14px, env(safe-area-inset-left)) 10px max(14px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: var(--accent);
  box-shadow: inset 0 0 0 3px var(--surface), inset 0 0 0 4px var(--accent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: .92rem; letter-spacing: -.005em; }
.brand-text small { font-size: .68rem; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; }

.topnav { margin-left: auto; display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.topnav a, .topnav button {
  font: inherit; font-size: .86rem; color: var(--ink-2);
  background: none; border: 0; border-radius: 999px;
  padding: 7px 12px; cursor: pointer; text-decoration: none;
}
.topnav a:hover, .topnav button:hover { background: var(--accent-soft); color: var(--accent); }
.topnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topnav .who { color: var(--muted); font-size: .8rem; padding-left: 8px; }

.main {
  max-width: 880px; margin: 0 auto; outline: none;
  padding: 22px max(14px, env(safe-area-inset-left)) 64px max(14px, env(safe-area-inset-right));
}

.footer {
  border-top: 1px solid var(--line);
  padding: 20px 16px 40px; max-width: 880px; margin: 0 auto;
  color: var(--muted); font-size: .76rem;
}

.loading { color: var(--muted); padding: 40px 0; text-align: center; }

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

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card.flat { box-shadow: none; }
.card.accent { border-color: var(--accent-line); background: var(--accent-soft); }
.card-head { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.eyebrow {
  font-size: .68rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 6px; font-weight: 600;
}

.grid { display: grid; gap: 14px; }
@media (min-width: 680px) { .grid.two { grid-template-columns: 1fr 1fr; } }

.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spread { display: flex; gap: 12px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .74rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

/* ----------------------------------------------------------------- buttons */

.btn {
  font: inherit; font-weight: 600; font-size: .92rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  text-decoration: none; transition: background .12s ease, border-color .12s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.small { padding: 7px 12px; font-size: .82rem; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--accent-soft); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

/* ------------------------------------------------------------------ fields */

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 5px; color: var(--ink-2); }
.field > span .opt { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=search],
select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
textarea { min-height: 90px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .option:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label {
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 6px 14px;
  font-size: .85rem; cursor: pointer; background: var(--surface-2);
}
.seg input { position: absolute; opacity: 0; width: 0; height: 0; }
.seg input:checked + span { color: var(--accent); }
.seg label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

.notice {
  border-left: 3px solid var(--accent-line); background: var(--accent-soft);
  padding: 12px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: .87rem;
}
.notice.warn { border-color: var(--warn); background: var(--warn-soft); }
.notice.error { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }

/* ----------------------------------------------------------------- metrics */

/* Cell separators come from each tile's own ring rather than from a coloured
   grid background, so a row that does not divide evenly leaves surface, not a
   grey orphan cell. */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 1px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.metric { background: var(--surface); padding: 12px 14px; box-shadow: 0 0 0 1px var(--line); }
.metric b { display: block; font-size: 1.42rem; font-weight: 600; font-variant-numeric: tabular-nums;
  letter-spacing: -.02em; line-height: 1.2; }
.metric span { font-size: .72rem; color: var(--muted); letter-spacing: .04em; }

.bar { height: 7px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 10px 0 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: .74rem; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--muted); background: var(--surface-2);
}
.chip.solid { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); font-weight: 600; }
.chip.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.chip.demo { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); font-weight: 600; }

/* ---------------------------------------------------------------- articles */

.article-title { font-family: var(--serif); font-size: 1.34rem; line-height: 1.35; margin: 0 0 8px; font-weight: 600; }
.article-meta { font-size: .78rem; color: var(--muted); margin-bottom: 12px; }
.article-meta a { color: var(--muted); }
.abstract {
  font-family: var(--serif); font-size: 1.02rem; line-height: 1.78; color: var(--ink-2);
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.abstract.collapsed { max-height: 4.6em; overflow: hidden; position: relative; }
.abstract.collapsed::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 2.4em;
  background: linear-gradient(to bottom, transparent, var(--surface));
}

.art-list { display: grid; gap: 10px; }
.art-item {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.art-item:hover { border-color: var(--accent-line); }
.art-item h3 { font-family: var(--serif); font-size: 1.02rem; margin: 0 0 6px; font-weight: 600; }

/* --------------------------------------------------------------- challenge */

.qbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.qcount { font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.timer { font-family: var(--mono); font-size: .95rem; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.qsteps { display: flex; gap: 5px; margin-bottom: 16px; }
.qsteps i { height: 3px; flex: 1; border-radius: 99px; background: var(--line); }
.qsteps i.on { background: var(--accent); }

.qtext { font-size: 1.1rem; font-weight: 600; line-height: 1.55; margin: 0 0 16px; }

.options { display: grid; gap: 9px; margin-bottom: 18px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; text-align: left; width: 100%;
  font: inherit; cursor: pointer; padding: 13px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.option:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.option[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); font-weight: 500; }
.option .key {
  flex: none; width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center;
  border: 1px solid var(--line-strong); font-size: .78rem; font-weight: 700; color: var(--muted);
}
.option[aria-pressed="true"] .key { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.option.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, var(--surface)); }
.option.wrong { border-color: var(--danger); background: var(--danger-soft); }
.option.correct .key { background: var(--ok); border-color: var(--ok); color: #fff; }
.option.wrong .key { background: var(--danger); border-color: var(--danger); color: #fff; }

.review { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; background: var(--surface); }
.review .verdict { font-size: .76rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.review .verdict.ok { color: var(--ok); }
.review .verdict.no { color: var(--danger); }
.explain { font-size: .9rem; color: var(--ink-2); border-top: 1px dashed var(--line-strong); margin-top: 12px; padding-top: 12px; }
.explain dt { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.explain dd { margin: 0 0 10px; }
.explain dd:last-child { margin-bottom: 0; }

.takeaway { border: 1px solid var(--accent-line); background: var(--accent-soft); border-radius: var(--radius); padding: 16px 18px; }
.takeaway p { font-family: var(--serif); font-size: 1.04rem; line-height: 1.7; margin: 0; }

.score { display: flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; }
.score b { font-size: 2.6rem; font-weight: 600; letter-spacing: -.03em; line-height: 1; }
.score span { font-size: 1.1rem; color: var(--muted); }

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tr.me td { background: var(--accent-soft); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; }

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px;
  font-size: .87rem; max-width: min(92vw, 460px); text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); color: #fff; }

/* -------------------------------------------------------------------- tabs */

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  font: inherit; font-size: .88rem; background: none; border: 0; cursor: pointer;
  padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

details.admin-item { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 8px; }
details.admin-item > summary { padding: 12px 14px; cursor: pointer; font-size: .92rem; }
details.admin-item > summary::marker { color: var(--muted); }
details.admin-item > .body { padding: 0 14px 14px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 14px; }

.hero { padding: 8px 0 18px; }
.hero h1 { font-family: var(--serif); font-size: clamp(1.6rem, 5vw, 2.15rem); margin-bottom: 10px; }
.hero p { font-size: 1.02rem; color: var(--ink-2); max-width: 46ch; }

@media (max-width: 540px) {
  .topbar { padding-top: 8px; padding-bottom: 8px; gap: 8px; }
  .topnav { gap: 0; margin-left: auto; }
  .topnav a, .topnav button { padding: 6px 9px; font-size: .82rem; }
  .topnav .who { display: none; }
  .brand-text small { display: none; }
  .card { padding: 15px; }
}

@media print { .topbar, .topnav, .footer, .toast { display: none; } }
