:root {
  color-scheme: light;
  --ink: #1d1a17;
  --muted: #6d665e;
  --paper: #f6f3ec;
  --card: #fffdf8;
  --line: #ddd6c9;
  --accent: #7a3b2e;
  --accent-dark: #5e2b20;
  --on-accent: #fff;
  --field: #fff;
  --warn-bg: #fff2d9;
  --warn-line: #d58b49;
  --ok: #2f6b45;
  --danger: #a43a2d;
  --shadow: #1d1a1714;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --ink: #e9e4da;
    --muted: #a39b90;
    --paper: #151311;
    --card: #1e1b18;
    --line: #36312b;
    --accent: #d98a72;
    --accent-dark: #e8a38d;
    --on-accent: #1a0f0b;
    --field: #110f0d;
    --warn-bg: #33280f;
    --warn-line: #a9762f;
    --ok: #7cc196;
    --danger: #e07d6c;
    --shadow: #00000059;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body { min-height: 100dvh; font-size: 16px; line-height: 1.45; }
[hidden] { display: none !important; }
a { color: var(--accent); }

.centered { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; box-shadow: 0 1px 3px var(--shadow); }
.login { width: min(360px, 100%); display: grid; gap: 10px; }
.login h1 { margin: 0 0 6px; font-family: var(--serif); }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--field); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button { background: var(--accent); color: var(--on-accent); border: 0; border-radius: 8px;
  padding: 8px 14px; cursor: pointer; font-weight: 600; }
button:hover { background: var(--accent-dark); }
button:disabled { opacity: .55; cursor: default; }
button.quiet { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.quiet:hover { border-color: var(--accent); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--paper); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.2rem; color: var(--ink);
  text-decoration: none; }
.top nav { display: flex; gap: 4px; overflow-x: auto; }
.top nav a { text-decoration: none; color: var(--muted); padding: 4px 10px; border-radius: 999px;
  white-space: nowrap; }
.top nav a.active { background: var(--card); color: var(--ink); border: 1px solid var(--line); }

#view { max-width: 920px; margin: 0 auto; padding: 16px; padding-bottom: 80px; }
h2 { font-family: var(--serif); margin: 8px 0 12px; }
h3 { margin: 20px 0 8px; font-size: 1rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.chip { display: inline-block; font-size: .78rem; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip.running, .chip.queued { border-color: var(--warn-line); background: var(--warn-bg); color: var(--ink); }
.chip.failed { border-color: var(--danger); color: var(--danger); }
.chip.done-state { border-color: var(--ok); color: var(--ok); }

.list { display: grid; gap: 8px; }
.item { display: block; text-decoration: none; color: inherit; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.item:hover { border-color: var(--accent); }
.item .title { font-family: var(--serif); font-size: 1.08rem; font-weight: 600; }
.item .meta { margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  font-size: .85rem; color: var(--muted); }

.form { display: grid; gap: 12px; }
.form label { font-weight: 600; font-size: .9rem; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.choice { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--card);
  cursor: pointer; display: grid; gap: 2px; }
.choice input { width: auto; margin: 0 6px 0 0; }
.choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.choice small { color: var(--muted); }

textarea.source-input { min-height: 40dvh; }
textarea.editor { min-height: 62dvh; font-family: var(--serif); font-size: 1.08rem;
  line-height: 1.6; padding: 14px 16px; resize: vertical; }
textarea.code { min-height: 60dvh; font-family: ui-monospace, Menlo, monospace; font-size: .88rem; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 12px 0;
  overflow-x: auto; }
.tabs button { background: none; color: var(--muted); border-radius: 8px 8px 0 0; font-weight: 500;
  padding: 8px 12px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

.banner { border: 1px solid var(--warn-line); background: var(--warn-bg); border-radius: 10px;
  padding: 10px 12px; margin: 8px 0; font-size: .92rem; }
.banner.failed { border-color: var(--danger); }
.banner .last { color: var(--muted); font-size: .85rem; margin-top: 2px; }

.prose { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px 18px; font-family: var(--serif); font-size: 1.04rem; line-height: 1.6;
  overflow-wrap: anywhere; }
.prose h2, .prose h1 { font-size: 1.15rem; }
.prose li { margin: 4px 0; }
pre.plain { white-space: pre-wrap; font-family: var(--serif); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; line-height: 1.6; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.corr { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: start;
  padding: 8px 0; border-bottom: 1px solid var(--line); }
.corr input { width: auto; margin-top: 4px; }
.corr del { color: var(--danger); }
.corr ins { color: var(--ok); text-decoration: none; font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 14px;
  border-radius: 999px; font-size: .9rem; max-width: calc(100% - 32px); }

.savebar { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: center;
  padding: 10px 0; padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--paper); flex-wrap: wrap; }

@media (max-width: 560px) {
  .top { gap: 8px; }
  .brand { font-size: 1.05rem; }
  #view { padding: 12px; }
}

@media (max-width: 560px) {
  th, td { padding: 5px 4px; font-size: .82rem; }
  td.muted:last-child { font-size: .75rem; }
}

details.manage { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 12px; }
details.manage summary { cursor: pointer; color: var(--muted); font-weight: 600; }
details.manage .form { margin-top: 12px; max-width: 420px; }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.danger:hover { background: var(--danger); color: var(--on-accent); }

.panel.checks { margin: 8px 0 12px; padding: 12px 16px; }
.panel.checks h3 { margin-top: 0; }
.corr .ctx { display: block; margin-top: 2px; font-family: var(--serif); }
button.small { padding: 2px 10px; margin-left: 10px; font-size: .85rem; }
