:root {
  --panel: rgba(14, 18, 34, .84);
  --edge: #2d3663;
  --ink: #e8ecff;
  --dim: #8a93b8;
  --gold: #ffd34d;
  --accent: #4f7cff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #10142a; color: var(--ink);
  font-family: "Trebuchet MS", system-ui, sans-serif; overflow: hidden; user-select: none; -webkit-user-select: none; }
#stage canvas { display: block; }
[hidden] { display: none !important; }
button { font: inherit; color: var(--ink); background: #252d55; border: 2px solid #3a4580; border-radius: 10px;
  padding: 8px 18px; cursor: pointer; }
button:hover, button:focus-visible { background: #313b70; border-color: #5b69b0; outline: none; }
button.big { font-size: 20px; padding: 10px 36px; background: var(--accent); border-color: #7a9bff; }
button.big:hover { background: #6a8fff; }

.panel { position: absolute; background: var(--panel); border: 2px solid var(--edge); border-radius: 12px;
  padding: 10px 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .35); }

/* ---------- HUD ---------- */
#status { top: 16px; left: 16px; min-width: 200px; }
#status .lvl { font-size: 12px; color: var(--dim); letter-spacing: .08em; text-transform: uppercase; }
#status .name { font-size: 20px; font-weight: bold; margin: 2px 0 8px; }
#status .row { display: flex; gap: 20px; }
#status .k { font-size: 11px; color: var(--dim); text-transform: uppercase; }
#status .v { font-size: 28px; font-weight: bold; font-variant-numeric: tabular-nums; }
#status .v.chips { color: var(--gold); }
#status .v.low { color: #ff6b6b; }

#compass { top: 16px; right: 16px; width: 64px; height: 64px; padding: 0; border-radius: 50%; }
#compass .dial { position: absolute; inset: 6px; transition: transform .05s linear; }
#compass span { position: absolute; font-size: 11px; font-weight: bold; color: var(--dim); width: 14px; text-align: center; }
#compass .n { color: #ff6b6b; top: 0; left: 50%; margin-left: -7px; }
#compass .s { bottom: 0; left: 50%; margin-left: -7px; }
#compass .e { right: 0; top: 50%; margin-top: -8px; }
#compass .w { left: 0; top: 50%; margin-top: -8px; }

#floors { right: 16px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column-reverse; gap: 6px; align-items: center; padding: 10px; }
#floors .f { width: 46px; height: 16px; border-radius: 4px; background: #283060; font-size: 10px; text-align: center; line-height: 16px; color: var(--dim); }
#floors .f.here { background: var(--accent); color: #fff; }
#floors .f .dot { color: var(--gold); }
#floors .lab { font-size: 10px; color: var(--dim); margin-top: 2px; letter-spacing: .08em; }

#hint { bottom: 92px; left: 50%; transform: translateX(-50%); max-width: min(460px, calc(100% - 32px)); text-align: center; font-size: 15px; }
#hint b { color: #7fd7ff; }

#inv { bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; padding: 8px 10px; }
.slot { width: 44px; height: 44px; border-radius: 8px; background: #1b2140; border: 1px solid #333d6e;
  display: grid; place-items: center; font-size: 22px; position: relative; }
.slot.off { opacity: .25; }
.slot.key i { width: 22px; height: 10px; border-radius: 5px; background: currentColor; position: relative; }
.slot.key i::before { content: ""; position: absolute; left: -8px; top: -4px; width: 12px; height: 12px; border: 4px solid currentColor; border-radius: 50%; }
.slot.red { color: #ff4f5a; } .slot.blue { color: #4f8dff; } .slot.yellow { color: #ffd34d; } .slot.green { color: #4fdc6a; }
.slot b { position: absolute; right: 3px; bottom: 1px; font-size: 11px; color: var(--ink); }
.sep { width: 8px; }

button.round { position: absolute; top: 92px; right: 16px; width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 14px; }

#dpad, #turn { position: absolute; bottom: 16px; display: none; }
#dpad { left: 16px; width: 150px; height: 150px; }
#dpad button, #turn button { position: absolute; width: 50px; height: 50px; padding: 0; font-size: 20px; border-radius: 12px; opacity: .85; touch-action: none; }
#dpad [data-k="0"] { left: 50px; top: 0; }
#dpad [data-k="2"] { left: 50px; bottom: 0; }
#dpad [data-k="3"] { left: 0; top: 50px; }
#dpad [data-k="1"] { right: 0; top: 50px; }
#turn { right: 16px; width: 110px; height: 50px; }
#turn [data-turn="-1"] { left: 0; } #turn [data-turn="1"] { right: 0; }
@media (pointer: coarse) {
  #dpad, #turn { display: block; }
  #inv { bottom: 180px; }
  #hint { bottom: 250px; }
}
@media (max-width: 640px) {
  #floors { right: 8px; }
  #status { min-width: 0; padding: 8px 10px; }
  #status .v { font-size: 22px; }
  .slot { width: 34px; height: 34px; font-size: 17px; }
}

/* ---------- screens ---------- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 16px; background: radial-gradient(ellipse at center, rgba(30, 38, 80, .6), rgba(10, 12, 28, .92)); }
#title { background: radial-gradient(ellipse at 50% 40%, #232c60, #0c0f22 75%); justify-content: flex-start; padding-top: 4vh; }
/* Scroll when the content is taller than the window (the level grid is), and
   stay centred when it fits: auto margins centre, unlike justify-content,
   without pushing the top out of reach. */
.screen { overflow-y: auto; }
.screen:not(#title) { justify-content: flex-start; }
.screen:not(#title) > :first-child { margin-top: auto; }
.screen:not(#title) > :last-child { margin-bottom: auto; }
h1 { font-size: clamp(40px, 8vw, 72px); margin: 0; letter-spacing: .04em; text-shadow: 0 4px 0 #1a2150; }
h1 span { color: var(--gold); }
.tag { color: var(--dim); margin: 4px 0 0; }
#mascot-stage { width: min(520px, 100%); height: min(38vh, 340px); }
#mascot-pick { display: flex; align-items: center; gap: 14px; }
#mascot-pick .arrow { width: 48px; height: 48px; padding: 0; border-radius: 50%; }
#m-card { width: min(320px, 60vw); }
#m-name { font-size: 28px; font-weight: bold; }
#m-animal { font-size: 12px; text-transform: uppercase; letter-spacing: .12em; color: var(--dim); }
#m-pitch { font-size: 14px; color: #c5cbe6; min-height: 3.6em; margin: 6px 0 0; }
.buttons { display: flex; gap: 12px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.keys { color: var(--dim); font-size: 12px; margin-top: 18px; }

#level-grid { display: grid; grid-template-columns: repeat(4, 130px); gap: 10px; }
@media (max-width: 600px) { #level-grid { grid-template-columns: repeat(2, 140px); } }
#level-grid button { height: 86px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
#level-grid .num { font-size: 12px; color: var(--dim); }
#level-grid .nm { font-weight: bold; }
#level-grid .best { font-size: 11px; color: var(--gold); min-height: 1.2em; }
#level-grid button:disabled { opacity: .35; cursor: default; }

.card { background: rgba(8, 10, 24, .55); }
.card-box { background: var(--panel); border: 2px solid var(--edge); border-radius: 16px; padding: 24px 28px;
  max-width: min(460px, 100%); box-shadow: 0 10px 40px rgba(0, 0, 0, .5); }
#card-kicker { font-size: 12px; color: var(--dim); letter-spacing: .1em; text-transform: uppercase; }
#card-title { margin: 6px 0 10px; font-size: 28px; }
#card-text { color: #c5cbe6; line-height: 1.5; margin: 0; }
#card-text .score { color: var(--gold); font-size: 22px; font-weight: bold; }

/* ---------- easter eggs ---------- */
#toast { top: 16px; left: 50%; transform: translateX(-50%); z-index: 20; max-width: min(420px, calc(100% - 32px));
  text-align: center; font-size: 15px; color: var(--gold); pointer-events: none; }
/* on the menu screens the logo and heading are up top, so use the bottom */
#title:not([hidden]) ~ #toast, #levels:not([hidden]) ~ #toast { top: auto; bottom: 24px; }
#toast.show { animation: toast-in .35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes toast-in { from { transform: translate(-50%, -20px) scale(.8); opacity: 0; } }
#mascot-stage { cursor: pointer; }
.heart { position: fixed; z-index: 20; pointer-events: none; font-size: 22px; animation: heart 1.1s ease-out forwards; }
@keyframes heart { to { transform: translate(var(--dx), -90px) scale(1.4) rotate(var(--rot)); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .heart, #toast.show { animation-duration: .01s; } }
#level-grid button.secret { border-color: #ff7ab8; background: #3a2350; }
#level-grid button.secret .num { color: #ff9fc4; }
#card-text .quip { color: #ffb4d2; }
