/* Agent Lab shared styles.
   Layout: a page header, then a two-pane lab: inputs on the left, "what actually gets sent" on the right.
   Stacks to one column under 900px. */
:root {
  --bg: #f2f5f5;
  --surface: #ffffff;
  --surface-2: #f7f9f9;
  --ink: #16242a;
  --muted: #5b6c72;
  --line: #d4dddf;
  --accent: #0d7472;
  --accent-soft: #dcefed;
  --star: #a8701a;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --bad: #b42318;
  --bad-soft: #fde4e1;
  --ok: #2e7d55;
  --ok-soft: #e1f2e8;
  --code-bg: #eaf0f1;
  /* token segment colours (same hue family in both themes) */
  --seg-system: #5b7fa6;
  --seg-tools: #8a6bb0;
  --seg-history: #4f9a8f;
  --seg-user: #c98a2e;
  --seg-attach: #b5677b;
  --seg-thinking: #7d8794;
  --seg-output: #3d8b4f;
  --seg-cache: #2f6f8f;
  /* json */
  --j-key: #0d5f8a;
  --j-str: #7a4a0c;
  --j-num: #6a3fa0;
  --j-bool: #b42318;
  --f-display: "LXGW WenKai TC", "Kaiti TC", "DFKai-SB", serif;
  --f-body: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", Consolas, "Courier New", monospace;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f171a; --surface: #16222a; --surface-2: #1a2830; --ink: #e2ebed; --muted: #93a5ab; --line: #2a3a41;
    --accent: #52c2bd; --accent-soft: #173739; --star: #e3b350; --warn: #f0a24a; --warn-soft: #3a2a14;
    --bad: #f27a6e; --bad-soft: #3d1c19; --ok: #63c48f; --ok-soft: #173326; --code-bg: #1d2c33;
    --j-key: #7cc4ea; --j-str: #e6b673; --j-num: #c4a2f0; --j-bool: #f27a6e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f171a; --surface: #16222a; --surface-2: #1a2830; --ink: #e2ebed; --muted: #93a5ab; --line: #2a3a41;
  --accent: #52c2bd; --accent-soft: #173739; --star: #e3b350; --warn: #f0a24a; --warn-soft: #3a2a14;
  --bad: #f27a6e; --bad-soft: #3d1c19; --ok: #63c48f; --ok-soft: #173326; --code-bg: #1d2c33;
  --j-key: #7cc4ea; --j-str: #e6b673; --j-num: #c4a2f0; --j-bool: #f27a6e;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.65; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }

.wrap { max-width: 1240px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }

/* page header */
.crumb { padding-block: 18px 0; font-size: 13px; }
.crumb a { text-decoration: none; }
.page-head { padding-block: 8px 18px; display: grid; gap: 6px; }
.page-head h1 { font-family: var(--f-display); font-size: 1.9rem; line-height: 1.25; margin: 0; text-wrap: balance; }
.page-head .lede { margin: 0; color: var(--muted); max-width: 70ch; }
.qref { display: flex; flex-wrap: wrap; gap: 6px; }
.qref span { font-family: var(--f-mono); font-size: 12px; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 1px 10px; }

/* two-pane lab */
.lab { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 16px; align-items: start; padding-bottom: 20px; }
@media (max-width: 900px) { .lab { grid-template-columns: minmax(0, 1fr); } }
.pane { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.pane > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.pane > header h2 { margin: 0; font-size: 14px; font-weight: 700; letter-spacing: .02em; }
.pane > header .hint { font-size: 12px; color: var(--muted); }
.pane .body { padding: 14px; display: grid; gap: 14px; min-width: 0; }
/* one shrinkable column: a wide child must scroll or wrap inside, never stretch the pane */
.pane .body { grid-template-columns: minmax(0, 1fr); }
.pane .body > * { min-width: 0; max-width: 100%; }
.pane.out { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 12px); }
@media (max-width: 900px) { .pane.out { position: static; } }

/* form bits */
.field { display: grid; gap: 4px; min-width: 0; }
.field > label, .field > .label { font-size: 13px; font-weight: 500; }
.field .sub { font-size: 12px; color: var(--muted); }
textarea, input[type="text"], input[type="number"], select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 64px; font-family: var(--f-body); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--accent); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn { font: inherit; font-size: 13px; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 6px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.seg-ctl { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-ctl button { font: inherit; font-size: 13px; border: 0; background: var(--surface); color: var(--ink); padding: 6px 12px; cursor: pointer; }
.seg-ctl button + button { border-left: 1px solid var(--line); }
.seg-ctl button[aria-pressed="true"] { background: var(--accent); color: var(--surface); }

/* output: JSON / code */
.code { font-family: var(--f-mono); font-size: 12.5px; line-height: 1.55; background: var(--code-bg); border-radius: 8px; padding: 12px; margin: 0; overflow: auto; max-height: 520px; white-space: pre; tab-size: 2; }
.code .k { color: var(--j-key); }
.code .s { color: var(--j-str); }
.code .n { color: var(--j-num); }
.code .b { color: var(--j-bool); }
.code .hl { background: var(--warn-soft); border-radius: 3px; outline: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }
.code .dim { opacity: .55; }
code { font-family: var(--f-mono); font-size: .88em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }

/* stacked token bar */
.tbar { display: flex; height: 22px; border-radius: 6px; overflow: hidden; background: var(--code-bg); }
.tbar > i { display: block; height: 100%; min-width: 2px; transition: width .25s; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.legend span::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--c); }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.stat .v { font-family: var(--f-mono); font-size: 18px; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }

/* tables */
.tbl { overflow-x: auto; }
.tbl table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 500; white-space: nowrap; }
.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; text-align: right; }

/* chips / callouts */
.chip { display: inline-block; font-size: 12px; font-weight: 500; padding: 1px 9px; border-radius: 999px; background: var(--code-bg); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.note { font-size: 13px; padding: 8px 12px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.note.ok { background: var(--ok-soft); border-color: transparent; }
.note.warn { background: var(--warn-soft); border-color: transparent; }
.note.bad { background: var(--bad-soft); border-color: transparent; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* timeline / steps */
.steps { display: grid; gap: 8px; counter-reset: s; }
.step { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 10px; align-items: start; }
.step::before { counter-increment: s; content: counter(s); font-family: var(--f-mono); font-size: 12px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--code-bg); color: var(--muted); }
.step.active::before { background: var(--accent); color: var(--surface); }
.step.done::before { background: var(--ok-soft); color: var(--ok); }

/* takeaways */
.takeaways { padding-block: 4px 48px; }
.takeaways .box { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; }
.takeaways h2 { font-family: var(--f-display); font-size: 1.2rem; margin: 0 0 6px; }
.takeaways ul { margin: 0; padding-left: 1.2em; }
.takeaways li { margin: 3px 0; }

.disclaimer { font-size: 12px; color: var(--muted); }

/* previous / next question links at the bottom of each lab page */
.pager { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; padding-block: 0 48px; }
.pager .pg { display: grid; gap: 2px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--ink); min-width: 0; }
.pager .pg:hover { border-color: var(--accent); }
.pager .pg span { font-size: 12.5px; color: var(--accent); }
.pager .pg b { font-family: var(--f-display); font-size: 1.05rem; }
.pager .next { text-align: right; grid-column: 2; }
.takeaways:has(+ .pager) { padding-bottom: 16px; }

/* "口試怎麼答": a ready-to-say 30-second answer at the bottom of each lab page */
.oral { padding-block: 0 20px; }
.oral .box { background: var(--accent-soft); border-radius: 12px; padding: 14px 18px; display: grid; gap: 8px; }
.oral h2 { font-family: var(--f-display); font-size: 1.2rem; margin: 0; }
.oral .say { margin: 0; font-size: 15px; line-height: 1.8; }
.oral .more { margin: 0; padding-left: 1.2em; font-size: 14px; color: var(--muted); }
.oral .more li { margin: 2px 0; }

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