:root {
  --bg: #faf8f3;
  --surface: #ffffff;
  --ink: #1f1d1a;
  --muted: #6b665d;
  --line: #e7e2d8;
  --gold: #b8860b;
  --gold-soft: #f7efd9;
  --ok: #2f6b3f;
  --warn: #7a5200;
  --bad: #9b2c2c;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513; --surface: #1f1e1b; --ink: #ece8df; --muted: #a39d92; --line: #34312c;
    --gold: #d9a520; --gold-soft: #3a2f14; --ok: #7cc58f; --warn: #e0b04a; --bad: #e88b8b;
  }
}
:root[data-theme="dark"] {
  --bg: #161513; --surface: #1f1e1b; --ink: #ece8df; --muted: #a39d92; --line: #34312c;
  --gold: #d9a520; --gold-soft: #3a2f14; --ok: #7cc58f; --warn: #e0b04a; --bad: #e88b8b;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 "Open Sans", system-ui, sans-serif; }
h1, h2 { font-family: Fraunces, Georgia, serif; font-weight: 600; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 18px; margin: 0 0 12px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; max-width: 868px; margin: 0 auto; padding: 24px 24px 8px; }
.sub { margin: 2px 0 0; color: var(--muted); }

.tabs { display: flex; gap: 4px; max-width: 868px; margin: 0 auto; padding: 0 24px; border-bottom: 1px solid var(--line); }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 12px; font: 600 14px "Open Sans"; color: var(--muted); cursor: pointer; }
.tab.active { color: var(--ink); border-bottom-color: var(--gold); }

.layout { display: grid; grid-template-columns: minmax(0, 820px); justify-content: center; gap: 24px; max-width: 1240px; margin: 0 auto; padding: 20px 24px 32px; align-items: start; }
.layout.with-trace { grid-template-columns: minmax(0, 820px) 360px; }
.panel { display: none; }
.panel.active { display: block; }
.trace { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; margin-bottom: 16px; }
.fields { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.fields + h2 { margin-top: 18px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.wide { flex: 1 1 220px; }
label.grow { flex: 1 1 260px; }
input, select { font: 15px "Open Sans"; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); min-width: 0; }
#years { width: 90px; }
button { font: 600 14px "Open Sans"; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
button.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
button.quiet { font-weight: 400; color: var(--muted); }
button.link { border: 0; background: none; color: var(--muted); padding: 9px 0; text-decoration: underline; font-weight: 400; }
button:disabled { opacity: .45; cursor: default; }
.actions { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-top: 14px; flex-wrap: wrap; }
#goal-card .actions { justify-content: flex-start; }

.hint, .meta { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.note { color: var(--warn); background: var(--gold-soft); border-radius: 8px; padding: 8px 12px; font-size: 14px; margin: 0 0 12px; }
.note:empty, .error:empty, .meta:empty { display: none; }
.error { color: var(--bad); font-size: 13px; }
.ok { color: var(--ok); font-size: 14px; }
details.add { margin-top: 14px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.small { margin-top: 16px; }
details.small ul { font-size: 13px; color: var(--muted); padding-left: 18px; }

.code { font-family: var(--mono); font-size: 12.5px; color: var(--muted); white-space: nowrap; }

/* starting-point options */
.options { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.options li { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.options li:hover, .options li.sel { border-color: var(--gold); background: var(--gold-soft); }
.options li .row1 { display: flex; justify-content: space-between; gap: 12px; }
.options li .leads { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.options.plain li { cursor: default; display: flex; gap: 12px; align-items: baseline; }
.options.plain li:hover { background: none; border-color: var(--line); }

/* the staircase: higher grades sit higher and further right */
.stair { display: flex; flex-direction: column-reverse; gap: 8px; }
.st { --g: 0; margin-left: calc(var(--g) * 18px); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; gap: 12px; align-items: flex-start; background: var(--surface); }
.st > input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--gold); flex: none; }
.st .body { flex: 1; min-width: 0; }
.st .label { font-size: 12px; font-weight: 600; color: var(--muted); }
.st.base { border: 2px solid var(--gold); }
.st.top { border-style: dashed; }
.st.done > .body > .text { text-decoration: line-through; color: var(--muted); }
.st details { margin-top: 8px; }
.st details label { flex-direction: row; gap: 8px; align-items: flex-start; color: var(--ink); font-size: 14px; margin: 6px 0; }
.st details label input { margin-top: 3px; accent-color: var(--gold); }
.st details label.done span { text-decoration: line-through; color: var(--muted); }

/* goal */
.goal-list { display: grid; gap: 10px; }
.gc { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.gc .label { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.gc p { margin: 4px 0 0; }
.gc.goal { border: 2px solid var(--gold); background: var(--gold-soft); }

/* caseload */
.group { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; }
.group .row1 { display: flex; justify-content: space-between; gap: 12px; }
.pill { display: inline-block; font-family: var(--mono); font-size: 12px; background: var(--gold-soft); border-radius: 999px; padding: 2px 10px; margin: 6px 6px 0 0; }

/* ask */
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 0; }
.examples button { font-weight: 400; font-size: 13px; padding: 5px 12px; border-radius: 999px; color: var(--muted); }
.answer { border-left: 3px solid var(--gold); padding: 10px 14px; margin-top: 16px; background: var(--gold-soft); border-radius: 0 8px 8px 0; }
.answer p { margin: 0; }
.answer .code { display: block; margin-top: 6px; white-space: normal; }

/* trace */
table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
th { text-align: left; color: var(--muted); font-weight: 600; }
th, td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; word-break: break-word; }
th:nth-child(1) { width: 30%; } th:nth-child(2) { width: 36%; } th:nth-child(3) { width: 24%; } th:nth-child(4) { width: 10%; }
td.args { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.o-unknown { color: var(--bad); } .o-not_in_graph { color: var(--warn); }

.foot { max-width: 868px; margin: 0 auto; padding: 0 24px 32px; color: var(--muted); font-size: 13px; text-align: center; }
.foot.bad { color: var(--bad); }

@media (max-width: 1100px) {
  .layout.with-trace { grid-template-columns: minmax(0, 1fr); }
  .trace { position: static; max-height: none; }
}
@media (max-width: 640px) {
  .top, .tabs, .layout, .foot { padding-left: 16px; padding-right: 16px; }
  .card { padding: 16px; }
  .st { margin-left: calc(var(--g) * 6px); }
  .fields > * { flex: 1 1 100%; }
  #years { width: 100%; }
}
