:root {
  color-scheme: light;
  --bg: #f5f4f0;
  --panel: #ffffff;
  --panel-2: #f0eee8;
  --ink: #1b1a17;
  --ink-2: #57534a;
  --ink-3: #7a7569;
  --line: #e0dcd2;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --hl: #157f57;
  --hl-bg: #e5f6ef;
  --num: #2a78d6;
  --num-bg: #e6f0fb;
  --good: #1d7a3e;
  --bad: #b3261e;
  --warn: #8a5a00;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 18px rgba(0,0,0,.04);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121316; --panel: #1b1c20; --panel-2: #24262b; --ink: #f2f0ea; --ink-2: #c3c0b6; --ink-3: #96938a; --line: #30333a;
  --accent: #5598e7; --accent-ink: #0b1220; --hl: #4fcf9d; --hl-bg: #15342a; --num: #86b6ef; --num-bg: #172a43;
  --good: #6fcf8e; --bad: #ff8a80; --warn: #f0c060; --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121316; --panel: #1b1c20; --panel-2: #24262b; --ink: #f2f0ea; --ink-2: #c3c0b6; --ink-3: #96938a; --line: #30333a;
    --accent: #5598e7; --accent-ink: #0b1220; --hl: #4fcf9d; --hl-bg: #15342a; --num: #86b6ef; --num-bg: #172a43;
    --good: #6fcf8e; --bad: #ff8a80; --warn: #f0c060; --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; overflow-x: hidden; }
a { color: var(--accent); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
code { font-size: .92em; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-2); }
.small { font-size: .86rem; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }

button, .filebtn { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost, .filebtn.ghost { background: transparent; }
button.ghost:hover:not(:disabled), .filebtn:hover { background: var(--panel-2); }
button.primary:hover:not(:disabled) { filter: brightness(1.06); }
button.small, .filebtn.small { min-height: 34px; padding: 4px 11px; font-size: .88rem; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .drop:focus-within, .filebtn:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
input[type="text"], input[type="search"], input[type="number"], input[type="date"], select, textarea {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; min-height: 38px;
}
textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88rem; }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.backlink { font-weight: 700; text-decoration: none; color: var(--ink); }
.appname { color: var(--ink-2); font-weight: 600; white-space: nowrap; }
.freechip { font-size: .78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--panel-2); color: var(--good); border: 1px solid var(--line); }
.topactions { display: flex; align-items: center; gap: 8px; }
.who { font-size: .86rem; color: var(--ink-2); }
.glyphbtn { width: 40px; padding: 0; font-size: 1.1rem; }

main { max-width: 1320px; margin: 0 auto; padding: 0 16px 40px; }
.hero { padding: 26px 0 6px; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); line-height: 1.12; margin: 0 0 10px; letter-spacing: -.015em; }
.lede { font-size: 1.05rem; color: var(--ink-2); max-width: 780px; margin: 0; }
body.loaded .hero { display: none; }
kbd { font: .82em ui-monospace, SFMono-Regular, Menlo, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--panel-2); }

.intake { margin: 18px 0 10px; }
.pastewrap { background: var(--panel); border: 2px dashed var(--line); border-radius: var(--radius); padding: 14px; transition: border-color .15s, background .15s; }
.pastewrap.over { border-color: var(--accent); background: var(--panel-2); }
.pastelabel { display: block; font-weight: 600; margin-bottom: 8px; }
#src { min-height: 120px; resize: vertical; }
body.loaded #src { min-height: 60px; height: 64px; }
.intakebar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.howto { margin-top: 10px; color: var(--ink-2); }
.howto summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.howto ol { margin: 8px 0 4px; padding-left: 22px; }
.howto li { margin: 3px 0; }
.note { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 10px; padding: 10px 14px; }

.work { scroll-margin-top: 70px; display: grid; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); gap: 16px; align-items: start; margin-top: 8px; }
.tablelist { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; position: sticky; top: 70px; max-height: calc(100vh - 90px); display: flex; flex-direction: column; }
.listhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.listhead h2 { font-size: 1rem; margin: 0; }
.toggle { display: inline-flex; gap: 5px; align-items: center; color: var(--ink-2); cursor: pointer; }
.cards { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1 1 auto; min-height: 60px; }
.card { display: flex; gap: 8px; align-items: flex-start; padding: 9px 8px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
.card + .card { margin-top: 4px; }
.card:hover { background: var(--panel-2); }
.card.active { border-color: var(--accent); background: var(--panel-2); }
.card input { margin-top: 4px; flex: none; width: 18px; height: 18px; }
.card .ct { font-weight: 600; line-height: 1.3; word-break: break-word; }
.card .cm { font-size: .8rem; color: var(--ink-3); }
.card .flag { display: inline-block; font-size: .72rem; padding: 0 6px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-2); margin: 3px 4px 0 0; }
.card.indent { margin-left: 16px; }
.bulk { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; display: grid; gap: 8px; }

.editor { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; box-shadow: var(--shadow); }
.edhead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.tname { font-size: 1.15rem; font-weight: 700; flex: 1 1 260px; min-width: 0; }
.opts { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.opts > label, .more label { display: flex; flex-direction: column; gap: 3px; font-size: .82rem; color: var(--ink-2); }
.opts label.check, .more label.check, .csvopts label.check { flex-direction: row; align-items: center; gap: 6px; font-size: .88rem; color: var(--ink); min-height: 38px; }
.more { position: relative; }
.more summary { cursor: pointer; min-height: 38px; display: flex; align-items: center; font-size: .88rem; color: var(--accent); }
.more[open] { flex-basis: 100%; }
.more[open] summary { min-height: 24px; }
.morebody { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-end; padding-top: 4px; }

.colstrip { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 6px; scrollbar-width: thin; }
.colchip { flex: 0 0 auto; width: 170px; border: 1px solid var(--line); border-radius: 10px; padding: 6px; background: var(--panel); display: grid; gap: 5px; }
.colchip.off { opacity: .55; background: var(--panel-2); }
.colchip .ctop { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: .78rem; color: var(--ink-3); }
.colchip .ctop label { display: inline-flex; gap: 4px; align-items: center; cursor: pointer; color: var(--ink-2); }
.colchip input[type=text] { width: 100%; min-height: 32px; padding: 4px 7px; font-size: .88rem; }
.typebtn { min-height: 24px; padding: 0 8px; font-size: .74rem; border-radius: 999px; font-weight: 600; }
.typebtn.num { background: var(--num-bg); color: var(--num); border-color: transparent; }
.typebtn.txt { background: var(--hl-bg); color: var(--hl); border-color: transparent; }
.facts { color: var(--ink-2); margin: 4px 0 8px; min-height: 1.2em; }

.preview { overflow: auto; max-height: 520px; border: 1px solid var(--line); border-radius: 10px; }
.preview table { border-collapse: separate; border-spacing: 0; font-size: .88rem; min-width: 100%; }
.preview th, .preview td { padding: 6px 10px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: left; white-space: nowrap; max-width: 340px; overflow: hidden; text-overflow: ellipsis; vertical-align: top; }
.preview th { position: sticky; top: 0; background: var(--panel-2); font-weight: 600; z-index: 1; }
.preview td.n { text-align: right; font-variant-numeric: tabular-nums; }
.preview td.raw { color: var(--warn); }
.preview td.nil { color: var(--ink-3); }
.preview tr:nth-child(even) td { background: color-mix(in srgb, var(--panel-2) 45%, transparent); }
.preview .empty { padding: 18px; color: var(--ink-3); }

.exportbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.csvopts { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 8px; color: var(--ink-2); }
.csvopts select { min-height: 32px; padding: 3px 8px; }

.faq { margin-top: 34px; max-width: 860px; }
.faq h2 { font-size: 1.15rem; }
.faq dt { font-weight: 700; margin-top: 12px; }
.faq dd { margin: 3px 0 0; color: var(--ink-2); }
.foot { max-width: 1320px; margin: 0 auto; padding: 18px 16px 30px; display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--ink-3); font-size: .86rem; border-top: 1px solid var(--line); }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: .92rem; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100vw - 32px); }

@media (max-width: 860px) {
  .work { grid-template-columns: minmax(0, 1fr); }
  .tablelist { position: static; max-height: none; }
  .cards { max-height: 300px; }
  .preview { max-height: 420px; }
  .exportbar button { flex: 1 1 auto; }
}
@media (max-width: 480px) {
  .appname { font-size: .95rem; }
  .opts > label { flex: 1 1 140px; }
  .opts select { width: 100%; }
}
