:root {
  --bg: #1c1a17;
  --paper: #f5eeda;
  --ink: #453321;
  --accent: #b0402c;
  --muted: #8a7a5f;
  --gold: #ffd75e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--paper);
  font-family: "Courier New", ui-monospace, monospace;
  -webkit-font-smoothing: none;
}

.wrap {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.masthead { text-align: center; margin-bottom: 18px; }
.masthead h1 {
  margin: 0;
  font-size: clamp(22px, 5vw, 40px);
  letter-spacing: 0.35em;
  color: var(--paper);
  text-shadow: 3px 3px 0 var(--accent);
}
.tagline {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.08em;
}

#stage {
  position: relative;
  width: 100%;
  border: 3px solid var(--paper);
  border-radius: 6px;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.4);
}

#game {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.overlay .panel {
  pointer-events: auto;
  text-align: center;
  color: var(--ink);
  padding: 12px 20px;
  max-height: 100%;
  overflow-y: auto;
}
#overlay-over .panel {
  background: rgba(245, 238, 218, 0.94);
  border-radius: 6px;
}
.overlay.hidden { display: none; }

.overlay h2 {
  margin: 0 0 6px;
  letter-spacing: 0.4em;
  font-size: clamp(15px, 3.2vw, 24px);
}
.big { font-size: 38px; margin-bottom: 4px; letter-spacing: 0.1em; }
.hint { margin: 4px 0; font-weight: bold; letter-spacing: 0.1em; }
.hint.small { font-weight: normal; font-size: 11px; color: #7a6a50; }
.key {
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 12px;
}

.cta {
  font-family: inherit;
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 0.2em;
  margin-top: 10px;
  padding: 10px 22px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
}
.cta:hover { background: var(--accent); border-color: var(--accent); }

/* ---- event / choice cards ---- */
.card {
  background: rgba(245, 238, 218, 0.96);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.25);
  max-width: 92%;
  min-width: min(480px, 88%);
  padding: 14px 22px 16px;
}
.card-art { font-size: 26px; margin: 2px 0; }
.card-art:empty { display: none; }
.card-body {
  font-size: 13px;
  line-height: 1.5;
  margin: 4px 0 10px;
  letter-spacing: 0.03em;
}
.card-body .stat-note { color: var(--accent); font-weight: bold; }
.choices {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: stretch;
}
.choices button {
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.08em;
  padding: 8px 14px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  text-align: center;
}
.choices button .sub {
  display: block;
  font-weight: normal;
  font-size: 10px;
  opacity: 0.85;
  letter-spacing: 0.05em;
  margin-top: 2px;
}
.choices button:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.choices button:disabled { opacity: 0.45; cursor: default; }

/* shop rows inside cards */
.shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px dashed rgba(69, 51, 33, 0.35);
  padding: 4px 0;
  font-size: 12.5px;
  text-align: left;
}
.shop-row .item { flex: 1; }
.shop-row .item .sub { display: block; font-size: 10px; color: #7a6a50; }
.shop-row button {
  font-family: inherit;
  font-size: 11.5px;
  font-weight: bold;
  padding: 4px 10px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  white-space: nowrap;
}
.shop-row button:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.shop-row button:disabled { opacity: 0.4; cursor: default; }
.shop-cash { font-weight: bold; margin: 6px 0 8px; letter-spacing: 0.1em; }

.score-line { margin: 2px 0 10px; font-weight: bold; letter-spacing: 0.15em; }

.tally {
  font-size: 12.5px;
  text-align: left;
  display: inline-block;
  margin: 2px 0 8px;
  line-height: 1.55;
}
.tally .trow { display: flex; justify-content: space-between; gap: 26px; }
.tally .trow span:last-child { font-weight: bold; }
.tally .epitaph { color: var(--accent); font-size: 11px; }
.tally hr { border: none; border-top: 2px solid var(--ink); margin: 4px 0; }

.submit-form {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.submit-form.hidden { display: none; }
.submit-form input {
  font-family: inherit;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 7px 10px;
  width: 180px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: #fffbe9;
  color: var(--ink);
  outline: none;
}
.submit-form button,
.restart {
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.1em;
  padding: 8px 14px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
}
.submit-form button:hover, .restart:hover { background: var(--accent); border-color: var(--accent); }
.submit-form button:disabled { opacity: 0.5; cursor: default; }

.restart { margin-top: 8px; background: transparent; color: var(--ink); }
.restart:hover { color: var(--paper); }

.over-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.turnstile-slot { flex-basis: 100%; display: flex; justify-content: center; }
.turnstile-slot:empty { display: none; }

.submit-msg { min-height: 16px; margin: 2px 0 0; font-size: 12px; color: var(--accent); font-weight: bold; }

/* ---- dashboard ---- */
#dashboard {
  margin-top: 12px;
  border: 3px solid var(--paper);
  border-radius: 6px;
  padding: 12px 14px;
  background: rgba(245, 238, 218, 0.04);
}
#dashboard.hidden, #logbox.hidden { display: none; }

#trailbar {
  position: relative;
  height: 26px;
  border: 2px solid var(--paper);
  border-radius: 4px;
  margin-bottom: 26px;
  background: rgba(245, 238, 218, 0.06);
}
#trail-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: rgba(176, 64, 44, 0.55);
  transition: width 0.4s;
}
#trail-marker {
  position: absolute;
  top: -2px;
  left: 0%;
  transform: translateX(-50%);
  font-size: 15px;
  line-height: 26px;
  transition: left 0.4s;
}
#trail-ticks { position: absolute; inset: 0; }
#trail-ticks .tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(245, 238, 218, 0.45);
}
#trail-ticks .tick i {
  position: absolute;
  top: 26px;
  left: 0;
  transform: translateX(-50%);
  font-style: normal;
  font-size: 9px;
  letter-spacing: 0.03em;
  color: var(--muted);
  white-space: nowrap;
}
#trail-ticks .tick.hit { background: var(--gold); }
#trail-ticks .tick.hit i { color: var(--gold); }

#stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 10px;
}
#stats .chip {
  border: 2px solid rgba(245, 238, 218, 0.35);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11.5px;
  letter-spacing: 0.05em;
}
#stats .chip b { color: var(--paper); }
#stats .chip.warn b { color: var(--gold); }
#stats .chip.bad b { color: #ff7a5c; }

#controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  align-items: center;
}
.ctl-group { display: flex; align-items: center; gap: 4px; }
.ctl-label { font-size: 10px; color: var(--muted); letter-spacing: 0.15em; margin-right: 2px; }
.ctl-group button {
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 0.08em;
  padding: 5px 9px;
  border: 2px solid rgba(245, 238, 218, 0.4);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.ctl-group button.on {
  color: var(--ink);
  background: var(--paper);
  border-color: var(--paper);
}
.ctl-group button:hover:not(.on) { border-color: var(--paper); color: var(--paper); }
.ctl-main {
  border-color: var(--accent) !important;
  color: var(--paper) !important;
  background: var(--accent) !important;
  font-size: 12px !important;
  padding: 6px 12px !important;
}
.ctl-main:hover { filter: brightness(1.15); }

/* ---- trail log ---- */
#logbox {
  margin-top: 12px;
  border: 3px solid var(--paper);
  border-radius: 6px;
  padding: 10px 14px 12px;
  background: rgba(245, 238, 218, 0.04);
}
#logbox h3 { margin: 0 0 6px; letter-spacing: 0.25em; font-size: 13px; }
#log {
  max-height: 150px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.65;
  color: rgba(245, 238, 218, 0.85);
}
#log .day { color: var(--muted); }
#log .bad { color: #ff7a5c; }
#log .good { color: var(--gold); }

.board {
  margin-top: 28px;
  border: 3px solid var(--paper);
  border-radius: 6px;
  padding: 14px 18px 18px;
  background: rgba(245, 238, 218, 0.04);
}
.board h3 {
  margin: 0 0 10px;
  letter-spacing: 0.25em;
  font-size: 15px;
  text-align: center;
}
#leaderboard {
  margin: 0;
  padding: 0 0 0 34px;
  font-size: 14px;
  line-height: 1.9;
}
#leaderboard li { letter-spacing: 0.05em; }
#leaderboard li .pts { float: right; font-weight: bold; }
#leaderboard li.me { color: var(--gold); }
#leaderboard li.muted { color: var(--muted); list-style: none; }

footer { text-align: center; margin-top: 26px; font-size: 12px; color: var(--muted); }
footer a { color: var(--accent); }

/* small screens: tighten the UI so cards and controls stay usable */
@media (max-width: 600px) {
  .wrap { padding: 14px 8px 36px; }
  .card { min-width: 96%; padding: 10px 12px 12px; }
  .card-body { font-size: 12px; }
  .choices button { font-size: 12px; padding: 7px 10px; }
  .shop-row { font-size: 11.5px; }
  .shop-row button { font-size: 11px; padding: 4px 8px; }
  .overlay h2 { letter-spacing: 0.2em; }
  #stats .chip { font-size: 10.5px; padding: 2px 6px; }
  .ctl-group button { font-size: 10px; padding: 4px 7px; }
  #trail-ticks .tick i { display: none; } /* landmark labels collide on narrow bars */
  #trailbar { margin-bottom: 10px; }
  #log { max-height: 110px; font-size: 11px; }
  .submit-form input { width: 140px; }
}
