/* Light theme is the default; dark applies from the system setting or an explicit data-theme. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --ink: #14181f;
  --ink-2: #4a5362;
  --ink-3: #727b8a;
  --accent: #0b6bcb;
  --accent-ink: #ffffff;
  --accent-soft: #e3effb;
  --code-bg: #f6f7f9;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #161a21;
  --surface-2: #1e232c;
  --border: #2b323d;
  --ink: #e8ebf0;
  --ink-2: #aab2bf;
  --ink-3: #8690a0;
  --accent: #5aa9f5;
  --accent-ink: #08121d;
  --accent-soft: #16304a;
  --code-bg: #10141a;
  --danger: #ff8a80;
  --shadow: none;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1e232c;
    --border: #2b323d;
    --ink: #e8ebf0;
    --ink-2: #aab2bf;
    --ink-3: #8690a0;
    --accent: #5aa9f5;
    --accent-ink: #08121d;
    --accent-soft: #16304a;
    --code-bg: #10141a;
    --danger: #ff8a80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 17px; }
h2 { font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); }
code, pre, textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mark { width: 14px; height: 14px; border-radius: 4px; background: var(--accent); }
.chip {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.chip.quiet:empty { display: none; }

main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 16px 24px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "prompt prompt" "answer metrics";
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.prompt { grid-area: prompt; padding: 14px 16px; display: grid; gap: 10px; }
.answer { grid-area: answer; display: flex; flex-direction: column; min-height: 320px; }
.metrics { grid-area: metrics; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-content: start; }
.metrics .tile, .metrics .note { grid-column: span 2; }
.metrics .tile.half { grid-column: span 1; }
.note { margin: 2px 2px 0; font-size: 12px; color: var(--ink-3); }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); }
.spacer { flex: 1; }
#presets { display: flex; gap: 8px; flex-wrap: wrap; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 6px 12px;
}
button:hover { border-color: var(--ink-3); }
button:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button[aria-pressed="true"], button[aria-checked="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
button.ghost { font-size: 13px; color: var(--ink-2); }
button.primary {
  min-width: 96px;
  padding: 8px 20px;
  font-weight: 600;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
button.primary:disabled { opacity: 0.55; cursor: default; }
.preset { font-size: 13px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; font-size: 13px; padding: 6px 14px; border-right: 1px solid var(--border); }
.segmented button:last-child { border-right: 0; }

textarea {
  width: 100%;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}
.status { font-size: 13px; color: var(--ink-2); }
.status.error { color: var(--danger); }

.card-head { display: flex; align-items: baseline; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.hint { font-size: 12px; color: var(--ink-3); }
.scroll { flex: 1; min-height: 0; overflow: auto; padding: 14px 16px; }
.md { overflow-wrap: anywhere; }
.md p { margin: 0 0 10px; white-space: pre-wrap; }
.md p.empty { color: var(--ink-3); }
.md h3 { margin: 14px 0 6px; font-size: 15px; }
.md pre {
  margin: 0 0 12px;
  padding: 12px 14px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--code-bg);
  font-size: 13px;
  line-height: 1.5;
}
.md pre[data-lang]::before {
  content: attr(data-lang);
  display: block;
  margin-bottom: 6px;
  color: var(--ink-3);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.md :not(pre) > code { padding: 1px 5px; border-radius: 4px; background: var(--surface-2); font-size: 13px; }
.reasoning { margin-bottom: 12px; padding: 8px 12px; border: 1px dashed var(--border); border-radius: 8px; color: var(--ink-2); font-size: 13px; }
.reasoning summary { cursor: pointer; font-weight: 600; }
.reasoning div { margin-top: 6px; white-space: pre-wrap; }

.tile { padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.tile .k { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); }
.tile .v { display: flex; align-items: baseline; gap: 6px; margin-top: 2px; font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.25; }
.tile .v small { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.tile .v.pair small { margin-right: 8px; }
.tile .s { margin-top: 2px; font-size: 12px; color: var(--ink-3); }
.tile.hero { border-color: var(--accent); }
.tile.hero .v { font-size: 38px; }
.tile .v .pending { font-weight: 400; color: var(--ink-3); }

@media (max-width: 900px) {
  html, body { height: auto; }
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; grid-template-areas: "prompt" "metrics" "answer"; }
  .answer { min-height: 240px; }
  .scroll { max-height: 70vh; }
}
