:root {
  --parchment: #F2E4C6;
  --ochre: #C9A961;
  --blue: #33557A;
  --red: #8C3A2E;
  --moss: #3E4A2E;
  --iron: #6E7681;
  --ink: #2A231C;

  --font-display: 'Metamorphous', 'Alegreya', Georgia, serif;
  --font-text: 'Alegreya', Georgia, 'Times New Roman', serif;
  --font-num: 'Alegreya Sans', 'Arial Narrow', Arial, sans-serif;

  --plate-h: 168px;
  --safe-top: max(8px, env(safe-area-inset-top));
  --safe-bottom: max(0px, env(safe-area-inset-bottom));
  --title-w: clamp(142px, 23vw, 274px);
  --title-h: calc(var(--title-w) * 0.665);
  --help-size: clamp(28px, calc(var(--title-w) * 0.16), 38px);
  --ui-pad: clamp(5px, 0.8vw, 12px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #2b2419;
  color: var(--ink);
  font-family: var(--font-text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body { position: fixed; inset: 0; }

#app { position: fixed; inset: 0; overflow: hidden; }

#game { position: fixed; inset: 0; z-index: 0; background: #3E4A2E; }
#game canvas { display: block; width: 100% !important; height: 100% !important; filter: saturate(0.99) contrast(1.085) sepia(0.08) brightness(1.0); }

#board-grade {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    repeating-linear-gradient(103deg, rgba(255, 250, 232, 0.022) 0 1px, rgba(255, 250, 232, 0) 1px 4px),
    repeating-linear-gradient(17deg, rgba(62, 45, 22, 0.018) 0 1px, rgba(62, 45, 22, 0) 1px 5px),
    radial-gradient(120% 92% at 38% 24%, rgba(255, 234, 184, 0.11) 0%, rgba(255, 234, 184, 0) 40%, rgba(76, 56, 30, 0.13) 72%, rgba(28, 22, 14, 0.34) 100%);
  box-shadow:
    inset 0 0 0 7px #4a3520,
    inset 0 0 0 9px #c9a961,
    inset 0 0 0 11px #2a231c,
    inset 0 0 70px rgba(30, 23, 14, 0.3);
}

#grain {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0.072;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

button {
  font-family: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ---------- Title ---------- */

#title-stack {
  position: fixed;
  left: 6px;
  top: var(--safe-top);
  width: var(--title-w);
  z-index: 5;
  pointer-events: none;
}

#title-plate {
  position: relative;
  width: var(--title-w);
  height: var(--title-h);
  filter: drop-shadow(0 4px 4px rgba(42, 35, 28, 0.35));
}
#title-plate img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.title-word {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 7%;
  height: 62%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(15px, calc(var(--title-w) * 0.125), 32px);
  line-height: 0.94;
  color: var(--ink);
  letter-spacing: 0.015em;
  text-align: center;
  text-shadow: 0 1px 0 rgba(242, 228, 198, 0.55);
}

#help-btn {
  pointer-events: auto;
  position: absolute;
  left: calc(50% - var(--help-size) / 2);
  top: calc(var(--title-h) - 20px);
  width: var(--help-size);
  height: var(--help-size);
  border-radius: 50%;
  background: var(--parchment);
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--ochre), 0 3px 4px rgba(42, 35, 28, 0.35);
  color: var(--ink);
  font-family: var(--font-text);
  font-weight: 700;
  font-size: clamp(15px, calc(var(--title-w) * 0.09), 21px);
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, background 0.12s ease;
}
#help-btn:active { transform: scale(0.94); }

/* ---------- Match state ---------- */

#match-state {
  position: fixed;
  top: var(--safe-top);
  right: 6px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: clamp(5px, 1vw, 14px);
  padding: clamp(4px, 0.55vw, 9px) clamp(7px, 1vw, 14px);
  min-height: 40px;
  background:
    radial-gradient(circle at 9px 9px, #6e7681 0 2.1px, #2a231c 2.1px 3.3px, transparent 3.4px),
    radial-gradient(circle at calc(100% - 9px) 9px, #6e7681 0 2.1px, #2a231c 2.1px 3.3px, transparent 3.4px),
    radial-gradient(circle at 9px calc(100% - 9px), #6e7681 0 2.1px, #2a231c 2.1px 3.3px, transparent 3.4px),
    radial-gradient(circle at calc(100% - 9px) calc(100% - 9px), #6e7681 0 2.1px, #2a231c 2.1px 3.3px, transparent 3.4px),
    linear-gradient(105deg, rgba(201,169,97,0.20), rgba(242,228,198,0) 38%),
    radial-gradient(120% 180% at 12% 0%, #fbf2da 0%, var(--parchment) 48%, #e2cfa6 100%);
  border: 2px solid var(--ink);
  border-radius: 5px;
  box-shadow:
    inset 0 0 0 2px rgba(201, 169, 97, 0.65),
    inset 0 2px 8px rgba(255, 248, 226, 0.55),
    0 4px 7px rgba(42, 35, 28, 0.33);
  color: var(--ink);
}
#match-state::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(42, 35, 28, 0.22);
  border-radius: 3px;
  pointer-events: none;
}

.clock { display: flex; align-items: center; gap: 5px; }
.clock-icon { width: clamp(19px, 2.2vw, 28px); height: auto; display: block; }
#timer {
  font-family: var(--font-num);
  font-weight: 500;
  font-size: clamp(15px, 1.55vw, 23px);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  line-height: 1;
}

.army { display: flex; align-items: center; gap: 4px; }
.shield { width: clamp(16px, 1.75vw, 25px); height: auto; filter: drop-shadow(0 1px 0 rgba(255, 247, 222, 0.6)); }
.army-col { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.army-count {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(14px, 1.5vw, 21px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.pips { display: flex; gap: 2px; height: 4px; }
.pips i {
  display: block;
  width: clamp(4px, 0.55vw, 7px);
  height: clamp(3px, 0.4vw, 4px);
  border-radius: 50%;
  background: rgba(42, 35, 28, 0.16);
}
.army-blue .pips i.on { background: var(--blue); }
.army-red .pips i.on { background: var(--red); }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  z-index: 14;
  top: calc(var(--safe-top) + var(--title-h) - 2px);
  left: 50%;
  transform: translateX(-50%);
  max-width: min(78vw, 520px);
  padding: 7px 16px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background:
    linear-gradient(100deg, rgba(201,169,97,0.18), rgba(242,228,198,0) 40%),
    var(--parchment);
  box-shadow: inset 0 0 0 2px var(--ochre), 0 4px 8px rgba(42,35,28,0.3);
  font-family: var(--font-text);
  font-size: clamp(12px, 1.25vw, 16px);
  line-height: 1.25;
  text-align: center;
  color: var(--ink);
  pointer-events: none;
  transition: opacity 0.25s ease;
}
#toast.out { opacity: 0; }

/* ---------- Command plate ---------- */

#command-plate {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--plate-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  z-index: 8;
  pointer-events: auto;
  filter: drop-shadow(0 -4px 8px rgba(42, 35, 28, 0.4));
}
.plate-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

#res-row {
  position: absolute;
  left: 3.4%;
  right: 3.4%;
  top: 4.5%;
  height: 30%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1%;
}

.res-chip {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, 0.9vw, 12px);
  min-width: 0;
  border-radius: 6px;
  color: var(--ink);
  transition: background 0.12s ease, box-shadow 0.12s ease, transform 0.1s ease;
}
.res-chip:active { transform: translateY(1px); }
.res-icon {
  height: clamp(22px, 5.6vh, 46px);
  width: auto;
  max-width: 38%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(42,35,28,0.28));
}
.res-text { display: flex; flex-direction: column; min-width: 0; align-items: flex-start; }
.res-count {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(16px, 2.3vw, 31px);
  line-height: 0.98;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.res-workers {
  font-family: var(--font-text);
  font-size: clamp(8px, 0.85vw, 12px);
  line-height: 1.1;
  color: rgba(42, 35, 28, 0.72);
  white-space: nowrap;
}
.res-chip.is-focus {
  background:
    radial-gradient(120% 120% at 50% 100%, rgba(201,169,97,0.32), rgba(201,169,97,0.05) 70%);
  box-shadow: inset 0 0 0 1px rgba(42,35,28,0.22), inset 0 -3px 0 var(--ochre);
}
.res-chip.is-focus::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 6px;
  height: 6px;
  background: var(--ochre);
  border: 1px solid var(--ink);
  transform: translateX(-50%) rotate(45deg);
}

#tile-row {
  position: absolute;
  left: 3.2%;
  right: 3.2%;
  top: 41%;
  bottom: 17%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.6%;
}

.action-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 1px;
  min-width: 0;
  color: var(--parchment);
  border-radius: 5px;
  transition: transform 0.1s ease, opacity 0.15s ease, filter 0.15s ease;
}
.action-tile:active { transform: translateY(1px); }
.tile-icon {
  height: clamp(30px, 7.4vh, 58px);
  width: auto;
  max-width: 92%;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4));
  pointer-events: none;
}
.tile-text { display: flex; flex-direction: column; align-items: center; min-width: 0; width: 100%; line-height: 1.05; }
.tile-label {
  font-family: var(--font-text);
  font-weight: 700;
  font-variant: small-caps;
  font-size: clamp(9px, 1.08vw, 15px);
  letter-spacing: 0.02em;
  color: #f7ead0;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  white-space: nowrap;
}
.tile-cost {
  font-family: var(--font-num);
  font-weight: 500;
  font-size: clamp(8px, 0.9vw, 12px);
  color: #eadbb9;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  font-variant-numeric: tabular-nums;
}
.tile-cost.poor { color: #f0b09b; }
.action-tile.is-poor { opacity: 0.62; filter: saturate(0.55); }
.action-tile.is-locked { opacity: 0.42; filter: saturate(0.4); }
.action-tile.is-active {
  box-shadow: inset 0 0 0 2px rgba(201,169,97,0.9), 0 0 8px rgba(201,169,97,0.35);
}
#tile-rally.is-rallying .tile-icon { animation: rallyPulse 0.5s ease; }
@keyframes rallyPulse {
  0% { transform: rotate(-8deg) scale(1); }
  50% { transform: rotate(7deg) scale(1.11); }
  100% { transform: rotate(0) scale(1); }
}

.info-tile {
  justify-content: center;
  padding: 2%;
  text-align: center;
  border-left: 1px solid rgba(201,169,97,0.35);
  background: linear-gradient(180deg, rgba(242,228,198,0.06), rgba(0,0,0,0.06));
  border-radius: 4px;
}
.info-name {
  font-family: var(--font-text);
  font-weight: 700;
  font-variant: small-caps;
  font-size: clamp(10px, 1.1vw, 16px);
  color: #f7ead0;
  text-shadow: 0 1px 2px rgba(0,0,0,0.55);
  line-height: 1.1;
}
.info-sub {
  font-family: var(--font-text);
  font-size: clamp(8px, 0.85vw, 11px);
  color: #d9c9a7;
  line-height: 1.15;
  max-width: 100%;
}
.info-sub.poor { color: #f0b09b; }

/* ---------- Sheets ---------- */

.sheet {
  position: fixed;
  left: 50%;
  bottom: calc(var(--plate-h) + var(--safe-bottom) + 8px);
  transform: translateX(-50%);
  pointer-events: auto;
  width: min(94vw, 660px);
  max-height: min(52vh, 430px);
  z-index: 20;
  overflow: auto;
  padding: clamp(10px, 1.4vw, 18px);
  background:
    radial-gradient(120% 100% at 12% 0%, #fbf2da 0%, #f0e0bf 55%, #ddc79c 100%);
  border: 2px solid #4a3a24;
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 3px rgba(201, 169, 153, 0.38),
    inset 0 0 40px rgba(120, 84, 40, 0.18),
    0 12px 30px rgba(0, 0, 0, 0.45);
  scrollbar-width: thin;
}
.sheet::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(74, 58, 36, 0.28);
  border-radius: 4px;
  pointer-events: none;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  position: relative;
}
.sheet-title {
  font-family: var(--font-text);
  font-weight: 700;
  font-variant: small-caps;
  font-size: clamp(16px, 1.8vw, 22px);
  color: #3a2c1d;
  letter-spacing: 0.03em;
}
.sheet-close {
  font-family: var(--font-text);
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
  width: 30px;
  height: 30px;
  border: 1.5px solid #4a3a24;
  border-radius: 50%;
  background: rgba(242,228,198,0.7);
  display: grid;
  place-items: center;
  color: #3a2c1d;
  flex: 0 0 auto;
}
.sheet-note {
  margin: 9px 0 2px;
  font-family: var(--font-text);
  font-size: clamp(10px, 1vw, 13px);
  font-style: italic;
  color: #6c5233;
  text-align: center;
}

#build-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(5px, 0.8vw, 10px);
}
.build-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px 7px;
  border: 1.5px solid rgba(74, 58, 36, 0.55);
  border-radius: 5px;
  background: linear-gradient(180deg, rgba(255,250,235,0.55), rgba(201,169,97,0.16));
  color: #3a2c1d;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.build-card:hover { background: rgba(255, 250, 235, 0.72); box-shadow: 0 2px 8px rgba(74,58,36,0.2); }
.build-card:active { transform: translateY(1px); }
.build-card.is-poor { opacity: 0.74; }
.build-card img {
  width: 100%;
  height: clamp(34px, 5.6vh, 58px);
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(42,35,28,0.2));
}
.build-name {
  font-family: var(--font-text);
  font-weight: 700;
  font-variant: small-caps;
  font-size: clamp(10px, 1.05vw, 14px);
  line-height: 1.05;
  text-align: center;
}
.build-perk {
  font-family: var(--font-text);
  font-size: clamp(8px, 0.8vw, 10px);
  line-height: 1.12;
  text-align: center;
  color: #6c5233;
  min-height: 2.2em;
}
.build-cost {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 5px;
  font-family: var(--font-num);
  font-weight: 500;
  font-size: clamp(9px, 0.9vw, 12px);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.build-cost .c { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; }
.build-cost .c img { width: 12px; height: 12px; object-fit: contain; }
.build-cost .c.no { color: #8C3A2E; }

.help-body { position: relative; font-family: var(--font-text); font-size: clamp(11px, 1.1vw, 15px); line-height: 1.32; color: #3a2c1d; }
.help-body p { margin: 0 0 7px; }
.help-body b { font-weight: 700; }
.help-small { font-style: italic; color: #6c5233; font-size: 0.92em; }

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(var(--plate-h) + var(--safe-bottom) + 14px);
  pointer-events: auto;
  background:
    radial-gradient(90% 80% at 50% 42%, rgba(242, 228, 198, 0.18), rgba(42, 35, 28, 0.58) 100%);
}

.intro-card {
  position: relative;
  width: min(92vw, 460px);
  max-height: calc(100vh - var(--plate-h) - 46px);
  max-height: calc(100dvh - var(--plate-h) - 46px);
  overflow: auto;
  padding: clamp(18px, 3.4vw, 32px) clamp(16px, 3.4vw, 34px) clamp(16px, 2.6vw, 24px);
  background:
    radial-gradient(110% 100% at 18% 0%, #fff7e4 0%, #f2e4c6 52%, #ddc79c 100%);
  border: 3px solid #4a3a24;
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 4px rgba(201, 169, 97, 0.55),
    inset 0 0 50px rgba(120, 84, 40, 0.16),
    0 18px 50px rgba(0, 0, 0, 0.6);
  text-align: center;
}
.intro-card::before,
.intro-card::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  height: 5px;
  background:
    repeating-linear-gradient(90deg, rgba(74,58,36,0.55) 0 2px, transparent 2px 9px);
  opacity: 0.55;
}
.intro-card::before { top: 7px; }
.intro-card::after { bottom: 7px; }
.intro-kicker {
  font-family: var(--font-text);
  font-style: italic;
  font-size: clamp(10px, 1.2vw, 14px);
  color: #6c5233;
  letter-spacing: 0.04em;
}
.intro-title {
  margin: 2px 0 6px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(33px, 6.4vw, 58px);
  line-height: 0.95;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(201, 169, 97, 0.45);
}
.intro-lede {
  margin: 0 auto 13px;
  max-width: 34ch;
  font-family: var(--font-text);
  font-size: clamp(12px, 1.35vw, 16px);
  line-height: 1.35;
  color: #4a3a24;
}
.intro-list {
  list-style: none;
  margin: 0 auto 16px;
  padding: 0;
  max-width: 38ch;
  text-align: left;
}
.intro-list li {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 4px 0;
  font-family: var(--font-text);
  font-size: clamp(11px, 1.2vw, 14px);
  line-height: 1.25;
  color: #4a3a24;
  border-bottom: 1px solid rgba(74, 58, 36, 0.14);
}
.intro-list li:last-child { border-bottom: 0; }
.intro-list li span {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 1.5px solid #4a3a24;
  border-radius: 50%;
  font-family: var(--font-num);
  font-size: 11px;
  font-weight: 700;
  color: #4a3a24;
  background: rgba(201, 169, 97, 0.22);
}
.intro-list b { font-weight: 700; color: var(--ink); }

#begin-btn,
#again-btn {
  display: inline-block;
  padding: 10px 26px;
  border: 2px solid #3a2c1d;
  border-radius: 4px;
  background:
    linear-gradient(180deg, #e2c27a 0%, #c9a961 55%, #a9873f 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 246, 210, 0.8),
    inset 0 -2px 0 rgba(74, 58, 36, 0.35),
    0 3px 6px rgba(0, 0, 0, 0.3);
  font-family: var(--font-text);
  font-weight: 700;
  font-variant: small-caps;
  font-size: clamp(14px, 1.5vw, 18px);
  letter-spacing: 0.04em;
  color: #2b2114;
  text-shadow: 0 1px 0 rgba(255, 248, 226, 0.45);
  transition: transform 0.1s ease, filter 0.12s ease;
}
#begin-btn:active,
#again-btn:active { transform: translateY(1px); }
#begin-btn:hover,
#again-btn:hover { filter: brightness(1.06); }
.intro-foot {
  margin-top: 10px;
  font-family: var(--font-text);
  font-size: clamp(9px, 0.95vw, 11px);
  font-style: italic;
  color: #7b6140;
}

#end-screen {
  background:
    radial-gradient(72% 68% at 50% 42%, rgba(255, 246, 222, 0.90) 0%, rgba(242, 228, 198, 0.8) 52%, rgba(210, 188, 143, 0.82) 100%);
  flex-direction: column;
}
.end-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: min(92vw, 460px);
  max-height: calc(100vh - var(--plate-h) - 36px);
  max-height: calc(100dvh - var(--plate-h) - 36px);
  overflow: auto;
  padding: 10px;
  animation: endIn 0.5s ease both;
}
@keyframes endIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
#end-seal {
  width: clamp(110px, 21vh, 190px);
  height: auto;
  filter: drop-shadow(0 8px 12px rgba(42, 35, 28, 0.35));
  margin-bottom: -4px;
}
.end-word {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(36px, 7vw, 62px);
  line-height: 0.95;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(201, 169, 97, 0.45);
}
.end-lede {
  margin: 7px 0 12px;
  font-family: var(--font-text);
  font-style: italic;
  font-size: clamp(13px, 1.4vw, 17px);
  color: #4a3a24;
}
.end-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  margin-bottom: 10px;
  font-family: var(--font-text);
  font-size: clamp(11px, 1.15vw, 14px);
  color: #4a3a24;
}
.end-stats b {
  display: block;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(15px, 1.7vw, 21px);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.end-board {
  width: 100%;
  max-width: 330px;
  margin: 0 0 14px;
  font-family: var(--font-text);
  font-size: clamp(10px, 1vw, 12px);
  color: #4a3a24;
}
.end-board .board-title {
  font-variant: small-caps;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-bottom: 1px solid rgba(74,58,36,0.25);
  padding-bottom: 2px;
  margin-bottom: 4px;
}
.end-board ol { margin: 0; padding: 0; list-style: none; }
.end-board li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 1px 0;
  border-bottom: 1px dotted rgba(74,58,36,0.16);
}
.end-board a { color: var(--blue); text-decoration: none; }
.end-board a:hover { text-decoration: underline; }

/* ---------- Wide action tiles ---------- */

@media (min-width: 900px) {
  .action-tile { flex-direction: row; gap: clamp(7px, 0.9vw, 16px); }
  .tile-text { align-items: flex-start; width: auto; }
  .tile-icon { height: clamp(34px, 6vh, 48px); }
  .info-tile { flex-direction: column; gap: 2px; }
}

/* ---------- Small screens ---------- */

@media (max-width: 560px) {
  :root {
    --title-w: clamp(118px, 34vw, 150px);
  }
  #match-state { gap: 5px; padding: 4px 7px; }
  .clock-icon { width: 18px; }
  #timer { font-size: 15px; }
  .shield { width: 16px; }
  .army-count { font-size: 14px; }
  #toast { top: calc(var(--safe-top) + var(--title-h) + 6px); max-width: 88vw; }

  #res-row { left: 4%; right: 4%; gap: 0; }
  .res-chip { flex-direction: column; gap: 0; justify-content: center; }
  .res-icon { height: clamp(22px, 3.4vh, 32px); max-width: 46%; }
  .res-text { align-items: center; }
  .res-count { font-size: clamp(13px, 4.1vw, 19px); }
  .res-workers { font-size: clamp(7px, 1.9vw, 9px); }
  .tile-icon { height: clamp(34px, 7.1vh, 54px); }
  .tile-label { font-size: clamp(8px, 2.45vw, 11px); }
  .tile-cost { font-size: clamp(7px, 1.9vw, 9px); }
  .info-name { font-size: clamp(9px, 2.5vw, 12px); }
  .info-sub { font-size: clamp(7px, 1.8vw, 9px); }
  #build-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .build-card:nth-child(4), .build-card:nth-child(5) { grid-column: span 1; }
  .sheet { max-height: 56vh; }
}

@media (orientation: landscape) {
  .pips { display: none; }
  #help-btn { left: calc(100% + 8px); top: 4px; }
}

@media (max-width: 360px) {
  .pips { display: none; }
}

@media (max-height: 560px) {
  :root { --title-w: clamp(120px, 19vw, 190px); }
  .intro-card { width: min(92vw, 690px); padding: 10px 18px 12px; }
  .intro-kicker { display: none; }
  .intro-title { font-size: clamp(24px, 4.2vw, 38px); margin-bottom: 2px; }
  .intro-lede { margin-bottom: 5px; font-size: 11px; }
  .intro-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 16px;
    width: 100%;
    max-width: none;
    margin-bottom: 7px;
  }
  .intro-list li { padding: 2px 0; font-size: 10.5px; border-bottom: 0; }
  .intro-list li span { width: 15px; height: 15px; font-size: 9px; }
  .intro-foot { display: none; }
  #begin-btn { padding: 6px 20px; font-size: 13px; }
}
