:root {
  --font-pixel: "Press Start 2P", ui-monospace, monospace;
  --font-body: "VT323", ui-monospace, monospace;
  --bg: #1b1410;
  --ink: #f4f1ea;
  --ink-dim: #b8b2a6;
  --panel: rgba(16, 12, 10, 0.86);
  --panel-edge: #000;
  --btn: #7d7d7d;
  --btn-hi: #b8b8b8;
  --btn-lo: #3c3c3c;
  --good: #5bd75b;
  --warn: #f2c230;
  --bad: #e2453c;
  --xp: #80ff20;
  --paper: #e9d9b4;
  --paper-ink: #2b1f12;
  --paper-edge: #8b6b3d;
  --gutter: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 20px;
  line-height: 1.2;
  overflow-x: hidden;
}

/* ---------- buttons ---------- */
.mc-button {
  font-family: var(--font-pixel);
  font-size: 12px;
  color: #fff;
  text-shadow: 2px 2px 0 #3f3f3f;
  background: var(--btn);
  border: 2px solid #000;
  box-shadow: inset 2px 2px 0 var(--btn-hi), inset -2px -2px 0 var(--btn-lo);
  padding: 10px 14px;
  cursor: pointer;
  image-rendering: pixelated;
}
.mc-button:hover, .mc-button:focus-visible { background: #8f9ad6; outline: none; }
.mc-button:active { box-shadow: inset -2px -2px 0 var(--btn-hi), inset 2px 2px 0 var(--btn-lo); }
.mc-button.small { font-size: 10px; padding: 6px 8px; }
.mc-button.good { background: #3f8f3f; }
.mc-button.bad { background: #9a2f2a; }
.mc-button[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- login ---------- */
body.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background-color: #6b4a2f;
  background-image:
    linear-gradient(45deg, rgba(0,0,0,.12) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.12) 75%),
    linear-gradient(45deg, rgba(0,0,0,.12) 25%, transparent 25%, transparent 75%, rgba(0,0,0,.12) 75%);
  background-size: 32px 32px;
  background-position: 0 0, 16px 16px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 4px solid var(--panel-edge);
  padding: 28px 24px;
  text-align: center;
}
.logo {
  font-family: var(--font-pixel);
  font-size: clamp(22px, 7vw, 34px);
  color: #c6c6c6;
  text-shadow: 3px 3px 0 #3a3a3a, 6px 6px 0 #000;
  margin: 0 0 8px;
  letter-spacing: 2px;
}
.splash {
  font-family: var(--font-pixel);
  color: #ffff55;
  font-size: 10px;
  transform: rotate(-8deg);
  margin: 0 0 24px;
  animation: splash 1s ease-in-out infinite alternate;
}
@keyframes splash { to { transform: rotate(-8deg) scale(1.08); } }
.login-card form { display: grid; gap: 10px; text-align: left; }
.login-card label { font-family: var(--font-pixel); font-size: 10px; color: var(--ink-dim); }
.login-card input {
  font: inherit;
  font-size: 22px;
  background: #000;
  color: #fff;
  border: 2px solid #a0a0a0;
  padding: 8px;
  width: 100%;
}
.login-error { color: #ff7a7a; font-size: 20px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  padding: 8px var(--gutter);
  background: linear-gradient(#000c, #0006);
}
.stat-row { display: flex; align-items: center; gap: 8px; }
.stat-label { font-family: var(--font-pixel); font-size: 9px; color: var(--ink-dim); }
.icons { display: inline-flex; gap: 1px; }
.icons img { width: 18px; height: 18px; image-rendering: pixelated; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge { font-family: var(--font-pixel); font-size: 9px; padding: 6px 8px; border: 2px solid #000; }
.badge.observe { background: #2d5d9a; }
.badge.active { background: #2f7d32; }
.badge.paused { background: var(--bad); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .55; } }
.clock { font-family: var(--font-pixel); font-size: 10px; color: var(--ink-dim); }

/* ---------- boss bar (pending decision) ---------- */
.bossbar {
  position: sticky;
  top: 52px;
  z-index: 19;
  margin: 6px auto 0;
  width: min(720px, calc(100% - 2 * var(--gutter)));
  text-align: center;
  background: #000a;
  padding: 8px 10px;
  border: 2px solid #000;
}
.bossbar-title { font-family: var(--font-pixel); font-size: clamp(8px, 2.4vw, 10px); color: #ff6bff; margin-bottom: 6px; overflow-wrap: anywhere; }
.bossbar-track { height: 8px; background: #3b0f3b; border: 1px solid #000; }
.bossbar-fill { height: 100%; background: #d63ad6; width: 100%; transition: width 1s linear; }
.bossbar-actions { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }

/* ---------- world ---------- */
.world-wrap { position: relative; width: 100%; }
#world { display: block; width: 100%; image-rendering: pixelated; cursor: default; }
#world.pointer { cursor: pointer; }
.tooltip {
  position: absolute;
  pointer-events: none;
  background: #100010f0;
  border: 2px solid #2a0a5e;
  outline: 2px solid #100010;
  padding: 6px 8px;
  max-width: 280px;
  font-size: 18px;
  z-index: 15;
}
.tooltip b { font-family: var(--font-pixel); font-size: 10px; color: #fff; display: block; margin-bottom: 4px; }

/* ---------- bottom HUD ---------- */
.hud-bottom {
  position: sticky;
  bottom: 0;
  z-index: 18;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  justify-items: center;
  padding: 8px var(--gutter) 12px;
  background: linear-gradient(#0000, #000c 40%);
}
.chat {
  justify-self: start;
  width: min(560px, 100%);
  max-height: 132px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  font-size: 19px;
}
.chat div { background: #0008; padding: 1px 6px; text-shadow: 2px 2px 0 #000; overflow-wrap: anywhere; }
.chat .who { color: #ffff55; }
.xp { width: min(546px, 100%); position: relative; }
.xp-track { height: 10px; background: #1a1a1a; border: 2px solid #000; }
.xp-fill { height: 100%; width: 0; background: var(--xp); box-shadow: inset 0 -3px 0 #4caf10; }
.xp-level {
  position: absolute; left: 50%; top: -16px; transform: translateX(-50%);
  font-family: var(--font-pixel); font-size: 12px; color: var(--xp); text-shadow: 2px 2px 0 #000;
}
.hotbar { display: flex; gap: 0; border: 3px solid #000; background: #8b8b8b; max-width: 100%; overflow-x: auto; }
.slot {
  position: relative;
  width: 58px; height: 58px;
  flex: 0 0 auto;
  border: 3px solid;
  border-color: #373737 #fff #fff #373737;
  background: #8b8b8b;
  display: grid; place-items: center;
  cursor: pointer;
  padding: 0;
}
.slot:focus-visible, .slot:hover { outline: 3px solid #fff; outline-offset: -6px; z-index: 1; }
.slot img { width: 32px; height: 32px; image-rendering: pixelated; }
.slot .count {
  position: absolute; right: 3px; bottom: 1px;
  font-family: var(--font-pixel); font-size: 11px; color: #fff; text-shadow: 2px 2px 0 #3f3f3f;
}
@media (max-width: 560px) {
  .slot { width: 44px; height: 44px; }
  .slot img { width: 24px; height: 24px; }
  .slot .count { font-size: 9px; }
  .chat { max-height: 88px; font-size: 17px; }
}

/* ---------- book panels ---------- */
.book {
  background: var(--paper);
  color: var(--paper-ink);
  border: 4px solid var(--paper-edge);
  box-shadow: 0 0 0 3px #000, 8px 8px 0 #0008;
}
.book h2, .book h3 { font-family: var(--font-pixel); font-weight: normal; margin: 0 0 12px; }
.book h2 { font-size: 14px; }
.book h3 { font-size: 11px; margin-top: 18px; }
.panel {
  position: fixed;
  z-index: 30;
  right: var(--gutter);
  top: 70px;
  bottom: 160px;
  width: min(440px, calc(100% - 2 * var(--gutter)));
  overflow-y: auto;
  padding: 18px;
}
.close {
  position: sticky; top: 0; float: right;
  font-family: var(--font-pixel); font-size: 16px;
  background: none; border: 0; color: var(--paper-ink); cursor: pointer;
}
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; }
.kv dt { color: #6b5233; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.list li { background: #0000000d; padding: 6px 8px; border-left: 4px solid #8b6b3d; overflow-wrap: anywhere; }
.list li.pass { border-color: #3f8f3f; }
.list li.warn { border-color: #c9a227; }
.list li.fail, .list li.error { border-color: #b3261e; }
.list li.skip { border-color: #8a8a8a; }
.list li button.link { all: unset; cursor: pointer; text-decoration: underline; }
.muted { color: #6b5233; }
.pill { font-family: var(--font-pixel); font-size: 8px; padding: 2px 4px; border: 1px solid currentColor; margin-right: 6px; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.ledger {
  position: fixed; inset: 0; z-index: 40;
  background: #000a;
  display: grid; place-items: center;
  padding: var(--gutter);
}
.ledger-inner {
  width: min(1000px, 100%);
  max-height: calc(100vh - 2 * var(--gutter));
  overflow: auto;
  padding: 18px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tabs .mc-button[aria-selected="true"] { background: #5a6fd6; }
.ledger-body { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 18px; }
th, td { text-align: left; padding: 4px 6px; border-bottom: 1px solid #8b6b3d55; vertical-align: top; }
th { font-family: var(--font-pixel); font-size: 9px; font-weight: normal; color: #6b5233; }
td.wrap { max-width: 420px; overflow-wrap: anywhere; }
.pager { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 12px; }
pre.report { white-space: pre-wrap; font-family: var(--font-body); font-size: 20px; margin: 0; overflow-wrap: anywhere; }

.toast {
  position: fixed; left: 50%; top: 90px; transform: translateX(-50%);
  z-index: 50;
  background: #212121; color: #fff; border: 3px solid #000;
  box-shadow: inset 2px 2px 0 #555;
  padding: 10px 14px;
  font-family: var(--font-pixel); font-size: 10px;
  max-width: calc(100% - 2 * var(--gutter));
}
.toast b { color: #ffff55; display: block; margin-bottom: 4px; }

/* ---------- crew forms ---------- */
.crew-form { display: grid; gap: 10px; max-width: 760px; }
.field { display: grid; gap: 3px; margin-bottom: 8px; }
.field > span { font-family: var(--font-pixel); font-size: 9px; color: #6b5233; }
.field small { font-size: 16px; }
.text, textarea.sop {
  font: inherit; font-size: 19px; color: var(--paper-ink);
  background: #fff8e6; border: 2px solid var(--paper-edge); padding: 6px 8px; width: 100%;
}
.text:disabled, textarea.sop[readonly] { background: #efe3c6; color: #5a4a35; }
textarea.sop { font-family: ui-monospace, Menlo, monospace; font-size: 13px; line-height: 1.45; min-height: 320px; resize: vertical; }
fieldset.conn { border: 2px dashed var(--paper-edge); padding: 10px 12px; margin: 4px 0 10px; }
fieldset.conn legend { font-family: var(--font-pixel); font-size: 9px; padding: 0 6px; }
.note { background: #fff3c4; border-left: 4px solid #c9a227; padding: 6px 10px; margin: 8px 0; }
.tokenbox { background: #1d1d1d; color: #e8e8e8; padding: 12px; margin: 10px 0; border: 3px solid #000; }
.tokenbox b { font-family: var(--font-pixel); font-size: 9px; color: #ffff55; display: block; margin-bottom: 6px; }
.tokenbox pre { white-space: pre-wrap; word-break: break-all; font-size: 13px; background: #000; padding: 8px; margin: 6px 0; }
.tokenbox .muted { color: #aaa; }
tr.retired td { color: #8a7a65; }
button.link { all: unset; cursor: pointer; text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .splash, .badge.paused { animation: none; }
}

/* money cloud: revenue at a glance, floating in the sky of the mine (owner only) */
.money-cloud {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 2 * var(--gutter));
  padding: 6px 14px 7px;
  background: #fffdf4;
  border: none;
  box-shadow: 0 -4px 0 #fffdf4, 0 4px 0 #fffdf4, -4px 0 0 #fffdf4, 4px 0 0 #fffdf4, 0 8px 0 #0000002e;
  color: var(--paper-ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.05;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.money-cloud:hover { background: #fff6cf; }
.money-cloud { transition: transform 0.12s ease-out; }
.money-cloud.ding { transform: translateX(-50%) scale(1.08); }
/* the miner with the most coins, in a little cloud of their own */
.coin-leader {
  position: absolute;
  top: 6px;
  left: var(--gutter);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 4px;
  background: #fffdf4;
  border: none;
  border-radius: 10px;
  box-shadow: 0 2px 0 #c9c1a6, -6px 3px 0 -2px #fffdf4, 6px 3px 0 -2px #fffdf4;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1;
  color: #5a4a2f;
  cursor: pointer;
}
.coin-leader:hover { background: #fff6cf; }
.coin-leader img { width: 12px; height: 12px; image-rendering: pixelated; }
.coin-leader .leader-crown { width: 10px; height: 8px; margin-right: -2px; }
.coin-leader .leader-name { font-family: var(--font-pixel); font-size: 8px; color: #2b1f12; }
.coin-leader .leader-coins { color: #b8860b; font-weight: bold; }
@media (prefers-reduced-motion: reduce) { .money-cloud { transition: none; } }
.money-cloud .money-total {
  display: block;
  font-family: var(--font-pixel);
  font-size: clamp(12px, 3.4vw, 18px);
  color: #b8860b;
  text-shadow: 2px 2px 0 #5a3d00;
  margin-bottom: 3px;
}
.money-cloud .money-total.loss { color: var(--bad); text-shadow: 2px 2px 0 #4a0d0a; }
.money-cloud .money-paper { color: #7a6a4f; }
.money-cloud .money-target { display: block; font-size: 15px; color: #7a6a4f; margin: -1px 0 3px; }
.money-cloud .money-bar { display: block; height: 6px; margin: 0 auto 4px; width: 100%; min-width: 120px; background: #e8dcb4; }
.money-cloud .money-bar > span { display: block; height: 100%; min-width: 2px; background: #b8860b; }
.money-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 8px 0; }
.money-form input, .money-form select { font: inherit; font-size: 18px; padding: 4px 6px; min-width: 0; }
.quest-form { display: grid; gap: 8px; margin: 8px 0 14px; }
.quest-form textarea { font: inherit; font-size: 18px; padding: 6px; width: 100%; box-sizing: border-box; resize: vertical; }
.quest-actions { margin: 4px 0; }
.amount-pos { color: #1f7a1f; }
.amount-neg { color: #b3261e; }
.table-scroll { overflow-x: auto; }
@media (max-width: 560px) {
  /* phones: a compact cloud in the top-right corner, clear of the foreman's speech bubble */
  .money-cloud { left: auto; right: var(--gutter); transform: none; font-size: 15px; padding: 4px 9px 5px; }
  .money-cloud.ding { transform: scale(1.08); }
  .coin-leader { font-size: 13px; padding: 2px 6px 3px; }
  .money-cloud .money-month, .money-cloud .money-paper { display: none; }
  .money-cloud .money-target { font-size: 12px; margin: 0 0 2px; }
}
