:root {
  --ink: #071629;
  --ink-deep: #030914;
  --panel: #102943;
  --paper: #f6e9c9;
  --white: #fff8e8;
  --cyan: #2de6ff;
  --blue: #2989ee;
  --gold: #ffb642;
  --rose: #ff5577;
  --stage-w: 1440px;
  --stage-h: 810px;
  --menu-w: 700px;
  --hud-h: 52px;
  --radius: 12px;
  --home-unit: min(1.35vw, 2.4vh);
  --shadow: rgba(0, 0, 0, .38);
  --mobile-page-pad: clamp(8px, 2vw, 16px);
  --mobile-gap: clamp(6px, 1.4vw, 12px);
  --mobile-radius: clamp(10px, 1.7vw, 16px);
  --mobile-title: clamp(20px, 6vh, 28px);
  --mobile-body: clamp(11px, 3.1vh, 14px);
  --mobile-button-text: clamp(12px, 3.4vh, 15px);
  --mobile-button-height: clamp(44px, 12vh, 52px);
  font-family: Inter, ui-rounded, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  height: 100svh;
  height: 100dvh;
  margin: 0;
  overflow: clip;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  color: var(--white);
  background:
    linear-gradient(rgba(246, 233, 201, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(246, 233, 201, .03) 1px, transparent 1px),
    radial-gradient(circle at 50% 18%, #123049 0%, #06182c 54%, #020711 100%);
  background-size: 46px 46px, 46px 46px, auto;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body.is-playing { touch-action: none; }

.shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: clip;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.stage-slot {
  position: relative;
  flex: none;
  overflow: visible;
}

.game-stage {
  position: relative;
  width: var(--stage-w);
  height: var(--stage-h);
  overflow: hidden;
  transform-origin: top left;
  isolation: isolate;
  background: transparent;
}

/* Menus and modals live outside the scaled stage so they size to the real viewport */
.ui-layer {
  position: fixed;
  inset: 0;
  z-index: 6;
  overflow: clip;
  pointer-events: none;
  --icon-btn: clamp(38px, 6.4vh, 52px);
}

.ui-layer > * { pointer-events: auto; }

button,
input { font: inherit; }

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

#gameCanvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #071629;
  touch-action: none;
  pointer-events: none;
}

body:not(.is-playing) #gameCanvas { opacity: 0; }
body.is-playing #gameCanvas { pointer-events: auto; }

/* Shared screens */
.screen {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .2s ease, visibility .2s ease;
}

.screen:not(.screen-active) { display: none; }

.screen-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Home */
.home {
  place-items: center;
  padding: clamp(12px, 3vh, 26px) clamp(16px, 4vw, 48px) clamp(18px, 6vh, 68px);
  overflow: hidden;
  touch-action: manipulation;
}

.home::before,
.home::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.home::before {
  background:
    linear-gradient(rgba(246, 233, 201, .052) 1px, transparent 1px),
    linear-gradient(90deg, rgba(246, 233, 201, .045) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at center, #000 0 48%, transparent 84%);
  animation: gridFloat 11s ease-in-out infinite alternate;
}

.home::after {
  background:
    radial-gradient(circle at 50% 42%, rgba(45, 230, 255, .075), transparent 38%),
    radial-gradient(circle at 50% 54%, rgba(255, 182, 66, .025), transparent 58%);
}

.home-art {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(circle at 8% 72%, rgba(255, 182, 66, .12) 0 3px, transparent 4px),
    radial-gradient(circle at 88% 24%, rgba(246, 233, 201, .1) 0 2px, transparent 3px),
    linear-gradient(157deg, transparent 0 78%, rgba(45, 230, 255, .045) 78.1% 78.5%, transparent 78.6%);
}

.home-art::before,
.home-art::after {
  content: "";
  position: absolute;
  pointer-events: none;
}

.home-art::before {
  left: clamp(20px, 7vw, 150px);
  bottom: clamp(38px, 9vh, 120px);
  width: clamp(84px, 10vw, 150px);
  aspect-ratio: 1;
  border: clamp(8px, .8vw, 13px) dotted rgba(246, 233, 201, .055);
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 clamp(12px, 1.3vw, 20px) rgba(45, 230, 255, .025),
    0 0 0 2px rgba(45, 230, 255, .035);
  transform: rotate(12deg);
}

.home-art::after {
  right: clamp(18px, 6vw, 130px);
  bottom: clamp(34px, 8vh, 105px);
  width: clamp(150px, 17vw, 260px);
  height: clamp(70px, 10vh, 130px);
  opacity: .11;
  background:
    linear-gradient(90deg, transparent 0 12%, var(--gold) 12% 15%, transparent 15% 79%, var(--paper) 79% 82%, transparent 82%),
    linear-gradient(155deg, transparent 0 47%, var(--cyan) 48% 50%, transparent 51%) 20% 0 / 58% 100% no-repeat,
    linear-gradient(205deg, transparent 0 47%, var(--cyan) 48% 50%, transparent 51%) 80% 0 / 58% 100% no-repeat;
  clip-path: polygon(0 100%, 0 78%, 16% 78%, 24% 54%, 35% 72%, 49% 35%, 63% 72%, 78% 52%, 88% 76%, 100% 76%, 100% 100%);
}

.home-art .stroke {
  position: absolute;
  width: 380px;
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(45, 230, 255, .22), transparent);
  opacity: .34;
}

.home-art .s1 { top: 13%; left: -8%; transform: rotate(-8deg); }
.home-art .s2 { right: -9%; bottom: 13%; transform: rotate(12deg); }

.home-inner {
  position: relative;
  z-index: 2;
  width: min(100%, var(--menu-w));
  display: grid;
  justify-items: center;
  gap: clamp(6px, 1.5vh, 13px);
  margin-top: clamp(-56px, -4vh, -22px);
  text-align: center;
  animation: homeIn .38s cubic-bezier(.2, .85, .2, 1) both;
}

.brand-lockup {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 0;
  filter: drop-shadow(0 13px 18px rgba(0, 0, 0, .3));
}

.brand-rider {
  width: clamp(190px, calc(var(--home-unit) * 27), 410px);
  height: auto;
  aspect-ratio: 420 / 118;
  margin-bottom: clamp(-22px, -2.1vh, -10px);
  overflow: visible;
}

.brand-rider-line {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 420;
  stroke-dashoffset: 420;
  filter: url(#brandGlow);
  animation:
    brandDraw .68s cubic-bezier(.2, .75, .25, 1) .08s both,
    brandInkIdle 4s ease-in-out 1s infinite;
}

.brand-rider-wheel {
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
  animation: brandWheelSettle .46s cubic-bezier(.2, 1.35, .35, 1) .55s both;
}

.brand-rider-wheel circle:first-child {
  fill: #10243d;
  stroke: var(--paper);
  stroke-width: 6;
}

.brand-rider-wheel circle:last-child {
  fill: var(--gold);
  stroke: #071629;
  stroke-width: 3;
}

h1 {
  position: relative;
  margin: -3px 0 0;
  color: var(--paper);
  font-size: clamp(38px, calc(var(--home-unit) * 5.7), 92px);
  line-height: .98;
  letter-spacing: -.045em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff9df 0 48%, #ecd59f 72%, #cba66d 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 1px rgba(255, 248, 232, .16);
  text-shadow: 0 7px 0 rgba(1, 8, 17, .42), 0 13px 18px rgba(0, 0, 0, .22);
}

h1::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -10px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--cyan), var(--gold), transparent);
  box-shadow: 0 2px 7px rgba(45, 230, 255, .22);
}

h2 {
  margin: 0;
  color: var(--paper);
  font-size: 28px;
}

.tagline {
  margin: clamp(13px, 2.2vh, 24px) 0 0;
  color: rgba(255, 248, 232, .76);
  font-size: clamp(13px, calc(var(--home-unit) * 1.5), 23px);
  line-height: 1.2;
  font-weight: 850;
  letter-spacing: .025em;
}

.home-progress {
  position: relative;
  width: min(100%, 610px);
  display: grid;
  gap: clamp(6px, 1vh, 9px);
  overflow: hidden;
  margin-top: clamp(3px, 1vh, 9px);
  padding: clamp(10px, 1.4vh, 13px) clamp(14px, 1.35vw, 17px);
  border: 1px solid rgba(98, 203, 229, .2);
  border-radius: 13px;
  color: var(--paper);
  font-weight: 950;
  background:
    radial-gradient(circle at 50% 0, rgba(45,230,255,.065), transparent 48%),
    linear-gradient(180deg, rgba(25, 57, 83, .9), rgba(5, 19, 34, .94));
  box-shadow:
    inset 0 1px rgba(255, 255, 255, .075),
    inset 0 -1px rgba(2, 10, 20, .68),
    0 7px 0 rgba(2, 12, 23, .42),
    0 13px 24px rgba(0, 0, 0, .24);
}

.home-progress::before {
  content: "";
  position: absolute;
  inset: 1px 10px auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(156,240,249,.38), transparent);
  pointer-events: none;
}

.progress-row {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

#homeCurrent,
#homeProgress {
  font-size: clamp(12px, calc(var(--home-unit) * 1.22), 19px);
  letter-spacing: .06em;
}

#homeCurrent { color: rgba(255,248,232,.94); text-shadow: 0 2px 5px rgba(0,0,0,.28); }

#homeProgress {
  flex: 0 0 72px;
  padding: 3px 7px;
  border: 1px solid rgba(246,233,201,.09);
  border-radius: 999px;
  text-align: center;
  font-size: clamp(12px, calc(var(--home-unit) * 1.08), 16px);
  white-space: nowrap;
  background: rgba(2,12,23,.4);
  box-shadow: inset 0 1px rgba(255,255,255,.035);
}

.medal-chip {
  position: relative;
  min-width: clamp(58px, calc(var(--home-unit) * 5.6), 78px);
  min-height: clamp(30px, calc(var(--home-unit) * 3), 42px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid rgba(255,249,210,.68);
  border-radius: 999px;
  color: var(--ink);
  font-size: clamp(12px, calc(var(--home-unit) * 1.22), 17px);
  background: linear-gradient(180deg, #fff7c7 0 28%, #ffd66d 52%, #e99a25 100%);
  box-shadow: 0 4px 0 #815019, 0 7px 12px rgba(0, 0, 0, .22), inset 0 1px rgba(255, 255, 255, .72);
  overflow: hidden;
}

.medal-chip::after {
  content: "";
  position: absolute;
  inset: -50% auto -50% -40%;
  width: 28%;
  transform: skewX(-18deg);
  background: rgba(255, 255, 255, .48);
  animation: medalShimmer 3.8s ease-in-out 1.1s infinite;
}

.medal-chip span { color: #895000; }

.bar-row { gap: 14px; }

.progress-track {
  flex: 1;
  height: clamp(10px, 1.7vh, 16px);
  overflow: hidden;
  border-radius: 999px;
  border: 1px solid rgba(246,233,201,.07);
  background: linear-gradient(180deg, rgba(1,10,20,.62), rgba(255,248,232,.1));
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .48), 0 1px rgba(255,255,255,.025);
}

.progress-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  border: 1px solid rgba(178,248,255,.32);
  background:
    linear-gradient(180deg, rgba(255,255,255,.26), transparent 54%),
    linear-gradient(90deg, #2de6ff, #238fe7 70%, #f1b34d);
  box-shadow: inset 0 1px rgba(255,255,255,.3), 0 0 9px rgba(45, 230, 255, .26);
  transform-origin: left;
  animation: progressReveal .58s cubic-bezier(.25, .75, .2, 1) .32s both;
  transition: width .3s ease;
}

.home-actions {
  position: relative;
  z-index: 3;
  width: min(100%, 610px);
  display: grid;
  gap: clamp(7px, 1.4vh, 12px);
  margin-top: clamp(4px, 1.4vh, 12px);
}

.secondary-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(8px, 1.4vw, 12px);
}

/* Buttons */
.btn {
  position: relative;
  isolation: isolate;
  min-height: 52px;
  overflow: hidden;
  padding: 0 22px;
  border-radius: var(--radius);
  color: var(--ink);
  font-weight: 1000;
  text-transform: uppercase;
  box-shadow: 0 8px 0 rgba(0, 0, 0, .24), 0 14px 28px var(--shadow);
  transition: transform .11s ease, box-shadow .11s ease, filter .11s ease, opacity .11s ease;
}

.btn::after {
  content: "";
  position: absolute;
  inset: 1px 1px auto;
  height: 44%;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, .28), transparent);
  pointer-events: none;
}

.btn:not(:disabled):hover { filter: brightness(1.07); }
.btn:not(:disabled):active { transform: translateY(4px) scale(.985); box-shadow: 0 4px 0 rgba(0, 0, 0, .25), 0 8px 16px var(--shadow); }
.btn:disabled { cursor: default; opacity: .62; }

.primary { background: linear-gradient(180deg, #6af2ff, #1bb7e6); }
.secondary { background: linear-gradient(180deg, #ffe3a2, #f6a734); }
.ghost { color: var(--white); background: linear-gradient(180deg, rgba(255, 248, 232, .2), rgba(255, 248, 232, .09)); border: 1px solid rgba(255, 248, 232, .26); }
.danger { color: #fff; background: linear-gradient(180deg, #ff7690, #d93656); }

.hero-action {
  min-height: clamp(48px, calc(var(--home-unit) * 5.1), 84px);
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: clamp(9px, 1.4vw, 15px);
  border-radius: 13px;
  border: 1px solid rgba(189, 249, 255, .52);
  background:
    radial-gradient(circle at 50% -12%, rgba(255, 255, 255, .46), transparent 48%),
    linear-gradient(180deg, #87f7ff 0, #36d1ee 43%, #159bd7 72%, #1278b8 100%);
  box-shadow:
    0 8px 0 #074b73,
    0 14px 23px rgba(0, 0, 0, .3),
    inset 0 1px rgba(255, 255, 255, .48),
    inset 0 -1px rgba(5,75,114,.4);
  transition: transform .11s ease, filter .14s ease, box-shadow .11s ease;
}

.hero-action::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: -30%;
  bottom: -30%;
  left: -24%;
  width: 17%;
  transform: skewX(-20deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .38), transparent);
  animation: heroSweep 4.2s ease-in-out 1.2s infinite;
  pointer-events: none;
}

.hero-action:not(:disabled):active {
  transform: translateY(5px) scale(.98);
  box-shadow:
    0 3px 0 #084d78,
    0 8px 14px rgba(0, 0, 0, .3),
    inset 0 1px rgba(255, 255, 255, .25);
}

.hero-action:not(:disabled):hover {
  transform: translateY(-1px);
  filter: brightness(1.045) saturate(1.03);
}

.hero-action:not(:disabled):active {
  transform: translateY(5px) scale(.98);
  filter: brightness(.99);
}

.btn-copy {
  display: grid;
  gap: 4px;
  text-align: left;
  line-height: 1;
}

.btn-copy b { font-size: clamp(17px, calc(var(--home-unit) * 1.72), 27px); letter-spacing: .025em; }
.btn-copy small { min-height: 12px; color: rgba(4, 31, 49, .67); font-size: clamp(10px, calc(var(--home-unit) * .9), 12px); letter-spacing: .07em; }

.compact-action {
  min-width: 0;
  min-height: clamp(40px, calc(var(--home-unit) * 3.5), 54px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: clamp(7px, 1vw, 10px);
  font-size: clamp(12px, calc(var(--home-unit) * 1.08), 17px);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.15);
  letter-spacing: .035em;
  transition: transform .11s ease, filter .14s ease, box-shadow .11s ease;
}

#levelsBtn {
  color: #2c1b08;
  border-color: rgba(255,244,196,.58);
  background: linear-gradient(180deg, #ffe9ad 0, #f5bd5d 48%, #df8e2e 100%);
  box-shadow: 0 6px 0 #825018, 0 11px 18px rgba(0, 0, 0, .24), inset 0 1px rgba(255, 255, 255, .58);
}

#settingsBtn {
  color: var(--paper);
  border-color: rgba(83, 210, 235, .3);
  background: linear-gradient(180deg, #3e6582 0, #244763 52%, #142f49 100%);
  box-shadow: 0 6px 0 #071a2c, 0 11px 18px rgba(0, 0, 0, .25), inset 0 1px rgba(255, 255, 255, .16);
  opacity: 1;
}

.compact-action:not(:disabled):hover {
  transform: translateY(-1px);
  filter: brightness(1.055) saturate(1.03);
}

.compact-action:not(:disabled):active {
  transform: translateY(4px) scale(.98);
}

.compact-action .btn-icon {
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.25));
}

.btn-icon {
  position: relative;
  width: 21px;
  height: 21px;
  flex: none;
}

.play-icon {
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 16px solid var(--ink);
}

.grid-icon::before {
  content: "";
  position: absolute;
  top: 1px;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: currentColor;
  box-shadow: 12px 0 currentColor, 0 12px currentColor, 12px 12px currentColor;
}

.gear-icon {
  width: 18px;
  height: 18px;
  border: 3px solid currentColor;
  border-radius: 50%;
}

.gear-icon::before {
  content: "";
  position: absolute;
  inset: -3px;
  background: currentColor;
  clip-path: polygon(
    40% 0, 60% 0, 64% 16%, 76% 22%, 90% 14%, 100% 32%,
    87% 42%, 87% 58%, 100% 68%, 90% 86%, 76% 78%, 64% 84%,
    60% 100%, 40% 100%, 36% 84%, 24% 78%, 10% 86%, 0 68%,
    13% 58%, 13% 42%, 0 32%, 10% 14%, 24% 22%, 36% 16%
  );
}

.gear-icon::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: #244d70;
  box-shadow: 0 0 0 2px currentColor;
}

.btn:focus-visible,
.icon-btn:focus-visible,
.level-tile:focus-visible {
  outline: 3px solid rgba(45, 230, 255, .78);
  outline-offset: 3px;
}

/* Panels */
.panel-screen {
  z-index: 12;
  place-items: center;
  padding: clamp(12px, 3vh, 28px);
  background: rgba(2, 7, 15, .64);
  backdrop-filter: blur(8px);
}

.panel {
  width: 760px;
  max-width: 94%;
  max-height: min(750px, 88vh);
  overflow: auto;
  padding: clamp(14px, 2.4vh, 22px);
  border: 1px solid rgba(246, 233, 201, .2);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(19, 48, 76, .98), rgba(7, 22, 41, .98));
  box-shadow: 0 24px 72px rgba(0, 0, 0, .46);
  scrollbar-width: thin;
  scrollbar-color: var(--cyan) rgba(255, 255, 255, .08);
}

.small-panel {
  width: 470px;
  display: grid;
  gap: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.levels-panel {
  width: min(760px, calc(100vw - 24px));
  max-width: none;
  height: min(750px, 88vh);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
  border-color: rgba(121, 204, 232, .24);
  border-radius: 20px;
  background:
    radial-gradient(circle at 50% 0, rgba(45, 230, 255, .055), transparent 36%),
    linear-gradient(180deg, rgba(20, 51, 80, .99), rgba(5, 17, 31, .99));
  box-shadow:
    inset 0 1px rgba(255,255,255,.055),
    0 28px 76px rgba(0, 0, 0, .48);
}

.levels-panel .panel-head {
  position: relative;
  flex: none;
  min-height: 78px;
  gap: 16px;
  margin: 0;
  padding: 13px 18px;
  border-bottom: 1px solid rgba(246,233,201,.1);
  background: linear-gradient(180deg, rgba(34, 74, 105, .72), rgba(13, 37, 61, .54));
  box-shadow: 0 8px 20px rgba(0,0,0,.12);
}

.levels-panel .panel-head::after {
  content: "";
  position: absolute;
  left: 78px;
  bottom: -1px;
  width: 82px;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), rgba(45,230,255,0));
}

.levels-panel .panel-head h2 {
  font-size: clamp(25px, 3.2vh, 32px);
  letter-spacing: -.025em;
  text-shadow: 0 4px 10px rgba(0,0,0,.25);
}

.levels-panel .panel-head .icon-btn {
  width: 48px;
  height: 48px;
  border-color: rgba(45,230,255,.22);
  border-radius: 14px;
  color: var(--paper);
  font-size: 30px;
  line-height: 1;
  background: linear-gradient(180deg, #315776, #162f48);
  box-shadow: 0 6px 0 #071a2b, 0 10px 16px rgba(0,0,0,.24), inset 0 1px rgba(255,255,255,.12);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}

.levels-panel .panel-head .icon-btn:hover { filter: brightness(1.08); }
.levels-panel .panel-head .icon-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #071a2b, 0 5px 10px rgba(0,0,0,.24);
}

.levels-panel .world-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 18px 20px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.levels-panel .world-list::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.icon-btn {
  width: var(--icon-btn, var(--hud-h));
  height: var(--icon-btn, var(--hud-h));
  display: grid;
  place-items: center;
  flex: none;
  border-radius: 12px;
  color: var(--white);
  background: rgba(7, 22, 41, .68);
  border: 1px solid rgba(246, 233, 201, .14);
  font-size: 22px;
  font-weight: 1000;
  box-shadow: 0 7px 18px rgba(0, 0, 0, .18);
}

.world-card {
  position: relative;
  overflow: hidden;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid rgba(246, 233, 201, .13);
  border-radius: 17px;
  background:
    linear-gradient(180deg, rgba(36, 71, 98, .54), rgba(8, 27, 45, .72));
  box-shadow:
    inset 0 1px rgba(255,255,255,.045),
    0 10px 24px rgba(0,0,0,.2);
}

.world-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, rgba(45,230,255,.7), rgba(45,230,255,.08) 48%, transparent);
}

.world-card[data-world="2"]::before { background: linear-gradient(90deg, rgba(224,139,65,.8), rgba(224,139,65,.08) 48%, transparent); }
.world-card[data-world="3"]::before { background: linear-gradient(90deg, rgba(154,204,220,.76), rgba(154,204,220,.08) 48%, transparent); }
.world-card[data-world="4"]::before { background: linear-gradient(90deg, rgba(77,134,255,.8), rgba(77,134,255,.08) 48%, transparent); }
.world-card[data-world="5"]::before { background: linear-gradient(90deg, rgba(130,246,255,.78), rgba(130,246,255,.08) 48%, transparent); }

.world-card:last-child {
  margin-bottom: 0;
}

.world-card.world-current {
  border-color: rgba(45, 230, 255, .42);
  box-shadow:
    inset 0 1px rgba(255,255,255,.055),
    0 10px 24px rgba(0,0,0,.22),
    0 0 0 1px rgba(45,230,255,.08);
}

.world-card.world-locked {
  opacity: .78;
  border-color: rgba(246,233,201,.08);
  background: linear-gradient(180deg, rgba(27,50,69,.42), rgba(6,19,33,.66));
}

.world-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 15px;
  padding: 0 2px 12px;
  border-bottom: 1px solid rgba(246,233,201,.08);
}

.world-card-head h3 {
  margin: 0;
  color: var(--paper);
  font-size: 15px;
  line-height: 1.15;
  letter-spacing: .055em;
  text-transform: uppercase;
  text-shadow: 0 3px 8px rgba(0,0,0,.25);
}

.world-progress-chip {
  min-width: 86px;
  display: grid;
  justify-items: end;
  gap: 6px;
  text-align: right;
  color: var(--paper);
}

.world-progress-chip strong {
  min-width: 43px;
  padding: 4px 8px;
  border: 1px solid rgba(246,233,201,.12);
  border-radius: 999px;
  color: rgba(255,248,232,.9);
  font-size: 12px;
  letter-spacing: .04em;
  text-align: center;
  background: rgba(3,14,27,.54);
  box-shadow: inset 0 1px rgba(255,255,255,.04);
}

.progress-track.mini {
  width: 86px;
  height: 7px;
  margin: 0;
  background: rgba(255,248,232,.09);
}

.levels-panel .progress-track.mini i {
  background: linear-gradient(90deg, #29d8f2, #67f2ff);
  box-shadow: 0 0 8px rgba(45,230,255,.28);
  animation-duration: .42s;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.level-tile {
  position: relative;
  min-height: 82px;
  display: grid;
  place-items: center;
  gap: 4px;
  overflow: hidden;
  padding: 10px 8px 9px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 13px;
  color: var(--ink);
  background: linear-gradient(180deg, #f7e8bf, #d8b572);
  box-shadow: 0 6px 0 #76552c, 0 10px 15px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.5);
  font-weight: 1000;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}

.level-tile::before {
  content: "";
  position: absolute;
  inset: 1px 1px auto;
  height: 38%;
  border-radius: 12px 12px 50% 50%;
  background: linear-gradient(180deg, rgba(255,255,255,.26), transparent);
  pointer-events: none;
}

.level-tile.completed {
  color: #2b1b0b;
  border-color: rgba(255,238,178,.42);
  background: linear-gradient(180deg, #ffe8a4, #e3a841);
  box-shadow: 0 6px 0 #88551a, 0 10px 16px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.55);
}

.level-tile.current {
  color: #032238;
  border-color: rgba(167,250,255,.78);
  background: linear-gradient(180deg, #85f7ff, #28c8ec 56%, #168acb);
  box-shadow:
    0 7px 0 #07527c,
    0 12px 20px rgba(0,0,0,.25),
    0 0 0 2px rgba(45, 230, 255, .28),
    0 0 17px rgba(45,230,255,.14);
}

.level-tile.locked {
  color: rgba(255, 248, 232, .58);
  border-color: rgba(246,233,201,.08);
  background: linear-gradient(180deg, rgba(47,74,96,.64), rgba(7, 22, 41, .94));
  box-shadow: 0 5px 0 #03101d, 0 9px 14px rgba(0,0,0,.2), inset 0 1px rgba(255,255,255,.055);
}

.level-tile:not(.locked):hover { filter: brightness(1.045); transform: translateY(-1px); }
.level-tile:not(.locked):active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.38), 0 5px 9px rgba(0,0,0,.2); }
.lvl-num { position: relative; z-index: 1; font-size: 19px; letter-spacing: .035em; }
.stars { position: relative; z-index: 1; display: flex; gap: 3px; }
.stars i { color: rgba(7, 22, 41, .2); font-style: normal; text-shadow: 0 1px rgba(255,255,255,.15); }
.stars i.lit { color: #9b5900; text-shadow: 0 1px #ffe49d; }

.lock-mark {
  position: relative;
  width: 18px;
  height: 14px;
  margin-top: 3px;
  border: 2px solid rgba(255,248,232,.58);
  border-radius: 4px;
  color: transparent;
  font-size: 0;
}

.lock-mark::before {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 10px;
  height: 9px;
  border: 2px solid rgba(255,248,232,.58);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}

.lock-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 4px;
  width: 3px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255,182,66,.7);
  transform: translateX(-50%);
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.game-icon {
  width: 1.25em;
  height: 1.25em;
  display: block;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings-panel {
  width: min(520px, calc(100vw - 24px));
  max-width: none;
  max-height: min(680px, calc(100dvh - 32px));
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.settings-panel::before {
  content: "";
  position: absolute;
  z-index: 2;
  top: 0;
  left: 68px;
  width: 54px;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255,182,66,.68), transparent);
  pointer-events: none;
}

.settings-panel .panel-head {
  min-height: 72px;
  margin: 0;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(246,233,201,.1);
  background: linear-gradient(180deg, rgba(38,77,107,.58), rgba(14,38,62,.42));
}

.settings-panel .panel-head .icon-btn {
  width: 46px;
  height: 46px;
  border-color: rgba(45,230,255,.2);
  background: linear-gradient(180deg, #315776, #162f48);
  box-shadow: 0 5px 0 #071a2b, 0 8px 14px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.1);
}

.settings-body {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.toggle-row {
  min-height: 72px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 13px;
  border: 1px solid rgba(246,233,201,.09);
  border-radius: 13px;
  background: linear-gradient(180deg, rgba(255,248,232,.075), rgba(255,248,232,.035));
  box-shadow: inset 0 1px rgba(255,255,255,.025);
  transition: background .16s ease, border-color .16s ease;
}

.toggle-row:hover {
  border-color: rgba(45,230,255,.16);
  background: linear-gradient(180deg, rgba(255,248,232,.095), rgba(255,248,232,.045));
}

.setting-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(45,230,255,.14);
  border-radius: 11px;
  color: #93eaf4;
  background: rgba(5,20,35,.48);
}

.setting-icon .game-icon { width: 21px; height: 21px; }

.setting-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
  text-align: left;
}

.setting-copy b {
  color: var(--paper);
  font-size: 15px;
  letter-spacing: .025em;
  text-transform: uppercase;
}

.setting-copy small,
.danger-copy small {
  color: rgba(255,248,232,.56);
  font-size: 11px;
  line-height: 1.25;
}

.switch {
  position: relative;
  width: 56px;
  height: 32px;
  padding: 3px;
  border: 1px solid rgba(246,233,201,.12);
  border-radius: 999px;
  background: linear-gradient(180deg, #263b50, #14283b);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.28);
  transition: background .19s cubic-bezier(.2,.7,.25,1), border-color .19s ease, box-shadow .19s ease;
}

.switch i {
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #aab5bd;
  box-shadow: 0 2px 5px rgba(0,0,0,.34), inset 0 1px rgba(255,255,255,.35);
  transition: transform .19s cubic-bezier(.2,.7,.25,1), background .19s ease;
}

.switch.on {
  border-color: rgba(117,243,255,.5);
  background: linear-gradient(180deg, #45ddec, #1599bd);
  box-shadow: inset 0 2px 4px rgba(4,62,79,.28), 0 0 9px rgba(45,230,255,.16);
}

.switch.on i {
  transform: translateX(24px);
  background: var(--paper);
}

.switch:focus-visible {
  outline: 3px solid rgba(45,230,255,.58);
  outline-offset: 3px;
}

.switch:active i { transform: scale(.94); }
.switch.on:active i { transform: translateX(24px) scale(.94); }

.danger-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 4px;
  padding: 14px 2px 0;
  border-top: 1px solid rgba(255,112,130,.15);
}

.danger-copy {
  display: grid;
  gap: 3px;
  text-align: left;
}

.danger-copy b {
  color: rgba(255,174,184,.88);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.compact-danger {
  min-height: 42px;
  flex: none;
  padding: 0 14px;
  font-size: 12px;
}

/* Gameplay HUD */
.game-ui {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .18s ease, visibility .18s ease;
}

.game-ui.active {
  opacity: 1;
  visibility: visible;
}

.game-ui.active::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  bottom: 0;
  height: 13%;
  background: linear-gradient(180deg, rgba(3, 8, 15, 0), rgba(3, 8, 15, .46) 62%, rgba(3, 8, 15, .68));
  pointer-events: none;
}

.hud {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  pointer-events: none;
}

.hud > * { pointer-events: auto; }

.top-hud {
  top: max(16px, env(safe-area-inset-top));
  left: 18px;
  width: min(760px, calc(100% - 36px));
  gap: 10px;
}

.level-label,
.attempts,
.ink-wrap {
  position: relative;
  overflow: hidden;
  min-height: var(--hud-h);
  display: flex;
  align-items: center;
  border: 1px solid rgba(246, 233, 201, .16);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(29, 59, 84, .86), rgba(5, 17, 32, .9));
  box-shadow:
    inset 0 1px rgba(255, 255, 255, .07),
    0 7px 18px rgba(0, 0, 0, .25);
  backdrop-filter: blur(9px);
  font-weight: 1000;
}

.level-label::after,
.attempts::after,
.ink-wrap::after {
  content: "";
  position: absolute;
  inset: 1px 1px auto;
  height: 38%;
  border-radius: 11px 11px 50% 50%;
  background: linear-gradient(180deg, rgba(255,255,255,.07), transparent);
  pointer-events: none;
}

.level-label {
  min-width: 90px;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
}

.level-label small { color: rgba(246, 233, 201, .62); font-size: 13px; }
.level-label b { color: var(--paper); font-size: 21px; }

.ink-wrap {
  flex: 1;
  min-width: 290px;
  max-width: 560px;
  gap: 12px;
  padding: 0 15px;
}

.ink-title {
  color: rgba(255, 248, 232, .9);
  font-size: 14px;
  text-transform: uppercase;
}

.ink-bar {
  flex: 1;
  height: 18px;
  overflow: hidden;
  border-radius: 999px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .05) 0 12px, transparent 12px 24px),
    rgba(255, 255, 255, .11);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, .48),
    0 0 0 1px rgba(255, 255, 255, .09);
}

.ink-bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, .2) 0 6px, transparent 6px 14px),
    linear-gradient(90deg, var(--cyan), var(--blue));
  box-shadow: inset 0 1px rgba(255,255,255,.35), 0 0 10px rgba(45, 230, 255, .34);
  transition: width .14s ease-out, filter .18s ease;
}

.ink-bar i.low { background: linear-gradient(90deg, var(--gold), var(--rose)); }

.attempts {
  min-width: 78px;
  justify-content: center;
  padding: 0 14px;
  font-size: 17px;
}

.bottom-hud {
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  gap: 10px;
  padding: 7px;
  border: 1px solid rgba(246, 233, 201, .14);
  border-radius: 15px;
  background: linear-gradient(180deg, rgba(23, 47, 69, .82), rgba(3, 10, 20, .84));
  box-shadow:
    inset 0 1px rgba(255,255,255,.06),
    0 10px 24px rgba(0, 0, 0, .32);
  backdrop-filter: blur(10px);
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

.bottom-hud .btn {
  min-width: 128px;
  min-height: 48px;
  padding: 0 18px;
  font-size: 16px;
}

.bottom-hud .go { min-width: 146px; font-size: 18px; }

#clearBtn {
  color: rgba(255,248,232,.9);
  border: 1px solid rgba(246,233,201,.18);
  background: linear-gradient(180deg, #38536c, #1b3046);
  box-shadow: 0 6px 0 #091a2a, 0 9px 15px rgba(0,0,0,.24), inset 0 1px rgba(255,255,255,.12);
}

.bottom-hud .go:disabled {
  color: rgba(255, 248, 232, .42);
  background: rgba(255, 248, 232, .08);
  box-shadow: 0 5px 0 rgba(0, 0, 0, .18), inset 0 0 0 1px rgba(255, 248, 232, .08);
}

#goBtn.armed:not(:disabled) {
  color: #042033;
  background: linear-gradient(180deg, #7df7ff, #14bce5);
  box-shadow: 0 7px 0 #08567a, 0 10px 17px rgba(0,0,0,.25), 0 0 13px rgba(45, 230, 255, .24);
}

#goBtn.go-press { animation: goPress .16s ease; }
.bottom-hud.is-ready {
  border-color: rgba(45,230,255,.3);
  box-shadow: inset 0 1px rgba(255,255,255,.07), 0 10px 24px rgba(0,0,0,.32), 0 0 14px rgba(45,230,255,.08);
}

.game-ui.active .bottom-hud.flash-clear { animation: clearFeedback .24s ease; }
.game-ui.active .bottom-hud.flash-go { animation: goFeedback .28s ease; }
.game-ui.active .top-hud { animation: hudDropIn .28s cubic-bezier(.2,.8,.25,1) both; }
.game-ui.active .bottom-hud { animation: dockRiseIn .3s cubic-bezier(.2,.8,.25,1) both; }
.game-ui.is-live .ink-wrap { opacity: .58; }
.game-ui.is-live .attempts { opacity: .78; }

.toast {
  position: absolute;
  z-index: 5;
  top: 82px;
  left: 50%;
  max-width: 440px;
  padding: 10px 16px;
  transform: translateX(-50%);
  border: 1px solid rgba(246,233,201,.16);
  border-radius: 11px;
  color: var(--paper);
  background: linear-gradient(180deg, rgba(35,67,92,.96), rgba(10,29,47,.97));
  box-shadow: 0 12px 26px rgba(0, 0, 0, .32), inset 0 1px rgba(255,255,255,.06);
  font-weight: 900;
  text-align: center;
}

.debug-panel {
  position: absolute;
  top: 84px;
  right: 16px;
  width: 230px;
  padding: 10px;
  border-radius: 8px;
  color: #b9fbff;
  background: rgba(0, 0, 0, .66);
  font: 12px Consolas, monospace;
  white-space: pre-line;
}

.fail-banner {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 88px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px 9px 16px;
  transform: translateX(-50%);
  border: 1px solid rgba(246,233,201,.15);
  border-radius: 13px;
  color: var(--paper);
  background: linear-gradient(180deg, rgba(40,70,94,.96), rgba(11,30,47,.97));
  box-shadow: 0 12px 26px rgba(0, 0, 0, .32), inset 0 1px rgba(255,255,255,.06);
  font-weight: 1000;
  text-transform: uppercase;
  pointer-events: auto;
}

.fail-banner .btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #042033;
  background: linear-gradient(180deg, #7bf5ff, #27c7ea);
  box-shadow: 0 4px 0 #07527c;
}

.fail-banner .fail-levels {
  color: var(--paper);
  border: 1px solid rgba(246,233,201,.15);
  background: linear-gradient(180deg, #36546f, #182f46);
  box-shadow: 0 4px 0 #071827;
}

/* Modal layers */
.popup-overlay {
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: rgba(2, 9, 18, .68);
  backdrop-filter: blur(3px);
}

.modal-layer {
  position: absolute;
  inset: 0;
  z-index: 14;
  display: grid;
  place-items: center;
  pointer-events: auto;
}

.popup-panel {
  position: relative;
  border: 1px solid rgba(99, 197, 224, .24);
  border-radius: 18px;
  color: var(--white);
  background:
    radial-gradient(circle at 50% 0, rgba(45,230,255,.055), transparent 38%),
    linear-gradient(180deg, #173b5e, #081b30);
  box-shadow:
    inset 0 1px rgba(255,255,255,.055),
    0 24px 64px rgba(0,0,0,.48),
    0 0 0 1px rgba(3,10,20,.45);
}

.popup-panel:focus { outline: none; }

.modal.popup-panel {
  width: 370px;
  max-width: min(92%, calc(100vw - 24px));
  max-height: min(92%, calc(100dvh - 24px));
  display: grid;
  gap: clamp(8px, 1.5vh, 13px);
  overflow: auto;
  padding: clamp(16px, 2.6vh, 24px);
  text-align: center;
}

.popup-scroll {
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.popup-scroll::-webkit-scrollbar,
.modal.popup-panel::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.popup-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.popup-title {
  margin: 0;
  color: var(--paper);
  font-size: 27px;
  line-height: 1.05;
  letter-spacing: -.02em;
  text-transform: uppercase;
  text-shadow: 0 3px 8px rgba(0,0,0,.2);
}

.popup-body { min-width: 0; }

.modal p {
  max-width: 300px;
  margin: 0 auto;
  color: rgba(255, 248, 232, .68);
  font-size: 13px;
  line-height: 1.45;
  font-weight: 750;
}

.popup-kicker {
  color: rgba(45,230,255,.72);
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.popup-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 4px;
}

.action-wide { grid-column: 1 / -1; }

.popup-actions .btn,
.settings-panel .btn {
  min-width: 0;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border-radius: 12px;
  font-size: 13px;
  letter-spacing: .025em;
  transition: transform .1s ease, filter .12s ease, box-shadow .12s ease;
}

.popup-actions .btn:hover,
.settings-panel .btn:hover { filter: brightness(1.07); }

.popup-actions .btn:active,
.settings-panel .btn:active { transform: scale(.98); }

.popup-actions .btn:focus-visible,
.settings-panel .btn:focus-visible,
.settings-panel .icon-btn:focus-visible {
  outline: 3px solid rgba(45,230,255,.58);
  outline-offset: 3px;
}

.game-button-primary {
  color: #042033;
  border: 1px solid rgba(255,255,255,.3);
  background: linear-gradient(180deg, #7bf5ff, #27c7ea 56%, #168acb);
  box-shadow: 0 6px 0 #07527c, 0 10px 16px rgba(0,0,0,.24), inset 0 1px rgba(255,255,255,.38);
}

.game-button-secondary {
  color: var(--paper);
  border: 1px solid rgba(246,233,201,.15);
  background: linear-gradient(180deg, #36546f, #182f46);
  box-shadow: 0 5px 0 #071827, 0 9px 14px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.1);
}

.game-button-danger {
  color: #fff3e6;
  border: 1px solid rgba(255,154,166,.26);
  background: linear-gradient(180deg, #a94356, #71273a);
  box-shadow: 0 5px 0 #3c1320, 0 9px 14px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.1);
}

.quiet-action { opacity: .88; }
.btn:disabled { filter: saturate(.35); }

.popup-emblem {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  justify-self: center;
  border: 1px solid rgba(246,233,201,.14);
  border-radius: 14px;
  color: var(--paper);
  background: rgba(5,19,34,.54);
  box-shadow: inset 0 1px rgba(255,255,255,.04), 0 8px 16px rgba(0,0,0,.18);
}

.popup-emblem .game-icon { width: 25px; height: 25px; }
.success-emblem { color: var(--gold); border-color: rgba(255,182,66,.28); }
.warning-emblem { color: #ff8b9f; border-color: rgba(255,85,119,.26); }
.lock-emblem { color: #ffd578; border-color: rgba(255,182,66,.24); }

.pause-modal { width: 390px !important; }
.result-modal { width: 380px !important; }
.unlock-modal { width: 350px !important; }
.small-confirm,
.compact-dialog { width: 340px !important; }

.pause-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.confirm-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.medal-badge {
  position: relative;
  overflow: hidden;
  justify-self: center;
  min-width: 128px;
  padding: 8px 18px;
  border-radius: 999px;
  color: var(--ink);
  box-shadow: 0 5px 0 rgba(75,43,10,.45), 0 9px 16px rgba(0,0,0,.2), inset 0 1px rgba(255,255,255,.5);
  font-weight: 1000;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.gold { background: linear-gradient(180deg, #fff4a5, #ffb642); }
.silver { background: linear-gradient(180deg, #f7fbff, #a7bdd0); }
.bronze { background: linear-gradient(180deg, #ffc18a, #bd6a34); }

.result-modal::before,
.result-modal::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  opacity: .48;
  box-shadow: 28px 12px var(--cyan), -22px 30px var(--paper), 36px 46px var(--gold);
  animation: resultMotes 1.8s ease-out both;
  pointer-events: none;
}

.result-modal::before { top: 16px; left: 45px; }
.result-modal::after { right: 56px; top: 24px; transform: scale(.75) rotate(35deg); }

.modal-layer:not(.hidden),
.rotate-overlay:not(.hidden) { animation: popupBackdropIn .2s ease both; }
.modal-layer:not(.hidden) .popup-panel,
.screen-active .settings-panel,
.rotate-overlay:not(.hidden) .popup-panel {
  animation: popupIn .21s cubic-bezier(.2,.75,.25,1) both;
}

.modal-layer.is-closing {
  pointer-events: none;
  animation: popupBackdropOut .16s ease both;
}

.modal-layer.is-closing .popup-panel,
.rotate-overlay.is-closing .popup-panel { animation: popupOut .16s ease both; }

.rotate-overlay.is-closing {
  pointer-events: none;
  animation: popupBackdropOut .16s ease both;
}

.finish-flash {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 62px;
  font-weight: 1000;
  letter-spacing: .06em;
  text-shadow: 0 7px 0 rgba(0, 0, 0, .26), 0 0 28px rgba(255, 182, 66, .55);
  pointer-events: none;
}

/* Portrait gameplay guard */
.rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  color: var(--white);
  background:
    linear-gradient(rgba(246, 233, 201, .025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(246, 233, 201, .022) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(20,54,81,.94), rgba(3,11,22,.98) 72%);
  background-size: 42px 42px, 42px 42px, auto;
  pointer-events: auto;
}

.rotate-card {
  display: grid;
  justify-items: center;
  gap: 11px;
  width: min(320px, calc(100vw - 36px));
  padding: 22px;
  text-align: center;
}

.rotate-glyph {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(45,230,255,.3);
  border-radius: 16px;
  color: var(--cyan);
  background: rgba(5,20,35,.52);
  box-shadow: inset 0 1px rgba(255,255,255,.05), 0 9px 18px rgba(0,0,0,.2);
}

.rotate-glyph .game-icon { width: 31px; height: 31px; }
.rotate-card h2 { text-transform: uppercase; }
.rotate-card p { margin: 0; color: rgba(255, 248, 232, .68); font-size: 13px; line-height: 1.4; font-weight: 750; }
.rotate-action {
  min-height: 48px;
  margin-top: 3px;
  padding: 0 18px;
  border-radius: 12px;
  font-size: 12px;
}

@keyframes homeIn {
  from { opacity: 0; transform: translateY(14px); }
}

@keyframes gridFloat {
  to { transform: translate3d(-12px, 8px, 0); opacity: .86; }
}

@keyframes brandDraw {
  from { stroke-dashoffset: 420; opacity: .25; }
  to { stroke-dashoffset: 0; opacity: 1; }
}

@keyframes brandInkIdle {
  50% { filter: url(#brandGlow) brightness(1.08); }
}

@keyframes brandWheelSettle {
  from { opacity: 0; transform: translateY(-8px) scale(.9); }
  66% { opacity: 1; transform: translateY(2px) scale(1.025); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes progressReveal {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes medalShimmer {
  0%, 68% { left: -40%; opacity: 0; }
  74% { opacity: .72; }
  88%, 100% { left: 125%; opacity: 0; }
}

@keyframes heroSweep {
  0%, 64% { left: -24%; opacity: 0; }
  70% { opacity: .72; }
  84%, 100% { left: 112%; opacity: 0; }
}

@keyframes popupBackdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popupBackdropOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes popupIn {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes popupOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(5px) scale(.975); }
}

@keyframes resultMotes {
  from { opacity: 0; transform: translateY(8px) scale(.6); }
  32% { opacity: .55; }
  to { opacity: 0; transform: translateY(-18px) scale(1); }
}

@keyframes goPress {
  45% { transform: translateY(4px) scale(.96); }
}

@keyframes hudDropIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes dockRiseIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes clearFeedback {
  45% { border-color: rgba(255,182,66,.46); filter: brightness(1.08); }
}

@keyframes goFeedback {
  45% { border-color: rgba(45,230,255,.52); filter: brightness(1.1); }
}

@keyframes pop {
  from { opacity: 0; transform: translateY(4px) scale(.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.pop-medal,
.finish-flash { animation: pop .28s cubic-bezier(.2,.8,.25,1); }

/* Laptop / tablet landscape: the stage is scaled down, so nudge in-stage UI up a little */
@media (orientation: landscape) and (min-height: 501px) and (max-height: 900px) {
  :root { --hud-h: 58px; }

  .level-label b { font-size: 23px; }
  .ink-bar { height: 20px; }
  .attempts { font-size: 18px; }
  .bottom-hud .btn { min-height: 54px; font-size: 17px; }
  .bottom-hud .go { font-size: 19px; }
}

/* Unified phone-landscape system */
@media (orientation: landscape) and (max-height: 500px) {
  body.phone-landscape { --hud-h: 100px; }

  body.phone-landscape .home {
    padding:
      max(var(--mobile-page-pad), env(safe-area-inset-top))
      max(var(--mobile-page-pad), env(safe-area-inset-right))
      max(var(--mobile-page-pad), env(safe-area-inset-bottom))
      max(var(--mobile-page-pad), env(safe-area-inset-left));
  }

  body.phone-landscape .home-inner {
    width: min(100%, 560px);
    gap: var(--mobile-gap);
    margin-top: 0;
  }

  body.phone-landscape .brand-rider {
    width: clamp(170px, 34vw, 230px);
    margin-bottom: -14px;
  }

  body.phone-landscape h1 { font-size: clamp(32px, 10vh, 42px); }
  body.phone-landscape h1::after { bottom: -7px; height: 2px; }
  body.phone-landscape .tagline { margin-top: 9px; font-size: var(--mobile-body); }
  body.phone-landscape .home-progress,
  body.phone-landscape .home-actions { width: min(100%, 490px); }
  body.phone-landscape .home-progress { gap: 4px; margin-top: 0; padding: 7px 11px; border-radius: var(--mobile-radius); }
  body.phone-landscape #homeCurrent,
  body.phone-landscape #homeProgress { font-size: 12px; }
  body.phone-landscape .progress-track { height: 9px; }
  body.phone-landscape .medal-chip { min-height: 28px; font-size: 12px; }
  body.phone-landscape .home-actions { gap: var(--mobile-gap); margin-top: 0; }
  body.phone-landscape .hero-action { min-height: var(--mobile-button-height); }
  body.phone-landscape .compact-action { min-height: 44px; font-size: var(--mobile-button-text); }
  body.phone-landscape .btn-copy b { font-size: clamp(16px, 4.5vh, 19px); }
  body.phone-landscape .btn-copy small { font-size: 10px; }
  body.phone-landscape .home-art::before,
  body.phone-landscape .home-art::after,
  body.phone-landscape .home-art .stroke { opacity: .04; }

  body.phone-landscape .panel-screen,
  body.phone-landscape .popup-overlay {
    padding:
      max(var(--mobile-page-pad), env(safe-area-inset-top))
      max(var(--mobile-page-pad), env(safe-area-inset-right))
      max(var(--mobile-page-pad), env(safe-area-inset-bottom))
      max(var(--mobile-page-pad), env(safe-area-inset-left));
  }

  body.phone-landscape .levels-panel {
    width: calc(100vw - var(--mobile-page-pad) * 2);
    height: calc(100dvh - var(--mobile-page-pad) * 2);
    max-height: calc(100dvh - var(--mobile-page-pad) * 2);
    border-radius: var(--mobile-radius);
  }

  body.phone-landscape .levels-panel .panel-head {
    min-height: 54px;
    padding: 5px 10px;
  }

  body.phone-landscape .levels-panel .panel-head h2 { font-size: var(--mobile-title); }
  body.phone-landscape .levels-panel .panel-head .icon-btn { width: 44px; height: 44px; }
  body.phone-landscape .levels-panel .world-list { padding: 9px 10px 12px; }
  body.phone-landscape .world-card { margin-bottom: 10px; padding: 10px; border-radius: var(--mobile-radius); }
  body.phone-landscape .world-card-head { gap: 8px; margin-bottom: 8px; padding-bottom: 8px; }
  body.phone-landscape .world-card-head h3 { font-size: 14px; }
  body.phone-landscape .world-progress-chip { min-width: 76px; gap: 4px; }
  body.phone-landscape .world-progress-chip strong { padding: 3px 7px; font-size: 11px; }
  body.phone-landscape .progress-track.mini { width: 76px; height: 6px; }
  body.phone-landscape .level-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  body.phone-landscape .level-tile { min-height: 58px; padding: 6px; border-radius: 10px; }
  body.phone-landscape .lvl-num { font-size: 16px; }
  body.phone-landscape .stars { gap: 2px; font-size: 12px; }

  body.phone-landscape .settings-panel {
    width: min(560px, calc(100vw - var(--mobile-page-pad) * 2));
    max-height: calc(100dvh - var(--mobile-page-pad) * 2);
  }

  body.phone-landscape .settings-panel .panel-head { min-height: 54px; padding: 5px 10px; }
  body.phone-landscape .settings-panel .panel-head .icon-btn { width: 44px; height: 44px; }
  body.phone-landscape .settings-panel .popup-title { font-size: var(--mobile-title); }
  body.phone-landscape .settings-body { gap: 6px; padding: 8px 10px 10px; }
  body.phone-landscape .toggle-row { min-height: 56px; grid-template-columns: 36px minmax(0,1fr) auto; gap: 9px; padding: 6px 9px; }
  body.phone-landscape .setting-icon { width: 32px; height: 32px; border-radius: 9px; }
  body.phone-landscape .setting-icon .game-icon { width: 19px; height: 19px; }
  body.phone-landscape .setting-copy b { font-size: 13px; }
  body.phone-landscape .setting-copy small,
  body.phone-landscape .danger-copy small { font-size: 10.5px; }
  body.phone-landscape .switch { width: 58px; height: 36px; }
  body.phone-landscape .switch i { width: 28px; height: 28px; }
  body.phone-landscape .switch.on i { transform: translateX(22px); }
  body.phone-landscape .switch.on:active i { transform: translateX(22px) scale(.94); }
  body.phone-landscape .danger-zone { padding-top: 8px; }
  body.phone-landscape .compact-danger { min-height: 44px; padding-inline: 12px; font-size: 11px; }

  body.phone-landscape .modal.popup-panel {
    max-width: calc(100vw - var(--mobile-page-pad) * 2);
    max-height: calc(100dvh - var(--mobile-page-pad) * 2);
    gap: 6px;
    padding: 11px 14px 13px;
  }

  body.phone-landscape .modal.popup-panel .popup-title { font-size: var(--mobile-title); }
  body.phone-landscape .modal.popup-panel p { font-size: 12px; }
  body.phone-landscape .popup-emblem { width: 38px; height: 38px; border-radius: 11px; }
  body.phone-landscape .popup-emblem .game-icon { width: 21px; height: 21px; }
  body.phone-landscape .popup-actions { gap: 7px; margin-top: 2px; }
  body.phone-landscape .popup-actions .btn { min-height: 48px; font-size: 12px; }
  body.phone-landscape .pause-modal,
  body.phone-landscape .result-modal { width: min(390px, calc(100vw - var(--mobile-page-pad) * 2)) !important; }
  body.phone-landscape .small-confirm,
  body.phone-landscape .compact-dialog,
  body.phone-landscape .unlock-modal { width: min(350px, calc(100vw - var(--mobile-page-pad) * 2)) !important; }
  body.phone-landscape .medal-badge { min-width: 112px; padding: 6px 14px; font-size: 11px; }

  body.phone-landscape .top-hud { top: 14px; width: min(1040px, calc(100% - 32px)); }
  body.phone-landscape #pauseBtn { width: 100px; height: 100px; font-size: 30px; }
  body.phone-landscape .level-label { min-width: 130px; }
  body.phone-landscape .level-label small { font-size: 20px; }
  body.phone-landscape .level-label b { font-size: 31px; }
  body.phone-landscape .ink-title { font-size: 21px; }
  body.phone-landscape .ink-bar { height: 29px; }
  body.phone-landscape .ink-wrap { min-width: 340px; }
  body.phone-landscape .attempts { min-width: 112px; font-size: 26px; }
  body.phone-landscape .bottom-hud {
    bottom: max(18px, env(safe-area-inset-bottom));
    gap: 10px;
    padding: 9px;
    border-radius: 18px;
  }

  body.phone-landscape .bottom-hud .btn {
    min-width: 184px;
    min-height: 100px;
    font-size: 27px;
  }

  body.phone-landscape .bottom-hud .go { min-width: 210px; font-size: 30px; }
  body.phone-landscape .toast { top: 120px; max-width: 620px; padding: 16px 24px; font-size: 28px; }
  body.phone-landscape .fail-banner {
    bottom: 142px;
    gap: 16px;
    padding: 14px 16px 14px 22px;
    border-radius: 17px;
    font-size: 24px;
  }

  body.phone-landscape .fail-banner .btn {
    min-height: 100px;
    gap: 9px;
    padding-inline: 26px;
    font-size: 24px;
  }
}

/* Portrait home on phones */
@media (orientation: portrait) and (max-width: 560px) {
  .home { padding-bottom: clamp(20px, 8vh, 60px); }
  .home-inner { width: 100%; gap: clamp(8px, 1.8vh, 16px); }
  .brand-rider { width: min(72vw, 320px); }
  h1 { font-size: clamp(40px, 12vw, 64px); }
  .tagline { font-size: clamp(14px, 4vw, 18px); }
  .home-progress,
  .home-actions { width: 100%; min-width: 0; }
  .home-progress { padding-inline: 12px; }
  .secondary-actions { gap: 10px; }
  .compact-action { padding-inline: 10px; }
  .btn-icon { width: 18px; height: 18px; }
}

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