:root {
  --bg: #0f1218;
  --panel: #161b24;
  --panel-2: #1d2430;
  --line: #2a3342;
  --text: #e6e9ef;
  --muted: #8f9aab;
  --accent: #ffd84a;
  --card: #141922;
  --done: #6fdc8c;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
body { min-height: 100vh; display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

.top { position: sticky; top: 0; z-index: 4; background: rgba(15,18,24,.96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); padding: 12px 16px 0; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top h1 { font-size: 19px; margin: 0; letter-spacing: .3px; }
.top h1 span { color: var(--accent); font-weight: 500; }
.back { font-size: 13px; text-decoration: none; border: 1px solid var(--line); padding: 5px 10px; border-radius: 7px; color: var(--text); white-space: nowrap; }
.back:hover { border-color: var(--accent); }
.links { display: flex; gap: 8px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0 10px; }
#q { flex: 1 1 260px; min-width: 0; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); outline: none; }
#q:focus { border-color: var(--accent); }
.right { display: flex; gap: 10px; align-items: center; }
.sel { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.sel select { background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; color: var(--text); max-width: 46vw; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { background: var(--panel); border: none; padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }
.cats { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; }
.cats::-webkit-scrollbar { display: none; }
.cats.more-r { -webkit-mask-image: linear-gradient(to left, transparent, #000 44px); mask-image: linear-gradient(to left, transparent, #000 44px); }
.cats.more-l { -webkit-mask-image: linear-gradient(to right, transparent, #000 44px); mask-image: linear-gradient(to right, transparent, #000 44px); }
.cats.more-l.more-r { -webkit-mask-image: linear-gradient(to right, transparent, #000 44px, #000 calc(100% - 44px), transparent); mask-image: linear-gradient(to right, transparent, #000 44px, #000 calc(100% - 44px), transparent); }
.cats button:hover { color: var(--text); }
.cats button { background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 10px; cursor: pointer; color: var(--muted); white-space: nowrap; font-size: 14px; }
.cats button.on { color: var(--text); border-bottom-color: var(--accent); }
.cats .n { font-size: 11px; color: var(--muted); background: var(--panel-2); border-radius: 9px; padding: 0 6px; margin-left: 5px; }

main { flex: 1; padding: 16px; }
.msg { color: var(--muted); margin: 8px 2px 16px; font-size: 14px; }
.msg:empty { display: none; }
.linkbtn { background: none; border: none; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font-size: inherit; }
.linkbtn:hover { color: var(--text); }
.ghead { grid-column: 1 / -1; margin: 14px 2px 0; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.ghead:first-child { margin-top: 0; }
.ghead .n { font-size: 11px; background: var(--panel-2); border-radius: 9px; padding: 1px 7px; letter-spacing: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 6px; transition: border-color .12s, transform .12s; }
.card:hover, .card:focus-visible { border-color: var(--accent); outline: none; }
.card .pic { aspect-ratio: 1; border-radius: 7px; background: radial-gradient(circle at 50% 42%, #2a3344 0%, #161b24 72%); display: grid; place-items: center; overflow: hidden; }
.card .pic img { width: 100%; height: 100%; object-fit: contain; }
.card .pic img.flat { width: 50%; height: 50%; image-rendering: pixelated; }
.card .nm { font-weight: 600; font-size: 14px; line-height: 1.25; }
.card .sub { font-size: 12px; color: var(--muted); line-height: 1.35; }

.tnote { color: var(--muted); font-size: 12.5px; line-height: 1.45; margin: 0 2px 10px; }
.tnote b { color: var(--text); font-weight: 600; }
.tnote:empty { display: none; }
.tnote details { display: inline; }
.tnote summary { display: inline; cursor: pointer; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.tnote summary:hover { color: var(--text); }
.tnote details > div { margin-top: 6px; }
/* The table scrolls in its own box (sized by fitTable in items.js), which keeps its headings in sight. */
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: separate; border-spacing: 0; font-size: 13px; width: max-content; min-width: 100%; }
th, td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
thead { position: sticky; top: 0; z-index: 3; }
th { background: var(--panel); font-weight: 600; user-select: none; font-size: 11.5px; line-height: 1.25; color: var(--muted); vertical-align: bottom; }
th.sortable, th.c0 { cursor: pointer; }
th.sortable:hover, th.c0:hover, th.sorted { color: var(--text); }
th.sorted::after { content: " \25BE"; color: var(--accent); }
th.sorted.asc::after { content: " \25B4"; }
/* headings wrap to a few short lines (width set per heading in items.js) */
th .hl { white-space: normal; margin-left: auto; }
th.txt .hl { margin-left: 0; }
th.sorted .hl { display: inline-block; vertical-align: bottom; }
/* "Primary X" / "Secondary X": one heading over two narrow columns, with a faint rule either side of the pair */
th.grp { text-align: center; border-bottom: none; padding-bottom: 2px; color: var(--muted); border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
th.grp .hl { margin: 0 auto; text-align: center; }
th.sub { font-weight: 500; padding-top: 2px; border-left: 1px solid var(--line); }
th.sub2 { border-left: none; border-right: 1px solid var(--line); }
td.p1 { border-left: 1px solid var(--line); }
td.p2 { border-right: 1px solid var(--line); }
td.scol { background: rgba(255,216,74,.06); }
/* the item name stays put while the stats scroll sideways */
.c0 { text-align: left; position: sticky; left: 0; background: var(--panel); z-index: 1; border-right: 1px solid var(--line); }
tbody tr:focus-visible { outline: none; }
tbody tr:focus-visible td { background: var(--panel-2); box-shadow: inset 0 2px var(--accent), inset 0 -2px var(--accent); }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--panel-2); }
.nmcell { display: flex; align-items: center; gap: 8px; min-width: 180px; }
.nmcell img { width: 30px; height: 30px; object-fit: contain; flex: none; }
/* stats only a few items have: listed in one cell as "name value" */
td.other { white-space: normal; min-width: 220px; max-width: 460px; line-height: 1.5; }
.okv { display: inline-block; margin-right: 12px; white-space: nowrap; }
.okv .k { color: var(--muted); }
td.dflt, .dflt { color: var(--muted); font-style: italic; }
td.empty { color: #3d4757; }
.kv td.none { color: var(--muted); }
td.txt, th.txt { text-align: left; }

#detail { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 10; overflow-y: auto; padding: 18px 18px 28px; box-shadow: -10px 0 30px rgba(0,0,0,.35); }
#detail { overscroll-behavior: contain; }
#detail:focus { outline: none; }
#detail[hidden], #scrim[hidden] { display: none; }
#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 9; }
.close { position: absolute; top: 10px; right: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 34px; font-size: 20px; line-height: 1; cursor: pointer; z-index: 1; }
.close:hover { border-color: var(--accent); }
.dnav { display: flex; align-items: center; gap: 6px; margin-right: 44px; min-height: 34px; }
.dnav button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.dnav button:hover:not(:disabled) { border-color: var(--accent); }
.dnav button:disabled { opacity: .4; cursor: default; }
.dnav .pos { color: var(--muted); font-size: 12px; margin-left: 4px; font-variant-numeric: tabular-nums; }
.hero { aspect-ratio: 1; max-width: 340px; margin: 6px auto 12px; border-radius: 12px; background: radial-gradient(circle at 50% 42%, #2c3547 0%, #161b24 70%); display: grid; place-items: center; }
.hero img { width: 100%; height: 100%; object-fit: contain; }
.hero img.flat { width: 40%; height: 40%; image-rendering: pixelated; }
#detail h2 { margin: 0 40px 4px 0; font-size: 21px; line-height: 1.25; }
.cat { color: var(--accent); font-size: 12.5px; text-transform: uppercase; letter-spacing: .6px; }
.effect { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 2px 12px 10px; margin: 0 0 14px; }
.effect h3 { margin-top: 10px !important; }
.effect p { margin: 0; font-size: 14px; line-height: 1.5; }
.desc { white-space: pre-line; line-height: 1.5; font-size: 14px; color: #cfd5df; margin: 12px 0 16px; }
#detail h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 18px 0 6px; font-weight: 600; }
.kv { width: 100%; font-size: 13.5px; }
.kv td { padding: 5px 2px; text-align: left; white-space: normal; }
.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.kv td:first-child { position: static; background: none; color: #c3cad6; }
.legend { font-size: 12px; color: var(--muted); margin-top: 6px; }
.maplinks { display: flex; flex-wrap: wrap; gap: 6px; }
.maplinks a { font-size: 13px; border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; text-decoration: none; color: var(--text); }
.maplinks a:hover { border-color: var(--accent); }
.src { font-size: 13.5px; margin: 10px 0 6px; }
.src a { color: var(--accent); }
.path { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: var(--muted); word-break: break-all; margin-top: 18px; }
.permalink { font-size: 12.5px; margin-top: 10px; display: inline-block; }
.foot { color: var(--muted); font-size: 12px; padding: 14px 16px 22px; border-top: 1px solid var(--line); }

/* ---- what a loaded save adds (saveui.js): the save bar above the list, and the marks on cards, rows and the panel */
.savebar { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0 0 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; transition: border-color .12s; }
.savebar:empty { display: none; }
.savebar.over { border-color: var(--accent); border-style: dashed; }
.save-sum { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.save-line { font-size: 13.5px; line-height: 1.45; overflow-wrap: anywhere; }
.save-line.muted { color: var(--muted); font-size: 12.5px; }
.save-total { font-size: 14px; }
.save-total b { font-size: 17px; font-variant-numeric: tabular-nums; }
.save-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.save-pick { position: relative; display: inline-block; font-size: 13.5px; border: 1px solid var(--accent); color: var(--accent); border-radius: 7px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.save-pick:hover, .save-pick:focus-within { background: rgba(255,216,74,.1); }
.save-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.save-actions .linkbtn { font-size: 13px; }
.save-hint { flex: 1 1 100%; margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.save-hint code { color: var(--text); overflow-wrap: anywhere; }
.save-hint.warn { color: #f0a64a; }
.sel select:disabled { opacity: .5; }
.bar { flex: 1; height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; min-width: 40px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.big { height: 8px; flex: none; max-width: 520px; width: 100%; }
.state { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; border-radius: 4px; padding: 0 5px; line-height: 17px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.state.done { background: rgba(111,220,140,.16); color: var(--done); }
/* green: done, recorded, obtained. Grey picture: not yet. A hollow mark or a fainter edge: had once, not held now. */
.card { position: relative; }
.card.is-done { border-color: rgba(111,220,140,.35); }
.card.is-had { border-color: rgba(111,220,140,.2); }
.card.is-todo .pic img, tr.is-todo .nmcell img, .hero.is-todo img { filter: grayscale(.85) brightness(.7); }
.card.is-todo:hover .pic img, .card.is-todo:focus-visible .pic img { filter: none; }
.mark { position: absolute; top: 16px; right: 16px; width: 20px; height: 20px; border-radius: 50%; background: var(--done); box-shadow: 0 0 0 2px var(--card); pointer-events: none; }
.mark::after { content: ""; position: absolute; left: 7px; top: 3.5px; width: 4px; height: 9px; border: solid #0f1218; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.mark.had { background: var(--card); box-shadow: inset 0 0 0 1.5px var(--done), 0 0 0 2px var(--card); }
.mark.had::after { border-color: var(--done); }
.card .sub .sv { color: var(--done); }
tr.is-done .c0 { box-shadow: inset 3px 0 var(--done); }
tr.is-had .c0 { box-shadow: inset 3px 0 rgba(111,220,140,.4); }
td.sv { color: var(--done); }
td.sv.had { color: var(--muted); }
.cstatus { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--muted); border-radius: 8px; padding: 8px 12px; font-size: 14px; line-height: 1.45; margin: 10px 0 6px; }
.cstatus.is-done, .cstatus.is-had { border-left-color: var(--done); }
.cstatus.is-done b { color: var(--done); }
.cstatus .src2 { color: var(--muted); font-size: 12.5px; }
.cstatus .more { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.ck { display: inline-block; width: 1.2em; text-align: center; color: #4d586a; font-weight: 700; }
.ck.yes { color: var(--done); }

@media (max-width: 600px) {
  main { padding: 12px; }
  .savebar { padding: 10px 12px; }
  .mark { top: 14px; right: 14px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .right { width: 100%; justify-content: space-between; flex-wrap: wrap; row-gap: 8px; }
  #detail { width: 100vw; border-left: none; }
  .nmcell { min-width: 0; width: 132px; white-space: normal; line-height: 1.25; }
  .nmcell img { width: 26px; height: 26px; }
  th, td { padding: 5px 7px; }
  td.other { min-width: 200px; max-width: 300px; }
  .hero { max-width: 260px; }
}
