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

:root {
  --font: 'Nunito', system-ui, sans-serif;
  --ink: #3a3350;
  --ink-soft: #6b6383;
  --cream: #fdf6ec;
  --panel: rgba(255, 252, 246, 0.94);
  --gold: #f0c040;
  --gold-dim: #d4a830;
  --green: #4f9a3e;
  --green-soft: #e8f4e0;
  --coral: #d9604f;
  --coral-soft: #fdeae6;
  --amber: #f0a830;
  --lav: #b9a5d8;
  --teal: #2a8c8c;
  --teal-deep: #1d5f66;
  --teal-glow: #7fe3d6;
  --metal: #3b4a58;
  --metal-dark: #232d38;
  --shadow: 0 10px 30px rgba(58, 51, 80, 0.18);
  --topbar-h: 68px;

  /* Rig geometry: the belt runs at --belt-top; the card stands on it. */
  --belt-top: 63%;
  --belt-h: 54px;
  --card-w: clamp(230px, 30vw, 330px);
  --card-h: clamp(176px, 32vh, 240px);   /* tallest a card can be (the tunnel is sized to it) */
  --card-min: 150px;
  --frame: 16px;               /* scanner frame thickness */
  --tunnel-pad: 22px;          /* gap between the card and the frame */
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: #1f2a36;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

button { font-family: var(--font); cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible {
  outline: 4px solid #4a90d9;
  outline-offset: 3px;
  border-radius: 12px;
}

/* ══ Top bar ══ */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px;
  background: var(--panel);
  border-bottom: 2px solid rgba(58, 51, 80, 0.08);
  backdrop-filter: blur(6px);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-shop { height: 44px; width: auto; flex-shrink: 0; filter: drop-shadow(0 2px 3px rgba(58, 51, 80, 0.25)); }
.topbar-title-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.topbar-title strong { font-size: 17px; font-weight: 900; white-space: nowrap; }
.topbar-title span { font-size: 12px; font-weight: 700; color: var(--ink-soft); white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.tb-btn {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 46px; padding: 8px 14px;
  border: 2px solid rgba(58, 51, 80, 0.14);
  border-radius: 14px;
  background: #fff; color: var(--ink);
  font-size: 14px; font-weight: 800;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}
.tb-btn:hover { transform: translateY(-1px); border-color: rgba(58, 51, 80, 0.3); }
.tb-btn svg { width: 20px; height: 20px; fill: var(--ink); stroke: var(--ink); flex-shrink: 0; }
.tb-btn.toggle[aria-pressed="false"] { opacity: 0.45; }
.tb-btn.toggle[aria-pressed="false"] span::after { content: " off"; font-weight: 700; }
.tb-btn.quick-exit { background: var(--ink); color: #fff; border-color: var(--ink); }
.tb-btn.quick-exit svg { fill: var(--gold); stroke: none; }
.tb-btn.quick-exit:hover { background: #2a2440; }

/* ══ Stage ══ */
.stage {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0;
  /* Image is set from config.background; this is the fallback tone. */
  background: #23303e center center / cover no-repeat;
}
.stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to bottom, rgba(10, 16, 28, 0.18) 0%, rgba(10, 16, 28, 0) 25%, rgba(10, 16, 28, 0) 60%, rgba(10, 16, 28, 0.35) 100%);
}

/* ══ Ambience: screen glow and floating pixels (decorative) ══ */
.ambience { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 2; }
.shop-glow {
  position: absolute; width: 40vw; height: 45vh; border-radius: 50%;
  filter: blur(30px); mix-blend-mode: screen;
  animation: glowBreathe 9s ease-in-out infinite;
}
.glow-1 { top: -10%; left: -8%; background: radial-gradient(ellipse, rgba(127, 227, 214, 0.35), rgba(127, 227, 214, 0) 70%); }
.glow-2 { top: -6%; right: -10%; background: radial-gradient(ellipse, rgba(120, 170, 255, 0.3), rgba(120, 170, 255, 0) 70%); animation-delay: -4s; }
@keyframes glowBreathe { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
.pixel {
  position: absolute; left: var(--px); top: var(--py);
  width: 6px; height: 6px; border-radius: 2px;
  background: rgba(127, 227, 214, 0.85);
  box-shadow: 0 0 8px rgba(127, 227, 214, 0.8);
  opacity: 0;
  animation: pixelFloat var(--ps) var(--pd) ease-in-out infinite;
}
@keyframes pixelFloat {
  0%   { transform: translate(0, 0) scale(0.7); opacity: 0; }
  20%  { opacity: 0.8; }
  50%  { transform: translate(14px, -30px) scale(1); opacity: 0.5; }
  80%  { opacity: 0.7; }
  100% { transform: translate(-8px, -56px) scale(0.6); opacity: 0; }
}

/* ══ Props: dartboard ══ */
.dartboard {
  position: absolute; left: var(--x); top: var(--y);
  width: var(--d); aspect-ratio: 1; transform: translate(-50%, -50%);
  pointer-events: auto; cursor: crosshair; touch-action: none;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.45));
}
.dartboard__svg { display: block; width: 100%; height: 100%; }
.dartboard__darts { position: absolute; inset: 0; pointer-events: none; }
.dart {
  position: absolute; width: 44%; height: 8%;
  left: 0; top: 0;
  transform-origin: 0% 50%;
  transform: rotate(var(--rot));
  pointer-events: none;
  filter: drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.5));
}
.dart svg { width: 100%; height: 100%; overflow: visible; display: block; }
.dart.flying { animation: dartFly 0.42s cubic-bezier(0.2, 0.7, 0.3, 1) forwards; }
.dart.stuck { animation: dartWobble 0.5s ease-out 1; }
.dart.fading { transition: opacity 0.6s; opacity: 0; }
@keyframes dartFly {
  0%   { transform: translate(var(--fx), var(--fy)) rotate(var(--rot)) scale(3.2); opacity: 0; }
  10%  { opacity: 1; }
  100% { transform: translate(0, 0) rotate(var(--rot)) scale(1); opacity: 1; }
}
@keyframes dartWobble {
  0%   { transform: rotate(calc(var(--rot) + 4deg)); }
  30%  { transform: rotate(calc(var(--rot) - 3deg)); }
  60%  { transform: rotate(calc(var(--rot) + 1.5deg)); }
  100% { transform: rotate(var(--rot)); }
}
/* Power meter: appears while the pointer is held on the board */
.dart-power {
  position: absolute; right: calc(100% + 8px); top: 4%; height: 92%;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  pointer-events: none;
}
.dart-power[hidden] { display: none; }
.dart-power__track {
  position: relative; flex: 1; width: 9px; border-radius: 999px;
  background: rgba(20, 22, 30, 0.7); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15), 0 2px 6px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.dart-power__fill {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0%;
  background: linear-gradient(to top, #4f9a3e, #f0c040 60%, #d9604f);
}
.dart-power__sweet {
  position: absolute; left: 0; right: 0; bottom: 66%; height: 16%;
  background: rgba(255, 255, 255, 0.35); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
  z-index: 1;
}
.dart-power__label {
  font: 800 clamp(9px, 0.85vw, 11px)/1 "Nunito", sans-serif; color: rgba(255, 250, 240, 0.9);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
.dart-clear {
  position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
  padding: 3px 10px; border: 0; border-radius: 999px;
  font: 800 clamp(10px, 0.95vw, 12px)/1.4 "Nunito", sans-serif; color: #3a3d55;
  background: rgba(255, 250, 240, 0.72); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  cursor: pointer; pointer-events: auto; white-space: nowrap;
  opacity: 0; transition: opacity 0.35s, background 0.2s;
}
.dart-clear:not([hidden]) { opacity: 1; }
.dart-clear:hover { background: rgba(255, 250, 240, 0.95); }
.dart-clear:focus-visible { outline: 2px solid var(--gold, #f0c040); outline-offset: 2px; }
.dart-score {
  position: absolute; transform: translate(-50%, -50%);
  font-weight: 900; font-size: clamp(11px, 1.3vw, 16px); color: #fff;
  text-shadow: 0 1px 0 #000, 0 0 8px rgba(0, 0, 0, 0.8);
  pointer-events: none; animation: dartScore 0.9s ease-out forwards;
}
@keyframes dartScore {
  0%   { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  20%  { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ══ Props: lava lamps on the shelves ══
   .props is sized by game.js to the same box the cover-fitted background
   occupies, so --x/--y are percentages of the artwork and land on the shelves.
   Lamp markup/animation adapted from LofiLamp (Saganaki22, Apache-2.0); the
   lamp keeps its native 180x500 size and is scaled with --s from its base. */
.props { position: absolute; pointer-events: none; }
.lava-lamp {
  --lava: #4bff91;
  --glass-a: color-mix(in srgb, var(--lava) 22%, #000);
  --glass-b: color-mix(in srgb, var(--lava) 40%, #000);
  --glass-c: color-mix(in srgb, var(--lava) 65%, #000);
  position: absolute; left: var(--x); top: var(--y);
  height: 500px; width: 180px;
  transform: translate(-50%, -100%) scale(var(--s));
  transform-origin: 50% 100%;
  filter: drop-shadow(0 20px 40px color-mix(in srgb, var(--lava) 25%, transparent));
}
/* Contact shadow on the counter (shelf lamp has none) */
.lava-lamp--counter::after {
  content: ""; position: absolute; left: 50%; bottom: -46px; z-index: 0;
  width: 240%; height: 120px; transform: translateX(-44%);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 50%, rgba(12, 8, 4, 0.7) 0%, rgba(12, 8, 4, 0.38) 40%, rgba(12, 8, 4, 0) 70%);
  filter: blur(10px);
}
.lava-lamp__main {
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  width: 100%; height: 100%; position: relative; overflow: hidden; z-index: 2;
  background: linear-gradient(180deg, #000 0%, #0a0f0a 100%);
}
.lava-lamp__main:after, .lava-lamp__main:before {
  background: linear-gradient(180deg, #000 0%, #0f1a0f 100%);
  content: ''; height: 12%; left: 0; position: absolute; width: 100%;
}
.lava-lamp__main:after { top: 0; border-radius: 50% 50% 0 0 / 100% 100% 0 0; }
.lava-lamp__main:before { bottom: 0; height: 26%; border-radius: 0 0 50% 50% / 0 0 35% 35%; }
.lava-lamp__glass {
  background: radial-gradient(ellipse at 50% 60%,
    color-mix(in srgb, var(--glass-a) 95%, transparent) 0%,
    color-mix(in srgb, var(--glass-b) 80%, transparent) 25%,
    color-mix(in srgb, var(--glass-c) 60%, transparent) 50%,
    color-mix(in srgb, var(--lava) 40%, transparent) 75%,
    color-mix(in srgb, var(--lava) 15%, transparent) 100%);
  border-radius: 50% / 10%; overflow: hidden;
  height: 70%; left: 0; position: absolute; top: 10%; width: 100%; z-index: 2;
  animation: glass-shimmer calc(8s * var(--rate, 1)) ease-in-out infinite;
  animation-delay: calc(var(--phase, 0) * 1s);
  box-shadow: inset 0 0 30px color-mix(in srgb, var(--lava) 20%, transparent);
}
@keyframes glass-shimmer {
  0%, 100% { filter: brightness(1) saturate(1); }
  50% { filter: brightness(1.05) saturate(1.1); }
}
.lava-lamp__glass:before {
  content: ''; position: absolute; top: 10%; left: 20%; width: 20%; height: 60%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0.1) 50%, transparent 100%);
  border-radius: 50%; filter: blur(10px);
}
.lava-lamp__glass:after {
  content: ''; position: absolute; bottom: 10%; left: 50%; transform: translateX(-50%);
  width: 80%; height: 30%;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--lava) 20%, transparent) 0%, transparent 70%);
  filter: blur(20px);
}
.lava-lamp__base {
  height: 20%; width: 100%; position: absolute; bottom: 0; overflow: hidden;
  border-radius: 0 0 50% 50% / 0 0 35% 35%;
}
.lava-lamp__base:before {
  content: ''; background: linear-gradient(180deg, #000 0%, #0a0f0a 100%);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  position: absolute; top: -60%; height: 500px; width: 180px;
}
.lava-lamp__lava {
  border-radius: 50% / 10%; height: 100%; overflow: hidden; position: absolute; width: 100%;
  filter: url('#goo');
}
.lava-lamp__svg { position: absolute; width: 100%; height: 100%; }
.blob {
  animation-delay: calc((var(--delay) + var(--phase, 0)) * 1s);
  animation-direction: var(--direction);
  animation-duration: calc(var(--speed) * var(--rate, 1) * 1s);
  animation-iteration-count: infinite;
  animation-name: blob-rise;
  animation-timing-function: ease-in-out;
  fill: var(--lava); opacity: 0.9;
}
.blob--top, .blob--bottom {
  animation: blob-sway calc(20s * var(--rate, 1)) infinite ease-in-out;
  animation-delay: calc(var(--phase, 0) * 1s);
}
@keyframes blob-rise {
  0% { transform: translateY(110%) scale(1); }
  50% { transform: translateY(-50%) scale(1.1); }
  100% { transform: translateY(-110%) scale(1); }
}
@keyframes blob-sway {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(20px); }
  75% { transform: translateX(-20px); }
}

/* ══ Meter (top-left) ══ */
.meter {
  position: absolute; top: 12px; left: 14px; z-index: 14;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  padding: 10px 14px 12px; border-radius: 18px;
  background: var(--panel); box-shadow: var(--shadow);
}
.meter-label { font-size: 14px; font-weight: 900; color: var(--ink-soft); }
.meter-locks { display: grid; grid-template-columns: repeat(5, 30px); gap: 6px; }
.meter-lock { width: 30px; height: 30px; }
.meter-lock svg { width: 100%; height: 100%; }
.meter-lock .mi-glass { fill: #e6e0ef; stroke: #cfc6de; stroke-width: 1.5; }
.meter-lock .mi-handle { fill: none; stroke: #cfc6de; stroke-width: 3; }
.meter-lock .mi-tick { stroke: #fff; stroke-width: 2.2; opacity: 0; }
.meter-lock.locked .mi-glass { fill: var(--gold); stroke: var(--gold-dim); }
.meter-lock.locked .mi-handle { stroke: var(--gold-dim); }
.meter-lock.locked .mi-tick { opacity: 1; stroke: var(--ink); }
.meter-lock.locked { animation: lockPop 0.5s ease; }
@keyframes lockPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.45) rotate(-6deg); }
  100% { transform: scale(1); }
}

/* Progress dots */
.progress {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 14;
  display: flex; gap: 7px;
}
.progress i {
  width: 11px; height: 11px; border-radius: 50%;
  background: rgba(255, 252, 246, 0.75);
  border: 2px solid rgba(58, 51, 80, 0.25);
}
.progress i.done { background: var(--green); border-color: var(--green); }
.progress i.now { background: var(--gold); border-color: var(--gold-dim); transform: scale(1.25); }

.card-hint {
  position: absolute; top: 14px; right: 14px; z-index: 14;
  font-size: 14px; font-weight: 800; color: #fff; white-space: nowrap;
  background: rgba(28, 38, 52, 0.6);
  padding: 6px 16px; border-radius: 999px;
  pointer-events: none;
}

/* ══ The rig ══ */
.rig { position: absolute; inset: 0; z-index: 4; pointer-events: none; }

/* Conveyor belt */
.belt {
  position: absolute; left: -2%; right: -2%;
  top: var(--belt-top); height: var(--belt-h);
  z-index: 5;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.35));
}
.belt-top {
  position: absolute; inset: 0;
  border-radius: 10px;
  background:
    repeating-linear-gradient(90deg, #3d444d 0 26px, #2d333b 26px 32px);
  background-size: 32px 100%;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.12), inset 0 -4px 0 rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.belt-top::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.25));
}
.belt.running .belt-top { animation: beltMove 0.55s linear infinite; }
@keyframes beltMove { to { background-position: 32px 0; } }
.belt-side {
  position: absolute; left: 1%; right: 1%; top: 100%; height: 16px;
  background: linear-gradient(to bottom, #6b7684, #3b4652 60%, #2a323c);
  border-radius: 0 0 10px 10px;
}
.belt-legs {
  position: absolute; left: 0; right: 0; top: calc(100% + 16px); height: 34px;
  background: repeating-linear-gradient(90deg,
    transparent 0 180px, #2f3841 180px 196px, transparent 196px 240px);
  opacity: 0.85;
}

/* Scanner machine: the container sits on the belt; its parts rise above it. */
.scanner {
  /* Centred with a margin rather than a transform, so it does not form its own
     stacking context: the back must sit behind the card and the front in front. */
  position: absolute; left: 50%; top: var(--belt-top); height: 0;
  width: calc(var(--card-w) + 2 * (var(--tunnel-pad) + var(--frame)));
  margin-left: calc(-0.5 * (var(--card-w) + 2 * (var(--tunnel-pad) + var(--frame))));
}
.scanner-back, .scanner-front {
  position: absolute; left: 0; right: 0; bottom: -6px;
  height: calc(var(--card-h) + var(--tunnel-pad) + var(--frame) + 14px);
  border-radius: 26px 26px 8px 8px;
}
.scanner-back {
  z-index: 6;
  background: radial-gradient(ellipse at 50% 60%, #1f4a52, #10262c 75%);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.scan-glow {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 55%, rgba(127, 227, 214, 0.22), rgba(127, 227, 214, 0) 70%);
  animation: glowBreathe 4s ease-in-out infinite;
}
.scan-beam {
  position: absolute; top: 0; bottom: 0; left: -12%; width: 12%;
  background: linear-gradient(90deg, rgba(127, 227, 214, 0), rgba(127, 227, 214, 0.55), rgba(127, 227, 214, 0));
  opacity: 0;
}
.scan-beam.sweep { animation: beamSweep 1.1s ease-in-out 1; }
@keyframes beamSweep {
  0% { left: -12%; opacity: 0; }
  15% { opacity: 1; }
  85% { opacity: 1; }
  100% { left: 100%; opacity: 0; }
}
.scanner-front {
  z-index: 9;
  /* Only the frame is painted; the tunnel in the middle stays clear so the
     message shows through. */
  border: var(--frame) solid #3f4d5b;
  border-bottom-width: 0;
  background: transparent;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4), inset 0 0 0 2px rgba(255, 255, 255, 0.06);
}
.scanner-front::before {
  /* Metallic sheen along the top of the frame */
  content: ""; position: absolute;
  left: calc(-1 * var(--frame)); right: calc(-1 * var(--frame)); top: calc(-1 * var(--frame));
  height: calc(var(--frame) * 0.55);
  border-radius: 26px 26px 0 0;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0));
  pointer-events: none;
}
.scanner-front::after {
  /* Soft glowing lip on the inside of the tunnel */
  content: ""; position: absolute; inset: 0;
  border-radius: 12px 12px 0 0;
  box-shadow: inset 0 0 0 3px rgba(127, 227, 214, 0.35), inset 0 0 24px rgba(127, 227, 214, 0.18);
  pointer-events: none;
}
.scanner-light {
  position: absolute; top: calc(-1 * var(--frame) + 5px); width: 7px; height: 7px; border-radius: 50%;
  background: #7fe3d6; box-shadow: 0 0 8px #7fe3d6;
  animation: lightBlink 2.4s ease-in-out infinite;
}
.scanner-light.l1 { right: 14px; }
.scanner-light.l2 { right: 28px; animation-delay: -0.8s; }
.scanner-light.l3 { right: 42px; animation-delay: -1.6s; background: var(--gold); box-shadow: 0 0 8px var(--gold); }
@keyframes lightBlink { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* The readout screen on top of the machine */
.scanner-screen {
  position: absolute; left: 0; right: 0; z-index: 9;
  bottom: calc(var(--card-h) + var(--tunnel-pad) + var(--frame) + 8px);
  min-height: 64px;
  padding: 9px 14px 10px;
  border: 4px solid #4a5866;
  border-bottom: none;
  border-radius: 16px 16px 4px 4px;
  background: linear-gradient(to bottom, #131b27, #0d131c);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.3), inset 0 0 22px rgba(127, 227, 214, 0.08);
  color: var(--teal-glow);
  font-weight: 800;
}
.screen-top { display: flex; align-items: center; gap: 10px; }
.screen-led {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
  background: #556; box-shadow: 0 0 6px rgba(0, 0, 0, 0.4);
  transition: background 0.3s, box-shadow 0.3s;
}
.screen-status { font-size: 15px; letter-spacing: 0.3px; flex: 1; min-width: 0; }
.screen-counter { font-size: 12px; color: rgba(255, 255, 255, 0.55); white-space: nowrap; }
.screen-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.screen-chips:empty { display: none; }
.chip {
  font-size: 12.5px; font-weight: 900; color: #2a2440;
  background: var(--gold); border-radius: 999px; padding: 3px 10px;
  animation: chipIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes chipIn { 0% { transform: scale(0.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.scanner-screen[data-mode="idle"] { color: rgba(255, 255, 255, 0.6); }
.scanner-screen[data-mode="scanning"] .screen-led { background: var(--teal-glow); box-shadow: 0 0 10px var(--teal-glow); animation: ledPulse 1s ease-in-out infinite; }
.scanner-screen[data-mode="scanning"] .screen-status { animation: ledPulse 1.6s ease-in-out infinite; }
.scanner-screen[data-mode="safe"] { color: #9fe38b; }
.scanner-screen[data-mode="safe"] .screen-led { background: #7ed66a; box-shadow: 0 0 10px #7ed66a; }
.scanner-screen[data-mode="sus"] { color: #ffb3a7; }
.scanner-screen[data-mode="sus"] .screen-led { background: var(--coral); box-shadow: 0 0 10px var(--coral); }
.scanner-screen[data-mode="look"] { color: #ffd27a; }
.scanner-screen[data-mode="look"] .screen-led { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
@keyframes ledPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ══ The message card, standing on the belt inside the scanner ══ */
.card-zone {
  /* Anchored by its bottom edge so cards of any height stand on the belt */
  position: absolute; left: 50%;
  bottom: calc(100% - var(--belt-top) - 4px);
  transform: translate(-50%, 0);
  z-index: 8;
  pointer-events: auto;
  will-change: transform;
}
.card-zone.parked { opacity: 0; }
.card-zone.rolling .msg-card { animation: cardJiggle 0.5s ease-in-out infinite; }
@keyframes cardJiggle { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-1.5px) rotate(0.3deg); } }
.msg-card {
  position: relative;
  width: var(--card-w); min-height: var(--card-min); max-height: var(--card-h);
  background: #fff;
  border-radius: 18px 18px 6px 6px;
  border: 3px solid rgba(58, 51, 80, 0.1);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.35);
  padding: 12px 14px 10px;
  display: flex; flex-direction: column; gap: 6px;
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
  transition: box-shadow 0.2s;
}
.msg-card.target { box-shadow: 0 0 0 5px var(--gold), 0 12px 26px rgba(0, 0, 0, 0.35); }
.msg-head { display: flex; align-items: center; gap: 10px; }
.msg-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--lav); color: #fff;
}
.msg-avatar svg { width: 24px; height: 24px; fill: currentColor; }
.av-friend, .av-photo { background: #5aa9d6; }
.av-warning { background: #e0a23a; }
.av-shop, .av-cart { background: #c47ab5; }
.av-gift { background: #e07a6a; }
.av-phone { background: #6f8fd6; }
.av-bank { background: #4f7f9a; }
.av-book { background: #7fa35a; }
.av-stranger { background: #9a8aa8; }
.msg-from-wrap { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.2; }
.msg-kind {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--ink-soft);
}
.msg-kind svg { width: 12px; height: 12px; fill: var(--ink-soft); }
.msg-from { font-size: 14px; font-weight: 900; overflow-wrap: anywhere; }
.msg-from small { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.msg-subject { font-size: 15px; font-weight: 900; padding-bottom: 4px; border-bottom: 2px solid rgba(58, 51, 80, 0.08); }
.msg-body { font-size: 16.5px; font-weight: 700; line-height: 1.38; }
.msg-card.long .msg-body { font-size: 14.5px; line-height: 1.32; }
.msg-card.long .msg-subject { font-size: 14px; }
.msg-link {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 800; color: #3a62b8;
  background: #e8eefb; border-radius: 999px; padding: 4px 12px;
  text-decoration: underline;
}
.msg-link svg { width: 14px; height: 14px; color: #3a62b8; }
.msg-link[hidden], .msg-subject[hidden], .msg-note[hidden] { display: none; }
.msg-note { margin-top: 2px; font-size: 12.5px; font-weight: 700; font-style: italic; color: var(--ink-soft); }
/* Warning-sign words: plain until the scanner reveals them */
mark.clue {
  background: transparent; color: inherit;
  border-radius: 5px; padding: 0 2px; margin: 0 -2px;
  transition: background 0.35s, box-shadow 0.35s;
}
.msg-card.revealed mark.clue {
  background: #ffe58a;
  box-shadow: 0 0 0 2px #ffe58a;
  animation: cluePulse 0.9s ease;
}
@keyframes cluePulse {
  0% { background: #fff3c4; box-shadow: 0 0 0 2px #fff3c4; }
  50% { background: #ffd54f; box-shadow: 0 0 0 5px #ffd54f; }
  100% { background: #ffe58a; box-shadow: 0 0 0 2px #ffe58a; }
}
.card-speak {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: var(--gold); border: 3px solid #fff;
  box-shadow: 0 3px 8px rgba(58, 51, 80, 0.25);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
.card-speak:hover { transform: scale(1.12); }
.card-speak svg { width: 20px; height: 20px; fill: var(--ink); stroke: var(--ink); }

/* Ink mark left by the stamp */
.ink {
  /* Sits a little low and to the right so the sender line stays readable */
  position: absolute; left: 54%; top: 58%;
  transform: translate(-50%, -50%) rotate(-12deg) scale(1.6);
  opacity: 0; pointer-events: none;
  color: var(--stamp, var(--green));
  border: 5px double var(--stamp, var(--green));
  border-radius: 12px;
  padding: 6px 14px;
  font-size: clamp(20px, 2.4vw, 28px); font-weight: 900; letter-spacing: 3px; white-space: nowrap;
  mix-blend-mode: multiply;
  transition: transform 0.18s ease-out, opacity 0.18s ease-out;
  text-shadow: 0 0 1px var(--stamp, var(--green));
}
.ink.show { opacity: 0.86; transform: translate(-50%, -50%) rotate(-12deg) scale(1); }
.ink.lift { opacity: 0; transform: translate(-50%, -50%) rotate(-12deg) scale(1.15) translateY(-24px); transition: transform 0.55s ease, opacity 0.5s ease; }

/* ══ Stamps ══ */
.stamp {
  position: absolute; bottom: 4vh; z-index: 11;
  display: flex; flex-direction: column; align-items: center; gap: 0;
  background: none; border: none;
  padding: 10px 12px;
  border-radius: 28px;
  touch-action: none;
  transition: background 0.18s ease;
}
#stampLeft { left: 6vw; }
#stampRight { right: 6vw; }
.stamp-body { display: block; line-height: 0; transition: transform 0.18s ease; transform-origin: bottom center; }
.stamp-svg {
  width: clamp(104px, 12.5vw, 156px); height: auto;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.4));
  overflow: visible;
}
.st-shadow { fill: rgba(0, 0, 0, 0.35); }
.st-base { fill: var(--stamp, #888); }
.st-base-top { fill: rgba(255, 255, 255, 0.28); }
.st-neck { fill: #e9e2d3; stroke: rgba(58, 51, 80, 0.18); stroke-width: 1.5; }
.st-knob { fill: var(--stamp, #888); stroke: rgba(0, 0, 0, 0.18); stroke-width: 1.5; }
.st-knob-shine { fill: rgba(255, 255, 255, 0.4); }
.stamp-label {
  font-size: clamp(15px, 1.6vw, 19px); font-weight: 900; color: #fff;
  padding: 8px 20px; border-radius: 999px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
  margin-top: -4px;
  background: var(--ink); /* real colour is set from config.bins[].color */
}
.stamp:hover .stamp-body, .stamp:focus-visible .stamp-body, .stamp.armed .stamp-body { transform: translateY(-6px) scale(1.05); }
.stamp.pressed .stamp-body { transform: translateY(6px) scale(0.96); }
.stamp.dragging { z-index: 30; }
.stamp.dragging .stamp-body { transition: none; }
.stamp.dragging .stamp-svg { filter: drop-shadow(0 22px 22px rgba(0, 0, 0, 0.45)); }
.stamp-body.returning { transition: transform 0.45s cubic-bezier(0.34, 1.3, 0.64, 1); }
.stamp.armed { background: rgba(255, 252, 246, 0.3); }
.stamp.armed::after {
  content: ""; position: absolute; inset: 0;
  border: 4px dashed rgba(255, 252, 246, 0.95);
  border-radius: 28px; pointer-events: none;
  animation: armedPulse 1s ease-in-out infinite;
}
@keyframes armedPulse { 0%, 100% { opacity: 0.65; } 50% { opacity: 1; } }
/* The flying copy of the stamp on its way to the message */
.stamp-fly {
  position: fixed; z-index: 40; pointer-events: none;
  will-change: transform;
}
.stamp-fly svg { width: 100%; height: 100%; filter: drop-shadow(0 18px 18px rgba(0, 0, 0, 0.45)); overflow: visible; }

/* ══ Byte ══ */
.sage {
  position: absolute; bottom: 3.5vh; left: 50%; transform: translateX(-50%);
  z-index: 13;
  display: flex; align-items: flex-end; gap: 12px;
  max-width: min(560px, 46vw);
}
.sage-face {
  width: 92px; height: 92px; border-radius: 50%;
  border: 4px solid #fff; object-fit: cover;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.sage-bubble {
  position: relative;
  background: var(--panel);
  border-radius: 20px 20px 20px 6px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
  min-width: 220px;
}
.sage-bubble p { font-size: 16px; font-weight: 800; line-height: 1.45; }
.sage-bubble.tip-good { border: 3px solid var(--green); }
.sage-bubble.tip-gentle { border: 3px solid var(--gold); }
.sage-bubble.tip-note { border: 3px solid var(--lav); }
.sage-bubble .btn { margin-top: 10px; }
.sage-bubble.pop { animation: bubblePop 0.35s ease; }
@keyframes bubblePop {
  0% { transform: scale(0.85); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}

/* ══ Demo hand ══ */
.demo-hand {
  position: fixed; z-index: 60; width: 64px; height: 64px;
  pointer-events: none;
  will-change: transform;
  filter: drop-shadow(0 6px 10px rgba(58, 51, 80, 0.35));
}

/* ══ Overlays & panels ══ */
.overlay[hidden] { display: none; }
.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 84px 16px 24px;
  background: rgba(20, 28, 40, 0.5);
  backdrop-filter: blur(5px);
  overflow-y: auto;
}
.panel {
  background: var(--panel);
  border-radius: 28px;
  box-shadow: 0 24px 64px rgba(30, 24, 48, 0.4);
  padding: 34px 38px;
  width: min(560px, 94vw);
  text-align: center;
  margin: auto;
}
.panel h1 { font-size: clamp(28px, 4vw, 40px); font-weight: 900; line-height: 1.1; margin-bottom: 4px; }
.panel h2 { font-size: 30px; font-weight: 900; margin-bottom: 8px; }
.panel-shop {
  font-size: 13px; font-weight: 900; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--teal); margin-bottom: 6px;
}
.entry-sage {
  width: 130px; height: 130px; border-radius: 50%;
  border: 5px solid var(--gold); object-fit: cover;
  margin: 18px auto 14px; display: block;
  box-shadow: var(--shadow);
}
.entry-welcome { font-size: 18px; font-weight: 700; line-height: 1.55; margin-bottom: 12px; text-wrap: pretty; }
.entry-note {
  font-size: 15px; font-weight: 800; color: var(--ink-soft);
  background: var(--green-soft); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 22px;
}
.entry-quick-note { margin-top: 18px; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.pause-text { font-size: 17px; font-weight: 700; color: var(--ink-soft); margin-bottom: 22px; }

.panel-buttons { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }

.btn {
  border-radius: 16px;
  background: #fff; color: var(--ink);
  border: 2px solid rgba(58, 51, 80, 0.16);
  font-weight: 900;
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px); }
.btn-big { font-size: 19px; padding: 15px 26px; min-height: 58px; }
.btn-small { font-size: 15px; padding: 8px 18px; min-height: 42px; }
.btn-primary {
  background: var(--gold); border-color: var(--gold);
  box-shadow: 0 5px 0 var(--gold-dim);
}
.btn-primary:hover { box-shadow: 0 7px 0 var(--gold-dim), 0 8px 18px rgba(58, 51, 80, 0.2); }
.btn-primary:active { box-shadow: 0 2px 0 var(--gold-dim); }

/* ══ Completion ══ */
.done-panel h2 { margin-top: 14px; }
.badge {
  width: 148px; height: 148px; margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #fff8e2, #ffe9a8);
  border: 6px solid var(--gold);
  box-shadow: 0 0 0 6px rgba(240, 192, 64, 0.3), var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; padding: 16px; overflow: hidden;
  animation: badgeSpin 0.9s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes badgeSpin {
  0% { transform: scale(0.2) rotate(-180deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.badge img { width: 62px; height: 62px; border-radius: 50%; object-fit: cover; }
.badge span {
  font-size: 12px; font-weight: 900; color: var(--gold-dim);
  text-transform: uppercase; letter-spacing: 0.5px;
  text-align: center; line-height: 1.15; max-width: 104px;
}
.done-text { font-size: 18px; font-weight: 700; line-height: 1.5; margin: 10px 0 22px; }

.help-box {
  margin-top: 24px; text-align: left;
  background: var(--cream); border-radius: 16px; padding: 16px 20px;
}
.help-title { font-size: 14px; font-weight: 900; margin-bottom: 10px; }
.help-box ul { list-style: none; }
.help-box li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 7px 0; font-size: 15px; font-weight: 700;
  border-bottom: 1px solid rgba(58, 51, 80, 0.08);
}
.help-box li:last-child { border-bottom: none; }
.help-box li span:last-child { color: var(--ink-soft); text-align: right; }

/* ══ Sparkles ══ */
.spark {
  position: fixed; z-index: 90; pointer-events: none;
  width: 12px; height: 12px;
  clip-path: polygon(50% 0%, 63% 37%, 100% 50%, 63% 63%, 50% 100%, 37% 63%, 0% 50%, 37% 37%);
  animation: sparkFly 0.9s ease-out forwards;
}
@keyframes sparkFly {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.1) rotate(180deg); opacity: 0; }
}

/* Smoke plumes from the scanner top (suspicious message caught) */
.smoke-stack {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 0; z-index: 8; pointer-events: none;
}
.smoke-puff {
  position: absolute; bottom: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 38%, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 55%),
    radial-gradient(circle at 60% 65%, rgb(var(--shade), var(--shade), calc(var(--shade) + 6)), rgba(150, 156, 164, 0.6) 58%, rgba(110, 116, 124, 0) 72%);
  filter: blur(7px);
  opacity: 0;
  transform: translate(0, 10px) scale(0.35) rotate(0deg);
  animation-name: smokeRise;
  animation-timing-function: cubic-bezier(0.2, 0.6, 0.35, 1);
  animation-fill-mode: forwards;
}
@keyframes smokeRise {
  0%   { opacity: 0; transform: translate(0, 10px) scale(0.35) rotate(0deg); }
  12%  { opacity: var(--peak); }
  55%  { opacity: calc(var(--peak) * 0.7); }
  100% { opacity: 0; transform: translate(var(--drift), var(--rise)) scale(var(--grow)) rotate(var(--spin)); filter: blur(14px); }
}

/* ══ Responsive ══ */
@media (max-height: 640px) {
  /* Short windows: lower belt, shorter tunnel, so the readout clears the top HUD */
  :root { --belt-top: 68%; --card-h: clamp(150px, 28vh, 200px); --card-min: 120px; }
  .card-hint { display: none; }
  .meter { padding: 8px 10px; }
  .meter-locks { grid-template-columns: repeat(5, 24px); gap: 4px; }
  .meter-lock { width: 24px; height: 24px; }
  .meter-label { font-size: 12px; }
  .msg-body { font-size: 15px; }
  .sage { bottom: 2vh; }
  .sage-face { width: 70px; height: 70px; }
  .sage-bubble p { font-size: 14px; }
}
@media (max-width: 900px) {
  .tb-btn span { display: none; }
  .tb-btn.quick-exit span { display: inline; }
  :root { --card-w: clamp(220px, 44vw, 300px); }
  .sage { max-width: 60vw; }
  .sage-face { width: 70px; height: 70px; }
  .sage-bubble p { font-size: 14px; }
  .stamp-svg { width: clamp(84px, 13vw, 120px); }
  .stamp-label { font-size: 14px; padding: 6px 14px; }
}
@media (max-width: 640px) {
  :root {
    --card-w: clamp(200px, 60vw, 270px); --card-h: clamp(160px, 26vh, 210px); --card-min: 130px;
    --belt-top: 60%; --tunnel-pad: 14px; --frame: 12px;
  }
  .meter { padding: 6px 9px 8px; gap: 5px; }
  .meter-label { font-size: 11px; }
  .meter-lock { width: 20px; height: 20px; }
  .meter-locks { grid-template-columns: repeat(5, 20px); gap: 3px; }
  .progress { left: auto; right: 14px; transform: none; top: 16px; }
  .card-hint { display: none; }
  .msg-body { font-size: 14.5px; }
  .msg-card.long .msg-body { font-size: 13.5px; }
  .ink { font-size: 18px; letter-spacing: 2px; }
  .belt-legs { display: none; }
  /* Stamps hug the bottom corners; Byte's bubble sits between them */
  .stamp { bottom: 1vh; padding: 4px; }
  #stampLeft { left: 0; }
  #stampRight { right: 0; }
  .stamp-svg { width: 60px; }
  .stamp-label { font-size: 11px; padding: 4px 9px; margin-top: -2px; }
  .sage { bottom: 1vh; max-width: calc(100vw - 156px); }
  .sage-bubble { min-width: 0; padding: 9px 11px; }
  .sage-bubble p { font-size: 12.5px; line-height: 1.38; }
  .sage-face { display: none; }
  .screen-status { font-size: 13px; }
  .screen-counter { display: none; }
  .chip { font-size: 11px; padding: 2px 8px; }
}

/* ══ Reduced motion ══ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
