:root {
  --pink-deep: #e91e8c;
  --pink-soft: #ffb7d9;
  --lavender: #c4b5fd;
  --sky-top: #7ec8ff;
  --sky-bottom: #b8e0ff;
  --pipe: #9ecfff;
  --pipe-dark: #5a8fd4;
  --hud-bg: rgba(18, 12, 40, 0.82);
  --text: #fff8ff;
  --accent: #ffd54f;
  --grid-bg: rgba(255, 255, 255, 0.08);
  --cell: rgba(255, 255, 255, 0.28);
  --shadow: 0 8px 32px rgba(80, 40, 120, 0.35);
  /* Layout / scaling — design cap for the 7×7 board */
  --board-max: 420px;
  /* Account bar + top bar (approx.); keeps portrait board sizing below the fold */
  --header-est: 6.5rem;
  --hud-est: 5.75rem;
  /* Wins list: one row ≈ li padding + symbol line + gap (see .collector-list li) */
  --collector-win-row-h: calc(0.35rem + 0.35rem + 1.35rem);
  --collector-win-row-gap: 0.35rem;
  --collector-list-3-rows-h: calc(
    3 * var(--collector-win-row-h) + 2 * var(--collector-win-row-gap)
  );
  /* Frame padding + header row (tallest: 26px info btn) + header margin-bottom */
  --collector-chrome-y: calc(0.75rem + 0.75rem + 26px + 0.5rem);
  --collector-fixed-h-portrait: calc(
    var(--collector-chrome-y) + var(--collector-list-3-rows-h)
  );
  --stage-pad-y: 0.75rem;
  --stage-pad-x: 1rem;
  /* Clears fixed HUD + safe area so the stage does not sit under the bar */
  --stage-pad-bottom: calc(var(--hud-est) + var(--stage-pad-y) + env(safe-area-inset-bottom, 0px));
  --stage-max-w: 1100px;
  /* Match .grid-shell vertical padding (12+12) + border (3+3) — keep in sync if shell changes */
  --grid-shell-y-chrome: 30px;
  font-family: "Nunito", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100%;
  display: flex;
  flex-direction: column;
  color: var(--text);
  overflow-x: hidden;
  background: #6ab8ff;
}

.bg-backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: #7ec8ff;
  background-image: url("../backdrop.jpg");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

.bg-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(20, 30, 70, 0.12) 0%,
    transparent 28%,
    transparent 55%,
    rgba(60, 20, 50, 0.18) 100%
  );
  pointer-events: none;
}

.top-bar {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.5rem 0.65rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
}

.tourney-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--hud-bg);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}

.trophy {
  font-size: 1.1rem;
  line-height: 1;
}

.rank-hash {
  font-size: 1rem;
  font-weight: 900;
  opacity: 0.75;
  margin-right: -0.15rem;
}

.tourney-time {
  opacity: 0.85;
  font-size: 0.75rem;
}

.logo {
  margin: 0;
  font-size: clamp(1.35rem, min(4.5vw, 4vh), 2.25rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  text-align: right;
  line-height: 1.15;
  background: linear-gradient(to bottom right, #fff, #fff8ff 12.61%, #ffb7d9 47.48%, #c4b5fd 80.25%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* Light stroke + drop shadows so the title stays readable on the candy backdrop. */
  -webkit-text-stroke: 0.05em rgba(255, 255, 255, 0.88);
  filter: drop-shadow(0 1px 0 rgba(45, 27, 78, 0.55)) drop-shadow(0 2px 6px rgba(120, 60, 140, 0.45));
}

.stage {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.5rem, min(2vw, 2.5vh), 1.75rem);
  padding: 0.5rem var(--stage-pad-x) var(--stage-pad-bottom);
  padding-left: max(var(--stage-pad-x), env(safe-area-inset-left));
  padding-right: max(var(--stage-pad-x), env(safe-area-inset-right));
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
  /* Fallback when orientation media is skipped; refined below */
  --stage-gap: clamp(0.5rem, min(2vw, 2.5vh), 1.75rem);
  --avail-v-fallback: calc(
    100vh - var(--header-est) - var(--stage-pad-y) - var(--stage-pad-bottom)
  );
  --board-size: min(
    var(--board-max),
    calc(min(100vw, var(--stage-max-w)) - 2 * var(--stage-pad-x) - 48px),
    calc(var(--avail-v-fallback) - 2.5rem)
  );
  --grid-shell-pad-x: 24px;
  --grid-shell-border-x: 6px;
  --grid-stack-h: calc(var(--board-size) + var(--grid-shell-y-chrome));
}

/* Landscape: wins panel + grid side by side; board fits width and height */
@media (orientation: landscape) {
  .stage {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: var(--stage-gap);
    --collector-w: min(200px, max(140px, 22vw));
    --stage-gap: clamp(0.5rem, min(2vw, 2.5vh), 1.75rem);
    --avail-v: calc(100vh - var(--header-est) - var(--stage-pad-y) - var(--stage-pad-bottom));
    --avail-v: calc(100dvh - var(--header-est) - var(--stage-pad-y) - var(--stage-pad-bottom));
    --board-by-height: calc(var(--avail-v) - 8px);
    --board-by-width: calc(
      min(100vw, var(--stage-max-w)) - 2 * var(--stage-pad-x) - var(--collector-w) - var(--stage-gap) - 40px
    );
    --board-size: min(var(--board-max), var(--board-by-width), var(--board-by-height));
    --grid-stack-h: calc(var(--board-size) + var(--grid-shell-y-chrome));
  }

  .grid-wrap {
    min-height: 0;
  }

  /* Same height as in-flow grid column (shell + square board); tops/bottoms line up with grid-wrap. */
  .collector {
    width: var(--collector-w);
    height: var(--grid-stack-h);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: var(--grid-stack-h);
  }

  .collector-frame {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .collector-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }
}

/* Portrait: stack wins above grid; board uses remaining vertical space */
@media (orientation: portrait) {
  .stage {
    flex-direction: column;
    flex-wrap: nowrap;
    /* Fixed wins panel = exactly 3 scrollable rows; grid size stays stable */
    --collector-cap: var(--collector-fixed-h-portrait);
    --stage-inner-v: calc(100vh - var(--header-est) - var(--stage-pad-y) - var(--stage-pad-bottom));
    --stage-inner-v: calc(100dvh - var(--header-est) - var(--stage-pad-y) - var(--stage-pad-bottom));
    --avail-v: calc(var(--stage-inner-v) - var(--collector-cap) - 1.25rem);
    --board-by-height: max(180px, var(--avail-v));
    --board-by-width: calc(min(100vw, var(--stage-max-w)) - 2 * var(--stage-pad-x) - 32px);
    --board-size: min(var(--board-max), var(--board-by-width), var(--board-by-height));
    --grid-stack-h: calc(var(--board-size) + var(--grid-shell-y-chrome));
  }

  /* Same width as .grid-wrap; stage align-items: center lines up left/right edges. */
  .collector {
    flex: 0 0 var(--collector-cap);
    width: min(
      calc(var(--board-size) + var(--grid-shell-pad-x) + var(--grid-shell-border-x)),
      100%
    );
    max-width: 100%;
    min-height: var(--collector-cap);
    max-height: var(--collector-cap);
    height: var(--collector-cap);
    display: flex;
    flex-direction: column;
  }

  .collector-frame {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .collector-list {
    flex: 0 0 auto;
    min-height: var(--collector-list-3-rows-h);
    max-height: var(--collector-list-3-rows-h);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

.collector {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.collector-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.75rem;
  border-radius: 20px;
  background: linear-gradient(145deg, rgba(180, 220, 255, 0.45), rgba(255, 200, 240, 0.35));
  border: 3px solid rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(8px);
}

.collector-glass {
  position: absolute;
  inset: 8px;
  border-radius: 14px;
  background: linear-gradient(
    125deg,
    rgba(255, 255, 255, 0.25) 0%,
    rgba(255, 255, 255, 0.05) 40%,
    rgba(200, 230, 255, 0.15) 100%
  );
  pointer-events: none;
}

.collector-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.collector-title {
  margin: 0;
  flex: 1;
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(40, 30, 80, 0.85);
}

.collector-info-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(40, 30, 80, 0.35);
  background: rgba(255, 255, 255, 0.5);
  color: rgba(40, 30, 80, 0.95);
  font-weight: 800;
  font-style: italic;
  font-size: 0.72rem;
  font-family: inherit;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.collector-info-btn:hover {
  background: rgba(255, 255, 255, 0.75);
}

.collector-list {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 0;
  overflow-y: auto;
}

.collector-list li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.4rem;
  margin-bottom: 0.35rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.35);
  color: #2d1b4e;
  font-size: 0.8rem;
  font-weight: 700;
  animation: pop-in 0.35s ease;
}

.collector-list li:last-child {
  margin-bottom: 0;
}

.collector-list .sym {
  font-size: 1.25rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.collector-symbol-img {
  width: 1.35rem;
  height: 1.35rem;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

@keyframes pop-in {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* Definite width (vs shrink-wrap loop); --board-size is the inner .grid — add shell pad + border. */
.grid-wrap {
  position: relative;
  flex: 0 0 auto;
  width: min(
    calc(var(--board-size) + var(--grid-shell-pad-x) + var(--grid-shell-border-x)),
    100%
  );
  min-width: 0;
  box-sizing: border-box;
}

.grid-frosting {
  position: absolute;
  top: -18px;
  left: 8%;
  right: 8%;
  height: 22px;
  border-radius: 12px 12px 0 0;
  background: linear-gradient(180deg, #fff, #ffe8f5);
  box-shadow: 0 4px 0 #f8b8d8;
  z-index: 2;
}

.grid-frosting::after {
  content: "";
  position: absolute;
  inset: 4px 10px auto;
  height: 6px;
  background: repeating-linear-gradient(
    90deg,
    #ff6b9d 0 6px,
    #ffd54f 6px 12px,
    #7bed9f 12px 18px,
    #a29bfe 18px 24px
  );
  border-radius: 4px;
  opacity: 0.85;
}

.grid-shell {
  width: 100%;
  box-sizing: border-box;
  padding: 12px;
  border-radius: 20px;
  /* Same glass treatment as .collector-frame so the playfield blurs the scene behind it. */
  background: linear-gradient(145deg, rgba(180, 220, 255, 0.45), rgba(255, 200, 240, 0.35));
  border: 3px solid rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: visible;
}

.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: max(4px, min(6px, calc(var(--board-size, 300px) * 0.014)));
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  padding: max(6px, min(10px, calc(var(--board-size, 300px) * 0.024)));
  border-radius: 12px;
  background: var(--grid-bg);
  overflow: visible;
  box-sizing: border-box;
  isolation: isolate;
}

/* Extra frost layer behind tiles (matches wins panel legibility). */
.grid::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(
    125deg,
    rgba(255, 255, 255, 0.22) 0%,
    rgba(255, 255, 255, 0.06) 45%,
    rgba(200, 230, 255, 0.14) 100%
  );
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.cell {
  position: relative;
  z-index: 1;
  border-radius: 12px;
  background: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.7rem, calc(var(--board-size, 280px) * 0.078), 1.85rem);
  line-height: 1;
  box-shadow: inset 0 2px 6px rgba(255, 255, 255, 0.35), 0 4px 8px rgba(60, 40, 100, 0.2);
  overflow: visible;
  transition: box-shadow 0.2s ease, opacity 0.25s ease;
}

.cell.empty {
  opacity: 0.15;
  box-shadow: none;
}

.cell-symbol-img {
  width: min(78%, 2.1em);
  height: min(78%, 2.1em);
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* New symbols dropping from above (--drop-cells, --drop-dur set in JS). */
.cell.fall-in {
  /* forwards only — "both" + delayed start made 0% snap visible after content was already drawn in the cell */
  animation: drop-cascade var(--drop-dur, 0.95s) cubic-bezier(0.28, 0, 0.22, 1) forwards;
  z-index: 2;
}

@keyframes drop-cascade {
  0% {
    transform: translateY(calc(-1 * var(--drop-cells, 1) * 100%));
    opacity: 0.2;
  }
  45% {
    opacity: 1;
  }
  88% {
    transform: translateY(5%);
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Survivors sliding down after holes open (--slide-rows = toR - fromR). */
.cell.fall-slide {
  animation: fall-slide var(--slide-dur, 0.45s) cubic-bezier(0.33, 0, 0.25, 1) forwards;
  z-index: 2;
}

@keyframes fall-slide {
  0% {
    transform: translateY(calc(-1 * var(--slide-rows, 1) * 100%));
    opacity: 0.88;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

.cell.highlight {
  box-shadow: 0 0 0 3px var(--pink-deep), 0 0 20px rgba(233, 30, 140, 0.6);
  z-index: 1;
}

.cell.blast-fall {
  animation: blast-fall 0.48s cubic-bezier(0.4, 0, 0.85, 0.5) forwards;
  z-index: 3;
}

@keyframes blast-fall {
  0% {
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    transform: translateY(calc(100% + 14px));
    opacity: 0;
  }
}

/* Session token — debugging only; sits just above the HUD */
.debug-player-token {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--hud-est) + env(safe-area-inset-bottom, 0px));
  z-index: 9;
  margin: 0;
  padding: 0.2rem 0.75rem;
  font-size: 0.62rem;
  line-height: 1.25;
  font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  color: rgba(255, 248, 255, 0.42);
  text-align: center;
  word-break: break-all;
  pointer-events: none;
}

.hud {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  background: var(--hud-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  flex-wrap: wrap;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.hud-center {
  flex: 1 1 180px;
  text-align: center;
  min-width: 0;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  font-weight: 800;
  font-style: italic;
  cursor: pointer;
}

.icon-btn[aria-pressed="true"] {
  opacity: 0.65;
  border-color: rgba(255, 255, 255, 0.2);
}

#muteBtn {
  font-style: normal;
  font-size: 0.95rem;
  line-height: 1;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.hud-stat .label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.75;
}

.hud-stat .value {
  font-weight: 800;
  font-size: 1rem;
  color: var(--accent);
}

.bet-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.bet-step {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
}

.bet-step:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.status-msg {
  margin: 0;
  font-weight: 800;
  font-size: 0.95rem;
}

.win-line {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  opacity: 0.9;
  min-height: 1.2em;
}

.spin-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.45);
  background: linear-gradient(145deg, #ff4d7d, var(--pink-deep));
  color: white;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(233, 30, 140, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, filter 0.15s;
}

.spin-btn:hover:not(:disabled) {
  transform: scale(1.05);
  filter: brightness(1.08);
}

.spin-btn:disabled {
  opacity: 0.55;
  cursor: wait;
  filter: grayscale(0.3);
}

.spin-icon {
  font-size: 1.4rem;
  margin-left: 3px;
}

/* Mobile: single-row compact HUD — keep --hud-est in sync with real bar height */
@media (max-width: 768px) {
  :root {
    --hud-est: 3.65rem;
  }

  .hud {
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.28rem;
    padding: 0.32rem 0.42rem;
    padding-bottom: max(0.32rem, env(safe-area-inset-bottom));
    padding-left: max(0.42rem, env(safe-area-inset-left));
    padding-right: max(0.42rem, env(safe-area-inset-right));
  }

  .hud-left,
  .hud-right {
    gap: 0.28rem;
    flex-shrink: 0;
  }

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

  .hud-center {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 0.15rem;
  }

  .hud-stat {
    gap: 0.02rem;
  }

  .hud-stat .label {
    font-size: 0.52rem;
    letter-spacing: 0.04em;
  }

  .hud-stat .value {
    font-size: 0.74rem;
    line-height: 1.15;
  }

  .bet-controls {
    gap: 0.15rem;
  }

  .bet-step {
    width: 24px;
    height: 24px;
    font-size: 0.92rem;
    border-radius: 6px;
  }

  .status-msg {
    font-size: 0.7rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .win-line {
    font-size: 0.6rem;
    margin: 0.08rem 0 0;
    min-height: 1.05em;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .icon-btn {
    width: 26px;
    height: 26px;
    border-width: 1.5px;
    font-size: 0.78rem;
  }

  #muteBtn {
    font-size: 0.82rem;
  }

  .spin-btn {
    width: 46px;
    height: 46px;
    border-width: 2.5px;
    box-shadow: 0 4px 14px rgba(233, 30, 140, 0.4);
  }

  .spin-icon {
    font-size: 1.02rem;
    margin-left: 2px;
  }
}

@media (max-width: 380px) {
  :root {
    --hud-est: 3.45rem;
  }

  .hud {
    gap: 0.22rem;
    padding: 0.28rem 0.32rem;
    padding-bottom: max(0.28rem, env(safe-area-inset-bottom));
  }

  .hud-left,
  .hud-right {
    gap: 0.22rem;
  }

  .hud-stat .label {
    font-size: 0.48rem;
  }

  .hud-stat .value {
    font-size: 0.68rem;
  }

  .bet-step {
    width: 22px;
    height: 22px;
    font-size: 0.85rem;
  }

  .status-msg {
    font-size: 0.64rem;
  }

  .win-line {
    font-size: 0.55rem;
  }

  .icon-btn {
    width: 24px;
    height: 24px;
    font-size: 0.72rem;
  }

  #muteBtn {
    font-size: 0.76rem;
  }

  .spin-btn {
    width: 42px;
    height: 42px;
    border-width: 2px;
  }

  .spin-icon {
    font-size: 0.95rem;
  }
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 5, 30, 0.65);
}

.modal-card {
  position: relative;
  max-width: 420px;
  padding: 1.5rem;
  border-radius: 16px;
  background: linear-gradient(180deg, #3d2b5c, #2a1f45);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: var(--shadow);
}

.modal-card h2 {
  margin-top: 0;
}

.modal-card .muted {
  opacity: 0.8;
  font-size: 0.9rem;
}

.primary-btn {
  margin-top: 1rem;
  padding: 0.5rem 1.25rem;
  border-radius: 999px;
  border: none;
  font-weight: 800;
  background: var(--accent);
  color: #2d1b4e;
  cursor: pointer;
}

.modal-card--scoring {
  max-width: min(480px, 100%);
  max-height: min(88vh, 640px);
  overflow-y: auto;
}

.modal-card--scoring h3.paytable-heading {
  margin: 1.25rem 0 0.35rem;
  font-size: 0.95rem;
}

.scoring-lead {
  margin-top: 0;
}

.scoring-formula code {
  font-size: 0.85em;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.25);
}

.paytable-note {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.paytable-note code {
  font-size: 0.8em;
  padding: 0.05rem 0.2rem;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.2);
}

.paytable-wrap {
  margin: 0.5rem 0 0.25rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.paytable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.paytable th,
.paytable td {
  padding: 0.4rem 0.45rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.paytable th {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.85;
  background: rgba(0, 0, 0, 0.2);
}

.paytable tbody tr:last-child td {
  border-bottom: none;
}

.paytable-emoji,
.paytable-icon {
  margin-right: 0.15rem;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.paytable-symbol-img {
  width: 1.35rem;
  height: 1.35rem;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

/* Narrow portrait: keep a fixed 3-row wins viewport (scroll inside); no wrap */
@media (orientation: portrait) and (max-width: 420px) {
  .collector-list li {
    flex-shrink: 0;
  }
}

/* —— Account bar + auth pages —— */
.account-bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 0.35rem 1.5rem 0;
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
  font-size: 0.82rem;
}

.account-bar a {
  color: var(--text);
  text-decoration: none;
  opacity: 0.92;
  font-weight: 700;
}

.account-bar a:hover {
  text-decoration: underline;
  opacity: 1;
}

.account-email {
  opacity: 0.88;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-logout {
  background: var(--hud-bg);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.account-logout:hover {
  filter: brightness(1.08);
}

.account-logout-form {
  display: inline;
  margin: 0;
}

.account-wallet {
  background: var(--hud-bg);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.account-wallet:hover {
  filter: brightness(1.08);
}

.modal-card--wallet {
  width: min(100%, 460px);
  max-height: min(92vh, 640px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-card--wallet > h2,
.modal-card--wallet > .wallet-balance-line,
.modal-card--wallet > .wallet-kind,
.modal-card--wallet > .wallet-amount-label,
.modal-card--wallet > .wallet-amount-input,
.modal-card--wallet > .wallet-msg,
.modal-card--wallet > .wallet-actions {
  flex-shrink: 0;
}

.wallet-balance-line {
  margin: 0 0 1rem;
  font-size: 0.95rem;
}

.wallet-kind {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.wallet-kind-btn {
  flex: 1;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-family: inherit;
  font-weight: 800;
  font-size: 0.85rem;
  cursor: pointer;
}

.wallet-kind-btn.is-active {
  background: var(--accent);
  color: #2d1b4e;
  border-color: transparent;
}

.wallet-amount-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  opacity: 0.9;
}

.wallet-amount-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
}

.wallet-msg {
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
}

.wallet-msg[hidden] {
  display: none;
}

.wallet-msg.is-error {
  color: #ffb4b4;
}

.wallet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1rem;
}

.wallet-actions .primary-btn {
  margin-top: 0;
}

.ghost-btn {
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.wallet-footnote {
  margin: 1rem 0 0;
  font-size: 0.78rem;
  flex-shrink: 0;
}

.wallet-history-heading {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.wallet-history-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.18);
}

table.wallet-history {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.wallet-history th,
.wallet-history td {
  padding: 0.4rem 0.35rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  vertical-align: top;
}

.wallet-history thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #35264d;
  font-weight: 800;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.92;
}

.wallet-history-num {
  text-align: right;
  white-space: nowrap;
}

.wallet-history .wallet-in {
  color: #9fe8b0;
  font-weight: 800;
}

.wallet-history .wallet-out {
  color: #ffb4b4;
  font-weight: 800;
}

.wallet-history-empty td {
  text-align: center;
  opacity: 0.75;
  font-style: italic;
  border-bottom: none;
  padding: 0.75rem 0.5rem;
}

.page-flashes {
  position: relative;
  z-index: 2;
  list-style: none;
  margin: 0 auto;
  padding: 0.5rem 1.5rem;
  max-width: 1200px;
}

.page-flashes li {
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--hud-bg);
  box-shadow: var(--shadow);
}

.page-flashes .error {
  border: 1px solid rgba(255, 120, 120, 0.5);
}

.page-flashes .info {
  border: 1px solid rgba(180, 220, 255, 0.45);
}

.auth-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.auth-shell {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem 2rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

.auth-back {
  margin: 0 0 1rem;
  width: 100%;
  max-width: 400px;
}

.auth-back a {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  opacity: 0.9;
}

.auth-back a:hover {
  text-decoration: underline;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--hud-bg);
  border-radius: 16px;
  padding: 1.35rem 1.35rem 1.15rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.auth-heading {
  margin: 0 0 0.75rem;
  font-size: 1.45rem;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.auth-lead {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  opacity: 0.9;
  line-height: 1.45;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.auth-label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.88;
}

.auth-input {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.5rem 0.65rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.auth-input:focus {
  outline: 2px solid var(--lavender);
  outline-offset: 1px;
}

.auth-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}

.auth-submit {
  margin-top: 0.35rem;
  width: 100%;
  justify-content: center;
}

.auth-field-error {
  margin: -0.35rem 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: #ffb4c4;
}

.auth-links {
  margin: 1rem 0 0;
  font-size: 0.88rem;
  text-align: center;
  opacity: 0.92;
}

.auth-links a {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.auth-links a:hover {
  text-decoration: underline;
}

.auth-flashes {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  width: 100%;
  max-width: 400px;
}

.auth-flash {
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  margin-bottom: 0.35rem;
  font-weight: 700;
  font-size: 0.88rem;
  background: rgba(18, 12, 40, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.auth-flash--error {
  border-color: rgba(255, 120, 120, 0.45);
}

.auth-flash--info {
  border-color: rgba(180, 220, 255, 0.4);
}
