:root {
  /* Layout: full-bleed map canvas; HUD strip on top, tool rail bottom-left, ledger panel on the right
     (bottom sheet on phones), minimap bottom-right. Single dark "lamplit ledger" look by choice. */
  --ink: #efe7d2;
  --muted: #a5b09c;
  --panel: rgba(18, 26, 21, .94);
  --panel-2: #1f2c24;
  --panel-solid: #141c17;
  --line: #3a4b3f;
  --brass: #d8a64a;
  --brass-ink: #1c150a;
  --good: #86c86f;
  --warn: #e8b44c;
  --bad: #e46a5c;
  --sea: #18324b;
  --font-display: 'IM Fell English SC', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-body: 'Alegreya Sans', 'Gill Sans', 'Segoe UI', system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--sea); color: var(--ink); font: 15px/1.4 var(--font-body); -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
#ground, #view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#view { touch-action: none; }
#view.roading { cursor: crosshair; }

.hud { position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: center; gap: 14px; padding: calc(env(safe-area-inset-top, 0px) + 7px) 14px 7px; background: linear-gradient(var(--panel), rgba(18, 26, 21, .82)); border-bottom: 1px solid var(--line); box-shadow: 0 1px 0 rgba(216, 166, 74, .18); }
.brand { font: 24px/1 var(--font-display); color: var(--brass); letter-spacing: .02em; white-space: nowrap; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1; }
.chips::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px 2px 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2); font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.chip img { width: 20px; height: 20px; }
.chip.low { border-color: var(--warn); color: var(--warn); }
.chip .tr { font-style: normal; font-size: 9px; margin-left: 1px; }
.chip .tr.up { color: var(--good); }
.chip .tr.dn { color: var(--bad); }
.chips.more { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); }
.panel.more { -webkit-mask-image: linear-gradient(#000 calc(100% - 40px), rgba(0, 0, 0, .25)); mask-image: linear-gradient(#000 calc(100% - 40px), rgba(0, 0, 0, .25)); }
.hud-right { display: flex; align-items: center; gap: 10px; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 3.2em; text-align: right; }
.speed { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.speed button { background: transparent; border: 0; padding: 4px 9px; cursor: pointer; font-variant-numeric: tabular-nums; }
.speed button + button { border-left: 1px solid var(--line); }
.speed button.on { background: var(--brass); color: var(--brass-ink); font-weight: 700; }
.icon-btn { background: transparent; border: 1px solid var(--line); border-radius: 8px; width: 34px; height: 30px; display: grid; place-items: center; cursor: pointer; }
.icon-btn .mute, .icon-btn.off .wave { display: none; }
.icon-btn.off .mute { display: inline; }
.icon-btn.off { color: var(--muted); }

.feed { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 56px); left: 12px; z-index: 4; margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; max-width: min(380px, calc(100% - 24px)); pointer-events: none; }
.feed li { pointer-events: auto; cursor: pointer; padding: 6px 12px; background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--muted); border-radius: 6px; font-size: 14px; animation: drop .25s ease-out; transition: opacity .6s; }
.feed li.good { border-left-color: var(--good); }
.feed li.warn { border-left-color: var(--warn); }
.feed li.bad { border-left-color: var(--bad); }
.feed li.old { opacity: 0; }
@keyframes drop { from { transform: translateY(-6px); opacity: 0; } }

.tools { position: fixed; left: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); z-index: 5; display: flex; gap: 6px; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.tools button { display: grid; justify-items: center; gap: 2px; width: 62px; padding: 6px 2px 4px; background: transparent; border: 1px solid transparent; border-radius: 8px; cursor: pointer; font-size: 12px; color: var(--muted); }
.tools button svg { width: 24px; height: 24px; color: var(--ink); }
.tools button:hover { border-color: var(--line); color: var(--ink); }
.tools button.on { background: var(--brass); color: var(--brass-ink); }
.tools button.on svg { color: var(--brass-ink); }

.panel { position: fixed; right: 12px; top: calc(env(safe-area-inset-top, 0px) + 58px); z-index: 6; width: 352px; max-height: calc(100% - 300px); min-height: 120px; overflow-y: auto; padding: 14px 16px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); }
.panel .close { position: absolute; top: 6px; right: 8px; width: 30px; height: 30px; border: 0; background: transparent; font-size: 22px; color: var(--muted); cursor: pointer; }
.panel h2 { margin: 0 32px 2px 0; font: 23px/1.1 var(--font-display); color: var(--brass); text-wrap: balance; display: flex; align-items: center; gap: 8px; }
.panel h2 img { width: 40px; height: 40px; object-fit: contain; }
.panel h3 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 700; }
.sub { margin: 0 0 8px; color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .03em; border: 1px solid currentColor; }
.pill.good { color: var(--good); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); } .pill.muted { color: var(--muted); }
.bar { height: 7px; border-radius: 4px; background: #0d1410; border: 1px solid var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brass); }
.rows { display: grid; gap: 4px; }
.row { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.row .grow { flex: 1; min-width: 0; }
.row img { width: 22px; height: 22px; }
.goods { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 4px; }
.goods .g { display: flex; align-items: center; gap: 3px; padding: 2px 4px; background: var(--panel-2); border-radius: 6px; font-variant-numeric: tabular-nums; font-size: 14px; }
.goods .g img { width: 20px; height: 20px; }
.goods .g.zero { opacity: .4; }
.glist { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px 14px; }
.glist div { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.glist span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.glist b { font-weight: 500; font-variant-numeric: tabular-nums; }
.glist img { width: 20px; height: 20px; }
.note.none img { width: 18px; height: 18px; opacity: .55; vertical-align: middle; }
.card .tl { display: inline-flex; align-items: center; gap: 1px; margin-left: auto; padding: 0 5px 0 2px; border-radius: 999px; background: rgba(255, 255, 255, .06); }
.card .tl.miss { color: var(--bad); background: rgba(224, 103, 90, .14); }
.pips { display: inline-flex; gap: 2px; margin-left: 6px; vertical-align: middle; }
.pips .rank { width: 14px; height: 14px; font-size: 9px; line-height: 14px; }
.gi3 { display: inline-flex; width: 58px; }
.gi3 img { width: 18px; height: 18px; }
.actions .pill { align-self: center; }
.tabs { display: flex; gap: 2px; margin: 10px 0 8px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 5px 8px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--brass); }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.card { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 2px 6px; padding: 6px; text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.card img.b { grid-row: span 2; width: 44px; height: 44px; object-fit: contain; }
.card b { font-weight: 500; font-size: 14px; line-height: 1.15; }
.card .cost { display: flex; gap: 4px; align-items: center; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card .cost img { width: 16px; height: 16px; }
.card:hover:not(:disabled) { border-color: var(--brass); }
.card:disabled { opacity: .38; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.coffee { flex-basis: 100%; display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 6px; color: var(--muted); font-size: 13.5px; text-decoration: none; }
.coffee:hover, .coffee:focus-visible { color: var(--brass); }
.coffee svg { width: 17px; height: 17px; flex: none; }
/* The main buttons of a long sheet stay in view at its foot. */
.sheet > .actions { position: sticky; bottom: -24px; margin: 14px -24px -24px; padding: 12px 24px 18px; background: linear-gradient(rgba(20, 28, 23, 0), var(--panel-solid) 35%); }
.btn { padding: 7px 12px; border-radius: 8px; border: 1px solid var(--brass); background: transparent; color: var(--ink); cursor: pointer; font-weight: 500; }
.btn.primary { background: var(--brass); color: var(--brass-ink); font-weight: 700; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.danger.primary { background: var(--bad); color: #1d0b08; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.stepper button { width: 28px; height: 26px; border: 0; background: var(--panel-2); cursor: pointer; }
.stepper span { min-width: 30px; text-align: center; font-variant-numeric: tabular-nums; }
.ranks { display: flex; flex-wrap: wrap; gap: 4px; }
.rank { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #111; }
.note { color: var(--muted); font-size: 13.5px; margin: 6px 0 0; }
.link { background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline dotted; cursor: pointer; text-align: left; }

.hint { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom, 0px) + 94px); z-index: 6; padding: 8px 14px; background: var(--panel); border: 1px solid var(--brass); border-radius: 999px; font-size: 14px; max-width: calc(100% - 32px); text-align: center; }
.minimap { position: fixed; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); z-index: 5; padding: 5px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.minimap canvas { display: block; width: 200px; height: 200px; border-radius: 6px; cursor: pointer; touch-action: none; }

.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(8, 13, 10, .5); backdrop-filter: blur(2px); }
.sheet { width: min(560px, 100%); max-height: calc(100% - 32px); overflow-y: auto; padding: 22px 24px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.xbar { position: sticky; top: 0; height: 0; display: flex; justify-content: flex-end; z-index: 2; }
.xbar .x { margin: -12px -14px 0 0; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel-solid); color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; }
.xbar .x:hover { color: var(--ink); }
.sheet h1 { margin: 0; font: clamp(44px, 9vw, 64px)/1 var(--font-display); color: var(--brass); letter-spacing: .01em; }
.sheet h2 { margin: 0 0 8px; font: 30px/1.1 var(--font-display); color: var(--brass); }
.sheet .lede { margin: 6px 0 18px; color: var(--muted); max-width: 46ch; }
.opt { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 8px; margin: 10px 0; }
.opt label.k { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 5px 11px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.seg input:checked + label { background: var(--brass); color: var(--brass-ink); border-color: var(--brass); font-weight: 700; }
.seg input:focus-visible + label { outline: 2px solid var(--brass); outline-offset: 2px; }
.seed { width: 120px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); font: inherit; font-variant-numeric: tabular-nums; }
.sheet.wide { width: min(780px, 100%); }
.guide h3 { margin: 18px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .09em; color: var(--brass); }
.guide p { margin: 0 0 10px; max-width: 68ch; }
.guide b { color: var(--brass); font-weight: 500; }
.guide .lede { max-width: 68ch; }
.steps { margin: 0 0 10px; padding-left: 22px; display: grid; gap: 4px; }
.steps li::marker { color: var(--brass); font-weight: 700; }
.sites, .badges { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 12px; }
.sites span, .badges span { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.sites img { width: 22px; height: 24px; object-fit: contain; }
.bdg { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: #1c150a; font: 700 12px/1 sans-serif; font-style: normal; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }
.codex { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 8px; }
.cx { display: grid; grid-template-columns: 52px 1fr; gap: 8px; padding: 8px; background: var(--panel-2); border-radius: 8px; }
.cx img.b { width: 52px; height: 52px; object-fit: contain; transform: scale(1.2); }
.guide .ranks { margin: 4px 0 10px; }
.cx b { display: block; font-size: 15px; }
.cx .note { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; margin: 1px 0 3px; font-size: 12.5px; }
.cx .note img, .cx .chain img { width: 18px; height: 18px; }
.cx p { margin: 3px 0 0; font-size: 13.5px; color: var(--muted); }
.gchain { padding: 8px 10px; margin: 0 0 8px; background: var(--panel-2); border-radius: 8px; }
.gchain b { display: block; margin-bottom: 2px; }
.gchain p { margin: 2px 0 0; font-size: 13.5px; color: var(--muted); }
.keys { width: 100%; border-collapse: collapse; margin: 4px 0 12px; font-size: 14px; }
.keys th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 8px 6px 0; }
.keys td { padding: 6px 8px 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
kbd { display: inline-block; min-width: 20px; padding: 0 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--panel-2); font: 600 12px/18px var(--font-body); text-align: center; }
.faq dt { margin-top: 10px; color: var(--ink); font-weight: 700; }
.faq dd { margin: 2px 0 0; color: var(--muted); }
.intro { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: -6px 0 10px; padding: 0; }
.intro li { display: grid; grid-template-columns: 44px 1fr; column-gap: 8px; align-items: center; padding: 8px; background: var(--panel-2); border-radius: 8px; }
.intro img { grid-row: span 2; width: 44px; height: 40px; object-fit: contain; transform: scale(1.3); }
.intro b { color: var(--brass); font-weight: 700; }
.intro span { font-size: 13px; line-height: 1.3; color: var(--muted); }
.about { margin: -2px 0 8px; font-size: 13.5px; color: var(--muted); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.pulse { animation: pulse 1.1s ease-in-out 4; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(216, 166, 74, .55); border-color: var(--brass); } }
.chain { display: inline-flex; flex-wrap: wrap; align-items: center; vertical-align: middle; gap: 3px; margin: 2px 12px 4px 0; font-size: 13px; color: var(--muted); }
.chain img { width: 24px; height: 24px; }

.goals { position: fixed; left: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 92px); z-index: 4; width: 280px; padding: 10px 14px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.goals .k { font-size: 12px; text-transform: uppercase; letter-spacing: .09em; color: var(--brass); font-weight: 700; }
.goals p { margin: 2px 24px 8px 0; }
.goals p.why { margin-top: -4px; font-size: 13px; color: var(--muted); }
.goals .row { display: flex; gap: 6px; margin: 0 0 8px; }
.goals .close { position: absolute; top: 4px; right: 6px; border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 4px 0 10px; }
.legend span, .stat-table td span, .tip span { display: inline-flex; align-items: center; gap: 6px; }
.legend i, .stat-table i, .tip i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.charts { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; }
.chart { margin: 0; min-width: 0; }
.chart figcaption { font-size: 12px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 700; }
.chart svg { width: 100%; height: auto; display: block; touch-action: none; }
.chart text { fill: var(--muted); font: 11px var(--font-body); font-variant-numeric: tabular-nums; }
.chart .ax { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.chart .gr { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .cross { stroke: var(--ink); stroke-width: 1; opacity: .5; }
.tip { position: absolute; z-index: 2; min-width: 150px; padding: 6px 10px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 8px; display: grid; gap: 2px; font-size: 13px; pointer-events: none; }
.tip em { font-style: normal; margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.stat-table { width: 100%; margin-top: 12px; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.stat-table th { text-align: right; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; padding: 4px 6px; }
.stat-table th:first-child, .stat-table td:first-child { text-align: left; }
.stat-table td { text-align: right; padding: 4px 6px; border-top: 1px solid var(--line); }

@media (max-width: 720px) {
  body { font-size: 14px; }
  .hud { gap: 8px; padding-inline: 8px; }
  .hud { flex-wrap: wrap; row-gap: 6px; }
  .brand { font-size: 19px; flex: 1; }
  .chips { order: 3; flex-basis: 100%; }
  .chip.xtra { display: none; }
  .clock { display: none; }
  .speed button { padding: 4px 6px; }
  .speed button[data-speed="8"] { display: none; }
  .tools { left: 8px; right: 8px; bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); justify-content: space-between; gap: 2px; }
  .tools button { width: auto; flex: 1; font-size: 11px; }
  .panel { left: 8px; right: 8px; width: auto; top: auto; bottom: calc(env(safe-area-inset-bottom, 0px) + 78px); max-height: 52%; }
  .minimap { top: calc(env(safe-area-inset-top, 0px) + 92px); bottom: auto; right: 8px; }
  .minimap canvas { width: 96px; height: 96px; }
  .feed { top: calc(env(safe-area-inset-top, 0px) + 92px); max-width: calc(100% - 128px); }
  .feed li:nth-child(n+3) { display: none; }
  .hint { bottom: auto; top: calc(env(safe-area-inset-top, 0px) + 92px); left: 8px; right: 116px; transform: none; max-width: none; border-radius: 12px; text-align: left; }
  .sheet > .actions { bottom: -20px; margin: 14px -16px -20px; padding: 12px 16px 16px; }
  .sheet .tabs { flex-wrap: wrap; row-gap: 2px; }
  .goals { left: 8px; right: 8px; width: auto; bottom: calc(env(safe-area-inset-bottom, 0px) + 78px); padding: 8px 12px; display: grid; grid-template-columns: 1fr auto; column-gap: 10px; align-items: center; }
  .goals .k { grid-column: 1 / -1; padding-right: 24px; }
  .goals p { margin: 0; font-size: 14px; line-height: 1.3; }
  .goals .why, .goals .bar { display: none; }
  .goals .row { margin: 0; grid-column: 2; grid-row: 2; flex-direction: column; }
  .intro { grid-template-columns: 1fr; margin-top: -8px; }
  .sheet { padding: 18px 16px 20px; }
  .keys { font-size: 13px; }
  .opt { grid-template-columns: 1fr; gap: 4px; }
  .charts { grid-template-columns: 1fr; }
  .stat-table { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { .feed li { animation: none; } .pulse { animation: none; outline: 2px solid var(--brass); } }
