:root {
  --bg: #f3ead6;
  --surface: #fffaf0;
  --ink: #2b2118;
  --muted: #6f6152;
  --line: #d9cbb0;
  --sea: #cfe1e6;
  --land: #e8dcc0;
  --accent: #9a3b1b;
  --danger: #a3202f;
  --p1: #d9761e;
  --p2: #3f5fb0;
  --p3: #2f8a57;
  --p4: #9b3fa0;
  --radius: 12px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 0 calc(24px + env(safe-area-inset-bottom));
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

#brand {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.04em;
  color: var(--accent);
}

#status {
  flex: 1;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  font-size: 14px;
  color: var(--muted);
}

#status .turn {
  white-space: nowrap;
}

#board {
  background: var(--sea);
  touch-action: manipulation;
}

#map {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

#panel {
  padding: 12px 16px;
}

h2 {
  font-size: 18px;
  margin: 16px 0 8px;
}

h3 {
  font-size: 16px;
  margin: 12px 0 6px;
}

p {
  margin: 8px 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

/* ---- map ---------------------------------------------------------------- */

#sea-coast {
  fill: var(--land);
}

.region {
  fill: var(--land);
  stroke: #8c7a5e;
  stroke-width: 1;
  stroke-linejoin: round;
  cursor: pointer;
  transition: opacity 120ms;
}

.region:focus {
  outline: none;
}

.region:focus-visible {
  stroke: var(--ink);
  stroke-width: 2.5;
}

.region.owner-p1 { fill: var(--p1); }
.region.owner-p2 { fill: var(--p2); }
.region.owner-p3 { fill: var(--p3); }
.region.owner-p4 { fill: var(--p4); }

.region.selected {
  stroke: var(--ink);
  stroke-width: 3.5;
}

.region.target {
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-dasharray: 5 3;
}

.terrain {
  pointer-events: none;
}

#pat-forest circle { fill: rgba(20, 50, 15, 0.4); }
#pat-mountain path { fill: none; stroke: rgba(50, 30, 10, 0.5); stroke-width: 1.2; }
#pat-river path { fill: none; stroke: rgba(10, 60, 120, 0.45); stroke-width: 1.2; }

#setu line {
  stroke: #8c7a5e;
  stroke-width: 2;
  stroke-dasharray: 2 3;
}

#labels {
  pointer-events: none;
}

.label text {
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(255, 250, 240, 0.85);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.label .name {
  font-size: 8.5px;
  font-weight: 600;
  fill: var(--ink);
}

.label .army {
  font-size: 13px;
  font-weight: 800;
  fill: var(--ink);
}

.arrow {
  stroke-width: 3;
  stroke-linecap: round;
  pointer-events: none;
}

.arrow.attack { stroke: var(--danger); }
.arrow.move { stroke: var(--ink); }
#arrowhead path { fill: context-stroke; }

/* ---- controls ------------------------------------------------------------- */

button {
  font: inherit;
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.danger {
  background: var(--danger);
  color: #fff;
  font-weight: 600;
}

.ghost {
  background: transparent;
  color: var(--accent);
  min-height: 40px;
  padding: 0 10px;
}

.choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.actions > button {
  flex: 1;
}

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  background: var(--muted);
  white-space: nowrap;
}

.chip.owner-p1 { background: var(--p1); }
.chip.owner-p2 { background: var(--p2); }
.chip.owner-p3 { background: var(--p3); }
.chip.owner-p4 { background: var(--p4); }

.hint {
  font-weight: 600;
}

.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px 12px 12px;
  margin: 8px 0;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.stepper button {
  width: 56px;
  font-size: 24px;
}

.stepper output {
  min-width: 96px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}

.orders {
  list-style: none;
  padding: 0;
  margin: 0;
}

.orders li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 2px 0;
}

.pass {
  margin-top: 25vh;
  text-align: center;
  border-top: 8px solid var(--muted);
  padding-top: 16px;
}

.pass.owner-p1 { border-color: var(--p1); }
.pass.owner-p2 { border-color: var(--p2); }
.pass.owner-p3 { border-color: var(--p3); }
.pass.owner-p4 { border-color: var(--p4); }

.pass button {
  width: 100%;
  margin-top: 16px;
}

.tagline {
  font-size: 18px;
}

.rules {
  color: var(--muted);
  font-size: 14px;
}

.winner {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
}

.log ul,
#log-body ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.log-event {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.log-turn h3 {
  margin-top: 16px;
}

.dump {
  font-size: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  overflow: auto;
  max-height: 60vh;
}

dialog {
  width: min(480px, 100vw);
  max-height: 85vh;
  border: none;
  border-radius: var(--radius);
  padding: 0 16px 16px;
  background: var(--bg);
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

dialog header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
}

/* ---- step 2: economy ----------------------------------------------------- */

.label .city {
  fill: var(--ink);
  stroke: rgba(255, 250, 240, 0.9);
  stroke-width: 1.2px;
  paint-order: stroke;
}

.treasury {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.treasury .label {
  font-weight: 600;
  color: var(--muted);
  font-size: 14px;
}

.treasury b {
  font-size: 18px;
}

.region-info {
  font-size: 14px;
  line-height: 1.6;
}

.unit-row {
  border-bottom: 1px solid var(--line);
  padding: 6px 0;
}

.unit-row p {
  margin: 2px 0 0;
  text-align: center;
}

.forecast {
  font-weight: 600;
}

.forecast.win { color: var(--p3); }
.forecast.lose { color: var(--danger); }

button.wide {
  width: 100%;
}

/* ---- glossary ------------------------------------------------------------ */

.ghost.small {
  font-size: 14px;
  padding: 0;
  min-height: 32px;
  text-decoration: underline;
}

.treasury .ghost.small {
  flex-basis: 100%;
  text-align: left;
}

#glossary-body dt {
  margin-top: 12px;
}

#glossary-body dd {
  margin: 2px 0 0;
  font-size: 14px;
}

/* ---- online -------------------------------------------------------------- */

#brand {
  cursor: pointer;
}

a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  flex: 1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0;
  font-weight: 600;
  font-size: 14px;
}

input[type='text'] {
  font: inherit;
  font-size: 16px; /* no zoom-on-focus in iOS Safari */
  min-height: 48px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.join-code {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

.join-code input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.notice {
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.code {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-align: center;
  margin: 0 0 8px;
  color: var(--accent);
}

.code-label {
  text-align: center;
  margin-bottom: 0;
}

.seats,
.my-games {
  list-style: none;
  padding: 0;
  margin: 0;
}

.seats li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.my-games li {
  margin-bottom: 8px;
}

.my-games button {
  text-align: left;
}

.your-move {
  color: var(--danger);
  font-weight: 700;
}

/* ---- heroes and astras --------------------------------------------------- */

#heroes {
  pointer-events: none;
}

.hero circle {
  stroke: #fffaf0;
  stroke-width: 1.4;
  fill: var(--muted);
}

.hero.owner-p1 circle { fill: var(--p1); }
.hero.owner-p2 circle { fill: var(--p2); }
.hero.owner-p3 circle { fill: var(--p3); }
.hero.owner-p4 circle { fill: var(--p4); }

.hero text {
  font-size: 7px;
  font-weight: 800;
  fill: #fff;
  text-anchor: middle;
}

.hero.penance circle {
  stroke: #f3d27a;
  stroke-width: 2;
}

.hero.resting {
  opacity: 0.45;
}

.heroes {
  list-style: none;
  padding: 0;
  margin: 0;
}

.hero-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px 12px;
  margin-bottom: 8px;
}

.hero-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.hero-card .where {
  font-weight: 400;
  color: var(--muted);
  font-size: 14px;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0;
}

.toggle-row button {
  min-height: 40px;
  padding: 0 12px;
  font-size: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
}

.toggle-row button[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.astra-list {
  font-size: 14px;
}

.astra-list b {
  color: var(--accent);
}

/* ---- boons and intelligence (step 5) ------------------------------------- */

.boon-card {
  border: 1px solid var(--accent);
  border-left-width: 6px;
  border-radius: var(--radius);
  background: var(--surface);
  padding: 8px 12px;
  margin: 8px 0;
}

.boon-card h2 {
  font-size: 14px;
  margin: 0;
  color: var(--muted);
  font-weight: 600;
}

.boon-card h3 {
  margin: 2px 0 4px;
  font-size: 17px;
  color: var(--accent);
}

.boon-card p {
  margin: 4px 0;
}

.intel-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 14px;
}

.intel-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.intel-list button {
  display: block;
  min-height: 40px;
  margin-top: 6px;
  padding: 0 12px;
  font-size: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.intel-list button[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* A Brahmastra's battlefield lies barren for a few turns. */
.region.blighted {
  fill-opacity: 0.45;
  stroke: var(--ink);
  stroke-dasharray: 2 2;
}

/* ---- yugas and dharma (step 6) ------------------------------------------- */

.yuga {
  white-space: nowrap;
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--ink);
}

.yuga-line {
  font-size: 14px;
  margin: 6px 0;
}

/* Time runs downhill: the age's colour darkens from gold to iron. */
.yuga.yuga-satya { background: #f6e7b0; }
.yuga.yuga-treta { background: #ead7a6; }
.yuga.yuga-dvapara { background: #d9c3a0; }
.yuga.yuga-kali { background: var(--ink); color: var(--surface); }

.res-dharma b { color: var(--accent); }
.res-dharma.low b,
.dharma-badge.low { color: var(--danger); }

.dharma-badge {
  font-size: 13px;
  font-weight: 600;
}

.warn {
  color: var(--danger);
}

.intel-list li > p {
  margin: 4px 0 0;
}

.intel-list .truce {
  margin-top: 4px;
}

/* ---- playtest (step 7) ---------------------------------------------------- */

.feedback textarea {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 16px; /* no zoom on focus in iOS */
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.feedback label {
  display: block;
  font-weight: 600;
  margin: 12px 0 4px;
}

#nudge {
  margin: 8px 0;
}
