:root {
  --ink: #fff6e8;
  --amber: #ffb15a;
  --ember: #ff6a2a;
  --panel: rgba(18, 6, 22, 0.62);
  --line: rgba(255, 186, 110, 0.45);
  --btn: #2a1424;
  --btn-on: #ff7a32;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #14041c;
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

*, *::before, *::after { -webkit-touch-callout: none; }
button, canvas, #controls, #move-bar, #top-hud { touch-action: none; user-select: none; -webkit-user-select: none; }
input[type="range"] { touch-action: none; min-height: 48px; }

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

button {
  min-width: 48px;
  min-height: 48px;
  border: 1px solid var(--line);
  background: linear-gradient(#3a2030, var(--btn));
  color: var(--ink);
  border-radius: 12px;
  font: 700 17px/1.1 "Trebuchet MS", "Segoe UI", sans-serif;
  letter-spacing: 0.02em;
  padding: 0 12px;
  cursor: pointer;
}

button:active { transform: translateY(1px) scale(0.98); }
button:disabled { opacity: 0.42; cursor: default; transform: none; }
button.is-on {
  background: linear-gradient(#ffb15a, var(--btn-on));
  color: #2a0c08;
  border-color: #ffe1b0;
}
button.dim { opacity: 0.55; }

#volume-btn {
  position: fixed;
  top: 6px;
  right: 6px;
  z-index: 8;
  height: 48px;
  min-width: 48px;
  width: 48px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#volume-btn svg { display: block; }
#volume-btn.is-muted .waves { display: none; }
body:not([data-screen="play"]) #volume-btn {
  top: auto;
  bottom: 8px;
}
body[data-screen="setup"] #volume-btn,
body[data-screen="title"] #volume-btn {
  top: 6px;
  right: 6px;
  bottom: auto;
}
body[data-screen="store"] #volume-btn,
body[data-screen="pass"] #volume-btn,
body[data-screen="handoff"] #volume-btn,
body[data-screen="settings"] #volume-btn,
body[data-screen="howto"] #volume-btn { display: none; }

#volume-pop {
  position: fixed;
  z-index: 9;
  top: 58px;
  right: 8px;
  width: min(240px, calc(100vw - 16px));
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(16, 6, 22, 0.94);
  border: 1px solid rgba(255, 186, 110, 0.55);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
#volume-pop[hidden] { display: none !important; }
body:not([data-screen="play"]) #volume-pop {
  top: auto;
  bottom: 60px;
}
body[data-screen="title"] #volume-pop {
  top: 58px;
  right: 8px;
  bottom: auto;
}
body[data-screen="setup"] #volume-pop {
  top: 6px;
  left: 8px;
  right: 62px;
  bottom: auto;
  width: auto;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
}
body[data-screen="setup"] #volume-pop .vol-lab {
  flex-direction: row;
  align-items: center;
  flex: 1 1 140px;
  min-width: 120px;
}
body[data-screen="setup"] #volume-pop button { flex: 0 0 auto; }
body[data-screen="setup"] .setup-head { padding-right: 56px; }
body[data-screen="setup"]:has(#volume-pop:not([hidden])) #screen-setup {
  padding-top: 64px;
}
.vol-lab {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 16px;
  font-weight: 700;
  color: #ffe7c4;
}
#volume-slider {
  width: 100%;
  height: 48px;
  accent-color: #ff8a3c;
}
#volume-pop button { height: 48px; min-height: 48px; }

#top-hud {
  display: none;
  position: fixed;
  z-index: 3;
  top: 6px;
  left: 6px;
  right: 118px;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  pointer-events: none;
}

.panel {
  background: rgba(18, 6, 22, 0.38);
  border: 1px solid rgba(255, 190, 120, 0.28);
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.15;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}
#hud-fuel { display: none; }
#hud-fuel.on { display: block; }

.health { display: flex; gap: 8px; align-items: center; }
.chip { display: inline-flex; gap: 4px; align-items: center; opacity: 0.75; }
.chip-on { opacity: 1; }
.chip-dead { opacity: 0.35; text-decoration: line-through; }
.chip i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px currentColor;
}
.chip b { font-weight: 800; font-size: 16px; }

#move-bar {
  display: none;
  position: fixed;
  z-index: 4;
  left: 8px;
  bottom: 64px;
  gap: 6px;
}
#move-bar button { display: none; height: 48px; min-height: 48px; min-width: 96px; }
#move-bar button.show { display: inline-flex; align-items: center; justify-content: center; }
body[data-screen="play"] #move-bar.on { display: flex; }

/* controls: see v5.1 block at the end */

#turn-banner {
  display: none;
  position: fixed;
  z-index: 4;
  left: 0;
  right: 0;
  top: 18%;
  height: 64px;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 16px;
  font: 800 40px/1 Impact, "Arial Black", sans-serif;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 #14040c, 0 0 12px rgba(0, 0, 0, 0.9), 0 8px 20px rgba(0, 0, 0, 0.55);
  -webkit-text-stroke: 5px rgba(16, 4, 10, 0.55);
  paint-order: stroke fill;
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px);
  transition: transform 0.28s ease;
}
#turn-banner.show { opacity: 1; transform: translateY(0); }

#screen-title, #screen-setup, #screen-winner,
#screen-store, #screen-pass, #screen-final, #screen-handoff,
#screen-settings, #screen-howto { display: none; }

body[data-screen="title"] #screen-title,
body[data-screen="setup"] #screen-setup,
body[data-screen="winner"] #screen-winner,
body[data-screen="store"] #screen-store,
body[data-screen="pass"] #screen-pass,
body[data-screen="final"] #screen-final,
body[data-screen="handoff"] #screen-handoff,
body[data-screen="settings"] #screen-settings,
body[data-screen="howto"] #screen-howto { display: flex; }

body[data-screen="play"] #top-hud,
body[data-screen="play"] #controls,
body[data-screen="play"] #turn-banner { display: flex; }

#screen-title {
  position: fixed;
  z-index: 5;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(16, 4, 18, 0.2), rgba(8, 2, 12, 0.62) 72%);
}
.logo-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 28px 2px;
  background: radial-gradient(ellipse at 50% 55%, rgba(10, 2, 14, 0.55), rgba(10, 2, 14, 0) 72%);
}
.logo-mark { margin-bottom: 2px; filter: drop-shadow(0 0 8px rgba(255, 120, 40, 0.65)); }
#screen-title h1 {
  margin: 0;
  position: relative;
  font: 900 88px/0.86 Impact, "Arial Black", sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background:
    linear-gradient(180deg,
      #fff 0%, #e8eef4 16%, #8b97a3 34%,
      #2a120c 42%, #2a120c 50%,
      #f7fbff 56%, #6a7580 74%, #d5dde6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1px rgba(40, 18, 12, 0.35);
  filter:
    drop-shadow(0 1px 0 rgba(255, 255, 255, 0.65))
    drop-shadow(0 5px 0 #3a1810)
    drop-shadow(0 0 16px rgba(255, 110, 40, 0.9));
  animation: logo-glow 3.6s ease-in-out infinite;
}
.logo-wrap::after { content: none; }
@keyframes logo-glow {
  0%, 100% { filter: drop-shadow(0 1px 0 rgba(255,255,255,0.65)) drop-shadow(0 5px 0 #3a1810) drop-shadow(0 0 12px rgba(255, 110, 40, 0.75)); }
  50% { filter: drop-shadow(0 1px 0 rgba(255,255,255,0.65)) drop-shadow(0 5px 0 #3a1810) drop-shadow(0 0 22px rgba(255, 150, 50, 1)); }
}
#screen-title .tag {
  margin: 6px 0 0;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  font-size: 16px;
  color: #ffd7b0;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}
.title-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
  flex-wrap: wrap;
  justify-content: center;
}
#play-btn {
  pointer-events: auto;
  min-width: 148px;
  height: 60px;
  font-size: 28px;
  background: linear-gradient(#ffd08a, #ff5a24);
  color: #2a0c08;
  border-color: #ffe7c4;
  box-shadow: 0 0 18px rgba(255, 90, 30, 0.45);
}
#settings-btn, #howto-btn {
  pointer-events: auto;
  height: 52px;
  min-width: 108px;
  font-size: 16px;
}
#screen-settings, #screen-howto {
  position: fixed;
  z-index: 6;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: #100610;
  pointer-events: auto;
}
#screen-settings .sheet {
  width: min(720px, 100%);
}
#screen-settings .sheet {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(16, 6, 22, 0.94);
  border: 2px solid rgba(255, 176, 90, 0.7);
}
#screen-settings h2, .howto-head h2 {
  margin: 0;
  font: 800 32px/1 Impact, "Arial Black", sans-serif;
  color: #ffe1b8;
  letter-spacing: 0.04em;
}
#screen-settings button { height: 48px; }
#settings-back-btn, #howto-back-btn {
  background: linear-gradient(#ffd08a, #ff5a24);
  color: #2a0c08;
  border-color: #ffe7c4;
}
#screen-howto {
  justify-content: flex-start;
  gap: 8px;
  padding: 8px 10px 10px;
}
.howto-head {
  width: min(720px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#howto-back-btn { height: 48px; min-width: 96px; }
.howto-scroll {
  width: min(720px, 100%);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  touch-action: pan-y;
  padding: 4px 14px 28px 4px;
  font-size: 17px;
  line-height: 1.35;
  color: #fff1dc;
  background: rgba(14, 5, 18, 0.94);
  border-radius: 14px;
  scrollbar-width: auto;
  scrollbar-color: #ff7a32 #2a140c;
  box-shadow: inset -12px 0 0 rgba(255, 122, 50, 0.28), inset 0 -22px 18px -18px rgba(0, 0, 0, 0.72);
}
.howto-scroll h3 {
  margin: 12px 0 4px;
  font: 800 20px/1.1 Impact, "Arial Black", sans-serif;
  letter-spacing: 0.04em;
  color: #ffd08a;
}
.howto-scroll p { margin: 0 0 6px; }
.howto-list { display: flex; flex-direction: column; gap: 6px; }
.howto-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 6px;
  border-radius: 10px;
  background: rgba(255, 244, 230, 0.05);
}
.howto-row .store-ic { width: 36px; height: 36px; }
.howto-row svg { width: 36px; height: 36px; }
.howto-row b { display: block; font-size: 17px; }
.howto-row span { display: block; font-size: 16px; color: #ffe0c4; }
.howto-end { margin-top: 12px; color: #ffd7b0; }
.howto-scroll::-webkit-scrollbar { width: 10px; }
.howto-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(#ffb15a, #ff5a24);
  border-radius: 8px;
}
.credit {
  pointer-events: none;
  margin: 10px 0 0;
  font-size: 16px;
  color: #fff1dc;
  text-shadow: 0 1px 2px #14080a, 0 0 8px rgba(0, 0, 0, 0.85);
}

/* setup: see v5.1 block at the end */

#screen-winner {
  position: fixed;
  z-index: 6;
  inset: 0;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(8, 2, 12, 0.28);
}
#winner-card {
  pointer-events: auto;
  min-width: min(760px, calc(100vw - 20px));
  max-width: calc(100vw - 16px);
  padding: 16px 16px 14px;
  text-align: center;
  background: rgba(16, 6, 22, 0.95);
  border: 2px solid rgba(255, 176, 90, 0.75);
  border-radius: 18px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45), 0 0 30px rgba(255, 100, 30, 0.18);
}
#winner-text {
  margin: 0;
  font: 800 36px/1 Impact, "Arial Black", sans-serif;
  letter-spacing: 0.03em;
  color: #ffe1b8;
}
#winner-tally { margin: 6px 0 6px; color: #ffd0a4; }
#money-summary {
  margin: 4px 0 10px;
  text-align: left;
  overflow: visible;
}
#money-summary[hidden] { display: none; }
.mtable {
  width: 100%;
  border-collapse: collapse;
  font-size: 16px;
  line-height: 1.25;
}
.mtable th {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: right;
  color: #ffd7a8;
  padding: 2px 6px 4px;
  border-bottom: 1px solid rgba(255, 186, 110, 0.45);
}
.mtable th:first-child,
.mtable td:first-child { text-align: left; }
.mtable td {
  text-align: right;
  padding: 3px 6px;
  color: #fff1dc;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid rgba(255, 186, 110, 0.16);
}
.mtable .mname { font-weight: 800; text-align: left; }
.mtable .mearned { font-weight: 800; color: #ffe08a; }
.mtable .mbal { font-weight: 800; }
.winner-row { display: flex; gap: 8px; justify-content: center; }
.winner-row button { height: 56px; min-width: 128px; font-size: 18px; }
.winner-row { flex-wrap: wrap; }
#next-round-btn {
  background: linear-gradient(#ffd08a, #ff5a24);
  color: #2a0c08;
  border-color: #ffe7c4;
}

#screen-store {
  position: fixed;
  z-index: 7;
  inset: 0;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  background: rgba(12, 4, 16, 0.94);
  pointer-events: auto;
}
.store-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
}
#store-title {
  margin: 0;
  flex: 1;
  font: 800 28px/1 Impact, "Arial Black", sans-serif;
  letter-spacing: 0.03em;
}
#store-cash {
  font: 800 22px/1 "Trebuchet MS", sans-serif;
  color: #ffe7b0;
}
#store-done-btn {
  height: 48px;
  min-width: 100px;
  background: linear-gradient(#ffd08a, #ff5a24);
  color: #2a0c08;
  border-color: #ffe7c4;
  font-size: 18px;
}
.store-note {
  margin: 0;
  min-height: 0;
  font-size: 16px;
  color: #ffd7b0;
}
.store-note:empty { display: none; }
.store-tabs { display: flex; gap: 6px; }
.store-tabs button { flex: 1; height: 48px; font-size: 17px; }
.store-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.store-grid {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
  align-content: start;
  touch-action: pan-y;
  padding-bottom: 8px;
}
.store-grid.can-scroll {
  mask-image: linear-gradient(#000 0, #000 calc(100% - 28px), transparent);
}
#store-more {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  color: #ffe7b0;
  pointer-events: none;
  text-shadow: 0 1px 4px #000;
}
#store-more[hidden] { display: none; }
.store-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(255, 244, 230, 0.06);
  border: 1px solid rgba(255, 186, 110, 0.35);
}
.store-top { display: flex; gap: 8px; align-items: center; }
.store-ic {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
}
.store-meta { display: flex; flex-direction: column; min-width: 0; }
.store-meta strong { font-size: 17px; }
.store-price { color: #ffd08a; font-size: 16px; font-weight: 800; }
.store-card p { margin: 0; font-size: 16px; color: #ffe0c4; line-height: 1.25; }
.store-own { font-size: 16px; color: #fff6e8; }
.store-actions { display: flex; gap: 6px; }
.store-actions button { flex: 1; height: 48px; min-height: 48px; }

#screen-handoff {
  position: fixed;
  z-index: 8;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: #10030f;
  pointer-events: auto;
}
.handoff-card {
  width: min(860px, 100%);
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  grid-template-areas:
    "pic copy"
    "go go";
  gap: 8px 12px;
  align-items: center;
  padding: 10px;
  border-radius: 16px;
  border: 3px solid #ffb15a;
  background: rgba(16, 6, 22, 0.94);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}
#handoff-portrait {
  grid-area: pic;
  width: 200px;
  height: 120px;
  border-radius: 12px;
  background: #1a0a14;
  justify-self: center;
}
.handoff-copy { grid-area: copy; min-width: 0; }
#handoff-round {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #ffd7a8;
}
#handoff-title {
  margin: 0;
  font: 800 32px/1.05 Impact, "Arial Black", sans-serif;
  text-align: left;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.55);
}
#handoff-stats, #handoff-wind {
  margin: 2px 0;
  font-size: 17px;
  font-weight: 800;
  color: #fff1dc;
}
#handoff-board {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.ho-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: 8px;
  background: rgba(255, 244, 230, 0.06);
  border: 1px solid rgba(255, 186, 110, 0.28);
  font-size: 16px;
  color: #fff6e8;
}
.ho-row.is-me { border-color: #fff; background: rgba(255, 244, 230, 0.14); }
.ho-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
#handoff-go-btn {
  grid-area: go;
  height: 56px;
  width: 100%;
  font-size: 22px;
  background: linear-gradient(#ffd08a, #ff5a24);
  color: #2a0c08;
  border-color: #ffe7c4;
}

#screen-pass {
  position: fixed;
  z-index: 7;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(8, 2, 14, 0.9);
  pointer-events: auto;
}
#pass-title {
  margin: 0;
  font: 800 40px/1.05 Impact, "Arial Black", sans-serif;
  text-align: center;
  padding: 0 16px;
}
#pass-continue-btn {
  height: 56px;
  min-width: 180px;
  font-size: 22px;
  background: linear-gradient(#ffd08a, #ff5a24);
  color: #2a0c08;
  border-color: #ffe7c4;
}

#screen-final {
  position: fixed;
  z-index: 7;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: rgba(8, 2, 14, 0.82);
  pointer-events: auto;
}
#screen-final h2 {
  margin: 0;
  font: 800 36px/1 Impact, "Arial Black", sans-serif;
  color: #ffe1b8;
}
#final-list {
  list-style: none;
  margin: 0;
  padding: 0;
  width: min(640px, 100%);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.final-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(16, 6, 22, 0.78);
  border: 1px solid rgba(255, 186, 110, 0.35);
}
.final-row b { width: 64px; font-size: 18px; }
.final-row span { font-size: 17px; color: #ffe7c8; }
.medal {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #2a1408;
  flex: 0 0 auto;
}
.medal.gold { background: #ffd15c; }
.medal.silver { background: #e6e8ee; }
.medal.bronze { background: #e09a62; }
.medal.plain { background: #6a5a68; color: #fff; }
#play-again-btn {
  height: 52px;
  min-width: 140px;
  background: linear-gradient(#ffd08a, #ff5a24);
  color: #2a0c08;
  border-color: #ffe7c4;
}

#rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(10, 3, 14, 0.88);
  color: #ffe7c4;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
#rotate-overlay strong {
  display: block;
  font: 800 32px/1.1 Impact, "Arial Black", sans-serif;
}
#rotate-overlay p { margin: 8px 0 0; font-size: 16px; }

@media (orientation: portrait) {
  #rotate-overlay { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  #screen-title h1 { animation: none; }
}
html.reduce-motion #screen-title h1 { animation: none; }

/* v5: wind gauge. Arrow grows with strength (full at 10); colour warms as it strengthens. */
.wind-chip {
  --wind-col: #bfe9c8;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 9px;
  border-color: color-mix(in srgb, var(--wind-col) 55%, transparent);
}
.wind-chip .wind-lab { font-size: 16px; font-weight: 700; opacity: 0.85; }
.wind-gauge {
  position: relative;
  display: inline-block;
  width: 92px;
  height: 18px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}
.wind-gauge .wind-mid {
  position: absolute; left: 50%; top: 3px; bottom: 3px; width: 2px; margin-left: -1px;
  background: rgba(255, 255, 255, 0.45);
}
.wind-gauge .wind-bar {
  position: absolute; top: 6px; height: 6px; left: 50%; width: 0;
  border-radius: 3px; background: var(--wind-col);
  box-shadow: 0 0 6px var(--wind-col);
  transition: width 0.25s ease, left 0.25s ease;
}
.wind-gauge .wind-head {
  position: absolute; top: 2px; width: 0; height: 0; margin-left: -2px;
  border-top: 7px solid transparent; border-bottom: 7px solid transparent;
  border-left: 11px solid var(--wind-col);
  transition: left 0.25s ease;
}
.wind-gauge .wind-head.left {
  margin-left: -9px;
  border-left: 0;
  border-right: 11px solid var(--wind-col);
}
.wind-chip .wind-num {
  min-width: 44px;
  font-size: 17px;
  font-weight: 800;
  color: var(--wind-col);
}
.wind-chip.wind-pulse { animation: windPulse 0.7s ease-out; }
@keyframes windPulse {
  0% { transform: scale(1.12); box-shadow: 0 0 14px var(--wind-col); }
  100% { transform: scale(1); box-shadow: none; }
}
.reduce-motion .wind-chip.wind-pulse { animation: none; }
#skip-store-btn[hidden] { display: none; }

/* =====================================================================
   v5.1 Stage 2: readability and touch.
   Rules of thumb: no rendered text under 16 CSS px, every control at least
   48 px (56-64 px for the main play buttons), clear labels instead of codes.
   ===================================================================== */

/* ---------- top HUD ---------- */
#top-hud {
  top: 8px;
  left: 8px;
  right: 66px;
  gap: 8px;
  flex-wrap: nowrap;
  overflow: hidden;
}
#hud-angle, #hud-power, #hud-weapon { display: none !important; }
#top-hud .panel {
  background: rgba(18, 6, 22, 0.66);
  border-color: rgba(255, 190, 120, 0.4);
  border-radius: 12px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}
#hud-turn { gap: 6px; font-size: 18px; font-weight: 800; border-left: 6px solid var(--turn-col, #fff6e4); }
#hud-turn .tn { color: var(--turn-col, #fff6e4); }
#hud-turn .rd { color: #ffe7c4; font-weight: 700; }
#hud-health { gap: 10px; }
.chip { opacity: 0.8; }
.chip-on { opacity: 1; }
.chip b { font-variant-numeric: tabular-nums; }
.wind-chip { gap: 8px; padding: 4px 10px; }
.wind-gauge { width: 84px; height: 18px; }
.wind-chip .wind-num { font-size: 18px; min-width: 46px; }

/* ---------- bottom controls ---------- */
#controls {
  display: none;
  position: fixed;
  z-index: 4;
  left: 8px;
  right: 8px;
  bottom: 8px;
  gap: 8px;
  align-items: stretch;
  justify-content: center;
}
.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(18, 6, 22, 0.78);
  border: 1px solid rgba(255, 190, 120, 0.45);
  flex: 0 0 auto;
}
#controls .step-btn {
  width: 56px;
  height: 56px;
  min-width: 56px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: linear-gradient(#ffe0b4, #ff8a3c);
  color: #2a0c08;
  border-color: #ffe7c4;
}
.step-btn svg { width: 30px; height: 30px; display: block; }
.step-read {
  position: relative;
  min-width: 72px;
  height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
.step-lab { font-size: 16px; font-weight: 700; color: #ffe0c2; }
.step-read b { margin-top: 3px; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; color: #fff8ee; }
.step-meter {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 2px;
  height: 4px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
#ctl-power-meter {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ffb15a, #ff4a16);
}
#controls button:disabled {
  background: #2c2430;
  color: #b4a6b2;
  border-color: #4a3c48;
  opacity: 0.6;
  box-shadow: none;
}
#controls:not(.live) .step-read { opacity: 0.6; }
#weapon-btn {
  flex: 1 1 200px;
  min-width: 0;
  max-width: 300px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  text-align: left;
  background: linear-gradient(#ffe0b4, #ff8a3c);
  color: #2a0c08;
  border-color: #ffe7c4;
  border-radius: 16px;
}
.wpn-ic { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 10px; background: rgba(42, 12, 8, 0.85); display: flex; align-items: center; justify-content: center; }
.wpn-ic svg { width: 36px; height: 36px; }
.wpn-txt { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 2px; }
.wpn-name { font-size: 18px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wpn-n { font-size: 16px; font-weight: 700; opacity: 0.85; }
.wpn-caret { font-size: 18px; flex: 0 0 auto; }
#fire-btn {
  flex: 0 1 220px;
  min-width: 112px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(#ffe7b0, #ff4a16);
  color: #2a0c08;
  border-color: #ffe7c4;
  font: 900 28px/1 Impact, "Arial Black", sans-serif;
  letter-spacing: 0.12em;
  box-shadow: 0 0 18px rgba(255, 80, 20, 0.55);
}
#controls.live #fire-btn { box-shadow: 0 0 22px rgba(255, 90, 20, 0.9), 0 0 4px rgba(255, 220, 160, 0.8); }

/* Move / Shield live just under the top HUD, over the sky, so they never hide a tank near the ground. */
#move-bar { left: 8px; top: 58px; bottom: auto; gap: 8px; }
#move-bar button { height: 52px; min-height: 52px; min-width: 104px; font-size: 17px; background: rgba(30, 12, 34, 0.9); }

/* ---------- weapon picker ---------- */
#weapon-pop {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 8px;
  background: rgba(8, 2, 12, 0.55);
}
#weapon-pop[hidden] { display: none !important; }
.wp-sheet {
  width: min(820px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(16, 6, 22, 0.97);
  border: 2px solid rgba(255, 176, 90, 0.8);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}
.wp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wp-head h2 { margin: 0; font: 800 26px/1 Impact, "Arial Black", sans-serif; letter-spacing: 0.04em; color: #ffe1b8; }
#weapon-pop-close { width: 52px; height: 52px; padding: 0; font-size: 22px; }
.wp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
  touch-action: pan-y;
}
.wp-opt {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  text-align: left;
  border-radius: 14px;
}
.wp-opt .wpn-ic { background: rgba(0, 0, 0, 0.35); }
.wp-opt.is-on { background: linear-gradient(#ffd08a, #ff7a32); color: #2a0c08; border-color: #fff0d0; }
.wp-opt.is-on .wpn-ic { background: rgba(42, 12, 8, 0.85); }

/* ---------- custom match setup ---------- */
#screen-setup {
  position: fixed;
  z-index: 5;
  inset: 0;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px 0;
  background: linear-gradient(180deg, rgba(12, 4, 16, 0.9), rgba(12, 4, 16, 0.72));
  pointer-events: auto;
}
.setup-top { display: flex; align-items: center; gap: 12px; padding-right: 58px; min-height: 52px; }
#setup-back-btn { height: 48px; min-width: 104px; }
.setup-title { margin: 0; font: 800 30px/1 Impact, "Arial Black", sans-serif; letter-spacing: 0.06em; color: #ffd7a8; }
.setup-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  touch-action: pan-y;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  grid-template-areas: "players match" "opts match";
  gap: 10px;
  align-content: start;
  padding-bottom: 90px;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(24, 8, 30, 0.9);
  border: 1px solid rgba(255, 186, 110, 0.42);
}
.card-players { grid-area: players; }
.card-match { grid-area: match; align-self: start; }
.card-opts { grid-area: opts; }
.card h3 { margin: 0; font: 800 22px/1 Impact, "Arial Black", sans-serif; letter-spacing: 0.05em; color: #ffd08a; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.seg {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.32);
}
.seg button { height: 48px; min-width: 52px; padding: 0 10px; border-radius: 11px; }
.seg-wrap { flex-wrap: wrap; }
.field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.flab { width: 72px; font-size: 18px; font-weight: 800; color: #fff1dc; }
#terrain-row { align-items: flex-start; }
#terrain-row .flab { padding-top: 15px; }
#terrain-row .seg { flex: 1 1 220px; }
#terrain-row .seg button { flex: 1 1 auto; }
.tank-row { display: flex; align-items: center; gap: 8px; min-height: 56px; }
.who { display: inline-flex; align-items: center; gap: 8px; width: 70px; flex: 0 0 auto; }
.swatch { width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 0 8px rgba(255, 180, 80, 0.45); flex: 0 0 auto; }
.tname { font-size: 18px; font-weight: 800; }
.who-btn { width: 108px; height: 48px; padding: 0 8px; flex: 0 0 auto; }
.who-btn.is-on { background: linear-gradient(#5b3a6a, #3a2048); color: #fff1dc; border-color: #c9a0ff; }
.who-btn:not(.is-on) { background: linear-gradient(#ffd08a, #ff7a32); color: #2a0c08; border-color: #fff0d0; }
.tank-row.is-human .skill-seg { display: none; }
.you-note { display: none; font-size: 16px; color: #ffe0c2; }
.tank-row.is-human .you-note { display: inline; }
.setup-note { margin: 0; font-size: 16px; color: #ffe0c2; }
.opt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt-grid button { height: 52px; }
#start-btn {
  position: fixed;
  z-index: 6;
  right: 14px;
  bottom: 12px;
  height: 64px;
  min-width: 190px;
  padding: 0 20px;
  font: 900 28px/1 Impact, "Arial Black", sans-serif;
  letter-spacing: 0.06em;
  background: linear-gradient(#ffd08a, #ff5a24);
  color: #2a0c08;
  border-color: #ffe7c4;
  border-radius: 16px;
  box-shadow: 0 0 22px rgba(255, 90, 30, 0.6), 0 8px 20px rgba(0, 0, 0, 0.5);
}

/* ---------- shared small-screen rules ---------- */
/* Under 900px the canvas labels (name · health + bar) carry health, so the chip row goes. */
@media (max-width: 900px) {
  #hud-health { display: none !important; }
  #fire-btn { flex: 0 0 150px; }
}
@media (max-width: 760px) {
  .setup-body {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "players players" "match opts";
  }
  .opt-grid { grid-template-columns: 1fr; }
  #hud-turn .rd-word, .chip .hn { display: none; }
  #controls { gap: 6px; left: 6px; right: 6px; }
  #controls .step-btn { width: 52px; height: 52px; min-width: 52px; }
  .step-read { min-width: 60px; height: 52px; }
  .step-read b { font-size: 22px; }
  .wpn-caret { display: none; }
  #weapon-btn { padding: 0 8px; gap: 6px; }
  #weapon-btn .wpn-name { font-size: 17px; }
  .wpn-ic { width: 34px; height: 34px; }
  .wpn-ic svg { width: 30px; height: 30px; }
  #fire-btn { flex: 0 0 116px; min-width: 116px; font-size: 26px; }
}

@media (max-height: 500px) {
  #screen-title { gap: 6px; }
  #screen-title h1 { font-size: 62px; letter-spacing: 0.06em; }
  #screen-title .tag { margin: 2px 0 0; }
  .logo-mark svg { width: 72px; height: 30px; }
  #play-btn { height: 56px; min-width: 132px; font-size: 26px; }
  #settings-btn, #howto-btn { height: 52px; min-width: 112px; font-size: 17px; padding: 0 12px; }
  .credit { margin: 2px 0 0; }
  #screen-howto, #screen-settings { padding: 6px 8px; }
  .howto-head, .howto-scroll, #screen-settings .sheet { width: 100%; }
  #screen-settings .sheet {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 10px;
    overflow-y: auto;
    max-height: 100%;
    touch-action: pan-y;
  }
  #screen-settings h2, #screen-settings .vol-lab, #settings-back-btn { grid-column: 1 / -1; }
  #screen-settings .vol-lab { flex-direction: row; align-items: center; gap: 12px; }
  #screen-settings h2, .howto-head h2 { font-size: 26px; }
  .handoff-card { grid-template-columns: 150px minmax(0, 1fr); padding: 8px; gap: 6px 10px; }
  #handoff-portrait { width: 150px; height: 92px; }
  #handoff-title { font-size: 26px; }
  #handoff-go-btn { height: 52px; font-size: 20px; }
  #turn-banner { font-size: 32px; top: 22%; height: 44px; }
  #top-hud { top: 6px; left: 6px; gap: 6px; }
  #volume-btn { top: 6px; right: 6px; }
  #controls { bottom: 6px; }
  #move-bar { top: 54px; }
  .setup-title { font-size: 26px; }
  .setup-top { min-height: 48px; }
  .setup-note { display: none; }
  .card { padding: 8px 10px; gap: 6px; }
  .tank-row { min-height: 52px; }
  #start-btn { height: 60px; min-width: 160px; font-size: 26px; right: 10px; bottom: 8px; }
  #winner-card { padding: 10px 12px; }
  #winner-text { font-size: 30px; }
  #screen-final h2, #pass-title, #handoff-title { font-size: 30px; }
  #screen-final { gap: 6px; padding: 8px; }
  .final-row { padding: 4px 10px; }
  #store-title { font-size: 24px; }
  #store-cash { font-size: 20px; }
  #screen-store { gap: 6px; padding: 6px 8px; }
  .store-head { min-height: 48px; }
  .store-grid { grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 6px; }
  .store-card {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) auto;
    grid-template-areas: "ic meta act" "ic own act";
    align-items: center;
    column-gap: 8px;
    row-gap: 0;
    padding: 6px 8px;
  }
  .store-top { display: contents; }
  .store-ic { grid-area: ic; }
  .store-meta { grid-area: meta; min-width: 0; }
  .store-meta strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .store-card p { display: none; }
  .store-own { grid-area: own; }
  .store-actions { grid-area: act; }
  .store-actions button { width: 64px; flex: 0 0 auto; }
  .mtable td, .mtable th { padding: 2px 6px; }
}

/* very small phones (667x375 class) */
@media (max-height: 400px) {
  #screen-title h1 { font-size: 54px; }
  .wind-gauge { width: 72px; }
  #hud-turn { font-size: 17px; }
}
#screen-settings .vol-lab input[type="range"] { flex: 1 1 auto; width: auto; min-width: 180px; }
