:root {
  --table: #33372C;          /* the olive drab of the map table itself */
  --table-2: #3D4235;
  --rule: #565C49;
  --chalk: #E7E1CD;
  --chalk-dim: #A9A797;
  --paper: #C9C2AB;          /* the printed sheet */
  --strip: #DED8C4;          /* duplicator stock, a shade lighter than the map */
  --mimeo: #6B4A9B;          /* aniline purple: spirit duplicator ink */
  --mimeo-pale: #8E71B8;
  --blue: #2C4A6B;
  --red: #9B2C22;
  --ink: #2A231A;
  /* The display face carries the personality and is used only where it can be
     read at size: the title, the date, the odds column. Anything a player has
     to read quickly or click on uses the interface face. */
  --face-display: 'Haettenschweiler', 'Arial Narrow', 'Oswald', 'Roboto Condensed', 'Impact', sans-serif;
  --face-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --face-data: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--table);
  color: var(--chalk);
  font-family: var(--face-data);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, .display {
  font-family: var(--face-display);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
}

button {
  font-family: var(--face-ui);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--chalk);
  background: transparent;
  border: 1px solid var(--rule);
  padding: 7px 13px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--table-2); border-color: var(--chalk-dim); }
button:focus-visible { outline: 2px solid var(--mimeo-pale); outline-offset: 2px; }
button:disabled { opacity: 0.35; cursor: default; }
button.on { background: var(--chalk); color: var(--ink); border-color: var(--chalk); }
button.primary { background: var(--mimeo); border-color: var(--mimeo); color: #fff; }
button.primary:hover { background: var(--mimeo-pale); border-color: var(--mimeo-pale); }

.muted { color: var(--chalk-dim); }
.hint { color: var(--mimeo-pale); }

/* ------------------------------------------------------------- opening */
#opening {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; overflow-y: auto;
}
.card {
  width: min(720px, 100%);
  background: var(--table-2);
  border: 1px solid var(--rule);
  padding: 28px 30px 24px;
}
#hero {
  display: block;
  width: 100%;
  height: 180px;
  margin: -28px -30px 18px;
  width: calc(100% + 60px);
  border-bottom: 1px solid var(--rule);
  background: #6E7A81;
}
.card h1 {
  font-size: clamp(38px, 8vw, 68px);
  line-height: 0.92;
  color: var(--chalk);
}
.eyebrow {
  font-family: var(--face-ui);
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--mimeo-pale);
  font-size: 11px;
  margin-bottom: 6px;
}
.rule { height: 1px; background: var(--rule); margin: 18px 0; }
.field { margin-bottom: 16px; }
.field > .label {
  font-family: var(--face-ui);
  font-weight: 600;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: var(--chalk-dim);
  text-transform: uppercase;
  display: block;
  margin-bottom: 7px;
}
.choices { display: flex; flex-wrap: wrap; gap: 7px; }
#scen-note { margin-top: 8px; color: var(--chalk-dim); }
#resume { margin-right: 8px; }

/* ------------------------------------------------------------- game */
#game { position: absolute; inset: 0; display: flex; flex-direction: column; }

#bar {
  display: flex; align-items: baseline; gap: 18px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--table-2);
  flex-wrap: wrap;
}
#bar .title { font-family: var(--face-display); font-size: 20px; letter-spacing: 0.08em; }
#date { font-family: var(--face-display); font-size: 17px; letter-spacing: 0.05em; }
#turnno, #phase { color: var(--chalk-dim); }
#phase { color: var(--mimeo-pale); }
#bar .spacer { flex: 1; }

#soundwrap { display: flex; align-items: center; gap: 8px; }
#soundwrap input[type=range] { width: 84px; accent-color: var(--mimeo); }
#soundwrap input[type=range]:disabled { opacity: 0.35; }

#body { flex: 1; display: flex; min-height: 0; }

#mapwrap { flex: 1; position: relative; min-width: 0; background: #6E7A81; }
#sheet { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }

#maptools {
  position: absolute; left: 10px; top: 10px;
  display: flex; gap: 6px; flex-wrap: wrap;
  background: rgba(51,55,44,0.88);
  border: 1px solid var(--rule);
  padding: 6px;
}
#maptools button { padding: 5px 9px; font-size: 11px; }

#legend {
  position: absolute; left: 10px; top: 52px;
  background: rgba(51,55,44,0.9);
  border: 1px solid var(--rule);
  padding: 5px 9px;
  max-width: 300px;
  color: var(--chalk-dim);
}
#legend .swatches { display: flex; gap: 4px; margin-top: 4px; align-items: center; }
#legend .sw { width: 20px; height: 10px; border: 1px solid rgba(0,0,0,0.35); }

#hexinfo {
  position: absolute; left: 10px; bottom: 10px;
  background: rgba(51,55,44,0.9);
  border: 1px solid var(--rule);
  padding: 5px 9px;
  max-width: calc(100% - 20px);
}

/* What is standing in this hex, read off the counter under the pointer. */
#tip {
  position: absolute;
  z-index: 30;
  pointer-events: none;
  background: rgba(38,41,33,0.97);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--mimeo);
  padding: 7px 10px;
  min-width: 190px;
  max-width: 268px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}
#tip .tip-where {
  font-family: var(--face-ui); font-weight: 600;
  font-size: 10px; letter-spacing: 0.11em; text-transform: uppercase;
  color: var(--chalk-dim); margin-bottom: 5px;
}
#tip .tip-unit + .tip-unit { margin-top: 7px; border-top: 1px solid var(--rule); padding-top: 6px; }
#tip .tip-name { font-family: var(--face-ui); font-weight: 600; font-size: 12.5px; }
#tip .tip-name.axis { color: #B9CBE0; }
#tip .tip-name.sov { color: #E7B3A8; }
#tip .tip-cls { font-size: 11px; color: var(--chalk-dim); }
#tip .tip-row { display: flex; justify-content: space-between; gap: 12px; font-size: 11.5px; }
#tip .tip-row span:first-child { color: var(--chalk-dim); }
#tip .tip-bar { height: 3px; background: rgba(0,0,0,0.35); margin: 4px 0 3px; }
#tip .tip-bar i { display: block; height: 3px; }
#tip .tip-flag { color: var(--mimeo-pale); font-size: 11px; }

#thinking {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(30,32,26,0.55);
  font-family: var(--face-ui);
  font-weight: 600;
  letter-spacing: 0.14em;
  font-size: 15px;
}

/* ------------------------------------------------------------- panel */
#panel {
  width: 340px; flex-shrink: 0;
  border-left: 1px solid var(--rule);
  background: var(--table-2);
  overflow-y: auto;
  padding: 12px 14px 20px;
}
.block { margin-bottom: 18px; }
.block > h3 {
  font-family: var(--face-ui); font-weight: 600;
  font-size: 11.5px; letter-spacing: 0.13em; color: var(--chalk-dim);
  border-bottom: 1px solid var(--rule); padding-bottom: 5px; margin-bottom: 9px;
}
.stats { display: flex; gap: 14px; flex-wrap: wrap; }
.stat .k { font-size: 10px; letter-spacing: 0.11em; text-transform: uppercase; color: var(--chalk-dim); font-family: var(--face-ui); font-weight: 600; }
.stat .v { font-size: 15px; }

.wx { display: flex; justify-content: space-between; padding: 2px 0; }
.wx-name { color: var(--chalk-dim); }

.ration { margin-bottom: 9px; }
.ration .top { display: flex; justify-content: space-between; }
.ration .name { font-family: var(--face-ui); font-weight: 600; letter-spacing: 0.02em; font-size: 12.5px; }
.ration input[type=range] { width: 100%; accent-color: var(--mimeo); }

.ledger-table { width: 100%; border-collapse: collapse; }
.ledger-table th {
  text-align: left; font-weight: 400; color: var(--chalk-dim);
  font-size: 11px; padding: 2px 0; letter-spacing: 0.04em;
}
.ledger-table td { text-align: right; padding: 2px 0; }

/* ---- the signature: the duplicated action ledger ---------------------- */
#ledgerwrap { position: relative; }
#ledgerwrap.flash .lg:first-child { animation: pull 420ms ease-out; }
@keyframes pull { from { transform: translateX(-14px); opacity: 0; } to { transform: none; opacity: 1; } }
.lg {
  background: var(--strip);
  color: var(--mimeo);
  margin-bottom: 6px;
  padding: 6px 9px 6px 15px;
  position: relative;
  /* the sprocket margin of a duplicator strip */
  background-image: radial-gradient(circle at 6px 6px, rgba(43,35,26,0.28) 1.6px, transparent 1.7px);
  background-size: 100% 11px;
  background-repeat: repeat-y;
}
.lg-own { box-shadow: inset 3px 0 0 var(--mimeo); }
.lg-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.lg-turn { font-size: 10px; letter-spacing: 0.1em; color: rgba(43,35,26,0.62); text-transform: uppercase; font-family: var(--face-ui); font-weight: 600; }
.lg-target { font-size: 12px; color: var(--ink); text-align: right; }
.lg-line { display: flex; gap: 7px; align-items: baseline; flex-wrap: wrap; margin-top: 3px; }
.lg-odds { font-family: var(--face-display); font-size: 19px; letter-spacing: 0.04em; }
.lg-shift, .lg-roll {
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  border: 1px solid rgba(107,74,155,0.5); padding: 1px 4px;
}
.lg-code {
  margin-left: auto;
  font-family: var(--face-display); font-size: 19px;
  color: #fff; background: var(--mimeo); padding: 0 7px;
}
.lg-foot { font-size: 10.5px; color: rgba(43,35,26,0.72); margin-top: 3px; }

#log p { margin: 0 0 5px; color: var(--chalk-dim); }

#toast {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--mimeo); color: #fff; padding: 8px 14px; z-index: 40;
}

#verdict-wrap {
  position: absolute; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(24,26,20,0.86); padding: 20px; overflow-y: auto;
}
#verdict { width: min(460px, 100%); background: var(--table-2); border: 1px solid var(--rule); padding: 24px; }
#verdict h2 { font-size: 34px; color: var(--chalk); margin-bottom: 4px; }
#verdict .ledger-table { margin: 14px 0 18px; }

@media (max-width: 820px) {
  #body { flex-direction: column; }
  #panel { width: auto; max-height: 46%; border-left: none; border-top: 1px solid var(--rule); }
  #mapwrap { min-height: 40%; }
  #soundwrap input[type=range] { display: none; }
  #bar { gap: 10px; padding: 6px 10px; }
  #bar .title { font-size: 15px; }
  #maptools { padding: 4px; gap: 4px; left: 6px; top: 6px; flex-wrap: nowrap; }
  #maptools button { padding: 4px 6px; font-size: 10px; letter-spacing: 0.04em; }
  #legend { top: 40px; left: 6px; font-size: 11px; max-width: calc(100% - 12px); }
  #hexinfo { font-size: 11px; }
  #hero { height: 128px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
