:root {
  --bg: #f4f4f2; --panel: #ffffff; --raised: #fafaf8; --line: #e2e1dc; --line-strong: #cfcdc6;
  --fg: #141413; --muted: #6b6a64; --faint: #9a988f;
  --accent: #141413; --accent-fg: #ffffff;
  --chg: #fff3cd; --chg-line: #c98a00; --chg-fg: #7a5200;
  --sheet: #e8eefc; --sheet-fg: #2d4aa8; --bad: #b3261e; --bad-soft: #fde8e6; --good: #1d7a45;
  --radius: 12px; --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #121211; --panel: #1b1b19; --raised: #22221f; --line: #2e2e2a; --line-strong: #3d3d38;
  --fg: #f1f0ea; --muted: #a3a197; --faint: #75736b; --accent: #f1f0ea; --accent-fg: #121211;
  --chg: #3a2f12; --chg-line: #e0aa2e; --chg-fg: #f3cf7a; --sheet: #1e2945; --sheet-fg: #9fb6ff;
  --bad: #ff8a80; --bad-soft: #3b1715; --good: #5fd08f; color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #121211; --panel: #1b1b19; --raised: #22221f; --line: #2e2e2a; --line-strong: #3d3d38;
  --fg: #f1f0ea; --muted: #a3a197; --faint: #75736b; --accent: #f1f0ea; --accent-fg: #121211;
  --chg: #3a2f12; --chg-line: #e0aa2e; --chg-fg: #f3cf7a; --sheet: #1e2945; --sheet-fg: #9fb6ff;
  --bad: #ff8a80; --bad-soft: #3b1715; --good: #5fd08f; color-scheme: dark }
* { box-sizing: border-box }
html, body { margin: 0 }
body { background: var(--bg); color: var(--fg); font: 15px/1.45 var(--sans); -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom, 0px) }
button, input, select, textarea { font: inherit; color: inherit }
button { cursor: pointer }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px }
.muted { color: var(--muted) }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: var(--panel); border-bottom: 1px solid var(--line) }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0 }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center;
  font-weight: 800; flex: none }
h1 { font-size: 17px; margin: 0; letter-spacing: -.01em }
.buildline { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.changes-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 999px;
  padding: 7px 8px 7px 14px; font-weight: 600; flex: none }
.changes-btn .count { min-width: 26px; height: 26px; padding: 0 7px; border-radius: 999px; background: var(--raised); display: grid; place-items: center;
  font: 600 13px var(--mono); font-variant-numeric: tabular-nums }
.changes-btn.has .count { background: var(--chg-line); color: #fff }

/* section tabs */
.tabs, .subtabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px 0; scrollbar-width: none }
.tabs::-webkit-scrollbar, .subtabs::-webkit-scrollbar { display: none }
.tabs button, .subtabs button { flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 7px 14px; font-weight: 600;
  font-size: 14px; white-space: nowrap }
.tabs button[aria-current="page"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent) }
.subtabs:empty { display: none }
.subtabs button { font-size: 13px; padding: 5px 12px; font-weight: 500 }
.subtabs button[aria-current="true"] { border-color: var(--fg); font-weight: 700 }

/* list + detail */
.layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; padding: 12px 16px 40px; max-width: 1400px; margin: 0 auto; align-items: start }
.list { position: sticky; top: 76px; max-height: calc(100vh - 160px); overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius) }
.search { position: sticky; top: 0; background: var(--panel); padding: 10px; border-bottom: 1px solid var(--line); z-index: 1 }
.search input { width: 100%; border: 1px solid var(--line); background: var(--raised); border-radius: 9px; padding: 8px 10px }
.group-title { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 12px 14px 4px }
.entry { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line);
  padding: 10px 14px; min-height: 52px }
.entry:last-child { border-bottom: 0 }
.entry:hover { background: var(--raised) }
.entry[aria-current="true"] { background: var(--raised); box-shadow: inset 3px 0 0 var(--fg) }
.entry .ic { width: 30px; height: 30px; border-radius: 8px; background: var(--raised); border: 1px solid var(--line); display: grid; place-items: center; flex: none; font-size: 16px }
.entry .tx { min-width: 0; flex: 1 }
.entry .t { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.entry .s { font-size: 12px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--chg-line); flex: none }
.add-entry { margin: 10px; width: calc(100% - 20px); border: 1px dashed var(--line-strong); background: none; border-radius: 9px; padding: 9px; font-weight: 600; color: var(--muted) }

.detail { min-width: 0; display: flex; flex-direction: column; gap: 14px }
.empty { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; color: var(--muted) }
.dhead { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap }
.dhead .big { width: 48px; height: 48px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); display: grid; place-items: center; font-size: 26px; flex: none }
.dhead h2 { margin: 0; font-size: 22px; letter-spacing: -.01em; line-height: 1.2 }
.dhead .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px }
.dhead .grow { flex: 1; min-width: 0 }
.back { display: none; border: 0; background: none; padding: 4px 0; font-weight: 600; color: var(--muted) }
.lede { margin: 0; color: var(--muted); max-width: 75ch }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0 }
.card > h3, .card > summary { margin: 0; font-size: 14px; font-weight: 700; padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px }
.card > summary { cursor: pointer; list-style: none; border-bottom: 0 }
.card[open] > summary { border-bottom: 1px solid var(--line) }
.card > summary::-webkit-details-marker { display: none }
.card > summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform .2s ease-out }
.card:not([open]) > summary::after { transform: rotate(-90deg) }
.card h3 small, .card summary small { font-weight: 500; color: var(--muted); font-size: 12px }
.card .body { padding: 4px 0 }
.sub-card { margin: 8px 14px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--raised) }
.sub-card > .sc-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 13px }
.sub-card > .sc-head .sp { flex: 1 }
.sub-card .row { padding-left: 12px; padding-right: 12px }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 14px; align-items: start }

/* a field */
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 4px 12px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--line) }
.body > .row:first-child, .sub-card > .row:first-of-type { border-top: 0 }
.row .lab { min-width: 0 }
.row .lab b { font-weight: 600; font-size: 14px }
.row .lab .unit { color: var(--faint); font-size: 12px; margin-left: 5px; font-family: var(--mono) }
.row .lab .key { display: block; color: var(--faint); font: 11px var(--mono) }
.row .help { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin: 0 }
.row .val { min-width: 0; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; justify-content: flex-end }
.row.chg { background: var(--chg); box-shadow: inset 3px 0 0 var(--chg-line) }
.row .was { grid-column: 1 / -1; font: 12px var(--mono); color: var(--chg-fg); text-align: right }
.row .was button { border: 0; background: none; color: inherit; text-decoration: underline; font: inherit; padding: 0 0 0 6px }
.chip { display: inline-block; font: 600 10px var(--sans); letter-spacing: .04em; text-transform: uppercase; padding: 2px 6px; border-radius: 5px; vertical-align: 2px; margin-left: 6px }
.chip.sheet { background: var(--sheet); color: var(--sheet-fg) }
.chip.dev { background: var(--chg); color: var(--chg-fg) }
input.v, select.v, textarea.v { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 9px; min-width: 0; width: 100%;
  font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums }
input.v.num { text-align: right }
input.v.unset, select.v.unset { border-style: dashed; color: var(--faint) }
input.v.bad { border-color: var(--bad); background: var(--bad-soft) }
textarea.v { font-family: var(--sans); resize: vertical; min-height: 64px; text-align: left }
textarea.json { font-family: var(--mono); font-size: 12px; min-height: 120px; white-space: pre; overflow-wrap: normal; overflow-x: auto }
.tuple { display: grid; grid-template-columns: repeat(var(--n), minmax(56px, 1fr)); gap: 6px; width: 100% }
.tuple label { display: flex; flex-direction: column; gap: 2px; font-size: 10px; color: var(--faint); font-family: var(--mono); min-width: 0 }
.mini { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 4px 9px; font-weight: 600; font-size: 12px; color: var(--muted) }
.mini.danger, .danger { color: var(--bad) }
.acts-row { display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 14px 12px }

/* tables (levels, stat modifiers, level preview) */
.tbl-wrap { overflow-x: auto; padding: 4px 14px 10px }
table.t { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums }
table.t th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: right; padding: 6px 6px; font-weight: 700; white-space: nowrap }
table.t th:first-child, table.t td:first-child { text-align: left }
table.t td:first-child { font-family: var(--sans); color: var(--muted) }
table.t td { padding: 4px 4px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 13px; text-align: right; white-space: nowrap }
table.t td input.v { width: 78px; padding: 5px 6px }
table.t td select.v { width: auto }
table.t tr.chg td { background: var(--chg) }

/* changes drawer */
.drawer { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .35); display: flex; justify-content: flex-end }
.drawer[hidden] { display: none }
.drawer-panel { width: min(560px, 100%); height: 100%; background: var(--panel); display: flex; flex-direction: column; gap: 10px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px)); overflow: auto }
@media (prefers-reduced-motion: no-preference) { .drawer:not([hidden]) .drawer-panel { animation: slidein .22s ease-out } }
@keyframes slidein { from { transform: translateX(24px); opacity: .6 } to { transform: none; opacity: 1 } }
.drawer-head { display: flex; align-items: center; justify-content: space-between }
.drawer-head h2 { margin: 0; font-size: 20px }
.drawer-sub, #drawer-sub { margin: 0 }
.icon-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; width: 38px; height: 38px }
.drawer-acts { display: flex; gap: 8px; flex-wrap: wrap }
button.primary { background: var(--accent); color: var(--accent-fg); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 18px; font-weight: 700 }
button.ghost { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 16px; font-weight: 600 }
button:disabled { opacity: .45; cursor: default }
.note { margin: 0; font-size: 13px; color: var(--good) }
.patch-text { width: 100%; min-height: 160px; font: 12px var(--mono); border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--raised) }
.change-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px }
.change-list li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px }
.change-list .where { font-weight: 600; font-size: 14px }
.change-list .path { grid-column: 1 / -1; font: 11px var(--mono); color: var(--faint); word-break: break-all }
.change-list .vals { grid-column: 1 / -1; font: 13px var(--mono); word-break: break-word }
.change-list .vals .old { color: var(--muted); text-decoration: line-through }
.change-list .vals .new { color: var(--fg); font-weight: 600 }
.change-list a { color: inherit }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--accent); color: var(--accent-fg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 60; max-width: calc(100% - 32px) }

/* phones: the list, or one entry full width */
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 10px 12px 40px }
  .list { position: static; max-height: none }
  body.open .list { display: none }
  body:not(.open) .detail { display: none }
  .back { display: inline-block }
  .row { grid-template-columns: minmax(0, 1fr) minmax(112px, 42%); padding: 7px 12px }
  .row.wide { grid-template-columns: minmax(0, 1fr) }
  .row.wide .val { justify-content: stretch }
  .row .help, .row .lab .key { display: none }
  .row:focus-within .help { display: block; font-size: 11.5px }
  .row:focus-within .lab .key { display: block }
  .grid2 { grid-template-columns: minmax(0, 1fr) }
  .sub-card { margin: 8px 10px 10px }
}
