:root {
  --bg: #2a1a12;
  --panel: rgba(62, 36, 22, 0.82);
  --line: rgba(255, 214, 150, 0.35);
  --text: #fff6e8;
  --muted: #e6c8a4;
  --cyan: #00e5ff;
  --gold: #ffb703;
  --magenta: #ff2e93;
  --emerald: #10e89b;
  --top: 108px;
  --bottom: 188px;
  color-scheme: dark;
}

* { box-sizing: border-box; user-select: none; -webkit-user-select: none; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #24160f;
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

body.night { background: #0c121c; }

#boot {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 18%, rgba(255, 196, 110, 0.22), transparent 46%),
    linear-gradient(180deg, #3a2416 0%, #1a0f0a 100%);
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
#boot.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-card { width: min(440px, 100%); text-align: center; }
.boot-mark {
  margin: 0 0 8px;
  color: #ffd27a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.boot-card h1 {
  margin: 0;
  color: #fff6e8;
  font-size: 42px;
  line-height: 0.95;
  letter-spacing: -0.03em;
}
.boot-feed {
  position: relative;
  display: flex;
  align-items: center;
  height: 86px;
  margin: 18px 0 10px;
}
.boot-rat {
  width: 118px;
  height: auto;
  flex: none;
  margin-left: -10px;
  pointer-events: none;
}
.boot-cheese {
  position: absolute;
  left: 0;
  top: 50%;
  z-index: 2;
  width: 42px;
  height: auto;
  transform: translateY(-50%);
  pointer-events: none;
  transition: left 0.2s ease;
}
.boot-bar {
  flex: 1;
  height: 10px;
  margin: 0;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 236, 210, 0.14);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.35);
}
#boot-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffb703, #ffe08a);
  transition: width 0.2s ease;
}
#boot-status { margin: 0; color: #e6c8a4; font-size: 13px; }
#btn-quality { display: none; }

#canvas-container { position: fixed; inset: 0; z-index: 1; touch-action: none; }
#canvas-container canvas { display: block; width: 100%; height: 100%; }

.hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 8px;
  gap: 8px;
}

.btn, .drawer, .modal, .win, .coach-card, .mission, .score-jewel, .actions, .dir-btn, .rot button {
  pointer-events: auto;
}

.deck, .console-dock, .console, .tilt-ring {
  pointer-events: none;
}

.deck {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
}
.hud-score {
  position: fixed;
  left: 50%;
  top: 14px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px 7px;
  border-radius: 16px;
  background: rgba(48, 26, 14, 0.55);
  border: 1px solid rgba(255, 214, 150, 0.4);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 236, 200, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transform: translateX(-50%);
  pointer-events: none;
}

.mission, .score-jewel, .actions {
  background: rgba(72, 40, 24, 0.78);
  border: 1px solid rgba(255, 214, 150, 0.35);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.mission {
  grid-column: 1;
  justify-self: start;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: start;
  gap: 1px 6px;
  width: max-content;
  max-width: min(228px, calc(100vw - 96px));
  padding: 5px 8px 5px 5px;
  border-radius: 14px;
  background:
    linear-gradient(165deg, rgba(120, 68, 34, 0.92), rgba(48, 24, 12, 0.9) 58%, rgba(28, 14, 8, 0.94));
  border-color: rgba(255, 214, 140, 0.55);
  box-shadow:
    0 18px 36px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 236, 200, 0.32),
    inset 0 -10px 18px rgba(0, 0, 0, 0.18);
}
.mission-cheese {
  width: 28px;
  height: 30px;
  margin-top: 1px;
  object-fit: contain;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.35));
}
.mission-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
}
.mission-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
  max-width: 100%;
}
.level-kicker {
  flex: none;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #ffd27a;
}
.challenge-line {
  margin-top: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: 0.03em;
  color: #ffe7c2;
  white-space: nowrap;
}
.challenge-line:empty { display: none; }
.mission strong {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.15;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.btn {
  border: 1px solid rgba(170, 206, 255, 0.28);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.04));
  color: var(--text);
  border-radius: 12px;
  min-height: 36px;
  padding: 0 12px;
  font: 700 13px/1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 8px 16px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(0, 229, 255, 0.75);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 10px 22px rgba(0, 229, 255, 0.16);
}
.btn:active:not(:disabled) { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary {
  background: linear-gradient(180deg, rgba(0, 229, 255, 0.42), rgba(16, 232, 155, 0.22));
  border-color: rgba(0, 229, 255, 0.7);
}
.btn.gold {
  background: linear-gradient(180deg, rgba(255, 206, 84, 0.95), rgba(255, 145, 0, 0.78));
  border-color: rgba(255, 226, 150, 0.85);
  color: #2a1a00;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 8px 18px rgba(255, 170, 0, 0.28);
}

.level-btn {
  border-radius: 999px;
  min-height: 28px;
  padding: 0 12px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: linear-gradient(180deg, rgba(0, 229, 255, 0.28), rgba(0, 229, 255, 0.08));
  border-color: rgba(0, 229, 255, 0.55);
}
.titles { display: flex; flex-direction: column; min-width: 0; width: 100%; }
.titles strong { font-size: 16px; letter-spacing: 0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titles span { color: var(--muted); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.score-jewel {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  backdrop-filter: none;
}
.move-orb {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  padding: 2px 6px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe08a, #ffb703);
  color: #3a2208;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
.move-orb b { font-size: 12px; line-height: 1; font-variant-numeric: tabular-nums; }
.move-orb small { color: #6a4010; }
.move-orb small {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6a4010;
}
.score-jewel em { color: var(--muted); font-style: normal; font-size: 11px; letter-spacing: 0.03em; }
.live-stars { display: flex; gap: 4px; margin-top: 1px; font-size: 18px; line-height: 1; }
.live-stars i { font-style: normal; color: rgba(255, 255, 255, 0.38); transition: color 0.15s ease, transform 0.15s ease; }
.live-stars i.on { color: var(--gold); text-shadow: 0 0 8px rgba(255, 183, 3, 0.55); }
.live-stars i.dim { color: rgba(255, 255, 255, 0.18); transform: scale(0.92); }

.menu-wrap {
  grid-column: 2;
  justify-self: end;
  position: relative;
  pointer-events: none;
}
#btn-menu {
  pointer-events: auto;
  min-width: 72px;
  min-height: 40px;
  border-radius: 16px;
}
.actions {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 8;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
  border-radius: 20px;
  width: 214px;
  max-width: calc(100vw - 16px);
}
.menu-wrap.open .actions { display: grid; }
.actions .btn { min-width: 0; min-height: 40px; font-size: 0; border-radius: 14px; }
.actions .btn::before { margin-right: 0; font-size: 16px; }
.actions #btn-sound,
.actions #btn-music {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 8px;
  overflow: hidden;
  font-size: 12px;
  letter-spacing: 0;
  white-space: nowrap;
}
.actions #btn-sound.off,
.actions #btn-music.off { opacity: 0.4; }
#btn-undo::before, #btn-reset::before, #btn-hint::before, #btn-sound::before, #btn-music::before, #btn-help::before {
  margin-right: 6px;
  font-weight: 800;
}
#btn-undo::before { content: "↩"; color: var(--cyan); }
#btn-reset::before { content: "⟳"; color: #9ad7ff; }
#btn-hint::before {
  content: "";
  display: inline-block;
  width: 18px;
  height: 22px;
  margin-right: 0;
  vertical-align: middle;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 28'%3E%3Ccircle cx='12' cy='10' r='7.2' fill='%233a2208'/%3E%3Crect x='8.6' y='16.6' width='6.8' height='2.3' rx='0.7' fill='%233a2208'/%3E%3Crect x='9.2' y='19.8' width='5.6' height='2' rx='0.5' fill='%233a2208'/%3E%3Crect x='9.8' y='22.6' width='4.4' height='2' rx='0.5' fill='%233a2208'/%3E%3C/svg%3E");
}
#btn-sound::before { content: "♪"; margin-right: 0; color: var(--cyan); }
#btn-music::before { content: "♫"; margin-right: 0; color: #ffd27a; }
#btn-help::before { content: "?"; color: #d7e8ff; }
#btn-quality {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: #ffe7c2;
}
#btn-quality::before { content: none; }
.vol {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 4px;
  color: #ffe7c2;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  pointer-events: auto;
}
.vol span { flex: none; }
.vol input {
  width: 100%;
  margin: 0;
  accent-color: #ffb703;
  cursor: pointer;
}
.actions #btn-levels {
  grid-column: 1 / -1;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-height: 34px;
}
.actions #btn-levels::before { content: none; }

.console-dock {
  display: none;
  align-items: flex-end;
}
body.show-pad .console-dock { display: flex; }
.console { display: flex; align-items: center; gap: 12px; }
.tilt-ring {
  display: none;
  position: relative;
  width: 168px;
  height: 168px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, rgba(18, 40, 72, 0.35), rgba(5, 10, 22, 0.82));
  border: 1px solid rgba(0, 229, 255, 0.38);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42), inset 0 0 28px rgba(0, 229, 255, 0.08);
}
.tilt-ring::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 1px dashed rgba(120, 220, 255, 0.28);
}
.wedge {
  position: absolute;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  border: 1px solid rgba(150, 210, 255, 0.4);
  background: linear-gradient(180deg, rgba(36, 64, 104, 0.95), rgba(10, 20, 40, 0.95));
  color: white;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 8px 16px rgba(0, 0, 0, 0.28);
}
.wedge.up { top: 10px; left: 50%; margin-left: -24px; }
.wedge.left { left: 10px; top: 50%; margin-top: -24px; }
.wedge.right { right: 10px; top: 50%; margin-top: -24px; }
.wedge.down { bottom: 10px; left: 50%; margin-left: -24px; }
.wedge:hover { border-color: rgba(0, 229, 255, 0.85); filter: brightness(1.15); }
.wedge:active { filter: brightness(1.3); }
.dir-btn.hint-glow, .dir-btn.preview {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(255, 196, 60, 0.95), rgba(196, 110, 0, 0.9));
  color: #2a1a00;
  box-shadow: 0 0 18px rgba(255, 183, 3, 0.55);
}
.orb-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 30%, #d8fbff, #3adfff 36%, #067a96 70%, #042838 100%);
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.55), inset 0 -6px 10px rgba(0, 30, 50, 0.35);
  animation: orbPulse 2.8s ease-in-out infinite;
}
.orb-core b {
  font-size: 10px;
  letter-spacing: 0.16em;
  color: #04222c;
}
@keyframes orbPulse {
  50% { box-shadow: 0 0 26px rgba(0, 229, 255, 0.85), inset 0 -6px 10px rgba(0, 30, 50, 0.35); }
}
.rot { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.rot-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #9eb6d8;
}
.rot button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid rgba(150, 210, 255, 0.4);
  background: linear-gradient(180deg, rgba(32, 56, 96, 0.95), rgba(8, 16, 32, 0.95));
  color: white;
  font-size: 22px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 8px 16px rgba(0, 0, 0, 0.28);
}
.rot button:hover { border-color: rgba(0, 229, 255, 0.8); }
.rot.locked { visibility: hidden; }

.coach {
  position: fixed;
  left: 50%;
  top: calc(var(--top) + 22px);
  transform: translateX(-50%);
  z-index: 8;
  pointer-events: none;
  display: none;
}
.coach.show { display: block; }
.coach-card {
  pointer-events: auto;
  background: rgba(8, 18, 36, 0.92);
  border: 1px solid rgba(0, 229, 255, 0.5);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.coach-card p { margin: 0 0 8px; font-size: 14px; }
.arrow-demo { font-size: 22px; letter-spacing: 8px; color: var(--cyan); animation: nudge 1s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(4px); } }

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--top) + 12px);
  transform: translateX(-50%) translateY(-6px);
  z-index: 12;
  max-width: min(520px, calc(100% - 24px));
  background: rgba(8, 16, 32, 0.92);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.win {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -46%) scale(0.94);
  z-index: 20;
  width: min(440px, calc(100% - 24px));
  padding: 22px 18px 16px;
  text-align: center;
  background: rgba(7, 22, 24, 0.94);
  border: 1px solid rgba(16, 232, 155, 0.7);
  border-radius: 18px;
  opacity: 0;
  pointer-events: none;
  overflow: visible;
  transition: 0.28s cubic-bezier(0.2, 1, 0.3, 1);
}
.win.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -46%) scale(1); }
.win:not(.show),
.win:not(.show) * { pointer-events: none; }
.win-ribbon {
  position: relative;
  z-index: 1;
  margin: -40px -8px 4px;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.32));
}
.win-ribbon h2 {
  margin: 0;
  padding: 11px 34px 13px;
  color: #3a2208;
  font-size: 24px;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  background: linear-gradient(180deg, #fff6cf 0%, #ffc84a 46%, #e8900c 100%);
  clip-path: polygon(16px 0, calc(100% - 16px) 0, 100% 50%, calc(100% - 16px) 100%, 16px 100%, 0 50%);
}
.win-ribbon::before,
.win-ribbon::after {
  content: "";
  position: absolute;
  top: calc(100% - 1px);
  width: 14px;
  height: 12px;
  background: #8d4e06;
}
.win-ribbon::before { left: 8px; clip-path: polygon(0 0, 100% 0, 100% 100%); }
.win-ribbon::after { right: 8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.win h2 { margin: 0; font-size: 26px; letter-spacing: 0.04em; }
.win-cheer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}
#win-mouse { width: 156px; height: 156px; object-fit: contain; display: block; flex: none; }
.win-cheer strong {
  color: #ffe08a;
  font-size: 22px;
  letter-spacing: 0.04em;
}
.win-stars { display: flex; justify-content: center; gap: 8px; margin: 10px 0; font-size: 42px; }
.win-stars span {
  color: rgba(255, 255, 255, 0.2);
  transform: scale(0.4);
  opacity: 0;
}
.win-stars span.pop { animation: starPop 0.42s cubic-bezier(0.2, 1.5, 0.35, 1) forwards; }
.win-stars span.got { color: var(--gold); text-shadow: 0 0 16px rgba(255, 183, 3, 0.8); }
.win-stars span.miss { color: rgba(255, 255, 255, 0.28); }
@keyframes starPop { to { transform: scale(1); opacity: 1; } }
.perfect {
  display: none;
  margin: 0 0 8px;
  color: #ffe08a;
  font-weight: 800;
  letter-spacing: 0.08em;
  animation: shine 1.2s linear infinite;
}
.perfect.show { display: block; }
@keyframes shine { 50% { text-shadow: 0 0 12px rgba(255, 214, 102, 0.9); } }
.win p { margin: 0 0 8px; color: #d9fff2; font-size: 14px; }
.world-line { color: var(--cyan) !important; font-weight: 700; min-height: 1.2em; }
.world-line:empty { display: none; min-height: 0; margin: 0; }
.win-actions { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(3, 6, 14, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.backdrop.open { display: flex; }
.modal {
  width: min(720px, 100%);
  max-height: min(86vh, 640px);
  overflow: auto;
  background: rgba(12, 18, 34, 0.96);
  border: 1px solid rgba(0, 229, 255, 0.45);
  border-radius: 16px;
  padding: 16px;
}
.modal h2 { margin: 0 0 8px; font-size: 20px; }
.modal p, .modal li { color: #d5e4ff; font-size: 14px; line-height: 1.45; }
.modal-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }

#drawer .saga-map { position: relative; margin-top: 4px; }
#drawer .modal { background: transparent; }
#drawer .saga-back {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 0;
  border-radius: 22px;
  background-size: cover;
  background-position: center;
  opacity: 1;
  pointer-events: none;
}
#drawer .saga-road {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}
#drawer .saga-road polyline { opacity: 0.9; }
#drawer .saga-world {
  position: absolute;
  left: 50%;
  z-index: 3;
  margin: 0;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(12, 18, 34, 0.94);
  font-size: 13px;
  white-space: nowrap;
}
#drawer .modal {
  scrollbar-width: none;
}
#drawer .modal::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}
#drawer .saga-world.world-1 { color: #ffc56a; }
#drawer .saga-world.world-2 { color: #ffe08a; }
#drawer .saga-world.world-3 { color: #ff9bb4; }
#drawer .saga-world.world-4 { color: #9fd0ff; }
#drawer .saga-world.world-5 { color: #c7b0ff; }
#drawer .lvl {
  position: absolute;
  z-index: 2;
  width: 88px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: #fff8ea;
  cursor: pointer;
  transform: translateX(-50%);
}
#drawer .lvl:disabled { opacity: 0.5; cursor: default; }
#drawer .lvl-cheese {
  position: relative;
  display: block;
  width: 74px;
  margin: 0 auto;
  animation: cheeseBob 2.8s ease-in-out infinite;
}
#drawer .lvl.locked .lvl-cheese { animation: none; filter: saturate(0.2) brightness(0.62); }
#drawer .lvl.locked { opacity: 1; cursor: not-allowed; }
#drawer .lvl.locked .lvl-cheese b { opacity: 0.55; }
#drawer .lvl-lock {
  position: absolute;
  z-index: 3;
  left: calc(50% + 14px);
  top: 42px;
  width: 28px;
  height: 32px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 28 32'%3E%3Cpath d='M8 14V10a6 6 0 0 1 12 0v4' fill='none' stroke='%235a3418' stroke-width='5' stroke-linecap='round'/%3E%3Cpath d='M8 14V10a6 6 0 0 1 12 0v4' fill='none' stroke='%23ffd66b' stroke-width='2.4' stroke-linecap='round'/%3E%3Crect x='2.5' y='13' width='23' height='17' rx='4.5' fill='%23ffc94a' stroke='%235a3418' stroke-width='2.5'/%3E%3Ccircle cx='14' cy='20.5' r='2.4' fill='%235a3418'/%3E%3Crect x='12.9' y='21' width='2.2' height='5' rx='1.1' fill='%235a3418'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55));
}
#drawer .saga-world.locked { opacity: 0.6; }
#drawer .saga-back.locked { filter: grayscale(0.7) brightness(0.55); }

#drawer .lvl.current { width: 112px; }
#drawer .lvl.current .lvl-cheese {
  width: 96px;
  animation-name: cheeseBobHigh;
  animation-duration: 1.8s;
}
#drawer .lvl-cheese img { width: 100%; height: auto; display: block; }
#drawer .lvl.current .lvl-cheese img { filter: drop-shadow(0 0 8px rgba(0, 229, 255, 0.85)); }
#drawer .lvl-cheese b {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  text-shadow: 0 2px 0 rgba(120, 48, 0, 0.85);
}
#drawer .lvl-stars {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1px;
  margin-top: -4px;
  min-height: 16px;
}
#drawer .lvl-stars i { font-style: normal; line-height: 1; }
#drawer .lvl-stars i.star::before {
  content: "★";
  font-size: 14px;
  color: transparent;
  -webkit-text-stroke: 1px #e7c27a;
}
#drawer .lvl-stars i.star.on::before {
  color: #ffd24a;
  -webkit-text-stroke: 0;
  text-shadow: 0 0 6px rgba(255, 183, 3, 0.85);
}
#drawer .lvl-stars i.gem::before {
  content: "◆";
  margin-left: 2px;
  color: #7ee7ff;
  font-size: 12px;
}
#drawer .lvl-mouse {
  position: absolute;
  left: -58px;
  top: 8px;
  width: 72px;
  height: auto;
  background: none;
  pointer-events: none;
  animation: cheeseBob 1.8s ease-in-out infinite;
}
#drawer .lvl-mouse.right { left: auto; right: -58px; }
#drawer .saga-map + .btn { display: block; margin: 14px auto 0; }
@keyframes cheeseBob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
@keyframes cheeseBobHigh {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

#error-fallback {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: #060913;
}

@media (max-width: 900px), (max-height: 560px) {
  :root {
    --top: 112px;
    --bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .hud {
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    padding-right: max(8px, env(safe-area-inset-right, 0px));
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
    padding-left: max(8px, env(safe-area-inset-left, 0px));
  }
  .deck {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: none;
    gap: 8px;
  }
  .mission, .menu-wrap { min-width: 0; grid-area: auto; }
  .mission {
    grid-column: 1;
    grid-template-columns: 26px minmax(0, 1fr);
    width: max-content;
    max-width: min(210px, calc(100vw - 88px));
    overflow: hidden;
    gap: 1px 5px;
    padding: 4px 7px 4px 4px;
    border-radius: 12px;
  }
  .mission-cheese { width: 26px; height: 28px; }
  .mission strong { font-size: 13px; }
  .challenge-line { white-space: nowrap; }
  .actions {
    grid-area: actions;
    gap: 6px;
    width: 196px;
    padding: 8px;
    border-radius: 16px;
  }
  .score-jewel {
    gap: 6px;
    padding: 0;
  }
  .level-btn {
    min-height: 24px;
    padding: 0 10px;
    font-size: 10px;
  }
  .titles strong { font-size: 12px; }
  .titles span { font-size: 10px; }
  .actions .btn {
    min-width: 36px;
    min-height: 32px;
    padding: 0 6px;
    font-size: 0;
    border-radius: 10px;
    letter-spacing: 0;
  }
  .actions .btn::before {
    margin-right: 0;
    font-size: 15px;
    line-height: 1;
  }
  .actions #btn-sound,
  .actions #btn-music { gap: 4px; padding: 0 4px; font-size: 11px; }
  .actions #btn-hint {
    min-height: 30px;
  }
  .actions #btn-hint::before {
    font-size: 14px;
  }
  .actions #btn-quality {
    font-size: 10px;
    letter-spacing: 0;
    color: #ffe7c2;
  }
  .move-orb b { font-size: 12px; }
  .move-orb small { font-size: 8px; }
  .score-jewel em { font-size: 11px; }
  .live-stars { font-size: 16px; }
  body.show-pad .console-dock { display: flex; }
  .win {
    top: max(8px, env(safe-area-inset-top, 0px));
    width: min(440px, calc(100% - 16px));
    max-height: calc(100dvh - 16px);
    overflow: auto;
    padding: 12px 12px 10px;
    transform: translate(-50%, 0) scale(0.94);
    scrollbar-width: none;
  }
  .win.show { transform: translate(-50%, 0) scale(1); }
  .win::-webkit-scrollbar { width: 0; height: 0; }
  .win-ribbon { margin: 0 0 2px; }
  .win-ribbon h2 { font-size: 18px; padding: 8px 18px 9px; }
  .win h2 { font-size: 18px; }
  #win-mouse { width: 84px; height: 84px; }
  .win-cheer { margin-top: 4px; gap: 8px; }
  .win-cheer strong { font-size: 18px; }
  .win-stars { font-size: 28px; margin: 4px 0; }
  .win p { margin: 0 0 4px; font-size: 13px; }
  .win-actions { margin-top: 6px; flex-wrap: wrap; }
}

.evo {
  position: fixed;
  left: 12px;
  top: 42%;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(72, 40, 24, 0.72);
  color: #fff6e8;
  font-size: 13px;
  pointer-events: none;
}
.evo b { color: #ffd27a; text-align: center; }
.arrow-keys {
  display: grid;
  grid-template-columns: 42px 42px 42px;
  grid-template-areas:
    ". up ."
    "left down right";
  justify-content: center;
  gap: 6px;
  margin: 0 auto 10px;
}
.arrow-keys .up { grid-area: up; }
.arrow-keys .left { grid-area: left; }
.arrow-keys .down { grid-area: down; }
.arrow-keys .right { grid-area: right; }
.arrow-keys .key {
  display: grid;
  place-items: center;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255, 214, 150, 0.55);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05));
  color: #fff6e8;
  font-size: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 4px 0 rgba(0, 0, 0, 0.28);
}
.coach.phone .arrow-keys { display: none; }
@keyframes bob { 50% { transform: translateY(10px); } }
.float-pop {
  position: fixed;
  left: 50%;
  top: 38%;
  z-index: 8;
  transform: translate(-50%, 12px);
  font-size: 28px;
  font-weight: 800;
  color: #fff6e8;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}
.float-pop.show { animation: popfloat 0.7s ease forwards; }
@keyframes popfloat {
  0% { opacity: 0; transform: translate(-50%, 12px) scale(0.8); }
  30% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -28px) scale(1); }
}
#btn-hint.hint-pulse { box-shadow: 0 0 0 3px rgba(255, 183, 3, 0.8); }
.key-overlay { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.key-overlay span {
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}
@media (max-height: 640px) {
  .deck {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: none;
    gap: 8px;
  }
  .mission { grid-column: 1; max-width: min(210px, calc(100vw - 88px)); padding: 4px 7px 4px 4px; }
  .menu-wrap { grid-column: 2; }
}

/* Narrow portrait phones: the score pill sat on top of the level card. */
@media (max-width: 520px) and (orientation: portrait) {
  .hud-score { top: calc(max(8px, env(safe-area-inset-top, 0px)) + 62px); }
}

/* CC BY attribution on the loading screen: plain text, small and subtle. */
.boot-credits {
  position: absolute;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(680px, calc(100% - 24px));
  margin: 0;
  text-align: center;
  font-size: 10px;
  line-height: 1.4;
  color: #e6c8a4;
  opacity: 0.5;
  pointer-events: none;
}
@media (max-height: 480px) {
  .boot-credits { font-size: 9px; bottom: 6px; line-height: 1.3; }
}

/* ===================== Warm kitchen theme (unified UI) ===================== */
:root { --cream: #fff4dc; --wood: #6b3f1f; --wood-dark: #3a2010; --honey: #f2a516; --ink: #4a2a12; --cyan: #f2a516; }
body { background: #24160f center / cover no-repeat; transition: background-image 0.4s ease; }
body.world-1 { background-image: url("../assets/backgrounds/world1.jpg"); }
body.world-2 { background-image: url("../assets/backgrounds/world2.jpg"); }
body.world-3 { background-image: url("../assets/backgrounds/world3.jpg"); }
body.world-4 { background-image: url("../assets/backgrounds/world4.jpg"); }
body.world-5 { background-image: url("../assets/backgrounds/world5.jpg"); }

.btn {
  border: 2px solid #8a5a32;
  background: linear-gradient(180deg, #fff6e2, #f1dcb4);
  color: var(--ink);
  box-shadow: inset 0 1px 0 #fff, 0 3px 0 #8a5a32, 0 8px 14px rgba(0, 0, 0, 0.25);
}
.btn:hover:not(:disabled) { border-color: #b07a3a; box-shadow: inset 0 1px 0 #fff, 0 4px 0 #8a5a32, 0 10px 18px rgba(0, 0, 0, 0.28); }
.btn.primary { background: linear-gradient(180deg, #ffd25a, #f2a516); border-color: #a8650e; color: #3a2008; box-shadow: inset 0 1px 0 #fff3c4, 0 3px 0 #a8650e, 0 8px 16px rgba(0, 0, 0, 0.25); }
.btn.gold { background: linear-gradient(180deg, #ffd25a, #f2a516); border-color: #a8650e; color: #3a2008; }
#btn-menu { background: linear-gradient(180deg, #fff6e2, #f1dcb4); color: var(--ink); }

.actions { background: linear-gradient(180deg, #fff4dc, #f0dcb6); border: 2px solid #8a5a32; box-shadow: 0 16px 30px rgba(0, 0, 0, 0.35); }
.actions .btn { font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 6px; }
.actions .btn::before { font-size: 15px; margin-right: 0; }
#btn-undo::before { content: "\21A9"; color: #8a5a32; }
#btn-reset::before { content: "\27F3"; color: #8a5a32; }
#btn-help::before { content: "?"; color: #8a5a32; }
#btn-sound::before, #btn-music::before { color: #8a5a32; }
.actions #btn-sound, .actions #btn-music { color: var(--ink); }
.vol { color: var(--ink); }

.goal-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: -2px; }
.goal-chips:empty { display: none; }
.goal-chip { display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px 1px 2px; border-radius: 999px; background: var(--cream); color: var(--ink); border: 1px solid #c79a5c; font-size: 11px; line-height: 1; }
.goal-chip img { width: 22px; height: 22px; }
.goal-chip b { font-weight: 800; white-space: nowrap; }
.goal-chip.met { background: #e2f5d6; border-color: #5aa04a; }
.goal-chip.met b::after { content: " \2713"; color: #3f8a3a; }
.mission { max-width: min(300px, calc(100vw - 96px)); }

/* panels: cream card, wooden border */
.coach-card, .modal, .win, .toast {
  background: linear-gradient(180deg, #fff6e4, #f3e0bd);
  border: 3px solid #8a5a32;
  color: var(--ink);
  box-shadow: 0 0 0 3px rgba(255, 236, 200, 0.35), 0 22px 50px rgba(0, 0, 0, 0.45);
}
.toast { border-width: 2px; font-weight: 700; }
.coach { top: auto; bottom: 22px; }
.coach-card { padding: 10px 16px; }
.coach-card p { color: var(--ink); font-weight: 700; }
.coach-card .key, .arrow-keys .key { background: #fff; color: var(--ink); border: 2px solid #8a5a32; box-shadow: 0 2px 0 #8a5a32; }
.backdrop { background: rgba(30, 16, 8, 0.6); }
.modal h2 { color: #5a3014; }
.modal p, .modal li { color: var(--ink); }
.help-body { font-size: 14px; }
.help-lead { margin: 2px 0 10px; font-weight: 600; }
.help-keys { display: grid; gap: 6px; margin-bottom: 12px; }
.help-key-row { color: var(--ink); }
.help-key-row.touch { display: none; }
body.touch-help .help-key-row.touch { display: block; }
body.touch-help .help-key-row.desk { display: none; }
.kbd { display: inline-block; min-width: 26px; padding: 3px 8px; margin: 0 2px; border-radius: 7px; background: #fff; border: 2px solid #8a5a32; box-shadow: 0 2px 0 #8a5a32; font-weight: 800; text-align: center; }
.help-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.help-item { display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; padding: 6px 8px; border-radius: 12px; background: rgba(255, 255, 255, 0.6); border: 1px solid #d8b47c; }
.help-item img, .help-swatch { grid-row: 1 / 3; width: 40px; height: 40px; }
.help-item b { font-size: 13px; color: #5a3014; }
.help-item span:not(.help-swatch) { font-size: 12px; color: #6b4a2a; }
.help-swatch { display: grid; place-items: center; border-radius: 10px; border: 2px solid rgba(0, 0, 0, 0.15); font-size: 22px; font-weight: 900; color: #7a4520; }
.help-swatch.tin { background: linear-gradient(90deg, #c4c9d1, #f1f3f6 45%, #b9bec7); box-shadow: inset 0 -12px 0 #3f7d4e, inset 0 -16px 0 #f3e3bf; border-radius: 8px 8px 8px 8px; }
.help-swatch.cracker { background: radial-gradient(circle, #a8702a 2px, transparent 3px) 0 0 / 12px 12px, #e8b866; }
.help-swatch.honey { background: radial-gradient(circle at 40% 35%, #ffd884, #f2a516 55%, #c7780a); border-radius: 50%; }
.help-swatch.flap { background: #f3e2bd; }
.help-swatch.hole { background: radial-gradient(circle, #1a0e08 45%, #8a5a32 48%, #c48a4a 70%, transparent 72%); border: 0; }
.help-foot { margin: 12px 0 0; font-size: 13px; opacity: 0.85; }

.win { border-width: 3px; }
.win p { color: var(--ink); }
.win-cheer strong { color: #8a4a10; }
.perfect { color: #b0650a !important; }
.world-line { color: #8a4a10 !important; }
.win-stars span.miss { color: rgba(90, 50, 20, 0.25); }

#drawer .modal { background: linear-gradient(180deg, #fff6e4, #f3e0bd); }
#drawer .modal-head h2 { color: #5a3014; }

/* touch pad in the same wood/cream style */
.tilt-ring { background: radial-gradient(circle at 50% 42%, rgba(255, 244, 220, 0.5), rgba(107, 63, 31, 0.75)); border: 2px solid #8a5a32; box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35); }
.tilt-ring::before { border-color: rgba(255, 236, 200, 0.4); }
.wedge, .rot button { background: linear-gradient(180deg, #fff6e2, #f1dcb4); border: 2px solid #8a5a32; color: var(--ink); }
.wedge:hover, .rot button:hover { border-color: #b07a3a; }
.orb-core { background: radial-gradient(circle at 35% 30%, #fff1c4, #ffc93a 40%, #c98a14 100%); box-shadow: 0 0 14px rgba(255, 190, 60, 0.6); animation: none; }
.orb-core b { color: #4a2a12; }
.rot-label { color: #fff1d6; }
.level-btn { background: linear-gradient(180deg, #ffd25a, #f2a516); border-color: #a8650e; color: #3a2008; }
.coach { left: 12px; bottom: 12px; top: auto; transform: none; }
.coach-card { padding: 8px 12px; }
html, body { -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
@media (max-width: 520px) and (orientation: portrait) {
  .hud-score { left: auto; right: 8px; transform: none; top: calc(max(8px, env(safe-area-inset-top, 0px)) + 54px); padding: 6px 10px; }
  .mission { max-width: calc(100vw - 150px); }
}
@media (orientation: portrait) {
  body.show-pad .tilt-ring { display: block; }
  body.show-pad .console-dock { justify-content: center; padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
}
/* Mouse speech bubbles (screen-space, placed by layoutBubbles so they never cover other mice) */
#bubble-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.mouse-bubble {
  position: absolute; left: 0; top: 0; box-sizing: border-box;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  padding: 3px 4px 4px; border-radius: 12px;
  background: #fff4dc; border: 2px solid #6b3f1f;
  box-shadow: 0 3px 8px rgba(40, 20, 6, 0.35);
  color: #4a2a12; font: 800 12px/1.05 "Segoe UI", system-ui, sans-serif; text-align: center;
  transition: opacity 0.2s ease; will-change: transform;
}
.mouse-bubble img { width: 58%; height: auto; flex: 0 1 auto; min-height: 0; object-fit: contain; }
.mouse-bubble span { white-space: nowrap; letter-spacing: -0.01em; }
.mouse-bubble em { font-style: normal; font-weight: 700; font-size: 0.8em; color: #1f6fc0; margin-top: -1px; }
.mouse-bubble::after {
  content: ""; position: absolute; width: 9px; height: 9px; background: inherit;
  border: 2px solid #6b3f1f; border-top: 0; border-left: 0;
}
.mouse-bubble[data-tail="down"]::after { left: calc(50% - 6px); bottom: -7px; transform: rotate(45deg); }
.mouse-bubble[data-tail="up"]::after { left: calc(50% - 6px); top: -7px; transform: rotate(-135deg); }
.mouse-bubble[data-tail="left"]::after { left: -7px; top: calc(50% - 6px); transform: rotate(135deg); }
.mouse-bubble[data-tail="right"]::after { right: -7px; top: calc(50% - 6px); transform: rotate(-45deg); }
.mouse-bubble.met { background: #e9f8df; border-color: #3f8a3a; }
.mouse-bubble.met::after { border-color: #3f8a3a; }
.mouse-bubble.met::before {
  content: "\2713"; position: absolute; top: -8px; right: -8px; width: 18px; height: 18px; border-radius: 50%;
  background: #3f9a3a; color: #fff; font-size: 12px; line-height: 18px; text-align: center; border: 2px solid #fff;
}
.mouse-bubble.crowded { opacity: 0.55; }

/* ===================== Landscape: HUD in the side rails ===================== */
/* The score pill moves under Menu on the right so the top centre is free for the board. */
@media (orientation: landscape) and (min-aspect-ratio: 6/5) {
  .hud-score {
    left: auto;
    right: max(8px, env(safe-area-inset-right, 0px));
    top: calc(max(8px, env(safe-area-inset-top, 0px)) + 54px);
    transform: none;
    padding: 6px 12px 5px;
  }
}
/* Landscape phones and tablets: slim level card in the left rail, chips stacked. */
@media (orientation: landscape) and (max-height: 560px), (orientation: landscape) and (max-width: 1180px) {
  .mission { max-width: clamp(172px, 22vw, 210px); }
  .goal-chips, .goal-chip { max-width: 100%; }
  .goal-chip b { overflow: hidden; text-overflow: ellipsis; }
  .challenge-line { white-space: normal; line-height: 1.25; }
  .goal-chips { flex-direction: column; align-items: flex-start; gap: 3px; }
}
/* Short landscape screens (phones on their side): smaller type and buttons. */
@media (orientation: landscape) and (max-height: 560px) {
  .mission {
    max-width: clamp(172px, 22vw, 196px);
    padding: 4px 6px 5px 4px;
  }
  .mission-cheese { width: 22px; height: 24px; }
  .mission strong { font-size: 12px; }
  .level-kicker { font-size: 9px; }
  .challenge-line { white-space: normal; font-size: 10px; line-height: 1.2; }
  .mission-copy { gap: 4px; }
  .goal-chips { flex-direction: column; align-items: flex-start; gap: 3px; }
  .goal-chip { font-size: 10px; padding: 1px 6px 1px 2px; }
  .goal-chip img { width: 18px; height: 18px; }
  #btn-menu { min-width: 64px; min-height: 36px; border-radius: 14px; font-size: 13px; }
  .hud-score { top: calc(max(8px, env(safe-area-inset-top, 0px)) + 48px); padding: 4px 10px; gap: 2px; }
  .live-stars { font-size: 13px; }
  .rot { gap: 6px; }
  .rot button { width: 44px; height: 44px; font-size: 19px; }
  .rot-label { font-size: 9px; }
  .coach { left: max(8px, env(safe-area-inset-left, 0px)); bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
  .coach-card { max-width: clamp(172px, 22vw, 196px); padding: 6px 8px; }
  .coach-card p { font-size: 12px; }
}
