:root {
  --bg: #e8e4dc;
  --bg-deep: #ddd8cf;
  --panel: #faf8f4;
  --panel-border: #d4cfc4;
  --fog: #b8b3a8;
  --fog-edge: #a39e93;
  --dead: #ddd9d0;
  --dead-edge: #c9c4ba;
  --alive: #2f6b58;
  --alive-light: #4f9a82;
  --alive-bright: #6ec4a8;
  --hazard: #b84a3a;
  --hazard-soft: #f0ddd9;
  --exit: #2f6b4f;
  --exit-soft: #d8ebe1;
  --player: #a67c2e;
  --player-soft: #f5ecd8;
  --text: #2a2724;
  --text-soft: #5c574f;
  --muted: #8a847a;
  --pin: #6b5b8a;
  --pin-soft: #e8e2ef;
  --accent: #3d6b5e;
  --c1: #4a7fd4;
  --c2: #3d9a62;
  --c3: #c45c4a;
  --c4: #7b5fae;
  --c5: #b07a28;
  --c6: #3a9ca8;
  --c7: #8f4f6b;
  --c8: #5a5a5a;
  --shadow: rgba(42, 39, 36, 0.08);
  --shadow-deep: rgba(42, 39, 36, 0.14);
  --cell-size: 2rem;
  --font-ui: 'Source Sans 3', system-ui, sans-serif;
  --font-display: 'Libre Baskerville', Georgia, serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 10px;
  --radius-sm: 6px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

body {
  display: flex;
  justify-content: center;
  padding: 1.75rem 1.25rem 2.5rem;
  transition: background-color 0.35s ease;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 15% 10%, rgba(110, 196, 168, 0.22), transparent 55%),
    radial-gradient(ellipse 70% 55% at 88% 18%, rgba(123, 95, 174, 0.14), transparent 50%),
    radial-gradient(ellipse 65% 50% at 42% 92%, rgba(196, 92, 74, 0.1), transparent 55%),
    radial-gradient(ellipse 55% 45% at 72% 68%, rgba(74, 127, 212, 0.1), transparent 50%),
    linear-gradient(165deg, #f2efe8 0%, #e6e1d8 45%, #ddd7cc 100%);
}

body.fx-death-tint::before {
  animation: none;
  background: linear-gradient(165deg, #f0ddd8 0%, #e8d0cb 100%);
}

.ambient {
  pointer-events: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}

.ambient-mesh {
  position: absolute;
  inset: -20%;
  background:
    conic-gradient(from 120deg at 30% 25%, rgba(79, 154, 130, 0.07), transparent 38%),
    conic-gradient(from 220deg at 75% 60%, rgba(176, 122, 40, 0.06), transparent 42%),
    conic-gradient(from 40deg at 55% 80%, rgba(123, 95, 174, 0.05), transparent 40%);
}

.ambient-dots {
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: radial-gradient(circle, rgba(61, 107, 94, 0.18) 1px, transparent 1px);
  background-size: 28px 28px;
}

.ambient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(52px);
  opacity: 0.42;
}

.ambient-orb--1 {
  width: 300px;
  height: 300px;
  top: 6%;
  left: 4%;
  background: rgba(79, 154, 130, 0.4);
}

.ambient-orb--2 {
  width: 240px;
  height: 240px;
  top: 52%;
  right: 8%;
  background: rgba(176, 122, 40, 0.28);
}

.ambient-orb--3 {
  width: 200px;
  height: 200px;
  bottom: 10%;
  left: 34%;
  background: rgba(47, 107, 79, 0.25);
}

.ambient-orb--4 {
  width: 260px;
  height: 260px;
  top: 28%;
  right: 28%;
  background: rgba(123, 95, 174, 0.2);
}

.ambient-orb--5 {
  width: 180px;
  height: 180px;
  bottom: 28%;
  left: 12%;
  background: rgba(74, 127, 212, 0.18);
}

.app {
  width: min(100%, 1120px);
  position: relative;
  z-index: 1;
}

.header {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--panel-border);
}

.title-block h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.title-brand {
  background: linear-gradient(
    120deg,
    var(--text) 0%,
    var(--alive-bright) 35%,
    var(--c4) 55%,
    var(--text) 90%
  );
  background-size: 220% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 0.4rem 0 0;
  color: var(--text-soft);
  font-size: 0.92rem;
  font-style: italic;
}

.hud {
  display: grid;
  gap: 0.35rem;
  text-align: right;
  font-size: 0.88rem;
  min-width: 18rem;
}

.meta,
.charges {
  min-height: 1.2rem;
  line-height: 1.2rem;
  color: var(--text-soft);
}

.hp {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--hazard);
  min-height: 1.35rem;
  line-height: 1.35rem;
}

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

.phase {
  color: var(--accent);
  min-height: 1.35rem;
  line-height: 1.35rem;
  font-size: 0.84rem;
}

.phase kbd {
  font-size: 0.7rem;
  padding: 0.05rem 0.3rem;
}

.hud-actions {
  display: flex;
  gap: 0.45rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

.btn-ghost,
.btn-primary {
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0.4rem 0.7rem;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn-ghost:active,
.btn-primary:active {
  transform: scale(0.98);
}

.btn-ghost,
a.btn-ghost {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text-soft);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-ghost:hover {
  border-color: #a8a196;
  color: var(--text);
  background: #fff;
}

.btn-ghost.active {
  border-color: var(--player);
  color: #7a5a18;
  background: var(--player-soft);
}

.btn-ghost.small {
  padding: 0.22rem 0.5rem;
  font-size: 0.74rem;
}

.btn-primary {
  background: var(--accent);
  border: 1px solid #325a4f;
  color: #f4faf7;
}

.btn-primary:hover {
  background: #325a4f;
}

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.85rem;
  width: max-content;
  max-width: 100%;
  transition: filter 0.2s ease;
  touch-action: pan-y;
}

.grid-viewport {
  width: 100%;
  display: flex;
  justify-content: center;
  max-width: 100%;
}

.board-wrap.grid-scrolls .grid-viewport {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 0.15rem;
  scrollbar-gutter: stable;
}

.board-wrap.grid-fits .grid-viewport {
  overflow: visible;
}

.mode-picker {
  display: flex;
  gap: 0.4rem;
  width: 100%;
  flex-wrap: wrap;
}

.mode-picker.locked {
  opacity: 0.55;
  pointer-events: none;
}

.mode-btn {
  flex: 1 1 auto;
  min-width: 5.5rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text-soft);
  font-family: var(--font-ui);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.mode-btn:hover:not(:disabled) {
  border-color: #a8a196;
  background: #fff;
  color: var(--text);
}

.mode-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.mode-btn.active {
  border-color: var(--accent);
  background: var(--exit-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(61, 107, 94, 0.2);
}

.mode-btn:disabled {
  cursor: not-allowed;
}

.mode-name {
  font-size: 0.78rem;
  font-weight: 700;
}

.mode-size {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
}

.mode-btn.active .mode-size {
  color: var(--accent);
}

.board-wrap.fx-flash-danger {
  animation: danger-flash 0.48s ease-out;
}

.tutorial-panel {
  width: 100%;
  max-width: 100%;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: 0 2px 12px var(--shadow);
}

.tutorial-panel.hidden {
  display: none;
}

.tutorial-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.tutorial-progress {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

.tutorial-panel h3 {
  margin: 0 0 0.45rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--text);
}

.tutorial-panel p {
  margin: 0.35rem 0;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text-soft);
}

.tutorial-hint {
  color: var(--player) !important;
  font-weight: 600;
}

.tutorial-panel .btn-primary {
  margin-top: 0.55rem;
}

.tutorial-panel .btn-primary.hidden {
  display: none;
}

.cell.tutorial-highlight {
  outline: 2px solid var(--player);
  outline-offset: -1px;
  z-index: 3;
}

.playfield {
  display: grid;
  grid-template-columns: max-content minmax(320px, 360px);
  gap: 1.35rem;
  align-items: start;
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
}

.grid {
  --ripple-x: 50%;
  --ripple-y: 50%;
  position: relative;
  display: grid;
  width: max-content;
  max-width: 100%;
  gap: 3px;
  padding: 0.65rem;
  background: #d6d0c6;
  border: 1px solid #c5bfb4;
  border-radius: var(--radius);
  box-shadow:
    0 4px 18px var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  overflow: hidden;
  isolation: isolate;
}

.grid::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(
    135deg,
    rgba(79, 154, 130, 0.12) 0%,
    rgba(123, 95, 174, 0.08) 35%,
    rgba(176, 122, 40, 0.08) 65%,
    rgba(74, 127, 212, 0.1) 100%
  );
  pointer-events: none;
}

.grid::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0;
  pointer-events: none;
  transform-origin: var(--ripple-x) var(--ripple-y);
  background: radial-gradient(
    circle 72px at var(--ripple-x) var(--ripple-y),
    rgba(110, 196, 168, 0.28),
    rgba(123, 95, 174, 0.1) 48%,
    transparent 72%
  );
}

.grid.fx-evolve-pulse::after {
  animation: grid-ripple 0.55s ease-out;
}

.grid.fx-evolve-pulse {
  animation: grid-tick 0.32s ease-out;
}

.grid.fx-disrupt {
  animation: grid-disrupt 0.4s ease-out;
}

.grid.fx-stabilize {
  animation: grid-stabilize 0.5s ease-out;
}

.grid.fx-bomb {
  animation: grid-bomb 0.55s ease-out;
}

.board-wrap.fx-flash-bomb {
  animation: bomb-flash 0.56s ease-out;
}

.app.fx-shake-bomb {
  animation: bomb-shake 0.52s ease-out;
}

.grid.fx-win-pulse {
  animation: grid-win 0.75s ease-out;
}

.grid > .cell {
  position: relative;
  z-index: 1;
}

.grid:not(.grid-playing) > .cell {
  cursor: default;
}

.grid.xray-active {
  box-shadow:
    0 4px 18px var(--shadow),
    inset 0 0 0 2px var(--player-soft);
  border-color: #c9a96a;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: none;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  cursor: default;
  border-radius: 3px;
  transition: background 0.12s ease, color 0.12s ease;
}

.cell.fog {
  background: linear-gradient(145deg, var(--fog) 0%, #d8d3c9 100%);
  color: transparent;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.35),
    inset -1px -1px 0 var(--fog-edge);
  contain: paint;
}

html[data-fog-shimmer='on'] .cell.fog:not(.xray) {
  animation: fog-shimmer 5s ease-in-out infinite;
}

.cell.fog.xray {
  background: #c5c0b6;
  animation: none;
}

.cell.fog.xray.alive {
  color: var(--alive);
  background: linear-gradient(145deg, #a8d9c8, #7fb8a4);
  box-shadow: inset 0 0 0 1px var(--alive-light);
}

.cell.revealed {
  background: var(--dead);
  color: var(--text-soft);
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.65),
    inset -1px -1px 0 var(--dead-edge);
}

.cell.revealed.count-1 { color: var(--c1); }
.cell.revealed.count-2 { color: var(--c2); }
.cell.revealed.count-3 { color: var(--c3); font-weight: 700; }
.cell.revealed.count-4 { color: var(--c4); }
.cell.revealed.count-5 { color: var(--c5); }
.cell.revealed.count-6 { color: var(--c6); }
.cell.revealed.count-7 { color: var(--c7); }
.cell.revealed.count-8 { color: var(--c8); font-weight: 700; }

.cell.revealed.alive {
  background: linear-gradient(145deg, var(--alive-bright) 0%, var(--alive-light) 55%, var(--alive) 100%);
  color: #f2faf7;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.25),
    inset 0 -2px 4px rgba(0, 0, 0, 0.08);
}

.cell.revealed.alive.fx-cell-born {
  animation: cell-born 0.38s ease-out;
}

.cell.fx-cell-died {
  animation: cell-died 0.36s ease-out forwards;
}

.cell.revealed.player.fx-player-land {
  animation: player-land 0.26s ease-out;
}

.cell.revealed.hazard:not(.player) {
  background: linear-gradient(145deg, #f5e0dc, var(--hazard-soft));
  color: var(--hazard);
  box-shadow:
    inset 0 0 0 2px var(--hazard),
    0 0 0 1px rgba(184, 74, 58, 0.18);
}

.cell.revealed.pinned {
  background: linear-gradient(145deg, #f0ebf8, var(--pin-soft));
  color: var(--pin);
  box-shadow: inset 0 0 0 1px #9a8ab0;
}

.cell.revealed.stabilized {
  outline: 1px dashed var(--c6);
  outline-offset: -2px;
}

.cell.revealed.exit {
  background: linear-gradient(145deg, #c8e8d6, var(--exit-soft));
  color: var(--exit);
  box-shadow:
    inset 0 0 0 2px var(--exit),
    0 0 0 1px rgba(61, 107, 94, 0.15);
}

.cell.revealed.player {
  background: linear-gradient(145deg, #fcecc8, var(--player-soft));
  color: #7a5a18;
  box-shadow: inset 0 0 0 2px var(--player);
  z-index: 2;
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  width: 100%;
  box-shadow: 0 2px 12px var(--shadow);
}

.sidebar-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem 1.25rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--panel-border);
}

.sidebar-block h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
}

.sidebar h2 {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
}

.sidebar h2:not(:first-child) {
  margin-top: 0.85rem;
}

.controls,
.log {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.84rem;
  color: var(--text-soft);
}

.controls li,
.log li {
  margin-bottom: 0.35rem;
}

.log {
  min-height: 5.5rem;
}

.log li.fx-log-new {
  animation: log-slide 0.45s ease-out;
}

.quickstart {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--text-soft);
}

.quickstart li {
  margin-bottom: 0.4rem;
}

.quickstart strong {
  color: var(--text);
  font-weight: 600;
}

.legend {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: var(--text-soft);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.75rem;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.swatch {
  width: 1rem;
  height: 1rem;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(42, 39, 36, 0.12);
}

.swatch.fog { background: var(--fog); }
.swatch.dead { background: var(--dead); }
.swatch.alive { background: linear-gradient(145deg, var(--alive-bright), var(--alive)); }
.swatch.hazard { background: var(--hazard-soft); box-shadow: inset 0 0 0 2px var(--hazard); }
.swatch.exit { background: var(--exit-soft); box-shadow: inset 0 0 0 2px var(--exit); }
.swatch.pinned { background: var(--pin-soft); }
.swatch.xray { background: #b8d4cb; }

.help-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(100%, 380px);
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  z-index: 300;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  overflow-y: auto;
  box-shadow: -8px 0 24px var(--shadow);
}

.help-drawer.open {
  transform: translateX(0);
}

.help-inner {
  padding: 1.5rem 1.25rem 2rem;
  position: relative;
}

.help-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
}

.help-close:hover {
  color: var(--text);
  background: #fff;
}

.help-drawer h2 {
  margin: 0 2rem 1rem 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--text);
}

.help-section {
  margin-bottom: 1.25rem;
}

.help-section h3 {
  margin: 0 0 0.45rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.help-section p,
.help-section li,
.help-section dd {
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--text-soft);
}

.help-section ul,
.help-section ol {
  margin: 0.4rem 0;
  padding-left: 1.2rem;
}

.help-section strong {
  color: var(--text);
}

.help-note {
  padding: 0.55rem 0.7rem;
  background: var(--exit-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-soft);
}

.ability-list {
  margin: 0;
}

.ability-list dt {
  font-size: 0.86rem;
  color: var(--text);
  font-weight: 600;
  margin-top: 0.5rem;
}

.ability-list dd {
  margin: 0.2rem 0 0.5rem;
}

.welcome-card {
  max-width: 28rem;
  text-align: left;
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 1.25rem 0 0.75rem;
}

.welcome-actions .btn-primary,
.welcome-actions .btn-ghost {
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
}

kbd {
  display: inline-block;
  padding: 0.12rem 0.38rem;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text);
  box-shadow: 0 1px 0 var(--shadow);
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(42, 39, 36, 0.35);
  backdrop-filter: blur(3px);
  z-index: 200;
}

.overlay.hidden {
  display: none;
}

.overlay.fx-overlay-in .overlay-card {
  animation: overlay-pop 0.4s ease-out;
}

.app.fx-shake-death {
  animation: screen-shake 0.55s ease-out;
}

.app.fx-win-glow {
  animation: win-glow 1.1s ease-out;
}

.overlay-card {
  text-align: center;
  padding: 2rem 2.25rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px var(--shadow-deep);
  max-width: 26rem;
}

.overlay-card h2 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--text);
}

.overlay-card p {
  margin: 0.5rem 0;
  color: var(--text-soft);
  line-height: 1.55;
}

.overlay-restart {
  width: 100%;
  margin-top: 1.1rem;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  min-height: 2.85rem;
  touch-action: manipulation;
}

.overlay-hint {
  margin-top: 0.85rem !important;
  color: var(--muted) !important;
  font-size: 0.84rem !important;
}

@media (max-width: 900px) {
  .overlay-hint-keys {
    display: none;
  }
}

.mobile-controls {
  display: none;
  width: 100%;
  gap: 0.55rem;
  padding: 0.65rem 0.5rem 0.25rem;
  border-top: 1px solid var(--panel-border);
  margin-top: 0.15rem;
}

.mobile-hint {
  margin: 0;
  text-align: center;
  font-size: 0.76rem;
  color: var(--muted);
}

.mobile-gadgets,
.mobile-util {
  display: grid;
  gap: 0.45rem;
}

.mobile-gadgets {
  grid-template-columns: repeat(3, 1fr);
}

.mobile-util {
  grid-template-columns: repeat(4, 1fr);
}

.mob-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 2.85rem;
  padding: 0.45rem 0.35rem;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.mob-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.mob-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.mob-btn-charge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--exit-soft);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  min-width: 1.35rem;
}

.mob-btn-disrupt {
  border-color: #d4a89a;
  background: #faf0ed;
}

.mob-btn-stabilize {
  border-color: #9ab8d4;
  background: #edf4fa;
}

.mob-btn-bomb {
  border-color: #d4b89a;
  background: #faf5ed;
}

.mob-btn-utility {
  min-height: 2.5rem;
  font-size: 0.74rem;
}

.mob-btn-utility.active {
  border-color: var(--player);
  background: var(--player-soft);
  color: #7a5a18;
}

.mob-btn-restart {
  border-color: var(--accent);
  background: var(--exit-soft);
  color: var(--accent);
}

.mob-btn-restart[hidden] {
  display: none;
}

@media (max-width: 900px) {
  .playfield {
    width: 100%;
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
  }

  .hud {
    text-align: left;
    min-width: 0;
  }

  .hud-actions .btn-ghost:nth-child(n + 3) {
    display: none;
  }

  .phase {
    display: none;
  }

  .board-wrap {
    margin-inline: auto;
    width: 100%;
    max-width: 100%;
    align-items: stretch;
  }

  .grid-viewport {
    width: 100%;
  }

  .grid {
    margin-inline: auto;
    flex-shrink: 0;
  }

  .mobile-controls {
    display: flex;
    flex-direction: column;
  }

  .sidebar {
    max-width: none;
    width: 100%;
  }

  .sidebar-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .sidebar-block h2 {
    font-size: 0.92rem;
  }

  .quickstart,
  .controls {
    font-size: 0.82rem;
  }

  .legend {
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem 0.75rem;
    font-size: 0.82rem;
  }

  .help-drawer {
    width: 100%;
  }
}

@media (max-width: 760px) {
  body {
    padding: 0.75rem 0.5rem 1.25rem;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }

  .title-block h1 {
    font-size: 1.45rem;
  }

  .tagline {
    font-size: 0.84rem;
  }

  .mode-btn {
    min-width: calc(33% - 0.35rem);
  }

  .sidebar-grid {
    grid-template-columns: 1fr;
  }

  .sidebar-block:nth-child(2) {
    display: none;
  }

  .legend {
    grid-template-columns: 1fr;
  }

  .mobile-util {
    grid-template-columns: repeat(2, 1fr);
  }

  .mob-btn-restart {
    grid-column: span 2;
  }

  .overlay-card {
    margin: 1rem;
    padding: 1.5rem 1.25rem;
    max-width: calc(100% - 2rem);
  }
}

@keyframes bg-shift {
  0%,
  100% {
    filter: hue-rotate(0deg) brightness(1);
  }
  50% {
    filter: hue-rotate(8deg) brightness(1.02);
  }
}

@keyframes mesh-spin {
  from {
    transform: rotate(0deg) scale(1);
  }
  to {
    transform: rotate(360deg) scale(1.05);
  }
}

@keyframes dots-drift {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 28px 28px;
  }
}

@keyframes ambient-drift {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  50% {
    transform: translate(12px, -8px) scale(1.02);
  }
}

@keyframes title-shimmer {
  0%,
  100% {
    background-position: 0% center;
  }
  50% {
    background-position: 100% center;
  }
}

@keyframes grid-mesh {
  0%,
  100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

@keyframes grid-ripple {
  0% {
    opacity: 0.7;
    transform: scale(0.85);
  }
  100% {
    opacity: 0;
    transform: scale(1.15);
  }
}

@keyframes fog-shimmer {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.04);
  }
}

@keyframes cell-breathe {
  0%,
  100% {
    filter: brightness(1) saturate(1);
  }
  50% {
    filter: brightness(1.05) saturate(1.08);
  }
}

@keyframes cell-born {
  0% {
    filter: brightness(1.2) saturate(1.2);
    transform: scale(0.92);
  }
  100% {
    filter: brightness(1) saturate(1);
    transform: scale(1);
  }
}

@keyframes cell-died {
  0% {
    opacity: 1;
  }
  40% {
    opacity: 0.5;
    filter: grayscale(0.25);
  }
  100% {
    opacity: 1;
    filter: none;
  }
}

@keyframes player-land {
  0% {
    transform: translate(var(--land-x, 0), var(--land-y, 0));
  }
  100% {
    transform: translate(0, 0);
  }
}

@keyframes grid-tick {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.003);
  }
}

@keyframes grid-disrupt {
  0%,
  100% {
    filter: none;
  }
  40% {
    filter: hue-rotate(-12deg) saturate(1.15);
  }
}

@keyframes grid-stabilize {
  0%,
  100% {
    box-shadow: 0 4px 18px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  }
  50% {
    box-shadow: 0 4px 20px rgba(58, 156, 168, 0.18), inset 0 0 0 1px rgba(58, 156, 168, 0.25);
  }
}

@keyframes grid-bomb {
  0%,
  100% {
    transform: scale(1);
    filter: none;
  }
  35% {
    transform: scale(1.012);
    filter: saturate(1.25) brightness(1.08);
  }
}

@keyframes bomb-flash {
  0%,
  100% {
    box-shadow: 0 4px 18px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  }
  40% {
    box-shadow:
      0 6px 28px rgba(184, 74, 58, 0.28),
      inset 0 0 0 2px rgba(184, 74, 58, 0.35);
  }
}

@keyframes bomb-shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-2px, 1px);
  }
  50% {
    transform: translate(2px, -1px);
  }
  75% {
    transform: translate(-1px, -1px);
  }
}

@keyframes grid-win {
  0%,
  100% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.008);
  }
}

@keyframes hazard-pulse {
  0%,
  100% {
    box-shadow: inset 0 0 0 2px var(--hazard);
  }
  50% {
    box-shadow: inset 0 0 0 2px var(--hazard), 0 0 0 1px rgba(184, 74, 58, 0.25);
  }
}

@keyframes exit-glow {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.06);
  }
}

@keyframes screen-shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-3px, 1px);
  }
  40% {
    transform: translate(3px, -2px);
  }
  60% {
    transform: translate(-2px, -1px);
  }
  80% {
    transform: translate(2px, 1px);
  }
}

@keyframes danger-flash {
  0%,
  100% {
    filter: none;
  }
  35% {
    filter: sepia(0.15) saturate(1.2);
  }
}

@keyframes win-glow {
  0%,
  100% {
    filter: none;
  }
  50% {
    filter: brightness(1.02) saturate(1.05);
  }
}

@keyframes log-slide {
  0% {
    opacity: 0;
    transform: translateX(6px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes overlay-pop {
  0% {
    opacity: 0;
    transform: scale(0.97) translateY(4px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  body::before {
    animation: none;
  }

  .title-brand {
    color: var(--text);
    background: none;
    -webkit-background-clip: unset;
    background-clip: unset;
  }
}