:root {
  --shaft: #0e1118;
  --stone: #232a36;
  --stone-2: #161b24;
  --lantern: #4fd1c5;
  --glimmer: #a78bfa;
  --danger: #e11d48;
  --win: #34d399;
  --panel: #11151d;
  --muted: #8b97ab;
  --ink: #eaf0f7;

  /* Asset seam: app.js overwrites these at boot from its ASSETS map, so
     dropping raster art into /assets/ needs no CSS edits. Each one is a
     background layer, so a missing file simply falls back to the gradient
     underneath instead of showing a broken image. */
  --asset-stone: url("/assets/stone-face.svg");
  --asset-glimmer: url("/assets/glimmer.svg");
  --asset-collapse: url("/assets/collapse.svg");
  --asset-lantern: url("/assets/lantern.svg");
  --asset-dust: url("/assets/dust.svg");
  --asset-cave: url("/assets/cave-texture.svg");

  --tile: 86px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background-color: var(--shaft);
  background-image:
    radial-gradient(circle at 50% -8%, rgba(79, 209, 197, 0.16), transparent 55%),
    linear-gradient(168deg, rgba(14, 17, 24, 0.88), rgba(22, 27, 36, 0.7)),
    var(--asset-cave);
  background-size: auto, auto, 320px 320px;
  background-repeat: no-repeat, no-repeat, repeat;
}

.layout {
  position: relative;
  z-index: 1;
  width: min(1120px, 96vw);
  margin: 1rem auto;
  padding: 1rem;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(35, 42, 54, 0.5), rgba(0, 0, 0, 0.45));
  border: 1px solid rgba(79, 209, 197, 0.22);
}

/* ---- topbar ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.3rem 0 0.6rem;
  flex-wrap: wrap;
}

.logo-wrap { position: relative; display: flex; align-items: center; gap: 0.7rem; }

.lantern-mark {
  display: inline-block;
  width: 46px;
  height: 46px;
  background: var(--asset-lantern) center/contain no-repeat;
  filter: drop-shadow(0 2px 10px rgba(79, 209, 197, 0.55));
}

.wordmark h1 {
  margin: 0;
  font-size: clamp(1.2rem, 3.4vw, 2rem);
  color: var(--lantern);
  letter-spacing: 0.14em;
  text-shadow: 0 2px 0 #070a0f, 0 0 18px rgba(79, 209, 197, 0.3);
}

.wordmark .tagline { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.76rem; letter-spacing: 0.04em; }

h2 { margin: 0 0 0.5rem; color: var(--lantern); font-size: 1rem; }

.topbar-right { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.pill {
  border: 1px solid rgba(79, 209, 197, 0.35);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  background: rgba(0, 0, 0, 0.42);
  font-weight: 700;
}

.mode-pill { color: var(--win); font-size: 0.78rem; letter-spacing: 0.1em; }
.balance-pill { color: var(--lantern); }

.demo-toggle { display: flex; align-items: center; gap: 0.35rem; color: var(--muted); font-size: 0.82rem; }
.demo-toggle input { accent-color: var(--lantern); width: 1.05rem; height: 1.05rem; }
.demo-reset {
  background: none;
  border: 1px solid rgba(79, 209, 197, 0.4);
  color: var(--lantern);
  padding: 0.3rem 0.7rem;
  font-size: 0.74rem;
  border-radius: 8px;
}
.demo-reset[hidden] { display: none; }
.demo-reset:disabled { opacity: 0.45; }

.sprinkle-zone { position: absolute; inset: -60% -40%; pointer-events: none; overflow: visible; }

.sprinkle-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  background: var(--asset-dust) center/contain no-repeat;
  filter: drop-shadow(0 0 6px rgba(79, 209, 197, 0.8));
  animation: sprinkle-fly 900ms ease-out forwards;
}

@keyframes sprinkle-fly {
  0% { transform: translate(0, 0) scale(0.3) rotate(0deg); opacity: 0; }
  18% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(var(--rot)); opacity: 0; }
}

/* ---- stage / grid ---- */

.stage {
  position: relative;
  margin-top: 0.4rem;
  border-radius: 18px;
  padding: 0.9rem;
  border: 2px solid rgba(79, 209, 197, 0.32);
  background: linear-gradient(180deg, #1b212c, var(--stone-2));
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.65), 0 10px 30px rgba(0, 0, 0, 0.5);
}

.shaft-frame {
  display: flex;
  justify-content: center;
  border-radius: 14px;
  padding: 0.7rem;
  background:
    radial-gradient(circle at 50% 0%, rgba(79, 209, 197, 0.12), transparent 62%),
    linear-gradient(180deg, #131820, #0d1117);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.grid {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.grid-row {
  display: flex;
  gap: 0.45rem;
}

.tile {
  position: relative;
  width: var(--tile);
  aspect-ratio: 1;
  padding: 0;
  border-radius: 12px;
  border: 1px solid rgba(109, 122, 140, 0.4);
  background-color: var(--stone);
  background-image: var(--asset-stone);
  background-size: 78% 78%;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  color: transparent;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
  will-change: transform;
}

.tile:hover:not(:disabled):not([aria-disabled="true"]) {
  transform: translateY(-3px);
  border-color: var(--lantern);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55), 0 0 14px rgba(79, 209, 197, 0.35);
}

.tile:focus-visible {
  outline: 3px solid var(--lantern);
  outline-offset: 2px;
}

.tile:disabled,
.tile[aria-disabled="true"] { cursor: default; }

.tile.chipping {
  border-color: var(--lantern);
  box-shadow: inset 0 0 22px rgba(79, 209, 197, 0.35);
}

.tile.glimmer {
  background-image: var(--asset-glimmer);
  background-color: rgba(167, 139, 250, 0.16);
  border-color: var(--glimmer);
  box-shadow: inset 0 0 20px rgba(167, 139, 250, 0.3), 0 0 14px rgba(167, 139, 250, 0.28);
  animation: glimmer-pop 320ms ease-out 1;
}

@keyframes glimmer-pop {
  0% { background-size: 26% 26%; }
  60% { background-size: 94% 94%; }
  100% { background-size: 78% 78%; }
}

.tile.collapse {
  background-image: var(--asset-collapse);
  background-color: rgba(225, 29, 72, 0.28);
  border-color: var(--danger);
  box-shadow: inset 0 0 24px rgba(225, 29, 72, 0.45), 0 0 18px rgba(225, 29, 72, 0.4);
  animation: tile-shake 300ms ease-in-out 1;
}

.tile.mine-shown {
  background-image: var(--asset-collapse);
  background-color: rgba(225, 29, 72, 0.1);
  border-color: rgba(225, 29, 72, 0.45);
  opacity: 0.6;
}

.tile.spent { pointer-events: none; }
.tile.spent:not(.glimmer):not(.collapse):not(.mine-shown) { opacity: 0.4; }

/* Every colour-coded state also carries a glyph, so the board is readable
   without relying on hue alone. */
.tile::after {
  position: absolute;
  right: 5px;
  bottom: 3px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.tile.glimmer::after { content: "+"; color: var(--glimmer); }
.tile.collapse::after { content: "X"; color: #ffd7e0; }
.tile.mine-shown::after { content: "x"; color: rgba(255, 215, 224, 0.8); }

@keyframes tile-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  45% { transform: translateX(6px); }
  70% { transform: translateX(-3px); }
}

.stage.flash-collapse { animation: flash-collapse 520ms ease-in-out 2; }

@keyframes flash-collapse {
  0%, 100% { box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.65); border-color: rgba(79, 209, 197, 0.32); }
  50% { box-shadow: inset 0 0 70px rgba(225, 29, 72, 0.5), 0 0 30px rgba(225, 29, 72, 0.45); border-color: var(--danger); }
}

/* ---- HUD ---- */

.hud {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.8rem;
  align-items: center;
  padding: 0.7rem 0.9rem;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(79, 209, 197, 0.22);
}

.hud-label { display: block; color: var(--muted); font-size: 0.7rem; letter-spacing: 0.16em; }

.hud-mult {
  display: block;
  font-size: clamp(1.9rem, 6vw, 3rem);
  color: var(--lantern);
  text-shadow: 0 0 22px rgba(79, 209, 197, 0.4);
  line-height: 1.05;
}

.hud-mult.pulse-win { animation: pulse-win 620ms ease-out; }

@keyframes pulse-win {
  0% { transform: scale(1) translateY(0); color: var(--lantern); }
  40% { transform: scale(1.16) translateY(-6px); color: var(--win); }
  100% { transform: scale(1) translateY(0); color: var(--lantern); }
}

.hud-side { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.hud-side strong { display: block; margin-top: 0.2rem; color: var(--lantern); font-size: 1rem; }

/* ---- controls ---- */

.controls {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: minmax(300px, 2fr) auto auto auto;
  gap: 0.6rem;
  align-items: stretch;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  color: #fff;
}

button:disabled { opacity: 0.45; cursor: not-allowed; }

.control-block { background: rgba(0, 0, 0, 0.42); border-radius: 10px; padding: 0.4rem 0.55rem; }
.control-block label { display: block; color: var(--muted); font-size: 0.74rem; }
.control-block select {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 0.45rem;
  color: #f1f1f1;
  background: var(--stone);
}

.mine-selector { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.3rem; margin-top: 0.3rem; }

.mine-btn {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.4rem 0.3rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 9px;
  background: #1c222c;
  font-size: 0.8rem;
}

.mine-btn .m-caption { font-size: 0.62rem; font-weight: 600; color: var(--muted); }
.mine-btn.active {
  border-color: var(--lantern);
  background: linear-gradient(180deg, rgba(79, 209, 197, 0.24), rgba(79, 209, 197, 0.05));
  color: var(--lantern);
}
.mine-btn.active .m-caption { color: #a8e8e1; }

.mine-custom {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.mine-custom span { color: var(--muted); font-size: 0.7rem; letter-spacing: 0.1em; }

.mine-custom input {
  width: 5rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  background: var(--stone);
  color: var(--ink);
}

.primary {
  background: linear-gradient(180deg, #9ff0e7, var(--lantern));
  color: #06312d;
  min-width: 138px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.collect { background: linear-gradient(180deg, #2e9d5b, #17603a); min-width: 176px; }

/* ---- history ---- */

.history-wrap { margin-top: 0.8rem; }
.history-strip { display: flex; gap: 0.35rem; overflow-x: auto; padding: 0.4rem 0; }
.history-empty { color: var(--muted); font-size: 0.82rem; }

.history-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.76rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.history-chip .chip-tag {
  font-style: normal;
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
}

.history-chip.win { background: rgba(52, 211, 153, 0.16); border-color: var(--win); color: #b9f5dc; }
.history-chip.loss { background: rgba(225, 29, 72, 0.18); border-color: var(--danger); color: #ffc9d4; }

/* ---- results / panels ---- */

.results {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.results div {
  background: linear-gradient(180deg, rgba(35, 42, 54, 0.7), rgba(0, 0, 0, 0.5));
  border: 1px solid rgba(79, 209, 197, 0.24);
  border-radius: 10px;
  padding: 0.55rem;
}

.results span { display: block; color: var(--muted); font-size: 0.74rem; }
.results strong { display: block; margin-top: 0.25rem; font-size: 0.92rem; color: var(--lantern); overflow-wrap: anywhere; }

.verify-link {
  display: block;
  margin: 0.7rem auto 0;
  background: none;
  border: 1px solid rgba(79, 209, 197, 0.4);
  color: var(--lantern);
  padding: 0.4rem 1rem;
  font-size: 0.78rem;
  border-radius: 8px;
}

.panels {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.7rem;
}

.panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.table-scroll { max-height: 260px; overflow-y: auto; }
.panel table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.panel th, .panel td { text-align: left; padding: 0.25rem 0.4rem; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.panel th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
.panel ul { margin: 0; padding-left: 1.1rem; color: #d6e0ee; }
.panel ul li { margin: 0.2rem 0; }

/* ---- toast / modal ---- */

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 21, 29, 0.97);
  color: #e4fbf7;
  border: 1px solid rgba(79, 209, 197, 0.45);
  border-radius: 10px;
  padding: 0.6rem 1.1rem;
  z-index: 60;
  max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
  overflow: auto;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  margin: auto;
  background: linear-gradient(180deg, #1c222c, #0d1117);
  border: 3px solid var(--lantern);
  border-radius: 16px;
  padding: 1.3rem 1.5rem;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
}

.modal-card h2 { margin-bottom: 0.4rem; }
.modal-card p { margin: 0.2rem 0 0.6rem; color: var(--muted); }

.verify-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.7rem;
  text-align: left;
  margin: 0 0 0.9rem;
  font-size: 0.8rem;
}

.verify-details dt { color: var(--muted); }
.verify-details dd { margin: 0; color: var(--lantern); overflow-wrap: anywhere; }

/* ---- ambience ---- */

.lantern-glow { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }

.lantern-glow span {
  position: absolute;
  top: -40px;
  width: 3px;
  height: 30px;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(79, 209, 197, 0.85), transparent);
  box-shadow: 0 0 12px 2px rgba(79, 209, 197, 0.32);
  animation: dust-fall linear infinite;
  opacity: 0;
}

.lantern-glow span:nth-child(1) { left: 11%; animation-duration: 14s; animation-delay: 0s; }
.lantern-glow span:nth-child(2) { left: 29%; animation-duration: 18s; animation-delay: 2.6s; }
.lantern-glow span:nth-child(3) { left: 52%; animation-duration: 12s; animation-delay: 4.4s; }
.lantern-glow span:nth-child(4) { left: 71%; animation-duration: 16s; animation-delay: 1.5s; }
.lantern-glow span:nth-child(5) { left: 89%; animation-duration: 13s; animation-delay: 3.7s; }

@keyframes dust-fall {
  0% { transform: translateY(0); opacity: 0; }
  12% { opacity: 0.65; }
  88% { opacity: 0.65; }
  100% { transform: translateY(112vh); opacity: 0; }
}

@media (max-width: 900px) {
  :root { --tile: 72px; }
  .controls { grid-template-columns: 1fr 1fr; }
  .controls .mine-block { grid-column: 1 / -1; }
  .results { grid-template-columns: 1fr 1fr; }
  .panels { grid-template-columns: 1fr; }
  .hud { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  :root { --tile: min(56px, 15vw); }
  .layout { padding: 0.6rem; }
  .stage { padding: 0.5rem; }
  .shaft-frame { padding: 0.4rem; }
  .grid { gap: 0.3rem; }
  .grid-row { gap: 0.3rem; }
  .controls { grid-template-columns: 1fr; }
  .results { grid-template-columns: 1fr; }
  .mine-selector { grid-template-columns: repeat(3, 1fr); }
  .collect, .primary { min-width: 0; width: 100%; }
}

/* The page is fully playable without motion: app.js swaps every GSAP tween
   for an instant state write when this query matches. */
@media (prefers-reduced-motion: reduce) {
  .lantern-glow { display: none; }
  .sprinkle-icon,
  .stage.flash-collapse,
  .tile.collapse,
  .tile.glimmer,
  .hud-mult.pulse-win { animation: none; }
  .tile { transition: none; }
}

/* ---- practices layer: celebration, framing, pacing ---- */

.bet-select-hidden { display: none; }

.bet-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.3rem; }

.bet-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(139, 151, 171, 0.45);
  background: rgba(35, 42, 54, 0.75);
  color: var(--ink);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.bet-chip.active {
  border-color: var(--lantern);
  background: rgba(79, 209, 197, 0.18);
  color: #d9fffa;
}

.bet-chip.anchor {
  border-color: #f5c542;
  background: linear-gradient(180deg, rgba(245, 197, 66, 0.28), rgba(245, 197, 66, 0.1));
  font-size: 1rem;
  font-weight: 700;
  padding: 0.5rem 0.9rem;
}

.bet-chip.anchor em {
  font-style: normal;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  color: #f5c542;
}

.bet-chip:disabled { opacity: 0.45; cursor: default; }

.fast-toggle { display: flex; align-items: center; gap: 0.35rem; color: var(--muted); font-size: 0.82rem; margin-top: 0.45rem; }
.fast-toggle input { accent-color: var(--lantern); width: 1.05rem; height: 1.05rem; }

.rebet {
  background: linear-gradient(180deg, rgba(245, 197, 66, 0.9), rgba(214, 158, 30, 0.9));
  color: #2e2003;
  min-width: 150px;
  font-weight: 700;
}

.mine-caption { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.8rem; font-style: italic; }

.tier-banner {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.9rem;
  margin-top: 0.8rem;
  padding: 0.7rem 1rem;
  border-radius: 14px;
  text-align: center;
  animation: tier-pop 420ms cubic-bezier(0.2, 1.6, 0.4, 1);
}

.tier-banner .tier-name { font-weight: 800; letter-spacing: 0.14em; }
.tier-banner .tier-amount { font-size: 1.5rem; font-weight: 800; }
.tier-banner .tier-mult { color: var(--muted); font-weight: 700; }

.tier-std { background: rgba(52, 211, 153, 0.14); border: 1px solid var(--win); }
.tier-big { background: rgba(245, 197, 66, 0.16); border: 1px solid #f5c542; color: #ffe9a8; }
.tier-mega { background: rgba(167, 139, 250, 0.2); border: 1px solid var(--glimmer); color: #ddd0ff; font-size: 1.05rem; }
.tier-epic {
  background: linear-gradient(90deg, rgba(245, 197, 66, 0.3), rgba(225, 29, 72, 0.3), rgba(167, 139, 250, 0.3));
  border: 1px solid #f5c542;
  color: #fff3cf;
  font-size: 1.15rem;
}

@keyframes tier-pop {
  0% { transform: scale(0.82); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.near-miss {
  margin-top: 0.6rem;
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  border: 1px solid rgba(245, 197, 66, 0.65);
  background: rgba(245, 197, 66, 0.1);
  color: #ffe9a8;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.03em;
  animation: tier-pop 300ms ease-out;
}

.grid.hot .tile:not(.glimmer):not(.collapse) { box-shadow: 0 0 0 1px rgba(245, 197, 66, 0.35), 0 0 14px rgba(245, 197, 66, 0.18); }
.grid.hotter .tile:not(.glimmer):not(.collapse) { box-shadow: 0 0 0 1px rgba(225, 29, 72, 0.5), 0 0 20px rgba(225, 29, 72, 0.28); animation: next-glow 0.9s ease-in-out infinite alternate; }

@keyframes next-glow {
  from { filter: brightness(1); }
  to { filter: brightness(1.22); }
}

#cashoutBtn.hot { animation: pulse-win 700ms ease-in-out infinite alternate; }

.social-chip { cursor: default; }
