:root {
  --bg: #14110e; --panel: #1e1915; --panel2: #272019; --line: #3a3128; --text: #e9e1d4; --muted: #a39683;
  --gold: #d4a64a; --gold-dim: #8b6a2a; --ok: #7fb069; --bad: #d96a5b; --warn: #e0a64a;
  --radius: 8px; --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; font-weight: 600; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; font-weight: 600; color: var(--gold); letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }

.top { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top .in { max-width: 1240px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-height: 52px; }
.brand { font-weight: 700; color: var(--gold); margin-right: 14px; letter-spacing: .04em; }
.top nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.top nav a { color: var(--text); padding: 8px 12px; border-radius: 6px; }
.top nav a:hover { background: var(--panel2); text-decoration: none; }
.top nav a.on { background: var(--panel2); color: var(--gold); }
.top form { margin: 0; display: flex; align-items: center; gap: 10px; }

main { max-width: 1240px; margin: 0 auto; padding: 24px 16px 64px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.stat { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.stat:last-child { border-bottom: 0; }
.stat b { font-weight: 600; }
.big { font-size: 2rem; font-weight: 700; line-height: 1.1; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: .78rem; border: 1px solid var(--line); background: var(--panel2); }
.pill.ok { color: var(--ok); border-color: #3d5a33; }
.pill.bad { color: var(--bad); border-color: #6b3028; }
.pill.warn { color: var(--warn); border-color: #6b5328; }
.pill.gold { color: var(--gold); border-color: var(--gold-dim); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: .82rem; white-space: nowrap; }
tr:hover td { background: rgba(255, 255, 255, .02); }
.scroll { overflow-x: auto; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

input, select, button { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; }
input:focus, select:focus { outline: 2px solid var(--gold-dim); outline-offset: 1px; }
button { cursor: pointer; background: var(--gold); color: #1a1409; border-color: var(--gold); font-weight: 600; }
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); font-weight: 400; }
button.danger { background: var(--bad); border-color: var(--bad); color: #190a08; }
form.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { color: var(--muted); font-size: .85rem; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid var(--line); }
.flash.ok { border-color: #3d5a33; background: rgba(127, 176, 105, .1); }
.flash.err { border-color: #6b3028; background: rgba(217, 106, 91, .1); }

.chart { width: 100%; height: auto; display: block; }
.chart polyline { fill: none; stroke: var(--gold); stroke-width: 2; stroke-linejoin: round; }
.chart line { stroke: var(--line); }

pre { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow: auto; max-height: 460px; margin: 0; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }

.login { max-width: 360px; margin: 14vh auto 0; padding: 0 16px; }
.login .card { padding: 26px; }
.login input { width: 100%; }
.login button { width: 100%; margin-top: 6px; }

.mb { margin-bottom: 16px; }
.mt { margin-top: 22px; }
.grow { flex: 1; min-width: 200px; }
.short { width: 150px; }
.narrow { max-width: 460px; }
.narrow input { width: 100%; }
a.tile { color: var(--text); display: block; }
a.tile:hover { border-color: var(--gold-dim); text-decoration: none; }
a.tile .big { color: var(--gold); }


main.wide { max-width: none; padding: 16px 16px 40px; }
.top nav.tech { flex: 0 0 auto; margin-left: auto; padding-left: 10px; border-left: 1px solid var(--line); }
.top nav.tech a { color: var(--muted); }
.top nav.tech a.on { color: var(--gold); }
.top nav { flex: 0 1 auto; }
h1 + .card, h2 + .card { margin-top: 0; }

.mapwrap { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.mapbox { position: relative; background: #0e0c0a; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; height: calc(100vh - 120px); min-height: 420px; }
#map { display: block; cursor: grab; touch-action: none; }
#map:active { cursor: grabbing; }
.maptools { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; }
.maptools button { width: 36px; height: 36px; padding: 0; font-size: 1.1rem; background: rgba(30, 25, 21, .9); }
.mapinfo { position: absolute; left: 10px; bottom: 10px; background: rgba(20, 17, 14, .85); border: 1px solid var(--line); border-radius: 6px; padding: 3px 9px; }
.mapside { display: grid; gap: 16px; }
.plist { display: grid; gap: 4px; max-height: 300px; overflow: auto; }
.prow { display: flex; justify-content: space-between; gap: 8px; width: 100%; text-align: left; background: var(--panel2); color: var(--text); border: 1px solid var(--line); font-weight: 400; }
.prow.sel { border-color: var(--gold); }
.check { display: flex; gap: 8px; align-items: center; padding: 3px 0; cursor: pointer; }

.sub { padding: 10px 0; border-bottom: 1px solid var(--line); }
.sub:last-child { border-bottom: 0; }
.sub ul { margin: 6px 0 0; padding-left: 20px; }
details.chest { margin: 8px 0 0 12px; }
details summary { cursor: pointer; padding: 3px 0; }
.danger-zone { border-color: #6b3028; }

.docs { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.toc { position: sticky; top: 68px; max-height: calc(100vh - 90px); overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.toc a { color: var(--text); font-size: .88rem; padding: 3px 6px; border-radius: 4px; }
.toc a.l1 { font-weight: 600; margin-top: 6px; }
.toc a.l2 { padding-left: 16px; color: var(--muted); }
.toc a:hover { background: var(--panel2); text-decoration: none; }
.md h1 { font-size: 1.4rem; } .md h2 { font-size: 1.15rem; margin-top: 28px; padding-top: 10px; border-top: 1px solid var(--line); }
.md h3 { font-size: 1rem; margin: 18px 0 6px; }
.md code { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md table { margin: 10px 0; display: block; overflow-x: auto; }
.md p, .md li { max-width: 90ch; }

.linkbox { border-color: var(--gold-dim); }
.linkfield { width: 100%; }
.permgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 2px 18px; }
.pwbox { font-size: 1.5rem; letter-spacing: .08em; background: var(--panel2); border: 1px dashed var(--gold-dim); border-radius: 6px; padding: 10px 14px; margin: 6px 0 0; user-select: all; }
.gain { color: var(--ok); } .loss { color: var(--bad); }

.chip { background: var(--panel2); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.chip.on { border-color: var(--gold); color: var(--gold); }
table.matrix th, table.matrix td { text-align: center; }
table.matrix th:first-child, table.matrix td:first-child { text-align: left; }
table.matrix th.role-col { cursor: pointer; }
table.matrix .group td { background: var(--panel2); color: var(--gold); font-weight: 600; text-align: left; font-size: .85rem; letter-spacing: .04em; }
table.matrix .sel { background: rgba(212, 166, 74, .13); }
table.matrix .yes { color: var(--ok); font-weight: 700; } table.matrix .no { color: var(--muted); }

@media (max-width: 900px) {
  .mapwrap, .docs { grid-template-columns: 1fr; }
  .mapbox { height: 60vh; }
  .toc { position: static; max-height: 220px; }
}

@media (max-width: 640px) {
  main { padding-top: 16px; }
  .big { font-size: 1.6rem; }
  th, td { padding: 7px 6px; }
}
