/* ============================================================
   style.css — page layout, frame, control panel, number pad
   ============================================================ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse at center, var(--bg-top) 0%, var(--bg-mid) 60%, var(--bg-bottom) 100%);
  overflow-x: hidden;
  transition: background 320ms ease, color 320ms ease;
}

/* Parchment noise — kills the "too digital" gradient look.
   Uses a tiny inline SVG turbulence so we need zero external files. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.12;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
  animation: noise-drift 18s steps(10) infinite;
}

/* Deeper vignette — the machine "sits" on an old oak desk */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0, 0, 0, 0.22) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(0, 0, 0, 0.22) 0%, transparent 50%),
    radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.3) 100%);
  pointer-events: none;
  z-index: 0;
  animation: vignette-drift 24s ease-in-out infinite;
}

:is(button, a, .cell):focus {
  outline: none;
}

:is(button, a, .cell):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--focus-ring-glow);
}

.cell:focus-visible {
  outline-offset: -2px;
}

/* ----------------------------------------------------------------
   .machine — the brass-framed box that holds the entire game
---------------------------------------------------------------- */
.machine {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 2rem auto;
  padding: 1.5rem;
  background:
    linear-gradient(145deg, var(--brass-shine) 0%, var(--brass-light) 34%, var(--brass) 72%, var(--brass-dark) 100%);
  border: 6px solid var(--frame-dark);
  border-radius: 18px;
  box-shadow:
    0 0 0 2px var(--brass-dark) inset,
    0 0 0 4px var(--brass) inset,
    inset 0 4px 12px rgba(255, 240, 200, 0.15),
    inset 0 -6px 16px rgba(0, 0, 0, 0.4),
    0 20px 60px rgba(0, 0, 0, 0.65),
    0 0 80px rgba(74, 216, 255, 0.08),
    0 2px 0 rgba(255, 230, 170, 0.15);
  animation: machine-hum 6.5s ease-in-out infinite;
}

/* Scanline overlay — faint horizontal lines, like an old CRT / brass ticker tape reader */
.machine::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 3px,
    var(--scanline) 3px,
    var(--scanline) 4px
  );
  pointer-events: none;
  z-index: 50;
}

/* Tarnish + scratch pass across the brass shell */
.machine::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(circle at 16% 12%, rgba(45, 28, 8, 0.22), transparent 35%),
    radial-gradient(circle at 84% 86%, rgba(20, 12, 4, 0.24), transparent 34%),
    repeating-linear-gradient(
      112deg,
      rgba(255, 245, 210, 0.05) 0px,
      rgba(255, 245, 210, 0.05) 1px,
      transparent 1px,
      transparent 7px
    ),
    repeating-linear-gradient(
      -22deg,
      rgba(22, 14, 5, 0.07) 0px,
      rgba(22, 14, 5, 0.07) 1px,
      transparent 1px,
      transparent 9px
    );
  mix-blend-mode: multiply;
}

/* ----------------------------------------------------------------
   Title plate — the riveted brass nameplate at the top
---------------------------------------------------------------- */
.title-plate {
  position: relative;
  background:
    linear-gradient(
      180deg,
      var(--brass-shine) 0%,
      var(--brass-light) 28%,
      var(--brass) 70%,
      var(--brass-dark) 100%
    );
  border: 3px solid var(--frame-dark);
  border-radius: 8px;
  padding: 1rem 2.5rem;
  margin-bottom: 1.25rem;
  text-align: center;
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.5),
    inset 0 -3px 8px rgba(0, 0, 0, 0.5),
    inset 0 0 20px rgba(0, 0, 0, 0.08),
    0 4px 8px rgba(0, 0, 0, 0.45),
    0 1px 0 rgba(255, 230, 170, 0.2);
  overflow: hidden;
}

.title-plate::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(160deg, rgba(255, 245, 210, 0.26), transparent 42%),
    radial-gradient(circle at 82% 18%, rgba(40, 26, 10, 0.2), transparent 38%),
    repeating-linear-gradient(
      -18deg,
      rgba(255, 236, 190, 0.08) 0px,
      rgba(255, 236, 190, 0.08) 1px,
      transparent 1px,
      transparent 6px
    );
}

.title {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: 0.18em;
  color: var(--ink);
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.4),
    0 -1px 0 rgba(0, 0, 0, 0.4);
}

.subtitle {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
  margin-top: 0.25rem;
  opacity: 0.92;
}

.rivet {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 30% 30%,
    var(--brass-shine),
    var(--brass) 50%,
    var(--brass-dark) 85%
  );
  border: 1px solid rgba(0, 0, 0, 0.35);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.6),
    inset 0 1px 1px rgba(255, 240, 200, 0.5),
    inset 0 -1px 1px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

/* Shimmer sweep — a light glint passes across each rivet head */
.rivet::after {
  content: '';
  position: absolute;
  top: -2px;
  left: -8px;
  width: 4px;
  height: 14px;
  background: rgba(255, 240, 200, 0.6);
  filter: blur(2px);
  transform: rotate(25deg);
  animation: rivet-shimmer 6s ease-in-out infinite;
}
.rivet--tr::after { animation-delay: 1.5s; }
.rivet--bl::after { animation-delay: 3s; }
.rivet--br::after { animation-delay: 4.5s; }

.rivet--tl { top: 6px; left: 6px; }
.rivet--tr { top: 6px; right: 6px; }
.rivet--bl { bottom: 6px; left: 6px; }
.rivet--br { bottom: 6px; right: 6px; }

.nixie-tube {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 30px;
  border-radius: 6px 6px 4px 4px;
  background: linear-gradient(
    180deg,
    rgba(74, 216, 255, 0.85),
    rgba(26, 74, 107, 0.95)
  );
  border: 1px solid var(--frame-dark);
  box-shadow:
    0 0 12px var(--nixie-glow),
    inset 0 0 6px rgba(255, 255, 255, 0.4);
  transform: translateY(-50%);
  animation: nixie-flicker 3.5s infinite;
}
.nixie-tube--left { left: 14px; }
.nixie-tube--right { right: 14px; animation-delay: 1.2s; }

/* ----------------------------------------------------------------
   Control panel — difficulty buttons and gauges
---------------------------------------------------------------- */
.control-panel {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.08)),
    linear-gradient(180deg, rgba(90, 68, 35, 0.3), transparent);
  border: 2px solid var(--brass-dark);
  border-radius: 6px;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.35),
    inset 0 -1px 0 rgba(255, 230, 170, 0.08),
    0 1px 0 rgba(255, 230, 170, 0.1);
}

.control-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 6px;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 24%, rgba(0, 0, 0, 0.2), transparent 32%),
    radial-gradient(circle at 86% 78%, rgba(255, 220, 150, 0.07), transparent 34%);
}

.difficulty-dial label,
.difficulty-dial #difficulty-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
  margin-bottom: 0.4rem;
}

.difficulty-buttons {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.diff-btn {
  position: relative;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  padding: 0.4rem 0.55rem;
  background: linear-gradient(180deg, var(--brass-light), var(--brass-dark));
  border: 1px solid var(--frame-dark);
  border-radius: 3px;
  color: var(--ink);
  cursor: pointer;
  transition: filter 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 1px 2px rgba(0, 0, 0, 0.4);
}
.diff-btn::after {
  content: '';
  position: absolute;
  top: -14px;
  left: -70%;
  width: 32%;
  height: 200%;
  background: rgba(255, 245, 210, 0.35);
  transform: rotate(18deg);
  transition: left 0.3s ease;
}
.diff-btn:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 0 6px var(--tube-glow);
}
.diff-btn:hover::after {
  left: 130%;
}
.diff-btn:active {
  transform: translateY(1px);
}
.diff-btn.active {
  background: linear-gradient(180deg, var(--nixie), var(--nixie-deep));
  color: #092537;
  text-shadow: 0 0 4px var(--nixie-glow);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 0 8px var(--nixie-glow);
}

/* SURVIVAL button — red-amber, distinct from the blue normal difficulties */
.diff-btn--survival {
  background: linear-gradient(180deg, #a75824, #3f1307);
  color: #fff;
  border-color: var(--danger-deep);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  animation: survival-idle 2.4s ease-in-out infinite;
}
.diff-btn--survival:hover {
  filter: brightness(1.18);
}
.diff-btn--survival.active {
  background: linear-gradient(180deg, #c83f30, #4f120c);
  color: #fff;
  text-shadow: 0 0 6px var(--danger-glow);
  animation: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 0 12px var(--danger-glow);
}

.skin-selector {
  margin-top: 0.55rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.skin-label {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.16em;
  color: var(--muted-text);
  font-weight: 700;
}

.skin-buttons {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.14rem;
  border-radius: 999px;
  border: 1px solid var(--brass-dark);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.24), rgba(0, 0, 0, 0.1));
}

.skin-btn {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.22rem 0.58rem;
  font-family: var(--font-mono);
  font-size: 0.54rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--paper);
  background: transparent;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.skin-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 6px var(--tube-glow);
}

.skin-btn.active {
  color: var(--ink);
  background: linear-gradient(180deg, var(--brass-light), var(--brass-dark));
  border-color: rgba(0, 0, 0, 0.45);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

/* Chrono gauge in warning state — used in survival when time <= 30s */
.gauge-value.warning {
  animation: pulse-warning 1s ease-in-out infinite;
}

/* Chrono gauge — short flash when survival adds or subtracts time */
.gauge-value.bonus {
  animation: time-bonus-flash 0.5s ease-out;
}
.gauge-value.penalty {
  animation: time-penalty-flash 0.5s ease-out;
}

.gauges {
  display: flex;
  gap: 0.6rem;
}

.gauge {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background:
    radial-gradient(ellipse at center, #1e1610 0%, var(--frame-dark) 100%);
  border: 2px solid var(--brass-dark);
  border-radius: 4px;
  min-width: 64px;
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.8),
    inset 0 0 16px rgba(0, 0, 0, 0.5),
    0 1px 0 rgba(255, 230, 170, 0.1);
}

/* Tiny pressure needle gives each gauge a mechanical heartbeat */
.gauge::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 2px;
  height: 16px;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(255, 238, 176, 0.9), rgba(123, 90, 30, 0.95));
  box-shadow: 0 0 4px rgba(255, 224, 130, 0.55);
  transform-origin: 50% 100%;
  animation: gauge-needle 2.8s ease-in-out infinite;
}
.gauges .gauge:nth-child(2)::after { animation-delay: 0.45s; }
.gauges .gauge:nth-child(3)::after { animation-delay: 0.9s; }
.gauges .gauge:nth-child(4)::after { animation-delay: 1.35s; }

.gauge-label {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--paper-dark);
  letter-spacing: 0.1em;
}

.gauge-value {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: var(--nixie);
  text-shadow: 0 0 6px var(--nixie-glow);
  animation: gauge-jitter 0.15s steps(2) infinite;
}

/* ----------------------------------------------------------------
   Number pad — 10 brass keys (1-9 + erase)
---------------------------------------------------------------- */
.number-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-top: 1rem;
}

.num-key {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 1.5rem;
  padding: 0.85rem 0;
  background: radial-gradient(
    circle at 30% 25%,
    var(--brass-shine) 0%,
    var(--brass-light) 18%,
    var(--brass) 50%,
    #96783a 75%,
    var(--brass-dark) 100%
  );
  border: 2px solid var(--frame-dark);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -2px 0 rgba(0, 0, 0, 0.45),
    inset 0 0 8px rgba(0, 0, 0, 0.08),
    0 3px 0 var(--brass-darker),
    0 5px 8px rgba(0, 0, 0, 0.55);
  transition: all 0.08s ease-out;
  animation: key-idle 5s ease-in-out infinite;
}
.number-pad .num-key:nth-child(odd) { animation-delay: 0.5s; }

.num-key:hover {
  filter: brightness(1.1);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -2px 0 rgba(0, 0, 0, 0.45),
    0 3px 0 var(--brass-darker),
    0 4px 10px var(--tube-glow);
}

/* the bottom-out — key sinks 3px into the panel, shadow collapses */
.num-key:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.5),
    inset 0 -1px 0 rgba(0, 0, 0, 0.3),
    0 0 0 var(--brass-darker);
  filter: brightness(0.95);
}

.num-key--erase {
  font-size: 1.2rem;
}

/* ----------------------------------------------------------------
   Action buttons (NEW GAME, HINT, ?, etc.)
---------------------------------------------------------------- */
.actions {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.action-btn {
  position: relative;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  padding: 0.6rem 1.6rem;
  background: linear-gradient(180deg, var(--copper) 0%, var(--copper-dark) 100%);
  border: 2px solid var(--frame-dark);
  border-radius: 5px;
  color: var(--paper);
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 3px 0 #2a1808,
    0 5px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}

.action-btn::after {
  content: '';
  position: absolute;
  top: -12px;
  left: -56%;
  width: 24%;
  height: 180%;
  background: rgba(255, 236, 196, 0.28);
  transform: rotate(16deg);
  transition: left 0.32s ease;
}
.action-btn:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.3), 0 3px 0 #2a1808, 0 0 10px var(--tube-glow);
  animation: valve-chatter 0.18s linear 2;
}
.action-btn:hover::after {
  left: 126%;
}
.action-btn:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 1px 0 #2a1808,
    0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Smaller variant for HINT and the [ ? ] button */
.action-btn--small {
  font-size: 0.7rem;
  padding: 0.5rem 0.95rem;
  letter-spacing: 0.12em;
}
.action-btn--icon {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: var(--font-title);
  font-weight: 800;
}

.action-btn--toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.62rem;
  min-width: 102px;
  justify-content: center;
}

.action-btn--toggle .toggle-text {
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  font-weight: 700;
}

.toggle-track {
  position: relative;
  width: 36px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.5);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.15));
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.45);
}

.toggle-thumb {
  position: absolute;
  left: 1px;
  top: 1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--paper), var(--paper-dark));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.action-btn--toggle.active {
  background: linear-gradient(180deg, var(--tube-amber), var(--copper-dark));
  color: var(--frame-dark);
  text-shadow: 0 0 4px var(--tube-glow);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 3px 0 #2a1808,
    0 0 10px var(--tube-glow);
}

.action-btn--toggle.active .toggle-thumb {
  transform: translateX(18px);
  background: radial-gradient(circle at 30% 30%, #fffbd9, var(--tube-amber));
  box-shadow: 0 0 6px var(--tube-glow);
}

/* Disabled button (e.g. HINT when hintsLeft === 0) */
.action-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.5);
}
.action-btn.disabled:hover {
  filter: grayscale(0.5);
  transform: none;
  animation: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 3px 0 #2a1808,
    0 5px 8px rgba(0, 0, 0, 0.5);
}
.action-btn.disabled:hover::after { left: -56%; }
.action-btn.disabled:active { transform: none; }

/* ----------------------------------------------------------------
   Help modal — backdrop blur + brass framed panel
---------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 6, 2, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  animation: modal-fade 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal-overlay[hidden] { display: none; }
.modal-overlay.is-closing {
  animation: modal-fade-out 0.22s ease forwards;
}

.modal-overlay::before {
  content: '';
  position: absolute;
  inset: -18%;
  z-index: 0;
  background:
    radial-gradient(circle at 28% 32%, rgba(255, 227, 175, 0.22), transparent 36%),
    radial-gradient(circle at 74% 62%, rgba(255, 239, 212, 0.16), transparent 40%);
  filter: blur(28px);
  pointer-events: none;
  animation: fog-drift 14s ease-in-out infinite;
}

.modal-panel {
  position: relative;
  z-index: 1;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  background:
    linear-gradient(145deg, var(--brass-shine) 0%, var(--brass-light) 35%, var(--brass) 75%, var(--brass-dark) 100%);
  border: 6px solid var(--frame-dark);
  border-radius: 14px;
  padding: 1.5rem 1.75rem;
  box-shadow:
    0 0 0 2px var(--brass-dark) inset,
    0 0 0 4px var(--brass) inset,
    inset 0 4px 12px rgba(255, 240, 200, 0.12),
    inset 0 -4px 12px rgba(0, 0, 0, 0.3),
    0 20px 60px rgba(0, 0, 0, 0.7),
    0 0 60px rgba(74, 216, 255, 0.18);
  animation: modal-rise 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-panel.modal-leave {
  animation: modal-sink 0.22s ease forwards;
}

.modal-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 8px;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 242, 204, 0.16), transparent 36%),
    radial-gradient(circle at 80% 78%, rgba(30, 18, 6, 0.22), transparent 38%),
    repeating-linear-gradient(
      -16deg,
      rgba(255, 236, 190, 0.06) 0px,
      rgba(255, 236, 190, 0.06) 1px,
      transparent 1px,
      transparent 8px
    );
  mix-blend-mode: multiply;
}

.modal-title {
  font-family: var(--font-title);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-align: center;
  color: var(--ink);
  margin: 0.4rem 0 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 2px solid var(--brass-dark);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
}

.modal-section {
  margin-bottom: 1rem;
}
.modal-section:last-of-type {
  margin-bottom: 0.5rem;
}

.modal-section h3 {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  color: var(--muted-text);
  margin-bottom: 0.45rem;
  opacity: 0.98;
}

.modal-section p,
.modal-section li {
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--ink);
  margin-bottom: 0.35rem;
}

.modal-section ul {
  list-style: none;
  padding-left: 0.4rem;
}

.modal-section li {
  position: relative;
  padding-left: 1rem;
}
.modal-section li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--brass-dark);
}

.modal-section strong {
  color: var(--frame-dark);
  font-weight: 700;
}

.modal-section kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.1rem 0.4rem;
  margin: 0 0.1rem;
  background: linear-gradient(180deg, var(--brass-light), var(--brass-dark));
  border: 1px solid var(--frame-dark);
  border-radius: 3px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 1px 1px rgba(0, 0, 0, 0.3);
  color: var(--ink);
}

.modal-close {
  display: block;
  margin: 1.2rem auto 0;
}

/* ----------------------------------------------------------------
   RANK gauge — wider than other gauges, with XP progress bar
---------------------------------------------------------------- */
.gauge--rank {
  min-width: 90px;
}

.gauge-value--rank {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.xp-bar {
  width: 100%;
  height: 4px;
  margin-top: 3px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid var(--brass-dark);
}

.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--nixie-deep), var(--nixie));
  border-radius: 2px;
  transition: width 0.5s ease-out;
  box-shadow: 0 0 6px var(--nixie-glow);
}

.xp-bar--large {
  height: 8px;
  margin-top: 6px;
  border-radius: 3px;
}
.xp-bar--large .xp-fill {
  border-radius: 3px;
}

/* ----------------------------------------------------------------
   Stats modal — rank display, stats grid, achievements
---------------------------------------------------------------- */
.stats-rank-display {
  text-align: center;
  padding: 0.5rem 0;
}

.stats-rank-name {
  font-family: var(--font-title);
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--nixie);
  text-shadow: 0 0 10px var(--nixie-glow);
  display: block;
  margin-bottom: 0.2rem;
}

.stats-xp-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted-text);
  display: block;
  margin-top: 4px;
  letter-spacing: 0.08em;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.45rem 0.3rem;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--brass-dark);
  border-radius: 4px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--nixie);
  text-shadow: 0 0 4px var(--nixie-glow);
}

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--muted-text);
  letter-spacing: 0.1em;
  margin-top: 2px;
}

/* Achievements list */
.achievements-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.achievement {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(61, 44, 10, 0.45);
  border-radius: 4px;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.achievement:not(.unlocked) .achievement-icon {
  color: var(--muted-text);
  opacity: 0.9;
}

.achievement:not(.unlocked) .achievement-name {
  color: var(--muted-text);
}

.achievement:not(.unlocked) .achievement-desc {
  color: var(--ink-soft);
}

.achievement.unlocked {
  background: rgba(0, 0, 0, 0.12);
  border-color: var(--nixie-deep);
  box-shadow: 0 0 6px rgba(74, 216, 255, 0.15);
}

.achievement-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 1.6rem;
  text-align: center;
}

.achievement-info {
  flex: 1;
  min-width: 0;
}

.achievement-name {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.05em;
}

.achievement-desc {
  font-family: var(--font-body);
  font-size: 0.68rem;
  color: var(--muted-text);
  line-height: 1.35;
}

/* ----------------------------------------------------------------
   Rank-up banner — slides in from top on promotion
---------------------------------------------------------------- */
.rank-up-banner {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.8rem 2.5rem;
  background: linear-gradient(145deg, var(--brass-shine) 0%, var(--brass-light) 50%, var(--brass-dark) 100%);
  border: 4px solid var(--frame-dark);
  border-top: none;
  border-radius: 0 0 14px 14px;
  box-shadow:
    0 8px 30px rgba(0, 0, 0, 0.6),
    0 0 40px rgba(74, 216, 255, 0.2);
  animation: rank-up-slide 2.5s ease-out forwards;
}
.rank-up-banner[hidden] { display: none; }

.rank-up-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
}

.rank-up-name {
  font-family: var(--font-title);
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--nixie);
  text-shadow: 0 0 14px var(--nixie-glow);
  animation: rank-up-glow 1s ease-in-out 3;
}

/* ----------------------------------------------------------------
   Donation modal
---------------------------------------------------------------- */
.modal-panel--wide {
  max-width: 540px;
}

.action-btn--donate {
  background: linear-gradient(180deg, var(--success), #2a6b2d);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
}
.action-btn--donate:hover { filter: brightness(1.2); }

.donate-desc {
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink);
  text-align: center;
  margin-bottom: 0.8rem;
}

.donate-fiat {
  text-align: center;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--brass-dark);
}

.donate-stripe-btn {
  display: inline-block;
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  padding: 0.7rem 2rem;
  background: linear-gradient(180deg, #635bff, #3d35b0);
  text-decoration: none;
}
.donate-stripe-btn:hover { filter: brightness(1.15); }

.crypto-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.crypto-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid var(--brass-dark);
  border-radius: 6px;
}

.crypto-label {
  font-family: var(--font-title);
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: 0.08em;
}

.crypto-qr {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  border-radius: 4px;
  border: 1px solid var(--brass-dark);
  overflow: hidden;
}

.crypto-qr canvas {
  width: 100%;
  height: 100%;
}

.crypto-addr {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  color: var(--ink);
  word-break: break-all;
  text-align: center;
  line-height: 1.4;
  max-width: 100%;
  font-weight: 700;
}

.crypto-network {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--warning-amber);
  letter-spacing: 0.04em;
  text-align: center;
  text-shadow: 0 0 4px var(--warning-amber-glow);
}

.copy-btn {
  font-size: 0.55rem;
  padding: 0.25rem 0.6rem;
}

/* ----------------------------------------------------------------
   Victory Certificate modal — brass-framed parchment diploma
---------------------------------------------------------------- */
.modal-panel--certificate {
  max-width: 440px;
  text-align: center;
  background:
    linear-gradient(145deg, var(--paper) 0%, var(--brass-shine) 30%, var(--brass-light) 60%, var(--brass) 100%);
  animation: certificate-reveal 0.5s ease-out;
}

.certificate-seal {
  font-size: 2.8rem;
  line-height: 1;
  margin: -0.2rem 0 0.3rem;
  color: var(--brass-dark);
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.3),
    0 0 20px var(--tube-glow);
  animation: seal-spin 0.6s ease-out;
}

.certificate-title {
  font-size: 1.1rem;
  letter-spacing: 0.2em;
  border-bottom: 2px solid var(--brass-dark);
  border-top: 2px solid var(--brass-dark);
  padding: 0.5rem 0;
  margin: 0 0 0.6rem;
}

.certificate-decree {
  font-family: var(--font-body);
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--ink);
  margin-bottom: 0.8rem;
  font-style: italic;
}

.certificate-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.cert-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.4rem 0.3rem;
  background: rgba(0, 0, 0, 0.1);
  border: 1px solid var(--brass-dark);
  border-radius: 4px;
  transition: background 0.2s, box-shadow 0.2s;
}
.cert-stat:hover {
  background: rgba(0, 0, 0, 0.18);
  box-shadow: 0 0 8px var(--tube-glow);
}

.cert-stat-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  color: var(--nixie);
  text-shadow: 0 0 6px var(--nixie-glow);
}

.cert-stat-label {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--muted-text);
  letter-spacing: 0.1em;
  margin-top: 2px;
}

.certificate-xp {
  font-family: var(--font-title);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--tube-amber);
  text-shadow: 0 0 14px var(--tube-glow-strong), 0 0 30px var(--tube-glow);
  margin: 0.6rem 0 0.4rem;
  animation: xp-pulse 1.2s ease-in-out 3;
}

.certificate-brand {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  letter-spacing: 0.25em;
  color: var(--muted-text);
  opacity: 0.82;
  margin-bottom: 0.8rem;
}

.certificate-actions {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
}

/* ----------------------------------------------------------------
   Game Over modal — dark, pressure-blown failure screen
---------------------------------------------------------------- */
.modal-panel--gameover {
  max-width: 400px;
  text-align: center;
  background:
    linear-gradient(145deg, #4a2a1a 0%, #2a1810 40%, #1a0e08 100%);
  border-color: var(--danger-deep);
  box-shadow:
    0 0 0 2px var(--danger-deep) inset,
    0 0 0 4px rgba(255, 69, 48, 0.3) inset,
    inset 0 4px 12px rgba(255, 69, 48, 0.08),
    inset 0 -4px 12px rgba(0, 0, 0, 0.5),
    0 20px 60px rgba(0, 0, 0, 0.7),
    0 0 60px rgba(255, 69, 48, 0.15);
  animation: gameover-shake 0.4s ease-out;
}

.gameover-title {
  color: var(--danger);
  text-shadow: 0 0 10px var(--danger-glow);
  border-bottom-color: var(--danger-deep);
}

.gameover-reason {
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--paper);
  margin-bottom: 0.8rem;
}

.modal-panel--gameover .cert-stat {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--danger-deep);
}

.modal-panel--gameover .modal-section h3 {
  color: var(--paper-dark);
}

@media (max-width: 780px) {
  .control-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .gauges {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .gauge {
    flex: 1 1 30%;
  }
}

/* Responsive: stack crypto cards on small screens */
@media (max-width: 420px) {
  .skin-selector {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }

  .skin-buttons {
    width: 100%;
    justify-content: space-between;
  }

  .skin-btn {
    flex: 1;
    text-align: center;
  }

  .action-btn--toggle {
    min-width: 0;
  }

  .action-btn--toggle .toggle-text {
    display: none;
  }

  .crypto-grid {
    grid-template-columns: 1fr;
    max-width: 200px;
    margin: 0.5rem auto 0;
  }
}
