:root {
  --bg: #f6f5f1; --fg: #1d1d1f; --muted: #6b6b70; --line: #d9d7d0;
  --inh: #6b6b70; --ovr-bg: #fff1c2; --ovr-fg: #5a3e00; --accent: #2f5bd3;
  --bad: #b3261e; --ok: #1f7a3d; --cap: #8a4bd6;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
main { max-width: 760px; margin: 0 auto; padding: 16px 14px 96px; }
h1 { font-size: 1.35rem; margin: .2em 0; }
h2 { font-size: 1.05rem; margin: 1.4em 0 .4em; }
a { color: var(--accent); }
.back { text-decoration: none; font-size: .9rem; }
.lead { margin: .6em 0 1em; }
.hint, .note, .legend { color: var(--muted); font-size: .88rem; margin: .2em 0 .6em; }
.status { font-size: .9rem; color: var(--muted); margin: 0; }
.status.done { color: var(--ok); font-weight: 600; }
.error { color: var(--bad); font-weight: 600; }

.players { list-style: none; padding: 0; }
.players a { display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; margin: 8px 0; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; text-decoration: none; color: var(--fg); font-size: 1.1rem; }
.tag { font-size: .8rem; color: var(--muted); }
.tag.done { color: var(--ok); font-weight: 600; }

/* Map: the Astra's Broken Crown draft-map style (navy panel, tiles, marks). */
.map-panel { --tile-space: #172238; --tile-edge: #516584; --tile-text: #f2f6ff; --tile-home: #264b43;
  --tile-resource: #ffed88; --tile-influence: #b5dcff; --tile-alpha: #ffb35a; --tile-beta: #86dfb1;
  background: #0c1220; border: 1px solid #263144; border-radius: 12px; overflow: hidden; margin: 0 0 1em; }
.map { width: 100%; max-height: 52vh; display: block; margin: 0 auto; padding: 8px 6px 4px; }
.hex .tile { fill: var(--tile-space); stroke: var(--tile-edge); stroke-width: 1; vector-effect: non-scaling-stroke; }
.hex.home .tile { fill: var(--tile-home); stroke: #416554; }
.hex text { font-family: Arial, Helvetica, sans-serif; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.hex .poslabel { font-weight: 700; }
.hex .faction, .hex .val { font-weight: 500; }
.hex .pname { font-weight: 600; }
.hex .worm { font-weight: 500; }
.hex.pickable { cursor: pointer; }
.hex.pickable .tile { stroke: var(--position-color); stroke-width: 2.5; stroke-opacity: .6; transition: fill .15s, stroke-width .15s; }
.hex.pickable:hover .tile, .hex.pickable:focus .tile { stroke-width: 4; stroke-opacity: 1;
  fill: color-mix(in srgb, var(--position-color) 18%, var(--tile-home)); }
.hex.pickable:focus { outline: none; }
.hex .beacon { pointer-events: none; }
.hex.claimed .tile { fill: #111b2b; stroke: var(--position-color); stroke-width: 3; }
.map-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; border-top: 1px solid #202b3d;
  padding: 9px 14px; font: 11px/1.3 Arial, Helvetica, sans-serif; color: #95a4bd; }
.map-legend > span { display: flex; gap: 5px; align-items: center; }
.map-legend .a { color: var(--tile-alpha); }
.map-legend .b { color: var(--tile-beta); }
.map-legend b { font-weight: 400; color: #e9cd71; }
.legend-hex { width: 10px; height: 11px; background: var(--tile-home); clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.field { display: flex; flex-direction: column; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; }
.field span { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field input { border: 0; font-size: 1.15rem; padding: 2px 0; background: transparent; width: 100%; outline: none; }
.field:focus-within { border-color: var(--accent); }
input.bad { color: var(--bad); }
.field:has(input.bad) { border-color: var(--bad); }

.matrixwrap { overflow-x: auto; }
.matrix { border-collapse: collapse; width: 100%; min-width: 330px; table-layout: fixed; background: #fff; }
.matrix thead th:first-child { width: 2.6em; }
.matrix th { font-size: .78rem; color: var(--muted); font-weight: 600; padding: 4px; }
.matrix tbody th { text-align: left; white-space: nowrap; }
.matrix td { border: 1px solid var(--line); text-align: center; position: relative; padding: 0; height: 44px; }
.matrix td.inh .cell { color: var(--inh); font-weight: 400; }
.matrix td.ovr { background: var(--ovr-bg); }
.matrix td.ovr .cell { color: var(--ovr-fg); font-weight: 700; }
.cell { width: 100%; height: 100%; border: 0; background: transparent; font-size: 1rem; cursor: pointer; padding: 0 4px; }
.cell:disabled { cursor: default; }
.cellinput { width: 100%; height: 100%; border: 2px solid var(--accent); text-align: center; font-size: 1rem; }
.reset { position: absolute; top: 0; right: 0; border: 0; background: transparent; color: var(--ovr-fg);
  font-size: .8rem; padding: 1px 3px; cursor: pointer; }
.cap { position: absolute; bottom: 1px; left: 2px; font-size: .58rem; color: var(--cap); font-weight: 700; pointer-events: auto; }
.legend .sw { display: inline-block; min-width: 2.4em; padding: 0 4px; margin: 0 4px 0 10px;
  border: 1px solid var(--line); text-align: center; position: relative; background: #fff; }
.legend .sw:first-child { margin-left: 0; }
.legend .sw.inh { color: var(--inh); }
.legend .sw.ovr { background: var(--ovr-bg); color: var(--ovr-fg); font-weight: 700; }
.legend .sw .cap { position: static; }

.advanced { margin: 1.4em 0; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.advanced summary { cursor: pointer; font-weight: 600; }

.bar { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line);
  display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 14px; }
.dirty { margin-right: auto; font-size: .85rem; color: var(--muted); }
.bar button { font-size: 1rem; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.bar button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.bar button:disabled { opacity: .45; }

/* advanced panel */
.pick { display: flex; flex-wrap: wrap; gap: 6px; margin: .6em 0; }
.pick button { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 6px 12px; font-size: .95rem; }
.pick button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.pick .n { font-size: .72rem; margin-left: 4px; opacity: .8; }
.rows { list-style: none; padding: 0; margin: .3em 0 .8em; }
.rows li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.rows li .what { flex: 1; min-width: 0; }
.rows li .what small { display: block; color: var(--muted); font-size: .78rem; }
.vbox { position: relative; width: 74px; height: 40px; border: 1px solid var(--line); text-align: center; background: #fff; }
.vbox.ovr { background: var(--ovr-bg); }
.vbox.inh .cell { color: var(--inh); }
.vbox.ovr .cell { color: var(--ovr-fg); font-weight: 700; }
.addform { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: .4em; }
.addform select, .addform input { font-size: 1rem; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%; }
.addform .full { grid-column: 1 / -1; }
.addform button { font-size: 1rem; padding: 9px; border-radius: 8px; border: 1px solid var(--accent); background: var(--accent); color: #fff; }
h3 { font-size: .95rem; margin: 1em 0 .2em; }

/* results */
.links { display: flex; gap: 16px; margin: 1em 0; }
.summary { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 1em 0; }
.summary b { font-size: 1.15rem; }
.order { padding-left: 1.4em; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 10px 0; }
.card h3 { margin: 0 0 .2em; font-size: 1.05rem; }
.card .meta { color: var(--muted); font-size: .88rem; margin-bottom: .5em; }
.lines { width: 100%; border-collapse: collapse; font-size: .92rem; }
.lines td { padding: 3px 0; vertical-align: top; }
.lines td.v { text-align: right; white-space: nowrap; padding-left: 10px; font-variant-numeric: tabular-nums; }
.lines tr.tot td { border-top: 1px solid var(--line); font-weight: 700; }
.src { display: inline-block; font-size: .72rem; border-radius: 4px; padding: 0 5px; margin-left: 4px; background: #eceae4; color: var(--muted); }
.src.ovr { background: var(--ovr-bg); color: var(--ovr-fg); }
.src.capped { background: #efe3fb; color: var(--cap); }
.tg { font-size: 1.1rem; font-weight: 700; color: var(--ok); }
details.alt { font-size: .82rem; color: var(--muted); margin-top: .3em; }
.factionform .field { margin: 6px 0; }
.ok { color: var(--ok); font-weight: 600; }
