/* ============================================================
   SKETCHFALL — Marketplace Edition UI
   Cohesive "midnight sketchbook" art direction, responsive HUD,
   safe-area support, and accessible interaction states.
   ============================================================ */

@font-face {
  font-family: "Lilita One";
  src: url("../assets/fonts/LilitaOne.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("../assets/fonts/Nunito-500.ttf") format("truetype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("../assets/fonts/Nunito-600.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("../assets/fonts/Nunito-700.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("../assets/fonts/Nunito-800.ttf") format("truetype");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --night-950: #090c19;
  --night-900: #10152b;
  --night-850: #171c36;
  --night-800: #1c2341;
  --night-700: #293052;
  --paper: #fff7e6;
  --paper-soft: #ddd6ca;
  --muted: #aaa9bc;
  --line: rgba(255, 247, 230, 0.13);
  --line-strong: rgba(255, 247, 230, 0.22);
  --amber: #f7b733;
  --amber-light: #ffd875;
  --amber-dark: #a95d12;
  --coral: #ed665c;
  --teal: #35d0b6;
  --teal-dark: #147f75;
  --violet: #8172f5;
  --violet-dark: #4939b9;
  --green: #54d58a;
  --danger: #f16c63;
  --shadow-lg: 0 24px 70px rgba(3, 5, 15, 0.54);
  --shadow-md: 0 12px 28px rgba(3, 5, 15, 0.34);
  --font-ui: "Nunito", "Segoe UI", system-ui, sans-serif;
  --font-display: "Lilita One", "Arial Black", system-ui, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--night-950);
  color: var(--paper);
  font-family: var(--font-ui);
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
}

button, input { font: inherit; }
button { -webkit-user-select: none; user-select: none; }

#app, #stage {
  position: relative;
  width: 100%;
  height: 100%;
}

#stage {
  --game-left: 0px;
  --game-top: 0px;
  --game-width: 100vw;
  --game-height: 100vh;
  overflow: hidden;
  isolation: isolate;
  container-type: size;
  container-name: stage;
  background-color: #10152b;
  background-image: url("../assets/art/background.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

#stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .23;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(to bottom, black, transparent 90%);
}

#stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: .045;
  background-image: url("../assets/art/noise.png");
  background-repeat: repeat;
  background-size: 256px 256px;
  mix-blend-mode: soft-light;
}

canvas {
  position: absolute;
  z-index: 1;
  display: block;
  width: var(--game-width);
  height: var(--game-height);
  left: var(--game-left);
  top: var(--game-top);
  max-width: none;
  touch-action: none;
  cursor: crosshair;
  outline: none;
  box-shadow: 0 22px 70px rgba(3, 4, 14, .35);
}

#stage.portrait canvas {
  border-block: 1px solid rgba(255, 247, 230, .12);
  box-shadow: 0 18px 55px rgba(3, 4, 14, .5);
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility .22s;
}
#hud.live { opacity: 1; visibility: visible; }

.hud-status {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: calc(var(--game-left) + 14px);
  display: flex;
  align-items: stretch;
  gap: 8px;
  max-width: min(58%, 610px);
  min-height: 55px;
  padding: 6px;
  border: 1px solid rgba(255, 247, 230, .14);
  border-radius: 17px;
  color: var(--paper);
  background: linear-gradient(180deg, rgba(25, 31, 58, .94), rgba(13, 17, 35, .91));
  box-shadow: 0 9px 24px rgba(4, 6, 16, .28), inset 0 1px 0 rgba(255,255,255,.05);
  backdrop-filter: blur(12px);
}

.level-card, .objective-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 2px 10px;
}
.level-card { width: clamp(138px, 19vw, 214px); }
.level-card strong {
  display: block;
  overflow: hidden;
  color: var(--paper);
  font-size: clamp(12px, 1.25vw, 15px);
  font-weight: 800;
  line-height: 1.22;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--amber-light);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.25px;
  line-height: 1.1;
}

#inkWrap {
  display: flex;
  flex: 1 1 170px;
  flex-direction: column;
  justify-content: center;
  min-width: 126px;
  max-width: 230px;
  padding: 3px 10px;
  border-inline: 1px solid var(--line);
}
.ink-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  color: var(--paper-soft);
  font-size: 9px;
  letter-spacing: 1.3px;
}
.ink-title { display: inline-flex; align-items: center; gap: 5px; }
.ink-drop {
  display: inline-block;
  width: 14px;
  height: 14px;
  object-fit: contain;
  pointer-events: none;
}
.star-pips { display: flex; gap: 2px; }
.star-pips span {
  color: rgba(255,255,255,.2);
  font-size: 11px;
  line-height: 1;
  transition: color .18s, transform .18s, text-shadow .18s;
}
.star-pips span.on {
  color: var(--amber-light);
  text-shadow: 0 0 9px rgba(255, 216, 117, .55);
  transform: translateY(-1px);
}
#inkTrack {
  position: relative;
  height: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.3);
}
#inkFill {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #35d0b6, #6c78ef);
  transition: width .12s linear, background .2s;
}
#inkFill::after {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 45%;
  border-radius: inherit;
  background: rgba(255,255,255,.24);
}
#inkTrack.mid #inkFill { background: linear-gradient(90deg, #ffd064, #f0a327); }
#inkTrack.low #inkFill { background: linear-gradient(90deg, #f68c65, #e94d55); }

.objective-card { min-width: 91px; }
.objective-value { display: flex; align-items: center; gap: 7px; }
#targetText { color: var(--paper); font-size: 13px; font-weight: 800; white-space: nowrap; }
#targetPips { display: flex; align-items: center; gap: 3px; }
.epip {
  width: 9px;
  height: 9px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 50%;
  background: linear-gradient(145deg, #ffd989, #e36f31);
  box-shadow: 0 1px 4px rgba(224, 121, 48, .45);
  transition: opacity .18s, transform .18s, filter .18s;
}
.epip.off { opacity: .2; filter: grayscale(1); transform: scale(.72); }

.hud-actions {
  position: absolute;
  top: max(15px, env(safe-area-inset-top));
  right: calc(100% - var(--game-left) - var(--game-width) + 14px);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  pointer-events: auto;
}

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 16px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 13px;
  outline: none;
  color: var(--paper);
  background: linear-gradient(180deg, #37405f, #252c49);
  box-shadow: 0 4px 0 #13182d, 0 8px 18px rgba(3, 5, 15, .24), inset 0 1px 0 rgba(255,255,255,.08);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .15px;
  line-height: 1;
  transform: translateY(0);
  transition: transform .1s ease, filter .16s ease, box-shadow .1s ease, border-color .16s, opacity .16s;
}
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(110deg, transparent 20%, rgba(255,255,255,.09), transparent 76%);
  transform: translateX(-110%);
  transition: transform .32s ease;
}
@media (hover: hover) and (pointer: fine) {
  .btn:hover { filter: brightness(1.1); border-color: rgba(255,255,255,.22); }
  .btn:hover::after { transform: translateX(110%); }
}
.btn:active, .btn.is-down {
  transform: translateY(3px) scale(.985);
  box-shadow: 0 1px 0 #13182d, 0 3px 8px rgba(3,5,15,.2);
  filter: brightness(.96);
}
.btn:focus-visible, .switch:focus-visible, .text-danger:focus-visible {
  outline: 3px solid rgba(255, 216, 117, .9);
  outline-offset: 3px;
}
.btn:disabled {
  opacity: .36;
  cursor: default;
  filter: grayscale(.35);
  pointer-events: none;
}
.btn .ui-icon, .section-icon .ui-icon, .result-emblem .ui-icon, #orientationTip .ui-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.btn.icon { width: 44px; padding: 0; }
.btn.subtle { background: linear-gradient(180deg, rgba(54,64,96,.96), rgba(34,41,70,.96)); }
.btn.primary {
  color: #302006;
  border-color: rgba(255, 239, 183, .48);
  background: linear-gradient(180deg, #ffda73, #f4ad2e);
  box-shadow: 0 4px 0 #a95d12, 0 8px 20px rgba(191, 111, 22, .26), inset 0 1px 0 rgba(255,255,255,.45);
}
.btn.primary:active { box-shadow: 0 1px 0 #a95d12, 0 3px 8px rgba(3,5,15,.2); }
.btn.danger {
  color: #fff7ee;
  border-color: rgba(255,255,255,.17);
  background: linear-gradient(180deg, #f57d72, #d44a4c);
  box-shadow: 0 4px 0 #842a35, 0 8px 20px rgba(174,42,50,.24);
}
.btn.quiet { color: var(--paper-soft); background: rgba(255,255,255,.055); box-shadow: none; }
.btn.wide { width: 100%; }
.btn.mode-drop {
  color: #fff;
  border-color: rgba(186,180,255,.36);
  background: linear-gradient(180deg, #8d80fb, #6655dc);
  box-shadow: 0 4px 0 #3d2d9c, 0 8px 18px rgba(52,39,154,.28);
}
.btn.mode-pin {
  color: #362205;
  border-color: rgba(255,236,171,.45);
  background: linear-gradient(180deg, #ffd469, #e99a20);
  box-shadow: 0 4px 0 #99520d, 0 8px 18px rgba(153,82,13,.25);
}
.mode-button { min-width: 86px; padding: 0 11px; }
.mode-button .btn-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.mode-button small { font-size: 7px; letter-spacing: 1px; opacity: .72; }
.mode-button #modeLabel { font-size: 11px; letter-spacing: .65px; }
.release-button, .retry-button { padding-inline: 13px; }
.btn.pulse { animation: releasePulse 1.5s ease-in-out infinite; }
@keyframes releasePulse {
  0%, 100% { transform: translateY(0); filter: brightness(1); }
  50% { transform: translateY(-1px); filter: brightness(1.08); }
}

/* ---------- Hint, toast, orientation ---------- */
#hint {
  position: absolute;
  z-index: 5;
  top: calc(var(--game-top) + 84px);
  left: calc(var(--game-left) + (var(--game-width) / 2));
  max-width: min(620px, calc(var(--game-width) - 30px));
  padding: 9px 16px;
  border: 1px solid rgba(255,247,230,.16);
  border-radius: 12px;
  color: var(--paper);
  background: rgba(11, 15, 31, .78);
  box-shadow: 0 7px 20px rgba(3,4,13,.22);
  backdrop-filter: blur(10px);
  font-size: clamp(11px, 1.3vw, 13px);
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) translateY(-5px);
  transition: opacity .28s ease, transform .28s ease;
}
#hud.live ~ #hint { opacity: 1; transform: translateX(-50%) translateY(0); }
#hud.live ~ #hint.dim { opacity: .22; }
#hint:empty { display: none; }
#hint.invalid { color: #ffe5df; border-color: rgba(241,108,99,.48); background: rgba(93,31,42,.88); }

#toast {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 14px));
  max-width: calc(100% - 28px);
  padding: 10px 16px;
  border: 1px solid rgba(255,216,117,.3);
  border-radius: 13px;
  color: var(--paper);
  background: rgba(12, 16, 32, .94);
  box-shadow: 0 10px 30px rgba(2,3,10,.34);
  font-size: 13px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: rgba(241,108,99,.55); }

#orientationTip {
  position: absolute;
  z-index: 5;
  display: none;
  align-items: center;
  gap: 7px;
  left: 50%;
  top: calc(var(--game-top) + var(--game-height) + 18px);
  color: rgba(255,247,230,.48);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .45px;
  transform: translateX(-50%);
  white-space: nowrap;
}
#orientationTip .ui-icon { width: 15px; height: 15px; }
#stage.portrait #hud.live ~ #orientationTip { display: flex; }

/* ---------- Overlays and panels ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 35%, rgba(101,84,194,.17), transparent 48%),
    rgba(7, 10, 22, .76);
  backdrop-filter: blur(12px) saturate(.82);
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s;
}
.overlay.show { opacity: 1; visibility: visible; }
.overlay:not(.show) { pointer-events: none; }

.panel {
  position: relative;
  width: min(650px, 100%);
  max-height: calc(100dvh - max(36px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
  overflow: hidden auto;
  padding: 30px 32px 27px;
  border: 1px solid rgba(255, 222, 151, .22);
  border-radius: 24px;
  color: var(--paper);
  background:
    linear-gradient(180deg, rgba(255,255,255,.045), transparent 28%),
    linear-gradient(155deg, rgba(33,40,72,.98), rgba(16,20,40,.985));
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,.07);
  text-align: center;
  transform: translateY(10px) scale(.975);
  transition: transform .24s cubic-bezier(.2,.85,.25,1), opacity .2s ease;
}
.overlay.show .panel { transform: translateY(0) scale(1); }
.panel::before {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(255,255,255,.045);
  border-radius: 17px;
  pointer-events: none;
}
.panel-sm { width: min(440px, 100%); }
.panel-wide { width: min(760px, 100%); }
.level-panel { width: min(820px, 100%); }
.title-panel { width: min(570px, 100%); }
.panel h2 {
  color: var(--paper);
  font-family: var(--font-display);
  font-size: clamp(25px, 4vw, 34px);
  font-weight: 400;
  letter-spacing: .5px;
  line-height: 1;
}
.panel p {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.55;
}
.panel p b { color: var(--paper); }
.panel .lede {
  width: min(440px, 100%);
  margin: 0 auto 20px;
  color: var(--paper-soft);
  font-size: 14px;
}
.panel-intro { margin: 10px auto 17px; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 6px;
  text-align: left;
}
.panel-header .eyebrow { margin-bottom: 5px; }
.section-icon {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(255,216,117,.25);
  border-radius: 14px;
  color: var(--amber-light);
  background: rgba(247,183,51,.09);
}
.section-icon .ui-icon { width: 23px; height: 23px; }
.split-header { justify-content: space-between; }
.header-title { display: flex; align-items: center; gap: 12px; }
.split-header > p { margin: 0; text-align: right; font-size: 12px; }

.row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px; }
.panel-actions { margin-top: 20px; }
.panel-actions .btn { min-width: 122px; }
.stack-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.two-col, .three-col { display: grid; gap: 10px; }
.two-col { grid-template-columns: 1fr 1fr; }
.three-col { grid-template-columns: repeat(3, 1fr); }
.three-col .btn { padding-inline: 8px; }

/* ---------- Brand and main menu ---------- */
.brand-mark {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 190px;
  height: 80px;
  margin: 0 auto 4px;
}
.wordmark {
  display: flex;
  justify-content: center;
  align-items: baseline;
  font-family: var(--font-display);
  font-size: clamp(36px, 7vw, 52px);
  font-weight: 400;
  letter-spacing: .9px;
  line-height: .95;
  text-shadow: 0 4px 0 rgba(3,5,14,.3);
}
.wordmark b { color: var(--amber); font-weight: 400; }
.tag {
  margin: 7px 0 13px;
  color: var(--teal) !important;
  font-size: 11px !important;
  font-weight: 800 !important;
  letter-spacing: 2.1px;
  text-transform: uppercase;
}
.hero-action { margin-bottom: 13px; }
.btn-play { min-width: 222px; min-height: 54px; font-size: 14px; letter-spacing: .55px; }
.btn-play .ui-icon { width: 22px; height: 22px; }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.menu-button { flex-direction: column; min-height: 66px; padding: 8px; color: var(--paper-soft); font-size: 11px; }
.menu-button .ui-icon { width: 21px; height: 21px; color: var(--amber-light); }
.meta-line { margin-top: 16px; color: var(--paper-soft); font-size: 12px; font-weight: 700; }
.edition { margin-top: 7px; color: rgba(255,247,230,.34); font-size: 8px; letter-spacing: 1.25px; }

/* ---------- Loading ---------- */
#ovLoad { z-index: 30; background: var(--night-900); }
.load-panel { width: min(450px, 100%); border-color: transparent; background: transparent; box-shadow: none; }
.load-panel::before { display: none; }
.load-panel .brand-mark { transform: scale(.9); margin-bottom: 0; }
.load-panel .wordmark { font-size: clamp(38px, 8vw, 50px); }
.load-well { margin: 20px auto 0; width: min(330px, 100%); }
.load-track {
  position: relative;
  height: 11px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px;
  background: rgba(255,255,255,.07);
  box-shadow: inset 0 2px 5px rgba(0,0,0,.32);
}
#loadFill {
  position: relative;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--violet), var(--amber));
  transition: width .12s linear;
}
#loadFill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.38), transparent);
  transform: translateX(-100%);
  animation: loadingSheen 1.1s linear infinite;
}
.load-meta { display: flex; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 10px; letter-spacing: .8px; }
#loadPct { color: var(--amber-light); font-variant-numeric: tabular-nums; }
@keyframes loadingSheen { to { transform: translateX(100%); } }

/* ---------- How to play ---------- */
.how-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; text-align: left; }
.how-card {
  display: flex;
  gap: 11px;
  min-height: 105px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255,255,255,.035);
}
.step-no {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(255,216,117,.22);
  border-radius: 10px;
  color: var(--amber-light);
  background: rgba(247,183,51,.08);
  font-size: 10px;
  letter-spacing: .5px;
}
.how-card h3 { margin: 2px 0 5px; color: var(--paper); font-size: 11px; letter-spacing: .75px; }
.how-card p { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.43; }
.drop-text { color: #a99fff !important; }
.pin-text { color: var(--amber-light) !important; }
.score-guide { display: flex; justify-content: center; flex-wrap: wrap; gap: 9px 18px; margin: 14px 0 11px; color: var(--muted); font-size: 10px; }
.score-guide i { margin-right: 4px; color: var(--amber-light); font-style: normal; letter-spacing: 1px; }
.keys { display: flex; justify-content: center; flex-wrap: wrap; gap: 7px 14px; color: var(--muted); font-size: 10px; }
.keys span { white-space: nowrap; }
kbd {
  display: inline-block;
  min-width: 25px;
  margin-right: 3px;
  padding: 2px 6px;
  border: 1px solid rgba(255,255,255,.18);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--paper-soft);
  background: rgba(255,255,255,.06);
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 800;
  text-align: center;
}

/* ---------- Settings ---------- */
.set-list { display: flex; flex-direction: column; gap: 9px; margin: 20px 0 14px; text-align: left; }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 70px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255,255,255,.035);
}
.setting-copy { min-width: 0; }
.set-row .lab { color: var(--paper); font-size: 13px; font-weight: 800; }
.set-row .sub { margin-top: 3px; color: var(--muted); font-size: 10.5px; font-weight: 600; line-height: 1.35; }
.switch {
  position: relative;
  width: 52px;
  height: 32px;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 999px;
  outline: none;
  background: #343a56;
  box-shadow: inset 0 2px 5px rgba(0,0,0,.35);
  cursor: pointer;
  transition: background .18s, border-color .18s;
}
.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #d9d9e1;
  box-shadow: 0 3px 7px rgba(0,0,0,.28);
  transition: transform .18s ease, background .18s;
}
.switch.on { border-color: rgba(255,224,150,.38); background: linear-gradient(180deg, #ffd269, #e89a24); }
.switch.on .knob { background: #fffaf0; transform: translateX(20px); }
.text-danger {
  padding: 5px;
  border: 0;
  border-radius: 5px;
  outline: 0;
  color: #f39791;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}
@media (hover:hover) { .text-danger:hover { color: #ffb2ac; } }

/* ---------- Level selection ---------- */
#levelGrid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
  max-height: min(440px, calc(100dvh - 240px));
  margin: 18px 0 4px;
  padding: 2px 8px 8px 2px;
  overflow: hidden auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(255,255,255,.2) transparent;
}
.chapter-label {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px 2px;
  color: var(--amber-light);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-align: left;
  text-transform: uppercase;
}
.chapter-label::after { content: ""; height: 1px; flex: 1; background: linear-gradient(90deg, rgba(255,216,117,.25), transparent); }
.lvBtn {
  aspect-ratio: 1.12 / 1;
  min-width: 0;
  min-height: 0;
  height: auto;
  flex-direction: column;
  gap: 3px;
  padding: 9px 5px 8px;
  border-radius: 15px;
}
.lvBtn .n { color: var(--paper); font-family: var(--font-display); font-size: 23px; font-weight: 400; line-height: 1; }
.lvBtn .nm { width: 100%; overflow: hidden; color: var(--paper-soft); font-size: 8.5px; font-weight: 700; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.lvBtn .s { min-height: 12px; color: var(--amber-light); font-size: 10px; letter-spacing: 1px; line-height: 1; }
.lvBtn.locked { opacity: .35; cursor: not-allowed; filter: grayscale(.5); box-shadow: 0 3px 0 #13182d; }
.lvBtn.current { border-color: rgba(255,216,117,.7); box-shadow: 0 4px 0 #9a590e, 0 0 0 2px rgba(255,216,117,.28); }

/* ---------- Results and pause ---------- */
.result-panel { padding-top: 28px; }
.result-emblem {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 13px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 19px;
  transform: rotate(-3deg);
}
.result-emblem .ui-icon { width: 30px; height: 30px; stroke-width: 2.2; }
.pause-emblem { color: #c5c0ff; background: rgba(129,114,245,.13); }
.win-emblem { color: #b9ffd7; background: rgba(53,208,182,.13); }
.fail-emblem { color: #ffd2cd; background: rgba(241,108,99,.13); }
.warning-emblem { color: var(--amber-light); background: rgba(247,183,51,.12); }
.result-panel > .eyebrow { margin-bottom: 7px; }
.result-panel h2 { margin-bottom: 10px; }
.result-panel > p { margin: 0 auto; width: min(350px, 100%); }
.stars { min-height: 50px; margin: 7px 0 9px; font-size: 39px; letter-spacing: 7px; filter: drop-shadow(0 4px 9px rgba(236,164,45,.32)); }
.stars .star { display: inline-block; color: var(--amber-light); transform: scale(0); }
.stars .star.off { color: rgba(255,255,255,.14); filter: none; }
.stars.pop .star { animation: starPop .4s cubic-bezier(.2,1.35,.35,1) forwards; }
.stars.pop .star:nth-child(2) { animation-delay: .1s; }
.stars.pop .star:nth-child(3) { animation-delay: .2s; }
@keyframes starPop { 0%{transform:scale(0) rotate(-20deg)} 70%{transform:scale(1.16) rotate(5deg)} 100%{transform:scale(1) rotate(0)} }

/* ---------- Scrollbars ---------- */
.panel::-webkit-scrollbar, #levelGrid::-webkit-scrollbar { width: 7px; }
.panel::-webkit-scrollbar-track, #levelGrid::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb, #levelGrid::-webkit-scrollbar-thumb { border-radius: 8px; background: rgba(255,255,255,.17); }

/* ---------- Responsive gameplay ---------- */
@media (max-width: 1120px) {
  .hud-status { max-width: 55%; }
  .level-card { width: clamp(120px, 18vw, 178px); }
  .objective-card { min-width: 76px; }
  #targetPips { display: none; }
  .release-button .action-text, .retry-button .action-text { display: none; }
  .release-button, .retry-button { width: 44px; padding: 0; }
}

@media (max-width: 760px) {
  .hud-status { left: calc(var(--game-left) + 8px); top: max(8px, env(safe-area-inset-top)); max-width: calc(100% - 300px); min-height: 50px; padding: 5px; border-radius: 14px; }
  .hud-actions { right: calc(100% - var(--game-left) - var(--game-width) + 8px); top: max(10px, env(safe-area-inset-top)); gap: 5px; }
  .btn.icon, .hud-actions .btn { min-width: 42px; min-height: 42px; height: 42px; }
  .hud-actions .btn.icon, .hud-actions .release-button, .hud-actions .retry-button { width: 42px; }
  .mode-button { min-width: 67px !important; padding: 0 8px !important; }
  .mode-button .ui-icon { display: none; }
  .level-card { width: 132px; padding-inline: 7px; }
  .objective-card { display: none; }
  #inkWrap { min-width: 105px; padding-inline: 7px; border-right: 0; }
  #hint { top: calc(var(--game-top) + 69px); }
}

/* Portrait uses empty space around the contained 3:2 world deliberately:
   stats above, controls below, canvas remains undistorted and fully visible. */
#stage.portrait .hud-status {
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  width: auto;
  max-width: none;
}
#stage.portrait .hud-actions {
  top: auto;
  right: auto;
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 8px));
  left: 50%;
  width: max-content;
  max-width: calc(100% - 18px);
  padding: 7px;
  gap: 5px;
  border: 1px solid rgba(255,247,230,.13);
  border-radius: 17px;
  background: linear-gradient(180deg, rgba(29,35,65,.95), rgba(13,17,35,.96));
  box-shadow: 0 11px 30px rgba(3,5,15,.35), inset 0 1px 0 rgba(255,255,255,.055);
  transform: translateX(-50%);
}
#stage.portrait #hint {
  top: max(82px, calc(var(--game-top) - 48px));
  max-width: calc(100% - 28px);
}
#stage.portrait #toast { bottom: max(87px, calc(env(safe-area-inset-bottom) + 82px)); }

@media (max-width: 520px) {
  .panel { padding: 23px 18px 21px; border-radius: 20px; }
  .title-panel { padding-top: 18px; }
  .brand-mark { height: 68px; transform: scale(.86); margin-top: -4px; margin-bottom: -3px; }
  .wordmark { font-size: 39px; }
  .panel .lede { font-size: 12.5px; margin-bottom: 16px; }
  .menu-grid { gap: 7px; }
  .menu-button { min-height: 61px; font-size: 10px; }
  .edition { display: none; }
  .level-card { width: 43%; }
  #inkWrap { flex: 1; max-width: none; }
  .objective-card { display: flex; min-width: 75px; padding-inline: 7px; }
  #stage.portrait .hud-status { min-height: 57px; }
  #stage.portrait .hud-actions .btn { min-width: 40px; width: 40px; height: 42px; padding: 0; }
  #stage.portrait .hud-actions .mode-button { min-width: 64px !important; width: 64px; }
  #stage.portrait .hud-actions { padding: 6px; }
  .how-grid { grid-template-columns: 1fr; }
  .how-card { min-height: 0; }
  .score-guide { gap: 6px 11px; }
  .keys { display: none; }
  .split-header { align-items: flex-start; flex-direction: column; gap: 8px; }
  .split-header > p { text-align: left; }
  #levelGrid { grid-template-columns: repeat(4, minmax(0, 1fr)); max-height: calc(100dvh - 230px); gap: 7px; }
  .lvBtn { border-radius: 12px; }
  .lvBtn .n { font-size: 20px; }
  .lvBtn .nm { display: none; }
  .chapter-label { padding-top: 7px; }
}

@media (max-width: 370px) {
  .panel { padding-inline: 14px; }
  .menu-button span { font-size: 9px; }
  .level-card { width: 38%; padding-inline: 5px; }
  .level-card strong { font-size: 10.5px; }
  #inkWrap { min-width: 86px; padding-inline: 5px; }
  .objective-card { display: flex; min-width: 57px; padding-inline: 4px; }
  .objective-card .eyebrow { font-size: 7px; letter-spacing: .8px; }
  #targetText { font-size: 11px; }
  #stage.portrait .hud-actions { gap: 4px; padding-inline: 5px; }
  #stage.portrait .hud-actions .btn { min-width: 37px; width: 37px; height: 40px; min-height: 40px; border-radius: 11px; }
  #stage.portrait .hud-actions .mode-button { min-width: 57px !important; width: 57px; }
  #stage.portrait .hud-actions .ui-icon { width: 18px; height: 18px; }
  #levelGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Short landscape: menus become compact and scroll safely. */
@media (max-height: 540px) and (orientation: landscape) {
  .hud-status {
    top: max(8px, env(safe-area-inset-top));
    left: calc(var(--game-left) + 8px);
    max-width: 215px;
    min-height: 48px;
    padding: 4px;
    gap: 3px;
  }
  .hud-status .level-card { width: 105px; padding-inline: 6px; }
  .hud-status .level-card strong { font-size: 10.5px; }
  .hud-status #inkWrap { min-width: 88px; padding-inline: 6px; border-right: 0; }
  .hud-status .objective-card { display: none; }
  .hud-actions { top: max(9px, env(safe-area-inset-top)); right: calc(100% - var(--game-left) - var(--game-width) + 8px); gap: 4px; }
  .hud-actions .btn, .hud-actions .btn.icon { width: 40px; min-width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 11px; }
  .hud-actions .mode-button { width: 64px; min-width: 64px; padding: 0 7px; }
  .hud-actions .mode-button .ui-icon { display: none; }
  #hint { top: calc(var(--game-top) + 70px); }
  .overlay { align-items: flex-start; padding-block: 10px; }
  .panel { margin: auto; max-height: calc(100dvh - 20px); padding: 18px 22px 16px; border-radius: 18px; }
  .title-panel .brand-mark { display: none; }
  .title-panel .wordmark { font-size: 34px; }
  .title-panel .tag { margin-block: 3px 7px; }
  .title-panel .lede { margin-bottom: 10px; font-size: 11.5px; }
  .btn-play { min-height: 44px; }
  .menu-button { min-height: 48px; flex-direction: row; }
  .meta-line { margin-top: 9px; }
  .edition { display: none; }
  .panel-header { margin-bottom: 2px; }
  .panel-header .section-icon { width: 38px; height: 38px; }
  .panel h2 { font-size: 24px; }
  .panel-intro { margin: 5px 0 9px; font-size: 11.5px; }
  .how-card { min-height: 76px; padding: 9px; }
  .how-card p { font-size: 10px; }
  .score-guide { margin-block: 8px 6px; }
  .keys { display: none; }
  .panel-actions { margin-top: 10px; }
  #levelGrid { grid-template-columns: repeat(8, minmax(0, 1fr)); max-height: calc(100dvh - 150px); margin-top: 9px; gap: 6px; }
  .chapter-label { padding-top: 5px; }
  .lvBtn .nm { display: none; }
  .result-emblem { width: 45px; height: 45px; margin-bottom: 7px; }
  .result-panel h2 { margin-bottom: 5px; }
  .stars { min-height: 34px; margin: 2px 0 4px; font-size: 29px; }
  .stack-actions { margin-top: 10px; }
}

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

/* ---------- Curated PNG artwork integration ---------- */
img.ui-icon,
img.score-star,
img.mini-star,
img.star,
.lvBtn .s img,
.epip {
  display: inline-block;
  object-fit: contain;
  image-rendering: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.brand-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 8px rgba(3, 5, 15, .3));
  animation: brandFloat 3.2s ease-in-out infinite;
}
@keyframes brandFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
.btn .ui-icon {
  width: 22px;
  height: 22px;
}
.btn.primary .ui-icon {
  filter: brightness(.32) saturate(1.4);
}
.mode-button .ui-icon { width: 21px; height: 21px; }
.section-icon .ui-icon { width: 25px; height: 25px; }
.menu-button .ui-icon { width: 24px; height: 24px; }
.result-emblem .ui-icon { width: 34px; height: 34px; }
#orientationTip .ui-icon { width: 17px; height: 17px; }
.star-pips img.score-star {
  width: 13px;
  height: 13px;
  opacity: .2;
  filter: grayscale(1);
  transition: opacity .18s, filter .18s, transform .18s;
}
.star-pips img.score-star.on {
  opacity: 1;
  filter: none;
  transform: translateY(-1px) scale(1.04);
}
.score-guide i {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  margin-right: 5px;
  vertical-align: middle;
}
.score-guide img.mini-star { width: 12px; height: 12px; }
.stars img.star {
  width: 46px;
  height: 46px;
  margin-inline: 2px;
}
.lvBtn .s {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.lvBtn .s img { width: 12px; height: 12px; }
.lvBtn .s img.off { opacity: .25; filter: grayscale(1); }
.epip {
  width: 14px;
  height: 14px;
  border: 0;
  background: none;
  box-shadow: none;
}
.epip.off { opacity: .18; filter: grayscale(1); transform: scale(.76); }

@media (max-width: 760px) {
  .mode-button .ui-icon { display: none; }
}
@media (max-width: 370px) {
  #stage.portrait .hud-actions .ui-icon { width: 19px; height: 19px; }
}
@media (max-height: 540px) and (orientation: landscape) {
  .hud-actions .mode-button .ui-icon { display: none; }
}
