/* Nova Merge — mobile-first neon styling */
:root {
  --safe-area-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-area-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --safe-area-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-area-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --play-region-left: 0px;
  --play-region-top: 0px;
  --play-region-width: 100vw;
  --play-region-height: 100dvh;
  --play-region-center-x: 50vw;
  --finish-line-y: 40px;
  --cream: #fff7ef;
  --candy-lilac: #ad8cff;
  --candy-pink: #ff91bc;
  --candy-peach: #ffc58f;
  --candy-mint: #69ead5;
  --deep-grape: #160d3a;
  --toybox-surface-cream-17: rgba(255, 247, 239, 0.17);
  --toybox-surface-lilac-07: rgba(173, 140, 255, 0.07);
  --toybox-border-pink-30: rgba(255, 190, 219, 0.3);
  --toybox-shadow-raised: rgba(17, 8, 45, 0.28);
  --toybox-highlight-cream-24: rgba(255, 247, 239, 0.24);
  --toybox-surface-plum-10: rgba(117, 78, 190, 0.1);
  --toybox-shadow-panel: rgba(8, 3, 28, 0.48);
  --toybox-highlight-cream-26: rgba(255, 247, 239, 0.26);
  --toybox-drawer-top: rgba(67, 43, 118, 0.72);
  --toybox-drawer-bottom: rgba(22, 13, 58, 0.88);
  --toybox-border-pink-27: rgba(255, 190, 219, 0.27);
  --toybox-surface-peach-07: rgba(255, 197, 143, 0.07);
  --toybox-border-peach-48: rgba(255, 197, 143, 0.48);
  --toybox-shadow-coin: rgba(17, 8, 45, 0.25);
  --toybox-primary-lilac-76: rgba(173, 140, 255, 0.76);
  --toybox-primary-pink-57: rgba(255, 145, 188, 0.57);
  --toybox-border-cream-40: rgba(255, 247, 239, 0.4);
  --toybox-shadow-primary: rgba(180, 87, 190, 0.34);
  --toybox-highlight-cream-38: rgba(255, 247, 239, 0.38);
  --toybox-secondary-mint-66: rgba(105, 234, 213, 0.66);
  --toybox-secondary-teal-46: rgba(45, 190, 190, 0.46);
  --toybox-border-cream-36: rgba(255, 247, 239, 0.36);
  --toybox-surface-cream-13: rgba(255, 247, 239, 0.13);
  --toybox-surface-lilac-06: rgba(173, 140, 255, 0.06);
  --toybox-border-pink-26: rgba(255, 190, 219, 0.26);
  --toybox-text-ghost: #eee5ff;
  --toybox-logo-lilac: #d7c7ff;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font-family: inherit; }

html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #0b0722;
  overflow: hidden;
  font-family: 'Dongle', ui-rounded, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: #eae6ff;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
  -webkit-user-select: none; user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  margin: 0;
  background: #0b0722;
  overflow: hidden;
  overflow: clip;
  box-shadow: none;
}

#app.screen-rumble {
  animation: app-rumble 720ms cubic-bezier(0.18, 0.72, 0.24, 1) both;
  transform-origin: center;
  will-change: transform;
}

@keyframes app-rumble {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(0) scale(1); }
  10% { transform: translate3d(-16px, 7px, 0) rotate(-1.2deg) scale(1.025); }
  22% { transform: translate3d(14px, -8px, 0) rotate(1deg) scale(1.025); }
  36% { transform: translate3d(-12px, 6px, 0) rotate(-0.8deg) scale(1.022); }
  52% { transform: translate3d(9px, -5px, 0) rotate(0.6deg) scale(1.018); }
  68% { transform: translate3d(-6px, 3px, 0) rotate(-0.35deg) scale(1.012); }
  84% { transform: translate3d(3px, -2px, 0) rotate(0.15deg) scale(1.006); }
}

#canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute; inset: 0;
  display: none;
  padding: 0;
  pointer-events: none;
  z-index: 8;
}
#hud.visible { display: block; }

.hud-rail {
  position: absolute;
  top: calc(var(--play-region-top) + var(--safe-area-top) + 6px);
  left: calc(var(--safe-area-left) + 8px);
  right: calc(var(--safe-area-right) + 8px);
  max-width: 520px;
  margin-inline: auto;
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(96px, 1fr) auto minmax(96px, 1fr);
  align-items: start;
  gap: 8px;
  pointer-events: none;
  z-index: 6;
}
.hud-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  pointer-events: none;
}
.hud-left { justify-self: start; }
.hud-right { justify-self: end; }
.hud-left #coin-chip { margin-top: 0; }

.hud-center {
  position: static;
  justify-self: center;
  flex: none;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: none;
  text-align: center;
  pointer-events: none;
  z-index: 9;
  transition: opacity 150ms ease;
}

.next-box {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  padding: 4px 6px 2px;
  text-align: center;
  backdrop-filter: blur(8px) saturate(1.3);
  -webkit-backdrop-filter: blur(8px) saturate(1.3);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.next-label { display: block; font-size: 15px; letter-spacing: 2px; color: #9f95d9; font-weight: 700; }
#next-canvas { width: 44px; height: 44px; display: block; margin: 0 auto; }

.score {
  font-size: 42px; font-weight: 900; line-height: 1;
  color: #fff;
  text-shadow: 0 0 18px rgba(150, 110, 255, 0.8), 0 2px 0 rgba(40, 20, 80, 0.9);
  font-variant-numeric: tabular-nums;
  font-family: 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif;
}
.best { font-size: 15px; letter-spacing: 2px; color: #b7aee8; font-weight: 700; margin-top: 2px; font-family: 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif; }

.icon-btn {
  pointer-events: auto;
  width: 44px; height: 44px;
  min-width: 44px; min-height: 44px;
  flex: 0 0 44px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.05));
  backdrop-filter: blur(8px) saturate(1.3);
  -webkit-backdrop-filter: blur(8px) saturate(1.3);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  color: #eae6ff;
  font-size: 15px; font-weight: 800;
  cursor: pointer;
}

/* ---------- hint ---------- */
#hint {
  position: absolute; left: 0; right: 0; bottom: 18%;
  text-align: center;
  font-size: 15px; font-weight: 700; letter-spacing: 1px;
  color: #cfc6ff;
  text-shadow: 0 0 12px rgba(120, 80, 255, 0.9);
  opacity: 0; transition: opacity 0.4s;
  pointer-events: none;
  z-index: 4;
  animation: hintFloat 1.6s ease-in-out infinite;
}
#hint.visible { opacity: 1; }
@keyframes hintFloat { 50% { transform: translateY(-6px); } }

#danger-warning {
  position: absolute;
  left: var(--play-region-center-x);
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px;
  border: 1px solid rgba(255, 110, 135, 0.8);
  border-radius: 999px;
  background: rgba(80, 10, 30, 0.92);
  box-shadow: 0 4px 18px rgba(255, 40, 85, 0.34);
  color: #fff;
  opacity: 0;
  transform: translate(-50%, -5px) scale(0.96);
  transition: opacity 0.14s, transform 0.14s;
  pointer-events: none;
}
#danger-warning.visible { opacity: 1; transform: translate(-50%, 0) scale(1); }
.danger-label { font-size: 15px; font-weight: 900; letter-spacing: 1.2px; white-space: nowrap; }
#danger-time { min-width: 32px; font-size: 15px; font-weight: 900; color: #ffd4dc; }

/* ---------- screens (glass) ---------- */
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  z-index: 10;
  padding: calc(var(--safe-area-top) + 16px) calc(var(--safe-area-right) + 22px) calc(var(--safe-area-bottom) + 20px) calc(var(--safe-area-left) + 22px);
  background: rgba(8, 4, 24, 0.42);
  backdrop-filter: blur(4px) saturate(1.2);
  -webkit-backdrop-filter: blur(4px) saturate(1.2);
}
.screen.visible { display: flex; }

.panel {
  width: 100%; max-width: 320px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.04));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 26px;
  padding: 28px 22px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  backdrop-filter: blur(18px) saturate(1.35);
  -webkit-backdrop-filter: blur(18px) saturate(1.35);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  animation: panelIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes panelIn { from { transform: scale(0.8); opacity: 0; } }

.panel h2 { font-size: 22px; font-weight: 900; letter-spacing: 4px; }

/* ---------- title ---------- */
#screen-title {
  --title-control-target: 44px;
  --title-mode-height: 52px;
  --title-control-gap: 8px;
  --title-mode-font-size: 15px;
  --title-toggle-font-size: 15px;
  --title-content-max-width: 380px;
  --title-dex-height: 74px;
  --title-dex-margin-top: 18px;
  --title-label-margin-top: 6px;
  --title-logo-margin-bottom: 6px;
  --title-logo-sub-margin-top: 8px;
  --title-best-margin-top: 14px;
  --title-mode-margin-top: 20px;
  --title-settings-margin-top: 18px;
  --title-credit-margin-top: 16px;
  --title-mode-padding-y: 10px;
  --title-mode-padding-x: 8px;
  --title-compact-spacing: 4px;
  --title-compact-section-spacing: 6px;
  --title-compact-logo-font-size: 34px;
  --title-compact-dex-height: 44px;
  background: rgba(8, 4, 24, 0.25);
}

.logo { text-align: center; margin-bottom: var(--title-logo-margin-bottom); animation: logoBob 3s ease-in-out infinite; font-family: 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif; }
@keyframes logoBob { 50% { transform: translateY(-8px); } }
.logo-top {
  font-size: 64px; font-weight: 900; line-height: 0.95; letter-spacing: 6px;
  background: linear-gradient(180deg, #fff, #b9a6ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 40px rgba(140, 90, 255, 0.5);
}
.logo-bottom {
  font-size: 64px; font-weight: 900; line-height: 0.95; letter-spacing: 6px;
  background: linear-gradient(180deg, #7f5cff, #37e5c8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo-sub { margin-top: var(--title-logo-sub-margin-top); font-size: 15px; letter-spacing: 4px; color: #9f95d9; font-weight: 700; }

#dex-canvas {
  width: 100%; max-width: var(--title-content-max-width); height: var(--title-dex-height);
  margin-top: var(--title-dex-margin-top);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.dex-label { margin-top: var(--title-label-margin-top); font-size: 15px; letter-spacing: 3px; color: #8d83c9; font-weight: 700; }

.title-best { margin-top: var(--title-best-margin-top); font-size: 15px; letter-spacing: 2px; color: #b7aee8; font-weight: 700; font-family: 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif; }
.btn-leaderboard {
  min-height: 42px;
  margin-top: 10px;
  padding: 8px 18px;
  border: 1px solid rgba(255, 233, 173, 0.38);
  border-radius: 999px;
  background: rgba(32, 19, 72, 0.76);
  color: #ffe9ad;
  font: 800 15px/1 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif;
  letter-spacing: 1px;
  cursor: pointer;
}
.btn-leaderboard:active { transform: scale(0.97); }
.btn-leaderboard:disabled { opacity: 0.58; cursor: wait; }
.leaderboard-status {
  min-height: 16px;
  margin-top: 5px;
  color: #8d83c9;
  font-size: 15px;
  line-height: 1.2;
  text-align: center;
}
#screen-over .btn-leaderboard { width: 100%; margin-top: 8px; }

.play-modes {
  width: 100%; max-width: var(--title-content-max-width); min-height: var(--title-mode-height); margin-top: var(--title-mode-margin-top);
  display: grid; grid-template-columns: 1fr; gap: var(--title-control-gap);
}
.play-modes .mode-btn { min-height: var(--title-mode-height); margin-top: 0; max-width: none; padding: var(--title-mode-padding-y) var(--title-mode-padding-x); font-size: var(--title-mode-font-size); font-family: 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif; }

.settings { display: flex; gap: var(--title-control-gap); margin-top: var(--title-settings-margin-top); flex-wrap: wrap; justify-content: center; }
.toggle {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
  color: #9f95d9;
  border-radius: 999px;
  min-height: var(--title-control-target);
  padding: 8px 12px;
  font-size: var(--title-toggle-font-size); font-weight: 700;
  cursor: pointer;
  opacity: 0.55;
  backdrop-filter: blur(10px) saturate(1.3);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
}
.toggle.on { color: #fff; opacity: 1; border-color: rgba(55, 229, 200, 0.6); }

.language-picker {
  min-height: 36px;
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #8d83c9;
  font-size: 15px;
  font-weight: 700;
}
.language-picker select {
  min-height: 36px;
  padding: 4px 28px 4px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: #211747;
  color: #eae6ff;
  font-weight: 700;
  color-scheme: dark;
}

.credit { margin-top: var(--title-credit-margin-top); font-size: 15px; color: #6d6599; letter-spacing: 1px; }

/* ---------- buttons (glass) ---------- */
.btn-primary, .btn-secondary, .btn-ghost {
  width: 100%;
  border-radius: 18px;
  padding: 16px;
  font-size: 17px; font-weight: 900; letter-spacing: 2px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s;
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
}
.btn-primary:active, .btn-secondary:active, .btn-ghost:active { transform: scale(0.96); }

.btn-primary {
  margin-top: 20px; max-width: 320px;
  background: linear-gradient(160deg, rgba(150, 110, 255, 0.6), rgba(92, 47, 224, 0.45));
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #fff;
  box-shadow: 0 8px 24px rgba(124, 77, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.btn-secondary {
  background: linear-gradient(160deg, rgba(55, 229, 200, 0.5), rgba(28, 185, 159, 0.38));
  border: 1px solid rgba(255, 255, 255, 0.26);
  color: #eafffb;
  box-shadow: 0 8px 24px rgba(55, 229, 200, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.btn-ghost {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04));
  color: #cfc6ff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-weight: 700;
}
.row { display: flex; gap: 10px; width: 100%; }

/* ---------- game over ---------- */
.newbest {
  display: none;
  background: linear-gradient(90deg, #ffcf40, #ff8a3c);
  color: #40230a;
  font-weight: 900; font-size: 15px; letter-spacing: 2px;
  font-family: 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif;
  padding: 7px 16px; border-radius: 999px;
  animation: bestPulse 0.9s ease-in-out infinite;
}
.newbest.visible { display: block; }
@keyframes bestPulse { 50% { transform: scale(1.08); } }

.over-score { font-size: 64px; font-weight: 900; line-height: 1; color: #fff;
  text-shadow: 0 0 30px rgba(150, 110, 255, 0.9); font-variant-numeric: tabular-nums; font-family: 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif; }
.over-best { font-size: 15px; letter-spacing: 2px; color: #b7aee8; font-weight: 700; font-family: 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif; }
.over-mode-date { font-size: 15px; letter-spacing: 1.5px; color: #cfc6ff; font-weight: 800; font-family: 'Baloo 2', 'Dongle', ui-rounded, system-ui, sans-serif; }
.over-stats { font-size: 15px; color: #8d83c9; letter-spacing: 1px; }
.blocked-status { min-height: 36px; color: #cfc6ff; font-size: 15px; text-align: center; }

/* ---------- toast & errors ---------- */
#toast {
  position: absolute; left: 50%; bottom: calc(var(--safe-area-bottom) + 90px);
  transform: translateX(-50%) translateY(20px);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.06));
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(12px) saturate(1.35);
  -webkit-backdrop-filter: blur(12px) saturate(1.35);
  color: #fff; font-size: 15px; font-weight: 700;
  padding: 10px 16px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  opacity: 0; transition: all 0.25s;
  pointer-events: none; z-index: 20;
  white-space: nowrap;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

#errbox {
  display: none;
  position: absolute; top: 0; left: 0; right: 0;
  background: #7a1020; color: #fff;
  font: 15px monospace;
  padding: 6px 10px; z-index: 99;
}

/* ---------- launch film ---------- */
#splash {
  position: absolute; inset: 0; z-index: 50; overflow: hidden;
  background: #190e3b;
  transition: opacity 0.25s, visibility 0.25s;
}
#splash.hide { opacity: 0; visibility: hidden; pointer-events: none; }
#intro-video { display: block; width: 100%; height: 100%; object-fit: contain; }
.intro-controls {
  position: absolute; inset: 0; pointer-events: none;
}
.intro-controls button {
  position: absolute; pointer-events: auto;
  min-height: 44px; padding: 10px 16px; border-radius: 999px;
  color: #fff; background: rgba(19, 10, 44, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.32);
  font: 700 14px/1.2 system-ui, sans-serif;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
#intro-skip {
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px));
  left: 50%; transform: translateX(-50%); max-width: calc(100% - 32px);
}
.intro-controls button:focus-visible { outline: 3px solid #ffe39a; outline-offset: 3px; }

#btn-privacy {
  min-height:44px; padding:8px 14px; border:0; border-radius:12px;
  background:transparent; color:#c1b7dd; font:500 12px/1.4 system-ui,sans-serif;
  text-decoration:underline; cursor:pointer;
}
#privacy-dialog {
  width:min(680px, calc(100% - 32px)); max-height:calc(100dvh - 64px);
  margin:auto; padding:0; border:1px solid #b9a5ff66; border-radius:20px;
  background:#151027; color:#f8f4ff; font:400 16px/1.65 system-ui,sans-serif;
  overflow-y:auto; overscroll-behavior:contain; touch-action:pan-y;
}
#privacy-dialog::backdrop { background:#070414dd; }
.privacy-header {
  position:sticky; top:0; display:flex; align-items:center; gap:12px;
  padding:12px 20px; background:#151027; border-bottom:1px solid #b9a5ff44;
}
.privacy-header h2 { flex:1; margin:0; font-size:20px; }
#privacy-close { min-width:44px; min-height:44px; padding:8px 12px; border:1px solid #b9a5ff66; border-radius:12px; background:#29203f; color:#fff; font:inherit; }
.privacy-content { padding:0 20px 20px; overflow-wrap:anywhere; }
.privacy-content a { color:#a2f6e2; }

.hidden { display: none !important; }

/* ---------- v1.1: coin chip ---------- */
#coin-chip {
  margin-top: 6px;
  display: inline-block;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(255, 224, 130, 0.35);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 15px; font-weight: 800;
  color: #ffe9ad;
  backdrop-filter: blur(8px) saturate(1.3);
  -webkit-backdrop-filter: blur(8px) saturate(1.3);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
#coin-chip.bump { animation: coinBump 0.35s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes coinBump {
  40% { transform: scale(1.18) rotate(-2deg); }
  70% { transform: scale(1.04) rotate(1deg); }
}

/* ---------- v1.1: items drawer ---------- */
#drawer-handle {
  position: relative;
  display: none;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: linear-gradient(200deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06));
  color: #eae6ff;
  padding: 10px;
  width: 44px; height: 44px;
  min-width: 44px; max-width: 44px; min-height: 44px; max-height: 44px;
  flex: 0 0 44px; overflow: hidden; white-space: nowrap;
  font-size: 15px; font-weight: 900; letter-spacing: 2.5px;
  cursor: pointer;
  pointer-events: auto;
  backdrop-filter: blur(10px) saturate(1.35);
  -webkit-backdrop-filter: blur(10px) saturate(1.35);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  z-index: 6;
  transition: box-shadow 0.25s, border-color 0.25s, transform 0.15s;
}
#drawer-handle.visible { display: flex; align-items: center; justify-content: center; }
#drawer-handle:active { transform: scale(0.96); }
#drawer-handle.armed {
  border-color: rgba(55, 229, 200, 0.9);
  box-shadow: 0 0 18px rgba(55, 229, 200, 0.55);
  animation: armedPulse 1s ease-in-out infinite;
}
@keyframes armedPulse {
  50% { transform: translateX(-2px); box-shadow: 0 0 26px rgba(105, 234, 213, 0.85); }
}

#drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(5, 2, 16, 0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
  z-index: 7;
}
#drawer-backdrop.visible { opacity: 1; pointer-events: auto; }

#item-drawer {
  position: absolute; left: 0; right: 0;
  width: 100%; max-width: 520px; margin-inline: auto;
  bottom: 0;
  bottom: calc(100dvh - var(--play-region-top) - var(--play-region-height));
  background: linear-gradient(180deg, rgba(40, 28, 84, 0.55), rgba(22, 14, 52, 0.72));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding: 8px calc(var(--safe-area-right) + 16px) calc(var(--safe-area-bottom) + 16px) calc(var(--safe-area-left) + 16px);
  transform: translateY(108%);
  transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
  z-index: 8;
  backdrop-filter: blur(16px) saturate(1.35);
  -webkit-backdrop-filter: blur(16px) saturate(1.35);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
#item-drawer.open { transform: translateY(0); }

.drawer-grip {
  width: 44px; height: 4px;
  border-radius: 999px;
  background: rgba(160, 150, 255, 0.4);
  margin: 4px auto 10px;
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.drawer-title { font-size: 15px; font-weight: 900; letter-spacing: 2px; color: #cfc6ff; }
.drawer-coins {
  font-size: 15px; font-weight: 900; color: #ffe9ad;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(255, 224, 130, 0.35);
  border-radius: 999px;
  padding: 4px 12px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(8px) saturate(1.3);
  -webkit-backdrop-filter: blur(8px) saturate(1.3);
}
.drawer-grid {
  display: grid; grid-template-columns: 1fr; gap: 9px;
}
.drawer-item {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  border-radius: 16px;
  padding: 12px 16px;
  color: #eae6ff;
  cursor: pointer;
  display: grid; grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center; gap: 3px 12px; min-height: 76px;
  backdrop-filter: blur(8px) saturate(1.3);
  -webkit-backdrop-filter: blur(8px) saturate(1.3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition: transform 0.08s, opacity 0.2s;
}
.drawer-item:active { transform: scale(0.94); }
.drawer-item .di-ic { grid-column: 1; grid-row: 1 / 3; width: 36px; height: 36px; }
.drawer-item .di-ic svg { display: block; width: 100%; height: 100%; }
.drawer-item .di-name { grid-column: 2; grid-row: 1; text-align: left; font-size: 20px; font-weight: 800; letter-spacing: 1px; }
.drawer-item .di-desc { grid-column: 2; grid-row: 2; text-align: left; font-size: 18px; line-height: 1.2; }
.drawer-item .di-cost {
  grid-column: 3; grid-row: 1 / 3;
  font-size: 22px; font-weight: 900; color: #ffe9ad;
  font-variant-numeric: tabular-nums;
}
.drawer-item.poor { opacity: 0.38; }
.drawer-item.armed {
  border-color: rgba(55, 229, 200, 0.9);
  box-shadow: 0 0 14px rgba(55, 229, 200, 0.5);
}
#item-deathBeam.armed {
  border-color: rgba(255, 96, 216, 0.95);
  box-shadow: 0 0 16px rgba(255, 96, 216, 0.52);
}
.drawer-tip {
  margin-top: 10px;
  font-size: 15px; color: #8d83c9;
  text-align: center; letter-spacing: 1px;
}

/* ---------- v1.1: shop (glass) ---------- */
.shop-panel { max-height: calc(100dvh - 48px); }
.shop-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%;
}
.shop-head h2 { flex: 1; text-align: center; margin-right: 44px; }
.back-btn {
  width: 44px; height: 44px; min-width: 44px; min-height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  color: #eae6ff; font-size: 22px; font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(10px) saturate(1.3);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
}
.shop-coins {
  font-size: 15px; font-weight: 900; color: #ffe9ad;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(255, 224, 130, 0.35);
  border-radius: 999px;
  padding: 6px 12px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(10px) saturate(1.3);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
}

#shop-tabs { display: flex; gap: 8px; width: 100%; }
.shop-tab {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03));
  color: #9f95d9;
  border-radius: 12px;
  padding: 9px;
  min-height: 44px;
  font-size: 15px; font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(10px) saturate(1.3);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
}
.shop-tab.active { color: #fff; border-color: rgba(55, 229, 200, 0.6); background: rgba(55, 229, 200, 0.14); }

#shop-list {
  width: 100%;
  display: flex; flex-direction: column; gap: 8px;
  max-height: 46dvh;
  overflow-y: auto;
}
.shop-row {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
  border-radius: 14px;
  padding: 8px 12px;
  cursor: pointer;
  color: #eae6ff;
  font-family: inherit;
  text-align: left;
  backdrop-filter: blur(10px) saturate(1.3);
  -webkit-backdrop-filter: blur(10px) saturate(1.3);
}
.shop-row.equipped { border-color: rgba(55, 229, 200, 0.7); background: rgba(55, 229, 200, 0.1); }
.shop-preview {
  width: 72px; height: 48px;
  border-radius: 8px;
  flex-shrink: 0;
}
.shop-name { flex: 1; font-weight: 800; font-size: 15px; }
.shop-tag { font-size: 15px; font-weight: 900; color: #ffe9ad; letter-spacing: 1px; }
.shop-tag.eq { color: #37e5c8; }
.shop-note { font-size: 15px; color: #8d83c9; text-align: center; }

/* ---------- compositor-only micro-motion ---------- */
.next-box { animation: nextFloat 3.2s ease-in-out infinite; }
@keyframes nextFloat { 50% { transform: translateY(-2px); } }

/* ---------- soft cosmic toybox surfaces ---------- */
.next-box,
.icon-btn,
#toast,
#dex-canvas,
.toggle,
.drawer-item,
.back-btn,
.shop-tab,
.shop-row {
  background: linear-gradient(145deg, var(--toybox-surface-cream-17), var(--toybox-surface-lilac-07));
  border-color: var(--toybox-border-pink-30);
  box-shadow: 0 7px 20px var(--toybox-shadow-raised), inset 0 1px 0 var(--toybox-highlight-cream-24);
}

.panel {
  background: linear-gradient(155deg, var(--toybox-surface-cream-17), var(--toybox-surface-plum-10));
  border-color: var(--toybox-border-pink-30);
  box-shadow: 0 20px 60px var(--toybox-shadow-panel), inset 0 1px 0 var(--toybox-highlight-cream-26);
}

#item-drawer {
  background: linear-gradient(180deg, var(--toybox-drawer-top), var(--toybox-drawer-bottom));
  border-color: var(--toybox-border-pink-27);
}

#coin-chip,
.drawer-coins,
.shop-coins {
  background: linear-gradient(145deg, var(--toybox-surface-cream-17), var(--toybox-surface-peach-07));
  border-color: var(--toybox-border-peach-48);
  box-shadow: 0 7px 20px var(--toybox-shadow-coin), inset 0 1px 0 var(--toybox-highlight-cream-24);
}

.btn-primary {
  background: linear-gradient(155deg, var(--toybox-primary-lilac-76), var(--toybox-primary-pink-57));
  border-color: var(--toybox-border-cream-40);
  box-shadow: 0 9px 26px var(--toybox-shadow-primary), inset 0 1px 0 var(--toybox-highlight-cream-38);
}

.btn-secondary {
  background: linear-gradient(155deg, var(--toybox-secondary-mint-66), var(--toybox-secondary-teal-46));
  border-color: var(--toybox-border-cream-36);
  color: var(--cream);
}

.btn-ghost {
  background: linear-gradient(155deg, var(--toybox-surface-cream-13), var(--toybox-surface-lilac-06));
  border-color: var(--toybox-border-pink-26);
  color: var(--toybox-text-ghost);
}

.logo-top,
.sp-a { background-image: linear-gradient(180deg, var(--cream), var(--toybox-logo-lilac)); }
.logo-bottom,
.sp-b { background-image: linear-gradient(180deg, var(--candy-lilac), var(--candy-mint)); }

/* ---------- performance mode (auto: fps < 24) / ?noglass=1 ---------- */
body:is(.lite-fx, .no-glass) .next-box,
body:is(.lite-fx, .no-glass) .hud-cluster,
body:is(.lite-fx, .no-glass) .hud-center,
body:is(.lite-fx, .no-glass) #coin-chip,
body:is(.lite-fx, .no-glass) .icon-btn,
body:is(.lite-fx, .no-glass) #drawer-handle,
body:is(.lite-fx, .no-glass) #item-drawer,
body:is(.lite-fx, .no-glass) .drawer-item,
body:is(.lite-fx, .no-glass) .drawer-coins,
body:is(.lite-fx, .no-glass) #toast,
body:is(.lite-fx, .no-glass) .screen,
body:is(.lite-fx, .no-glass) .panel,
body:is(.lite-fx, .no-glass) .btn-primary,
body:is(.lite-fx, .no-glass) .btn-secondary,
body:is(.lite-fx, .no-glass) .btn-ghost,
body:is(.lite-fx, .no-glass) .toggle,
body:is(.lite-fx, .no-glass) #dex-canvas,
body:is(.lite-fx, .no-glass) .back-btn,
body:is(.lite-fx, .no-glass) .shop-coins,
body:is(.lite-fx, .no-glass) .shop-tab,
body:is(.lite-fx, .no-glass) .shop-row {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
body:is(.lite-fx, .no-glass) .next-box { background: rgba(24, 16, 58, 0.78); }
body:is(.lite-fx, .no-glass) .hud-cluster { background: transparent; }
body:is(.lite-fx, .no-glass) .hud-center { background: transparent; }
body:is(.lite-fx, .no-glass) #coin-chip { background: rgba(24, 16, 58, 0.8); }
body:is(.lite-fx, .no-glass) .icon-btn { background: rgba(24, 16, 58, 0.78); }
body:is(.lite-fx, .no-glass) #drawer-handle { background: rgba(24, 16, 58, 0.85); }
body:is(.lite-fx, .no-glass) #item-drawer { background: rgba(24, 15, 58, 0.97); }
body:is(.lite-fx, .no-glass) .drawer-item { background: rgba(30, 20, 66, 0.88); }
body:is(.lite-fx, .no-glass) .drawer-coins { background: rgba(24, 16, 58, 0.85); }
body:is(.lite-fx, .no-glass) #toast { background: rgba(24, 15, 58, 0.94); }
body:is(.lite-fx, .no-glass) .screen { background: rgba(8, 4, 24, 0.7); }
body:is(.lite-fx, .no-glass) .panel { background: rgba(22, 13, 54, 0.94); }
body:is(.lite-fx, .no-glass) .btn-primary { background: linear-gradient(180deg, #8b5cff, #5c2fe0); }
body:is(.lite-fx, .no-glass) .btn-secondary { background: linear-gradient(180deg, #37e5c8, #1cb99f); color: #063a31; }
body:is(.lite-fx, .no-glass) .btn-ghost,
body:is(.lite-fx, .no-glass) .toggle,
body:is(.lite-fx, .no-glass) .shop-row,
body:is(.lite-fx, .no-glass) .shop-tab,
body:is(.lite-fx, .no-glass) .back-btn { background: rgba(20, 12, 50, 0.72); }
body:is(.lite-fx, .no-glass) #dex-canvas { background: rgba(20, 12, 50, 0.6); }
body:is(.lite-fx, .no-glass) .shop-coins { background: rgba(24, 16, 58, 0.85); }

button:focus-visible {
  outline: 3px solid #37e5c8;
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  #splash { transition: none; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #hint { transform: none; }
}

@media (max-height: 700px) {
  .hud-rail { top: calc(var(--play-region-top) + var(--safe-area-top) + 4px); min-height: 52px; }
  #next-canvas { width: 40px; height: 40px; }
  .score { font-size: 36px; }
  .screen {
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }
  .screen > .panel {
    flex: none;
    margin-block: auto;
  }
  #screen-title {
    --title-mode-height: 44px;
    --title-mode-padding-y: 4px;
    --title-compact-logo-font-size: 30px;
    --title-compact-dex-height: 36px;
    --title-logo-margin-bottom: var(--title-compact-spacing);
    --title-logo-sub-margin-top: var(--title-compact-spacing);
    --title-dex-height: var(--title-compact-dex-height);
    --title-dex-margin-top: var(--title-compact-spacing);
    --title-label-margin-top: var(--title-compact-spacing);
    --title-mode-margin-top: var(--title-compact-section-spacing);
    --title-best-margin-top: var(--title-compact-spacing);
    --title-settings-margin-top: var(--title-compact-section-spacing);
    --title-credit-margin-top: var(--title-compact-spacing);
    justify-content: flex-start;
    padding-top: calc(var(--safe-area-top) + 4px);
    padding-bottom: calc(var(--safe-area-bottom) + 4px);
    scrollbar-width: none;
  }
  #screen-title::-webkit-scrollbar { display: none; }
  .logo { margin: var(--title-compact-spacing) 0; }
  .logo-top, .logo-bottom { font-size: var(--title-compact-logo-font-size); }
  #dex-canvas { height: var(--title-dex-height); margin-top: var(--title-dex-margin-top); }
  .play-modes .mode-btn { padding: var(--title-mode-padding-y) var(--title-mode-padding-x); }
  .settings { gap: var(--title-compact-spacing); }
  .language-picker { margin-top: var(--title-compact-spacing); }
}

@media (max-width: 360px) {
  .hud-rail {
    left: calc(var(--safe-area-left) + 5px);
    right: calc(var(--safe-area-right) + 5px);
    grid-template-columns: minmax(82px, 1fr) auto minmax(82px, 1fr);
    gap: 4px;
  }
  .hud-cluster { gap: 4px; }
  .next-box { padding-inline: 4px; }
  #coin-chip { padding-inline: 7px; }
  .score { font-size: 36px; }
  .handle-tx { font-size: 0; }
  .handle-tx::before { content: '🎒'; font-size: 18px; }
  #drawer-handle {
    width: 44px;
    min-width: 44px;
    padding: 0;
    letter-spacing: 0;
    flex: 0 0 44px;
  }
}

@media (max-height: 280px) {
  #screen-pause {
    padding-top: calc(var(--safe-area-top) + 4px);
    padding-bottom: calc(var(--safe-area-bottom) + 4px);
  }
  #screen-pause .panel {
    padding: 8px 16px;
    gap: 4px;
  }
  #screen-pause .panel h2 { line-height: 1; }
  #screen-pause .btn-primary,
  #screen-pause .btn-ghost {
    min-height: 44px;
    margin-top: 0;
    padding: 8px 12px;
  }
}

/* Probe segment geometry without forcing a half-screen layout for a crease. */
@media (horizontal-viewport-segments: 2), (vertical-viewport-segments: 2) {
  :root {
    --fold-first-left: env(viewport-segment-left 0 0);
    --fold-first-top: env(viewport-segment-top 0 0);
    --fold-first-width: env(viewport-segment-width 0 0);
    --fold-first-height: env(viewport-segment-height 0 0);
  }
}
@media (horizontal-viewport-segments: 2) {
  :root {
    --fold-first-end: env(viewport-segment-right 0 0);
    --fold-second-start: env(viewport-segment-left 1 0);
  }
}
@media (vertical-viewport-segments: 2) {
  :root {
    --fold-first-end: env(viewport-segment-bottom 0 0);
    --fold-second-start: env(viewport-segment-top 0 1);
  }
}
