:root {
  --page-bg: #071018;
  --panel-bg: rgba(13, 26, 37, 0.95);
  --panel-line: rgba(214, 235, 247, 0.16);
  --text: #eff8ff;
  --muted: #9eb3c3;
  --red: #d9434f;
  --red-light: #ff8790;
  --red-dark: #761923;
  --blue: #3d7ee8;
  --blue-light: #8ab7ff;
  --blue-dark: #153e86;
  --green: #53a76a;
  --green-dark: #1f5830;
  --gold: #f1c55a;
  --board-size: min(72vw, calc(100svh - 260px), 720px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 50% 0%, rgba(59, 113, 146, 0.19), transparent 42%),
    linear-gradient(145deg, #071018 0%, #03070b 100%);
  color: var(--text);
}

body {
  min-height: 100svh;
  overflow-x: hidden;
}

button {
  font: inherit;
}

button:disabled {
  cursor: default;
}

.game-shell {
  width: min(1120px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: clamp(2px, 0.7vw, 8px);
  user-select: none;
}

.brand-letter {
  width: clamp(35px, 5vw, 58px);
  display: grid;
  justify-items: center;
  line-height: 1;
}

.brand-letter > span {
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(2.2rem, 5.1vw, 4.3rem);
  letter-spacing: 0.035em;
  color: #f4f7fa;
  text-shadow: 0 2px 0 #647482, 0 6px 12px rgba(0, 0, 0, 0.55);
}

.brand-letter > small {
  min-height: 1em;
  margin-top: 2px;
  font-size: clamp(0.7rem, 1.4vw, 1rem);
  color: var(--gold);
  text-shadow: 0 0 10px rgba(241, 197, 90, 0.58);
}

.top-actions,
.footer-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ui-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 9px;
  background: linear-gradient(180deg, #f3cb6a, #b77a22);
  color: #14100a;
  font-weight: 900;
  letter-spacing: 0.025em;
  cursor: pointer;
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.28);
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease, opacity 120ms ease;
}

.ui-button:hover:not(:disabled) {
  filter: brightness(1.08);
}

.ui-button:active:not(:disabled) {
  transform: translateY(1px) scale(0.985);
}

.ui-button:focus-visible,
.colour-choice:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.82);
  outline-offset: 3px;
}

.ui-button:disabled {
  opacity: 0.42;
}

.ui-button--secondary {
  background: linear-gradient(180deg, #20394d, #101f2c);
  color: var(--text);
}

.ui-button--danger {
  background: linear-gradient(180deg, #ef6570, #a91f2b);
  color: white;
}

.ui-button--small {
  min-height: 34px;
  padding-inline: 12px;
  font-size: 0.82rem;
}

.scoreboard {
  width: min(950px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(98px, 0.9fr) minmax(220px, 2.25fr) minmax(98px, 0.9fr) minmax(98px, 0.9fr);
  gap: 8px;
}

.score-card,
.turn-card {
  min-height: 58px;
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  background: var(--panel-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.score-card {
  gap: 10px;
  padding: 8px 12px;
}

.score-card strong {
  font-size: 1.5rem;
}

.score-name {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.score-label {
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0.11em;
}

.score-role {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.57rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-card--red {
  border-color: rgba(217, 67, 79, 0.38);
}

.score-card--red strong {
  color: var(--red-light);
}

.score-card--blue {
  border-color: rgba(61, 126, 232, 0.4);
}

.score-card--blue strong {
  color: var(--blue-light);
}

.score-card--neutral {
  border-color: rgba(83, 167, 106, 0.38);
}

.score-card--neutral strong {
  color: #85d99c;
}

.score-card.is-active {
  border-color: rgba(255, 255, 255, 0.84);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1), 0 0 20px rgba(255, 255, 255, 0.15);
}

.score-card.is-human {
  background-image: linear-gradient(145deg, rgba(255, 255, 255, 0.045), transparent 70%);
}

.turn-card {
  position: relative;
  flex-direction: column;
  padding: 7px 12px;
  text-align: center;
}

.turn-label {
  font-size: 0.94rem;
  font-weight: 950;
  letter-spacing: 0.095em;
}

.turn-label.turn-red {
  color: #ff818a;
}

.turn-label.turn-blue {
  color: #87b3ff;
}

.turn-instruction {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
}

.ai-indicator {
  position: absolute;
  right: 10px;
  bottom: 7px;
  display: flex;
  gap: 3px;
}

.ai-indicator i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold);
  animation: aiPulse 900ms infinite ease-in-out;
}

.ai-indicator i:nth-child(2) { animation-delay: 130ms; }
.ai-indicator i:nth-child(3) { animation-delay: 260ms; }

@keyframes aiPulse {
  0%, 65%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.play-area {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  place-items: center;
}

.board-frame {
  width: var(--board-size);
  height: var(--board-size);
  max-width: 100%;
  max-height: 100%;
  padding: clamp(5px, 0.8vw, 9px);
  border: 1px solid rgba(190, 218, 235, 0.28);
  border-radius: 15px;
  background: linear-gradient(145deg, rgba(65, 88, 104, 0.62), rgba(12, 24, 33, 0.88));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.46), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.game-board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: clamp(1px, 0.22vw, 3px);
  touch-action: manipulation;
  user-select: none;
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: visible;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: clamp(3px, 0.55vw, 7px);
  color: white;
  cursor: default;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 -4px 8px rgba(0, 0, 0, 0.12);
  transition: transform 100ms ease, filter 100ms ease, box-shadow 130ms ease, opacity 130ms ease;
}

.tile--red {
  background: radial-gradient(circle at 35% 26%, #e45f69, var(--red) 52%, var(--red-dark));
}

.tile--blue {
  background: radial-gradient(circle at 35% 26%, #5b96f4, var(--blue) 52%, var(--blue-dark));
}

.tile--green {
  background: radial-gradient(circle at 35% 26%, #70be84, var(--green) 52%, var(--green-dark));
}

.tile--dead,
.tile.is-no-mans-land {
  background: radial-gradient(circle at 35% 26%, #667079, #3f474e 55%, #252b30);
  border-color: rgba(220, 227, 232, 0.25);
  filter: grayscale(1);
  cursor: not-allowed;
}

.tile.is-no-mans-land .tile-symbol {
  color: #d7dde1;
  font-size: clamp(1rem, calc(var(--board-size) / 20), 2.35rem);
  text-shadow: 0 2px 4px #000, 0 0 9px rgba(255,255,255,0.16);
}

.tile.is-worn {
  box-shadow: inset 0 0 0 2px rgba(255, 197, 85, 0.32), inset 0 0 18px rgba(80, 42, 10, 0.24);
}

.tile.is-critical {
  box-shadow: inset 0 0 0 3px rgba(255, 90, 76, 0.56), inset 0 0 22px rgba(80, 10, 10, 0.42);
  animation: attritionWarning 900ms ease-in-out infinite alternate;
}

@keyframes attritionWarning {
  from { filter: brightness(0.92) saturate(0.8); }
  to { filter: brightness(1.1) saturate(1.05); }
}

.tile.is-selectable {
  cursor: pointer;
}

.tile.is-selectable:hover {
  filter: brightness(1.12);
  transform: translateY(-1px);
}

.tile.is-selected {
  z-index: 12;
  border-color: white;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.82), 0 0 22px 5px rgba(255, 255, 255, 0.48), inset 0 0 10px rgba(255, 255, 255, 0.25);
  transform: scale(1.035);
}

.tile.is-target {
  z-index: 10;
  cursor: pointer;
  animation: targetGlow 1.1s infinite alternate ease-in-out;
}

.tile.is-ai-target {
  animation-duration: 550ms;
}

@keyframes targetGlow {
  from {
    border-color: rgba(255, 244, 166, 0.75);
    box-shadow: 0 0 6px 2px rgba(255, 223, 108, 0.48), inset 0 0 8px rgba(255, 248, 190, 0.2);
  }
  to {
    border-color: white;
    box-shadow: 0 0 15px 5px rgba(255, 223, 108, 0.88), inset 0 0 13px rgba(255, 248, 190, 0.38);
  }
}

.tile:disabled {
  opacity: 1;
}

.tile-symbol {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, calc(var(--board-size) / 22), 2.15rem);
  font-weight: 850;
  line-height: 1;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.48);
  pointer-events: none;
}

.tile-sub-symbol {
  position: absolute;
  left: 5%;
  bottom: 5%;
  width: 30%;
  height: 30%;
  display: grid;
  place-items: center;
  border-radius: 3px;
  background: rgba(4, 10, 15, 0.72);
  color: #fff3b0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.48rem, calc(var(--board-size) / 49), 0.92rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 2px black;
  pointer-events: none;
}

.tile-sub-symbol:empty {
  display: none;
}

.tile.is-locked {
  cursor: default;
  filter: saturate(0.88) brightness(0.93);
}

.tile.is-locked::after {
  content: "◆";
  position: absolute;
  top: 4%;
  right: 5%;
  color: var(--gold);
  font-size: clamp(0.42rem, calc(var(--board-size) / 65), 0.72rem);
  text-shadow: 0 0 6px rgba(241, 197, 90, 0.88);
  pointer-events: none;
}

.tile.is-permanent-lock::after {
  content: "✦";
  color: #fff2a9;
}

.tile.lock-top { border-top: clamp(3px, 0.5vw, 6px) solid var(--gold); }
.tile.lock-right { border-right: clamp(3px, 0.5vw, 6px) solid var(--gold); }
.tile.lock-bottom { border-bottom: clamp(3px, 0.5vw, 6px) solid var(--gold); }
.tile.lock-left { border-left: clamp(3px, 0.5vw, 6px) solid var(--gold); }

.game-board.is-computer-turn .tile:not(.is-selected):not(.is-target) {
  filter: saturate(0.9) brightness(0.95);
}

.game-footer {
  min-height: 62px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 14px;
  align-items: center;
  width: min(950px, 100%);
  margin: 0 auto;
}

.action-message {
  margin: 0;
  color: #dceaf3;
  font-size: 0.88rem;
}

.lock-hint {
  grid-column: 1 / -1;
  margin: 0;
  color: #718999;
  font-size: 0.7rem;
}

.modal-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: grid;
  place-items: center;
  background: rgba(0, 5, 9, 0.77);
  backdrop-filter: blur(8px);
}

.modal-backdrop[hidden],
.modal[hidden] {
  display: none;
}

.modal {
  width: min(570px, 100%);
  max-height: min(84svh, 760px);
  overflow-y: auto;
  padding: clamp(22px, 4vw, 34px);
  border: 1px solid rgba(222, 239, 250, 0.22);
  border-radius: 18px;
  background:
    linear-gradient(150deg, rgba(32, 56, 72, 0.98), rgba(8, 19, 27, 0.99)),
    #0b1720;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.62), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.modal h2 {
  margin: 0 0 16px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.6rem, 5vw, 2.5rem);
}

.modal-kicker {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 950;
  letter-spacing: 0.16em;
}

.rules-copy {
  margin-bottom: 22px;
  color: #cbdbe6;
  line-height: 1.52;
}

.rules-copy p {
  margin: 0 0 12px;
}

.modal--decision {
  text-align: center;
}

.modal--decision .modal-actions {
  justify-content: center;
  margin-top: 22px;
}

.modal--colour {
  text-align: center;
}

.colour-intro {
  max-width: 430px;
  margin: -4px auto 24px;
  color: #b8cad6;
  line-height: 1.45;
}

.difficulty-picker {
  margin: 0 auto 22px;
  padding: 14px;
  border: 1px solid rgba(222, 239, 250, 0.14);
  border-radius: 14px;
  background: rgba(2, 10, 16, 0.3);
}

.difficulty-title {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 950;
  letter-spacing: 0.15em;
}

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

.difficulty-choice {
  min-height: 76px;
  padding: 10px 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  display: grid;
  align-content: center;
  gap: 4px;
  background: rgba(14, 31, 42, 0.9);
  color: #dcebf5;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.difficulty-choice:hover {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.45);
}

.difficulty-choice.is-selected {
  border-color: var(--gold);
  background: linear-gradient(145deg, rgba(73, 61, 25, 0.92), rgba(25, 38, 45, 0.96));
  box-shadow: 0 0 0 2px rgba(241, 197, 90, 0.12), 0 8px 20px rgba(0, 0, 0, 0.24);
}

.difficulty-choice strong {
  font-size: 0.9rem;
  letter-spacing: 0.03em;
}

.difficulty-choice small {
  color: #93a9b8;
  font-size: 0.62rem;
  line-height: 1.25;
}

.difficulty-choice.is-selected small {
  color: #e4d8a7;
}

.colour-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.colour-choice {
  min-height: 185px;
  padding: 20px 12px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 15px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  color: white;
  cursor: pointer;
  box-shadow: 0 12px 25px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  transition: transform 130ms ease, filter 130ms ease, border-color 130ms ease;
}

.colour-choice:hover {
  transform: translateY(-3px);
  filter: brightness(1.1);
  border-color: rgba(255, 255, 255, 0.65);
}

.colour-choice--red {
  background: radial-gradient(circle at 35% 22%, #ed6973, var(--red) 50%, var(--red-dark));
}

.colour-choice--blue {
  background: radial-gradient(circle at 35% 22%, #64a0ff, var(--blue) 50%, var(--blue-dark));
}

.colour-emblem {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 3.25rem;
  line-height: 1;
  text-shadow: 0 4px 9px rgba(0, 0, 0, 0.42);
}

.colour-choice strong {
  font-size: 1.25rem;
  letter-spacing: 0.04em;
}

.colour-choice small {
  color: rgba(255, 255, 255, 0.78);
  font-weight: 700;
}

.toast {
  position: fixed;
  z-index: 150;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  max-width: min(90vw, 520px);
  padding: 10px 15px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 9px;
  background: rgba(7, 17, 24, 0.95);
  color: white;
  font-size: 0.84rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 160ms ease, transform 160ms ease;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.42);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px) {
  :root {
    --board-size: min(calc(100vw - 18px), calc(100svh - 280px), 690px);
  }

  .game-shell {
    gap: 7px;
    padding-inline: 9px;
  }

  .topbar {
    min-height: 57px;
  }

  .top-actions {
    gap: 5px;
  }

  .ui-button {
    min-height: 38px;
    padding-inline: 11px;
    font-size: 0.78rem;
  }

  .scoreboard {
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
  }

  .turn-card {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 47px;
  }

  .score-card {
    grid-row: 2;
    min-height: 48px;
    padding: 5px 8px;
  }

  .score-card--red { grid-column: 1; }
  .score-card--neutral { grid-column: 2; }
  .score-card--blue { grid-column: 3; }

  .score-card strong {
    font-size: 1.25rem;
  }

  .score-role {
    font-size: 0.48rem;
  }

  .game-footer {
    min-height: 65px;
  }

  .action-message {
    font-size: 0.78rem;
  }

  .lock-hint {
    font-size: 0.61rem;
  }
}

@media (max-width: 480px) {
  :root {
    --board-size: min(calc(100vw - 12px), calc(100svh - 278px));
  }

  .brand-letter {
    width: 29px;
  }

  .brand-letter > span {
    font-size: 2.15rem;
  }

  .brand-letter > small {
    font-size: 0.62rem;
  }

  .top-actions .ui-button {
    padding-inline: 9px;
  }

  .score-card {
    gap: 5px;
  }

  .score-label {
    font-size: 0.61rem;
  }

  .turn-label {
    font-size: 0.82rem;
  }

  .turn-instruction {
    font-size: 0.66rem;
  }

  .difficulty-picker {
    padding: 10px;
    margin-bottom: 14px;
  }

  .difficulty-choices {
    gap: 5px;
  }

  .difficulty-choice {
    min-height: 68px;
    padding-inline: 5px;
  }

  .difficulty-choice small {
    font-size: 0.56rem;
  }

  .colour-choices {
    grid-template-columns: 1fr;
  }

  .colour-choice {
    min-height: 125px;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    text-align: left;
    column-gap: 16px;
  }

  .colour-emblem {
    grid-row: 1 / 3;
    font-size: 2.7rem;
  }

  .colour-choice strong,
  .colour-choice small {
    justify-self: start;
  }
}

@media (max-height: 690px) and (min-width: 761px) {
  :root {
    --board-size: min(68vw, calc(100svh - 225px), 650px);
  }

  .topbar {
    min-height: 54px;
  }

  .brand-letter > span {
    font-size: 2.7rem;
  }

  .score-card,
  .turn-card {
    min-height: 48px;
  }

  .game-footer {
    min-height: 50px;
  }
}

/* REBUS v3: cloaking, nuanced locks and Delta bomb feedback */
.tile.is-cloaked .tile-symbol {
  color: rgba(236, 246, 255, 0.92);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(0.95rem, calc(var(--board-size) / 23), 2rem);
  text-shadow: 0 0 7px rgba(224, 243, 255, 0.75), 0 2px 4px rgba(0, 0, 0, 0.68);
  animation: cloakPulse 1.9s ease-in-out infinite;
}

.tile.is-cloaked::before {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(230, 246, 255, 0.15), rgba(130, 163, 184, 0.06) 48%, transparent 72%);
  pointer-events: none;
}

@keyframes cloakPulse {
  0%, 100% { opacity: 0.66; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1.05); }
}

.tile.is-uniform-lock::after {
  content: "◆";
  color: #fff1a0;
}

.tile.is-mixed-lock::after {
  content: "◇";
  color: #d6e6f2;
  text-shadow: 0 0 6px rgba(190, 220, 240, 0.82);
}

.tile.is-large-lock::after {
  font-size: clamp(0.5rem, calc(var(--board-size) / 58), 0.82rem);
}

.tile.is-mixed-lock.lock-top { border-top-color: #c5d7e4; }
.tile.is-mixed-lock.lock-right { border-right-color: #c5d7e4; }
.tile.is-mixed-lock.lock-bottom { border-bottom-color: #c5d7e4; }
.tile.is-mixed-lock.lock-left { border-left-color: #c5d7e4; }

.tile.is-lock-cycle {
  z-index: 18;
  animation: lockCyclePulse 900ms ease-in-out infinite alternate;
}

@keyframes lockCyclePulse {
  from { filter: saturate(0.92) brightness(0.96); box-shadow: inset 0 0 0 1px rgba(255, 245, 184, 0.2); }
  to { filter: saturate(1.08) brightness(1.12); box-shadow: inset 0 0 0 2px rgba(255, 238, 139, 0.7), 0 0 12px rgba(241, 197, 90, 0.35); }
}

.tile.is-delta-centre {
  z-index: 24;
  animation: deltaCentreFlash 850ms ease-out both;
}

.tile.is-delta-blast {
  z-index: 22;
  animation: deltaBlastFlash 850ms ease-out both;
}

@keyframes deltaCentreFlash {
  0% { transform: scale(0.78); filter: brightness(2.4); box-shadow: 0 0 0 0 rgba(255, 239, 132, 1); }
  35% { transform: scale(1.12); filter: brightness(1.75); box-shadow: 0 0 26px 12px rgba(255, 218, 82, 0.95); }
  100% { transform: scale(1); filter: brightness(1); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 -4px 8px rgba(0, 0, 0, 0.12); }
}

@keyframes deltaBlastFlash {
  0% { filter: brightness(2.1) saturate(0.3); box-shadow: inset 0 0 22px rgba(255, 245, 173, 1); }
  45% { filter: brightness(1.55) saturate(1.35); box-shadow: 0 0 18px 7px rgba(255, 205, 74, 0.82), inset 0 0 16px rgba(255, 245, 173, 0.82); }
  100% { filter: brightness(1) saturate(1); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 -4px 8px rgba(0, 0, 0, 0.12); }
}

#persistentYieldButton:not([hidden]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (prefers-reduced-motion: reduce) {
  .tile.is-cloaked .tile-symbol,
  .tile.is-delta-centre,
  .tile.is-delta-blast {
    animation: none;
  }
}


/* REBUS v4: one-turn recapture protection */
.tile.is-recapture-protected {
  cursor: not-allowed;
  box-shadow:
    inset 0 0 0 2px rgba(222, 243, 255, 0.78),
    inset 0 0 15px rgba(202, 235, 255, 0.32),
    0 0 8px rgba(185, 225, 250, 0.28);
}

.tile.is-recapture-protected .tile-symbol::after {
  content: "↶";
  position: absolute;
  top: 3%;
  left: 7%;
  color: #e8f7ff;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(0.42rem, calc(var(--board-size) / 62), 0.78rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 5px rgba(179, 225, 255, 0.95), 0 1px 2px rgba(0, 0, 0, 0.75);
}

/* REBUS v5: point scoring, successive capture and turn nomination */
:root {
  --board-size: min(72vw, calc(100svh - 305px), 720px);
}

.score-totals {
  display: grid;
  justify-items: end;
  gap: 1px;
  line-height: 1;
}

.score-totals small {
  color: #b8cad6;
  font-size: 0.62rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.points-key {
  width: min(950px, 100%);
  margin: 0 auto;
  min-height: 31px;
  padding: 6px 10px;
  border: 1px solid rgba(190, 218, 235, 0.16);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px 13px;
  background: rgba(9, 22, 31, 0.68);
  color: #aabfcd;
  font-size: 0.66rem;
  letter-spacing: 0.025em;
}

.points-key strong {
  color: var(--gold);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
}

.points-key .delta-limit,
.points-key .attrition-limit {
  color: #d8e7f2;
  font-weight: 850;
  letter-spacing: 0.06em;
}

.points-key .win-target {
  color: #fff0ad;
  font-weight: 900;
  letter-spacing: 0.08em;
}

#endChainButton:not([hidden]) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: rgba(255, 224, 116, 0.52);
  color: #fff1b4;
}

.tile.is-chain-target {
  animation-duration: 680ms;
}

.tile.is-chain-target::after {
  content: "+";
  position: absolute;
  top: 4%;
  right: 7%;
  color: #fff2a3;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(0.55rem, calc(var(--board-size) / 55), 0.92rem);
  font-weight: 950;
  text-shadow: 0 0 7px rgba(255, 222, 102, 0.95);
  pointer-events: none;
}

.game-board.is-nominating .tile {
  filter: saturate(0.75) brightness(0.8);
}

.game-board.is-nominating .tile.is-nomination-option {
  z-index: 11;
  cursor: pointer;
  filter: saturate(1.05) brightness(1.06);
  animation: nominationGlow 950ms infinite alternate ease-in-out;
}

@keyframes nominationGlow {
  from {
    border-color: rgba(167, 226, 255, 0.72);
    box-shadow: 0 0 5px rgba(143, 214, 250, 0.35), inset 0 0 7px rgba(202, 239, 255, 0.14);
  }
  to {
    border-color: #e9f8ff;
    box-shadow: 0 0 14px 4px rgba(143, 214, 250, 0.72), inset 0 0 12px rgba(202, 239, 255, 0.28);
  }
}

.tile.is-pending-protection {
  filter: saturate(0.7) brightness(0.8) !important;
  box-shadow:
    inset 0 0 0 2px rgba(222, 243, 255, 0.68),
    inset 0 0 13px rgba(202, 235, 255, 0.25);
}

.tile.is-pending-protection .tile-symbol::after {
  content: "◆";
  position: absolute;
  top: 4%;
  left: 7%;
  color: #e8f7ff;
  font-size: clamp(0.4rem, calc(var(--board-size) / 66), 0.72rem);
  text-shadow: 0 0 5px rgba(179, 225, 255, 0.95);
}

/* Cloaked enemy specials are intentionally blank rather than question-marked. */
.tile.is-cloaked .tile-symbol {
  color: transparent;
  text-shadow: none;
}

@media (max-width: 760px) {
  :root {
    --board-size: min(calc(100vw - 18px), calc(100svh - 326px), 690px);
  }

  .points-key {
    gap: 3px 9px;
    padding: 5px 7px;
    font-size: 0.58rem;
  }

  .score-totals small {
    font-size: 0.53rem;
  }
}

@media (max-width: 480px) {
  :root {
    --board-size: min(calc(100vw - 12px), calc(100svh - 330px));
  }

  .points-key {
    max-height: 45px;
    overflow: hidden;
  }

  .footer-actions {
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-board.is-nominating .tile.is-nomination-option {
    animation: none;
  }
}


/* REBUS v7 mobile and accessibility refinements */
html {
  min-height: 100%;
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  padding: 0;
}

button,
a,
.tile {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.modal-actions--rules {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.game-over-split {
  color: var(--gold);
}

@media (max-width: 760px) {
  :root {
    --board-size: min(calc(100vw - 12px), 620px);
  }

  .game-shell {
    width: 100%;
    min-height: 100dvh;
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    gap: 6px;
  }

  .topbar {
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 6px;
  }

  .brand {
    justify-content: center;
  }

  .brand-letter {
    width: 31px;
  }

  .brand-letter > span {
    font-size: 2.25rem;
  }

  .brand-letter > small {
    font-size: 0.63rem;
  }

  .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .top-actions .ui-button {
    width: 100%;
    min-height: 40px;
    padding: 0 8px;
    font-size: 0.76rem;
  }

  .scoreboard {
    gap: 4px;
  }

  .turn-card {
    min-height: 43px;
    padding: 4px 8px;
  }

  .score-card {
    min-width: 0;
    min-height: 50px;
    padding: 5px 6px;
    gap: 4px;
  }

  .score-name,
  .score-totals {
    min-width: 0;
  }

  .score-card strong {
    font-size: 1.22rem;
  }

  .score-totals small {
    font-size: 0.52rem;
  }

  .play-area,
  .board-frame,
  .game-board {
    width: var(--board-size);
    max-width: 100%;
  }

  .board-frame {
    margin-inline: auto;
  }

  .tile {
    min-width: 0;
    min-height: 0;
  }

  .points-key {
    width: 100%;
    max-height: none;
    padding: 5px 6px;
    gap: 3px 7px;
    font-size: 0.57rem;
    line-height: 1.2;
  }

  .delta-limit,
  .attrition-limit,
  .win-target {
    flex-basis: 100%;
    text-align: center;
  }

  .game-footer {
    width: 100%;
    min-height: 0;
    grid-template-columns: 1fr;
    gap: 5px;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .action-message {
    min-height: 2.4em;
    text-align: center;
    font-size: 0.75rem;
    line-height: 1.25;
  }

  .footer-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .footer-actions .ui-button {
    width: 100%;
    min-height: 42px;
    padding-inline: 5px;
    font-size: 0.7rem;
  }

  .footer-actions .ui-button[hidden] {
    display: none;
  }

  .lock-hint {
    text-align: center;
    font-size: 0.58rem;
    line-height: 1.25;
  }

  .modal-backdrop {
    align-items: end;
    padding: max(8px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .modal {
    width: 100%;
    max-height: min(92dvh, 880px);
    padding: 20px 16px max(18px, env(safe-area-inset-bottom));
    border-radius: 18px 18px 10px 10px;
  }

  .modal h2 {
    font-size: 1.65rem;
    margin-bottom: 12px;
  }

  .rules-copy {
    font-size: 0.88rem;
    line-height: 1.48;
  }

  .difficulty-choice,
  .colour-choice {
    min-height: 72px;
  }
}

@media (max-width: 390px) {
  .brand-letter {
    width: 28px;
  }

  .brand-letter > span {
    font-size: 2rem;
  }

  .score-label {
    font-size: 0.56rem;
  }

  .score-role {
    font-size: 0.43rem;
  }

  .turn-label {
    font-size: 0.76rem;
  }

  .turn-instruction {
    font-size: 0.6rem;
  }

  .points-key {
    font-size: 0.53rem;
  }

  .difficulty-choices {
    grid-template-columns: 1fr;
  }

  .difficulty-choice {
    min-height: 58px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  :root {
    --board-size: min(62dvh, 62vw);
  }

  .game-shell {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(260px, 0.8fr);
    grid-template-areas:
      "board top"
      "board score"
      "board points"
      "board footer";
    align-content: center;
    column-gap: 10px;
  }

  .topbar { grid-area: top; }
  .scoreboard { grid-area: score; }
  .play-area { grid-area: board; }
  .points-key { grid-area: points; }
  .game-footer { grid-area: footer; }

  .topbar {
    align-self: end;
  }

  .brand-letter > span {
    font-size: 1.7rem;
  }

  .brand-letter > small {
    font-size: 0.48rem;
  }

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

  .turn-card {
    grid-column: 1 / -1;
  }

  .lock-hint {
    display: none;
  }
}


.modal--decision.is-split-victory {
  border-color: rgba(241, 197, 90, 0.78);
  background:
    radial-gradient(circle at 50% 0%, rgba(241, 197, 90, 0.18), transparent 42%),
    linear-gradient(150deg, rgba(44, 48, 35, 0.98), rgba(8, 19, 27, 0.99));
}

.modal--decision.is-split-victory .modal-kicker {
  color: #fff0a6;
  text-shadow: 0 0 12px rgba(241, 197, 90, 0.5);
}

@media (prefers-reduced-motion: reduce) {
  .tile.is-lock-cycle { animation: none; }
}


/* v9.1 attrition test mode */
.test-panel {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(94vw, 620px);
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 18px;
  background: rgba(7,16,24,.96);
  box-shadow: 0 18px 50px rgba(0,0,0,.45);
  text-align: center;
}
.test-panel[hidden] { display: none; }
.test-panel-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.test-panel small { color: rgba(255,255,255,.72); line-height: 1.35; }
.tile::after {
  content: attr(data-change-count) "/7";
  position: absolute;
  right: 3px;
  top: 2px;
  font-size: clamp(.5rem, 1.8vw, .68rem);
  font-weight: 900;
  color: rgba(255,255,255,.82);
  text-shadow: 0 1px 3px #000;
}
.tile[data-change-count="0"]::after { opacity: .35; }
@media (max-width: 520px) {
  .test-panel { padding: 11px; }
  .test-panel-actions .ui-button { flex: 1 1 42%; }
}


/* ---------- Battery-conscious rendering ---------- */
.game-board { contain: layout paint style; }
.tile { contain: layout paint style; }
body.is-backgrounded *, body.is-game-over .tile { animation-play-state: paused !important; }

@media (max-width: 720px), (pointer: coarse) {
  .modal-backdrop { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; background: rgba(2, 8, 14, .88); }
  .score-card, .turn-card, .board-frame, .modal, .game-footer, .points-key {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  .tile.is-target, .tile.is-chain-target, .tile.is-nomination-option,
  .tile.is-critical, .tile.is-lock-cycle, .tile.is-cloaked {
    animation: none !important;
  }
  .tile.is-target, .tile.is-chain-target {
    box-shadow: 0 0 0 2px rgba(255, 223, 108, .88), inset 0 0 8px rgba(255, 248, 190, .22) !important;
  }
  .tile.is-nomination-option {
    box-shadow: 0 0 0 2px rgba(143, 214, 250, .75), inset 0 0 7px rgba(202, 239, 255, .16) !important;
  }
  .board-frame { box-shadow: 0 10px 28px rgba(0,0,0,.32); }
  .tile { transition: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .001ms !important;
  }
}

/* Core strips out points, cloaking and attrition indicators. */
body.core-mode .score-totals small,
body.core-mode .tile::after,
body.core-mode .tile-sub-symbol:empty { display: none !important; }
body.core-mode .score-totals { justify-content: center; }

/* Mode labels and four-level difficulty selector */
.mode-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid rgba(244,197,94,.45);
  border-radius: 999px;
  background: rgba(98,65,15,.36);
  color: #f4c55e;
  font-size: .68rem;
  font-weight: 950;
  letter-spacing: .14em;
}
.mode-chip--core { border-color: rgba(92,224,163,.45); background: rgba(24,103,71,.32); color: #88efba; }
.difficulty-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.difficulty-choice--mike { border-color: rgba(244,197,94,.38); }
.difficulty-choice--mike.is-selected { background: linear-gradient(145deg, rgba(112,57,12,.96), rgba(39,24,16,.98)); }
body.core-mode .score-totals small,
body.core-mode .tile::after,
body.core-mode .tile-sub-symbol:empty { display: none !important; }
body.core-mode .points-key { display: flex !important; }
@media (max-width: 520px) {
  .mode-chip { order: 2; }
  .difficulty-choices { grid-template-columns: 1fr 1fr; }
  .difficulty-choice { min-height: 64px; }
}


/* Result sharing */
.result-share {
  margin: 20px 0 16px;
  padding: 14px;
  border: 1px solid rgba(222, 239, 250, 0.16);
  border-radius: 14px;
  background: rgba(2, 10, 16, 0.34);
}

.result-share-title {
  margin: 0 0 10px;
  color: #dceaf3;
  font-size: 0.78rem;
  font-weight: 950;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-share-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: 7px;
}

.share-button {
  min-height: 39px;
  padding: 8px 9px;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: 9px;
  color: #fff;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

.share-button:hover { filter: brightness(1.1); }
.share-button:active { transform: scale(0.975); }
.share-button:focus-visible { outline: 3px solid rgba(255,255,255,.82); outline-offset: 2px; }
.share-button[hidden] { display: none; }
.share-button--native { background: linear-gradient(180deg, #f3cb6a, #b77a22); color: #171006; }
.share-button--whatsapp { background: linear-gradient(180deg, #35c96f, #168844); }
.share-button--facebook { background: linear-gradient(180deg, #3978d6, #214e9e); }
.share-button--x { background: linear-gradient(180deg, #30343b, #101216); }
.share-button--copy { background: linear-gradient(180deg, #506879, #243642); }

@media (max-width: 560px) {
  .result-share { margin-top: 16px; padding: 11px; }
  .result-share-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .share-button--native { grid-column: 1 / -1; }
  .share-button { min-height: 42px; font-size: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .share-button { transition: none; }
}
