/* Pocket: phone-first styles. Colours are tokens; dark mode follows the system unless overridden. */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #1a1f36;
  --muted: #5b6380;
  --line: #d9deeb;
  --accent: #2d4fd6;
  --accent-ink: #ffffff;
  --accent-soft: #e3e9ff;
  --good: #1f8a4c;
  --good-soft: #dff4e7;
  --bad: #c2362f;
  --bad-soft: #fbe4e2;
  --warn: #a65f00;
  --warn-soft: #fff1d6;
  --code-bg: #f1f3f9;
  --shadow: 0 1px 2px rgba(20, 30, 70, .08), 0 2px 8px rgba(20, 30, 70, .05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", "Thonburi", "Sarabun", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1220;
    --surface: #171c2e;
    --surface-2: #20263b;
    --text: #e8ebf5;
    --muted: #a3abc6;
    --line: #2d3550;
    --accent: #8fa6ff;
    --accent-ink: #0e1220;
    --accent-soft: #252f57;
    --good: #5fd08f;
    --good-soft: #163527;
    --bad: #ff8a80;
    --bad-soft: #3c1c1c;
    --warn: #ffbe5c;
    --warn-soft: #3a2c12;
    --code-bg: #12172a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1220;
  --surface: #171c2e;
  --surface-2: #20263b;
  --text: #e8ebf5;
  --muted: #a3abc6;
  --line: #2d3550;
  --accent: #8fa6ff;
  --accent-ink: #0e1220;
  --accent-soft: #252f57;
  --good: #5fd08f;
  --good-soft: #163527;
  --bad: #ff8a80;
  --bad-soft: #3c1c1c;
  --warn: #ffbe5c;
  --warn-soft: #3a2c12;
  --code-bg: #12172a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  overflow-x: hidden;
}
a { color: var(--accent); }
code, pre, textarea.code { font-family: var(--mono); }
code { background: var(--code-bg); border-radius: 5px; padding: 0 .3em; font-size: .9em; overflow-wrap: anywhere; }
button { font: inherit; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 18px; display: flex; align-items: center; gap: 6px; }
.brand-mark { font-family: var(--mono); font-size: 13px; background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 1px 5px; }
.streak { margin-left: auto; font-size: 14px; color: var(--muted); white-space: nowrap; }
.streak b { color: var(--text); }
.topnav { display: flex; gap: 4px; }
.topnav a { text-decoration: none; padding: 6px 8px; border-radius: 8px; font-size: 15px; }

main { max-width: 680px; margin: 0 auto; padding: 16px 16px 96px; outline: none; }
.loading { color: var(--muted); }
h1 { font-size: 22px; line-height: 1.35; margin: 4px 0 12px; }
h2 { font-size: 18px; margin: 22px 0 8px; }
h3 { font-size: 16px; margin: 16px 0 6px; }
p { margin: 8px 0; }
ul { padding-left: 22px; margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* cards and buttons */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; box-shadow: var(--shadow); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; font-weight: 600;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .btn { flex: 1 1 140px; }
.stack > * + * { margin-top: 10px; }

/* home */
.today { display: flex; align-items: center; gap: 14px; }
.ring { width: 64px; height: 64px; flex: 0 0 64px; }
.ring circle { fill: none; stroke-width: 7; }
.ring .bg { stroke: var(--surface-2); }
.ring .fg { stroke: var(--accent); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }
.today .big { font-size: 20px; font-weight: 700; }
.modes { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
.mode-card { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.mode-card .name { font-weight: 700; font-size: 17px; }
.mode-card .desc { color: var(--muted); font-size: 14px; margin-top: 2px; }
.mode-card .counts { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.pill { display: inline-block; font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.due { background: var(--warn-soft); color: var(--warn); }
.pill.new { background: var(--accent-soft); color: var(--accent); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.day { text-align: center; font-size: 12px; color: var(--muted); }
.day .dot { height: 30px; border-radius: 8px; background: var(--surface-2); margin-bottom: 3px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: var(--muted); }
.day .dot.on { background: var(--good-soft); color: var(--good); }
.day.today-mark .dot { outline: 2px solid var(--accent); outline-offset: 1px; }

/* item views */
.item-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.statement { font-size: 17px; }
.statement p { margin: 8px 0; }
.limits { font-size: 15px; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; margin: 10px 0; overflow-wrap: anywhere; }
.limits b { color: var(--text); }
.question { font-weight: 700; margin: 16px 0 8px; }
.options { display: flex; flex-direction: column; gap: 8px; }
.opt {
  text-align: left; width: 100%; min-height: 52px; padding: 12px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer;
  line-height: 1.5; -webkit-tap-highlight-color: transparent; touch-action: manipulation; font-size: 16px;
}
.opt:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.opt.picked { border-color: var(--accent); background: var(--accent-soft); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt .why { display: block; margin-top: 6px; font-size: 14px; color: var(--muted); }
.opt .tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-right: 6px; background: var(--surface-2); color: var(--muted); }
.verdict { font-weight: 700; font-size: 18px; margin: 14px 0 6px; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }
.solution dl { margin: 0; }
.solution dt { font-weight: 700; font-size: 14px; color: var(--muted); margin-top: 8px; }
.solution dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.sticky-actions { position: sticky; bottom: 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(to bottom, transparent, var(--bg) 30%); margin-top: 10px; }

/* triage */
.timer { position: sticky; top: 52px; z-index: 5; background: var(--bg); padding: 6px 0 8px; }
.timer .bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.timer .bar > i { display: block; height: 100%; background: var(--accent); width: 100%; transition: width .9s linear; }
.timer .bar.low > i { background: var(--bad); }
.timer .meta { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-top: 4px; }
.timer .meta b { color: var(--text); font-variant-numeric: tabular-nums; }
.plan { width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 16px; }
.dots { display: flex; gap: 6px; flex-wrap: wrap; }
.dots button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 700; }
.dots button.done { background: var(--accent-soft); border-color: var(--accent); }
.dots button.here { outline: 2px solid var(--accent); outline-offset: 1px; }
.explain dt { font-weight: 700; font-size: 14px; color: var(--muted); margin-top: 8px; }
.explain dd { margin: 2px 0 0; }

/* snippet */
.codeblock { background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; overflow-x: auto; font-size: 14px; line-height: 1.5; white-space: pre; -webkit-overflow-scrolling: touch; }
.codeblock.dim { color: var(--muted); }
.toggle { background: none; border: none; color: var(--accent); padding: 8px 0; cursor: pointer; font-size: 15px; min-height: 40px; }
.editor { display: flex; border: 1.5px solid var(--accent); border-radius: 10px; background: var(--code-bg); overflow: hidden; }
.editor .gutter { margin: 0; padding: 10px 6px 10px 8px; text-align: right; color: var(--muted); font-family: var(--mono); font-size: 15px; line-height: 1.5; user-select: none; background: var(--surface-2); min-width: 34px; overflow: hidden; white-space: pre; }
.editor .gutter .err { color: var(--bad); font-weight: 700; }
.editor textarea {
  flex: 1; min-width: 0; min-height: 230px; border: 0; outline: none; resize: vertical; padding: 10px; margin: 0;
  background: transparent; color: var(--text); font-family: var(--mono); font-size: 15px; line-height: 1.5;
  white-space: pre; overflow-wrap: normal; overflow-x: auto; tab-size: 4;
}
.keys { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.keys button { flex: 0 0 auto; min-width: 42px; height: 42px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-family: var(--mono); font-size: 17px; touch-action: manipulation; }
.results { margin-top: 12px; }
.results, .run-status, section.card, .timer + div { scroll-margin-top: 72px; }
.trow { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.trow .st { width: 22px; flex: 0 0 22px; text-align: center; font-weight: 700; }
.trow .st.ok { color: var(--good); }
.trow .st.no { color: var(--bad); }
.trow .st.wait { color: var(--muted); }
.trow .note { flex: 1; min-width: 0; }
.trow .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.failbox { background: var(--bad-soft); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.failbox h3 { margin: 4px 0; color: var(--bad); }
.failbox pre { background: var(--surface); border-radius: 8px; padding: 8px 10px; max-height: 220px; overflow: auto; font-size: 13px; white-space: pre; margin: 4px 0 8px; }
.passbox { background: var(--good-soft); border-radius: 10px; padding: 10px 12px; margin: 10px 0; color: var(--good); font-weight: 700; }
.errbox { background: var(--warn-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; margin: 10px 0; overflow-wrap: anywhere; }
.errbox b { color: var(--warn); }

/* stats */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 112px 1fr 64px; gap: 8px; align-items: center; font-size: 14px; }
.bar-row .track { height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-row .track > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar-row .num { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart7 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 120px; margin-top: 8px; }
.chart7 .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 12px; color: var(--muted); }
.chart7 .col i { display: block; width: 70%; background: var(--accent); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.chart7 .col .n { font-weight: 700; color: var(--text); font-size: 12px; }
.list a { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); }
.list a .muted { font-size: 13px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.simple td.n, table.simple th.n { text-align: right; font-variant-numeric: tabular-nums; }

/* forms */
label.field { display: block; margin: 10px 0; }
label.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input[type="number"], select, textarea.paste { width: 100%; min-height: 46px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; }
textarea.paste { min-height: 120px; font-family: var(--mono); font-size: 13px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; min-height: 44px; border: 0; background: var(--surface); color: var(--text); cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); z-index: 50; }
#toast.on { opacity: 1; }

@media (min-width: 560px) {
  .modes { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
