:root {
  --bg: #f6f5f1; --card: #fff; --ink: #1d2433; --muted: #5d6677; --line: #dcd9d0; --brand: #7b2d26; --brand-ink: #fff;
  --accent: #1f5f8b; --ok: #1d7a4a; --warn: #a56200; --bad: #b3261e; --soft: #efece4;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15181f; --card: #1e232d; --ink: #e8e6e0; --muted: #a2a9b7; --line: #343b49; --brand: #d9776c; --brand-ink: #1a0f0d; --accent: #6fb1e0; --soft: #272d39; --ok: #5fcf8f; --warn: #e5a94f; --bad: #ff8b82; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.5; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; } h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; } h3 { margin: 0 0 .25rem; font-size: 1rem; }
.loading { padding: 2rem; text-align: center; color: var(--muted); }
header.top { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header.top .in { max-width: 1100px; margin: 0 auto; padding: .5rem 1rem; display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--brand); text-decoration: none; font-size: 1.15rem; margin-right: .5rem; }
nav { display: flex; gap: .15rem; flex-wrap: wrap; flex: 1; }
nav a { padding: .4rem .7rem; border-radius: 6px; text-decoration: none; color: var(--ink); }
nav a.on { background: var(--soft); font-weight: 600; }
nav a:hover { background: var(--soft); }
main { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; margin: .75rem 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .75rem; }
.stat { text-align: center; } .stat b { font-size: 1.8rem; display: block; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; } .row.between { justify-content: space-between; }
button, .btn { font: inherit; padding: .45rem .9rem; border-radius: 7px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { background: var(--soft); }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.danger { color: var(--bad); border-color: var(--bad); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--ink); width: 100%; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .6rem 0 .15rem; }
.form2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 .75rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
tr.click { cursor: pointer; } tr.click:hover { background: var(--soft); }
.tablewrap { overflow-x: auto; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--soft); border: 1px solid var(--line); }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; z-index: 50; max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 1.25rem; max-width: 560px; width: calc(100% - 2rem); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.5); }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 1.25rem; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--brand); background: var(--soft); }
.check { display: flex; gap: .6rem; padding: .4rem 0; align-items: flex-start; }
.check .dot { width: 1.4rem; height: 1.4rem; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: .8rem; }
.check.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.check.done .t { text-decoration: line-through; color: var(--muted); }
.auth { max-width: 420px; margin: 3rem auto; }
.part { display: flex; justify-content: space-between; gap: .5rem; padding: .4rem 0; border-top: 1px solid var(--line); align-items: center; flex-wrap: wrap; }
.linkbox { word-break: break-all; background: var(--soft); padding: .5rem; border-radius: 6px; font-family: ui-monospace, monospace; font-size: .85rem; }
.banner { background: var(--soft); border-left: 4px solid var(--warn); padding: .6rem .8rem; border-radius: 6px; margin: .75rem 0; }
@media (max-width: 600px) { main { padding: .6rem; } th:nth-child(n+4), td:nth-child(n+4) { display: none; } table.keep th, table.keep td { display: table-cell !important; } }
@media print { header.top, .noprint { display: none !important; } }

/* search */
mark { background: color-mix(in srgb, var(--brand) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 .1em; }
.qs { position: relative; }
.qs input { width: 14rem; padding: .35rem .6rem; }
.qs-dd { position: absolute; right: 0; top: calc(100% + .25rem); width: min(26rem, 90vw); background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); z-index: 20; overflow: hidden; }
.qs-dd a { display: block; padding: .5rem .75rem; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.qs-dd a:hover, .qs-dd a:focus { background: var(--soft); }
.mobile-only { display: none; }
table.lib tr:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (max-width: 700px) { .hide-narrow { display: none !important; } .mobile-only { display: block; } .qs input { width: 9rem; } }
.filters select { width: auto; flex: 1 1 9rem; min-width: 8rem; }
.filters .link { flex: none; }
header.top nav a { white-space: nowrap; }
/* header: brand + tools on the first row, navigation on its own row below */
header.top .in { row-gap: .15rem; }
header.top nav { order: 5; flex: 1 1 100%; flex-wrap: wrap; }
header.top .brand { margin-right: auto; }
@media (max-width: 700px) { header.top .in { padding: .4rem .6rem; gap: .4rem; } header.top .in > .small { max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }
footer.foot { max-width: 1100px; margin: 1.5rem auto 2rem; padding: 0 1rem; text-align: center; color: var(--muted); font-size: .85rem; }
footer.foot a, footer.foot button { color: var(--muted); }
table.lib .hide-narrow { }
@media (max-width: 700px) { table.lib th.hide-narrow, table.lib td.hide-narrow { display: none !important; } table.lib td, table.lib th { padding: .5rem .35rem; } }
/* accessibility */
.skip { position: absolute; left: -999px; top: 0; background: var(--brand); color: var(--brand-ink); padding: .5rem .8rem; z-index: 100; border-radius: 0 0 8px 0; }
.skip:focus { left: 0; }
h1:focus, main:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }

details.more { position: relative; }
details.more > summary { list-style: none; cursor: pointer; padding: .4rem .7rem; border-radius: 6px; user-select: none; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary:hover, details.more.on > summary, details.more[open] > summary { background: var(--soft); }
details.more.on > summary { font-weight: 600; }
.more-menu { position: absolute; left: 0; top: calc(100% + .2rem); min-width: 12rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); z-index: 30; padding: .25rem; display: flex; flex-direction: column; }
.more-menu a { padding: .45rem .7rem; }
@media (max-width: 700px) { header.top nav { flex-wrap: nowrap; overflow-x: auto; } .more-menu { position: fixed; left: .6rem; right: .6rem; top: auto; } }

/* piece chooser */
dialog.chooser { max-width: 1120px; width: 96vw; height: min(92vh, 900px); padding: 0; overflow: hidden; }
dialog.chooser[open] { display: flex; flex-direction: column; }
.ch-head { display: flex; gap: .75rem; align-items: center; justify-content: space-between; padding: .75rem 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ch-head h2 { font-size: 1.1rem; }
.ch-head select { width: auto; }
.ch-body { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); flex: 1; min-height: 0; }
.ch-left, .ch-right { overflow-y: auto; padding: .75rem 1rem; min-height: 0; }
.ch-right { border-left: 1px solid var(--line); background: var(--soft); display: flex; flex-direction: column; gap: .5rem; }
.ch-filters select { width: auto; flex: 1 1 8rem; min-width: 7rem; }
.ch-list { display: flex; flex-direction: column; gap: .4rem; }
.ch-card { display: flex; gap: .6rem; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; background: var(--card); }
.ch-card.picked { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 8%, var(--card)); }
.ch-main { flex: 1; min-width: 0; }
.ch-star { border: 0; background: none; font-size: 1.3rem; line-height: 1; padding: .2rem .3rem; color: var(--warn); }
.ch-add { flex: none; min-width: 5.5rem; }
.ch-basket-list { flex: 1; overflow-y: auto; min-height: 4rem; }
.ch-item { display: flex; gap: .4rem; align-items: center; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.ch-item .ch-t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ch-item button { padding: .15rem .5rem; }
@media (max-width: 800px) {
  .ch-body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .ch-right { border-left: 0; border-top: 1px solid var(--line); max-height: 52vh; padding: .5rem .75rem; gap: .25rem; }
  .ch-right:not(.open) > :not(.ch-top):not(.ch-actions) { display: none; }
  .ch-right.open { max-height: 60vh; }
}
.ch-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.ch-toggle { display: none; }
@media (max-width: 800px) { .ch-toggle { display: inline-block; } }
/* notifications */
a.bell { text-decoration: none; padding: .3rem .5rem; border-radius: 6px; color: var(--ink); white-space: nowrap; }
a.bell:hover { background: var(--soft); }
a.notice.unread { border-left: 4px solid var(--accent); }
a.notice:hover { background: var(--soft); }

@media print { .runsheet table th, .runsheet table td { border-bottom: 1px solid #999; } .runsheet h1 { font-size: 1.6rem; } body { background: #fff; color: #000; } }
table.tidy input { padding: .3rem .4rem; }
table.tidy input.saved { outline: 2px solid var(--ok); }
