:root {
  --ink: #1b2b33; --muted: #62767f; --line: #dde5e9; --bg: #f3f6f7; --panel: #fff;
  --accent: #146b75; --good: #1f7a4d; --info: #3d6680; --ai: #6a4fa3; --warn: #a3621a;
  --label: #3d525b; --input-bg: #fff; --input-line: #c4d1d7; --ghost-line: #b9d3d7;
  --button: #146b75; --button-text: #fff; --header: #133f54; --header-muted: #b8d0d9;
  --pdf: #e6f1f2; --pdf-hover: #d4e9eb; --error: #9b3a33;
  --good-line: #a9d5bd; --good-bg: #eef8f2; --info-line: #bdd0dc; --info-bg: #f1f6f9;
  --ai-line: #cfc2e8; --ai-bg: #f5f1fb; --warn-line: #e7c79f; --warn-bg: #fdf6ec;
  color-scheme: light;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg);
}
/* Dark mode: chosen with the header button, defaulting to the system setting */
:root[data-theme="dark"] {
  --ink: #e2eaed; --muted: #94a9b2; --line: #2a3a41; --bg: #10181c; --panel: #172228;
  --accent: #6cc4cc; --good: #6cc896; --info: #93b8cf; --ai: #b9a2e8; --warn: #e3a95f;
  --label: #b8c8ce; --input-bg: #111b20; --input-line: #3a4d55; --ghost-line: #2f5f66;
  --button: #1f7a84; --button-text: #fff; --header: #0b2633; --header-muted: #8fb1be;
  --pdf: #1c3439; --pdf-hover: #244148; --error: #ef8f86;
  --good-line: #2f5e45; --good-bg: #13261c; --info-line: #35526a; --info-bg: #15222b;
  --ai-line: #4e4075; --ai-bg: #1f1a2e; --warn-line: #6a5130; --warn-bg: #2a2115;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
header { background: var(--header); color: #fff; }
.bar { display: flex; justify-content: space-between; align-items: center; min-height: 56px; gap: 8px 16px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { font-weight: 750; font-size: 18px; letter-spacing: -.3px; }
.brand span { font-weight: 450; opacity: .7; margin-left: 8px; }
header .muted { color: var(--header-muted); font-size: 12px; }
.brand a { color: inherit; text-decoration: none; }
.brand a:hover { text-decoration: underline; }
.bar-right { display: flex; align-items: center; gap: 14px; }
.theme-toggle { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); padding: 5px 12px; font-size: 12px; font-weight: 600; white-space: nowrap; flex: none; }
.theme-toggle:hover { background: rgba(255,255,255,.12); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

form { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin: 18px 0; }
label { font-size: 12px; font-weight: 600; color: var(--label); display: flex; flex-direction: column; gap: 5px; }
label.wide { grid-column: span 2; }
input, select { font: inherit; padding: 7px 9px; border: 1px solid var(--input-line); border-radius: 5px; background: var(--input-bg); color: var(--ink); width: 100%; }
.pair { display: flex; gap: 6px; }
button { font: inherit; font-weight: 600; border: 0; border-radius: 5px; padding: 8px 16px; background: var(--button); color: var(--button-text); cursor: pointer; }
form button { align-self: end; }
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--ghost-line); }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .35; cursor: default; }

.resultbar { display: flex; justify-content: space-between; align-items: baseline; }
.resultbar h2 { font-size: 16px; margin: 4px 0 10px; }
a { color: var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; }
.cardhead { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.cardhead h3 { margin: 0; font-size: 18px; font-variant-numeric: tabular-nums; }
.where { color: var(--muted); }
.card > button { margin-top: 8px; }

.set { border-top: 1px solid var(--line); padding: 10px 0 4px; }
.sethead { display: grid; grid-template-columns: 150px 1fr auto; gap: 14px; align-items: start; }
.when { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.when .muted { font-size: 12px; }
.typewrap { display: inline-flex; gap: 8px; align-items: center; }
.type { font-weight: 650; }
.src { font-size: 11px; padding: 1px 7px; border-radius: 10px; border: 1px solid; cursor: help; }
.src.good { color: var(--good); border-color: var(--good-line); background: var(--good-bg); }
.src.info { color: var(--info); border-color: var(--info-line); background: var(--info-bg); }
.src.ai { color: var(--ai); border-color: var(--ai-line); background: var(--ai-bg); }
.src.warn { color: var(--warn); border-color: var(--warn-line); background: var(--warn-bg); }
.src.muted { color: var(--muted); border-color: var(--line); }
.note { font-size: 12px; margin-top: 4px; }
.note.warn { color: var(--warn); }
.note.quote { color: var(--ai); font-style: italic; }
.actions { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
a.pdf { font-weight: 600; text-decoration: none; padding: 4px 10px; border-radius: 5px; background: var(--pdf); }
a.pdf:hover { background: var(--pdf-hover); }

.sheets { margin: 8px 0 4px 164px; border-left: 2px solid var(--line); padding-left: 12px; }
.sheet { display: grid; grid-template-columns: 70px 150px 1fr 220px; gap: 10px; padding: 3px 0; font-size: 12px; align-items: baseline; }
.sheet a.pdf { padding: 1px 6px; }
.sheet .kind { font-weight: 600; color: var(--label); }
.sheet .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet .file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

nav { display: flex; gap: 16px; justify-content: center; align-items: center; margin: 18px 0; }
.empty { background: var(--panel); border: 1px dashed var(--input-line); border-radius: 8px; padding: 30px; text-align: center; color: var(--muted); }
.error { color: var(--error); }
.foot { font-size: 12px; margin: 20px 0 40px; }

@media (max-width: 860px) {
  form { grid-template-columns: 1fr 1fr; }
  .sethead { grid-template-columns: 1fr; gap: 6px; }
  .sheets { margin-left: 0; }
  .sheet { grid-template-columns: 60px 1fr; }
  .sheet .title, .sheet .file { grid-column: 1 / -1; }
}
.note.paid { color: var(--label); }
a.ext { color: var(--muted); text-decoration: none; font-size: 12px; }
a.ext:hover { color: var(--accent); }
.variant { color: var(--label); font-size: 13px; }
.nolink { font-size: 12px; color: var(--muted); }
