* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #1a1a1a;
  --bg: #efe9dd;
  --panel: #fbf8f2;
  --muted: #8a8577;
  --border: #ddd5c6;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

header {
  display: flex; align-items: baseline; gap: 0.9rem; flex-wrap: wrap;
  padding: 0.9rem 1.4rem; border-bottom: 1.5px solid var(--ink);
}
header h1 { font-size: 1.4rem; letter-spacing: -0.02em; font-weight: 600; }
header .tag {
  font-family: ui-monospace, monospace; font-size: 11px; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--muted);
}

.layout {
  display: flex; gap: 1rem; align-items: flex-start;
  max-width: 1280px; margin: 0 auto; padding: 1rem 1.4rem 3rem;
}
.map-wrap {
  flex: 1 1 auto; min-width: 0; position: relative;
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
  background: var(--panel); line-height: 0;
}
.map-wrap svg { width: 100%; display: block; touch-action: none; }

/* On-map zoom controls (bottom-right). Touch-sized for phones. */
.zoom-ctrl {
  position: absolute; right: 8px; bottom: 8px; z-index: 20;
  display: flex; flex-direction: column; gap: 4px; line-height: 1;
}
.zoom-ctrl .zbtn {
  width: 34px; height: 34px; padding: 0; border: 1.5px solid var(--border);
  border-radius: 7px; background: rgba(251,248,242,0.92); color: var(--ink);
  font-size: 18px; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.zoom-ctrl .zbtn:hover { border-color: var(--ink); }
.zoom-ctrl .zbtn:active { background: #efe9dd; }

.event-toast {
  position: absolute; top: 12%; left: 50%; transform: translate(-50%, -12px) scale(0.96);
  min-width: 240px; max-width: 70%; padding: 0.9rem 1.2rem 1rem; border-radius: 10px;
  background: rgba(26,22,16,0.92); color: #f4ead2; text-align: center; line-height: 1.35;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35); pointer-events: none;
  opacity: 0; transition: opacity 0.9s ease, transform 0.9s ease; z-index: 30;
}
.event-toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); pointer-events: auto; cursor: pointer; }
.event-toast .et-tag { font-family: ui-monospace, monospace; font-size: 10px; letter-spacing: 0.16em;
  text-transform: uppercase; color: #c9a24a; margin-bottom: 0.3rem; }
.event-toast .et-title { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; }
.event-toast .et-impact { font-size: 0.85rem; color: #d9ccae; margin-top: 0.25rem; }
.event-toast .et-dismiss { font-family: ui-monospace, monospace; font-size: 9px; letter-spacing: 0.14em;
  text-transform: uppercase; color: #9a8f78; margin-top: 0.5rem; }

.hud {
  flex: 0 0 280px; display: flex; flex-direction: column; gap: 0.7rem;
}
.turn { font-size: 15px; font-weight: 500; min-height: 2.6em; }
.turn .who { font-weight: 700; }
.turn .hint2 { font-size: 11px; font-weight: 400; color: var(--muted); margin-top: 3px; line-height: 1.5; }

.newgame-row { display: flex; gap: 0.5rem; }
.newgame-row .btn { flex: 1; }
.select {
  font-family: ui-monospace, monospace; font-size: 12px; padding: 0.5rem;
  border: 1.5px solid var(--border); border-radius: 6px; background: var(--panel);
  color: var(--ink); cursor: pointer;
}

.btn {
  font-family: ui-monospace, monospace; font-size: 12px; letter-spacing: 0.06em;
  padding: 0.6rem 0.9rem; border: 1.5px solid var(--ink); border-radius: 6px;
  background: var(--ink); color: #fff; cursor: pointer; text-transform: uppercase;
}
.btn:disabled { opacity: 0.35; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.btn.ghost:hover:not(:disabled) { border-color: var(--ink); }
.btn.ghost.active { background: #f5c542; border-color: #caa42f; color: #1a1a1a; }
.btn.wide { width: 100%; }
.btn-row { display: flex; gap: 0.5rem; }
.btn-row .btn { flex: 1; }

.econ {
  display: flex; flex-direction: column; gap: 0.4rem;
  padding: 0.6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--panel);
}
.econ .cards { font-family: ui-monospace, monospace; font-size: 13px; color: #4a463c; }
.econ .bounty { font-size: 12px; color: #4a463c; }
.econ .bounty .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.2); vertical-align: middle; }
.econ .hint2 { font-size: 11px; color: var(--muted); margin-top: 2px; }
.btn.small { font-size: 11px; padding: 0.4rem 0.6rem; align-self: flex-start; }

.counts { display: flex; flex-direction: column; gap: 0.25rem; font-size: 13px; }
.counts .row { display: flex; align-items: center; gap: 0.5rem; }
.counts .dot { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.15); }
.counts .row.dead { opacity: 0.4; text-decoration: line-through; }

.counts .nums { margin-left: auto; font-family: ui-monospace, monospace; font-size: 12px; color: #4a463c; }

.battle {
  font-family: ui-monospace, monospace; font-size: 12px; color: #4a463c;
  min-height: 2.4em; background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.5rem 0.6rem;
}

.log-wrap { border: 1px solid var(--border); border-radius: 6px; background: var(--panel); }
.log {
  height: 150px; overflow-y: auto; padding: 0.5rem 0.6rem;
  font-family: ui-monospace, monospace; font-size: 11px; color: #6a6558;
  display: flex; flex-direction: column-reverse; gap: 2px;
}

.banner {
  padding: 0.7rem 0.9rem; border-radius: 6px; font-weight: 700; text-align: center;
  color: #fff; background: var(--ink);
}
.status { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); }

.header-right { margin-left: auto; }

.modal {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(20,16,10,0.55); padding: 1.5rem;
}
.modal[hidden] { display: none; }
.modal-card {
  position: relative; background: var(--panel); color: var(--ink);
  max-width: 640px; max-height: 85vh; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 10px; padding: 1.6rem 1.8rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.3); line-height: 1.6;
}
.modal-card h2 { font-size: 1.6rem; letter-spacing: -0.02em; margin-bottom: 0.4rem; }
.modal-card h3 { font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); margin: 1.1rem 0 0.35rem; }
.modal-card p { font-size: 0.9rem; margin-bottom: 0.5rem; }
.modal-card ul { font-size: 0.9rem; margin: 0 0 0.5rem 1.1rem; }
.modal-card li { margin-bottom: 0.3rem; }
.modal-card .footnote {
  font-size: 0.68rem; color: var(--muted); line-height: 1.5;
  border-top: 1px solid var(--border); margin-top: 1rem; padding-top: 0.7rem;
}
.modal-card .modal-foot { font-size: 0.72rem; color: var(--muted); margin-top: 0.55rem; }
.modal-card a { color: var(--ink); }
.modal-close {
  position: absolute; top: 0.6rem; right: 0.8rem; background: none; border: none;
  font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer;
}
.modal-close:hover { color: var(--ink); }

@media (max-width: 820px) {
  .layout { flex-direction: column; gap: 0.8rem; padding: 0.8rem; }
  .hud { flex-basis: auto; width: 100%; }
  /* Cap the map height so the HUD is reachable without a long scroll on tall phones. */
  .map-wrap { max-height: 62vh; }
  .map-wrap svg { max-height: 62vh; width: auto; margin: 0 auto; }
  .event-toast { max-width: 88%; }
  .event-toast .et-title { font-size: 1.1rem; }
}

@media (max-width: 560px) {
  header { padding: 0.7rem 1rem; gap: 0.5rem 0.7rem; }
  header h1 { font-size: 1.2rem; }
  .layout { padding: 0.6rem; }
  /* Bigger touch targets on small screens. */
  .btn { padding: 0.7rem 0.8rem; }
  .btn.small { padding: 0.45rem 0.7rem; }
  .select { padding: 0.6rem 0.5rem; }
  .zoom-ctrl .zbtn { width: 40px; height: 40px; font-size: 20px; }
  .log { height: 110px; }
}
