/* Mirror Maze. Menus are flat: solid fills, 1px borders, no gradients or shadows.
   All the glow lives inside the 3D view. */

:root {
  --bg: #06080d;
  --panel: #0b0f18;
  --panel-2: #121826;
  --line: #242d42;
  --ink: #eef2fa;
  --mute: #98a4bb;
  --accent: #29e6ff;
  --accent-ink: #04121a;
  --good: #48ff9a;
  --warn: #ff5a5a;
  --gold: #ffd24a;
  --display: 'Unbounded', 'Arial Black', system-ui, sans-serif;
  --body: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .tile:focus-visible, .icon-btn:focus-visible, .swatch:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ffffff; border-color: #ffffff; }
.btn.big { min-height: 52px; padding: 0 28px; font-size: 17px; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; min-width: 58px; }

/* ---------- screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  padding: 20px 16px 52px;
  background: rgba(4, 6, 10, 0.78);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.on { display: flex; align-items: flex-start; }
#intro, #pause { background: rgba(4, 6, 10, 0.55); }

.menu-inner {
  width: min(1080px, 100%);
  margin: auto;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 44px;
  align-items: center;
}

.title {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.6rem, 5.6vw, 4.6rem);
  line-height: 0.96;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}
.title span { display: block; }
/* The title's reflection: the same letters upside down, cut off partway. */
.title-flip {
  height: 0.9em;
  font-size: clamp(2.6rem, 5.6vw, 4.6rem);
  overflow: hidden;
  margin-top: 6px;
  user-select: none;
  pointer-events: none;
}
.title-flip .title {
  transform: scaleY(-1);
  color: var(--accent);
  opacity: 0.2;
  font-size: 1em;
}
.title-flip .title span:first-child { display: none; }

.tag { margin: 14px 0 20px; font-size: 18px; color: var(--ink); max-width: 30ch; }
.play-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.total { color: var(--gold); font-weight: 700; font-size: 15px; }
.how { margin: 18px 0 0; color: var(--mute); font-size: 14px; max-width: 46ch; }

.options {
  margin-top: 18px;
  display: grid;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  max-width: 420px;
}
.options.in-card { margin: 4px 0 20px; max-width: none; }
.opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 54px;
  padding: 8px 14px;
}
.opt + .opt { border-top: 1px solid var(--line); }
.opt-label { font-size: 14px; font-weight: 700; color: var(--mute); }
.swatches { display: flex; gap: 8px; }
.swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--panel);
  outline: 1px solid var(--line);
}
.swatch.on { outline: 2px solid var(--ink); }

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 160px;
  height: 28px;
  background: transparent;
  margin: 0;
}
input[type='range']::-webkit-slider-runnable-track { height: 4px; background: var(--line); border-radius: 2px; }
input[type='range']::-moz-range-track { height: 4px; background: var(--line); border-radius: 2px; }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px; margin-top: -8px;
  border-radius: 50%; background: var(--accent); border: 0;
}
input[type='range']::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: 0; }
input[type='range']:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 6px; }

.list-head {
  margin: 0 0 10px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--mute);
}
.levels { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }

.tile {
  display: grid;
  gap: 2px;
  justify-items: start;
  text-align: left;
  padding: 12px 12px 10px;
  min-height: 112px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--t, var(--accent));
  border-radius: 10px;
  background: var(--panel);
}
.tile:hover:not(:disabled) { border-color: var(--t, var(--accent)); background: var(--panel-2); }
.tile-num { font-family: var(--display); font-weight: 800; font-size: 22px; line-height: 1.1; }
.tile-name { font-size: 13px; font-weight: 700; line-height: 1.25; min-height: 2.5em; }
.tile-stars, .big-stars { letter-spacing: 2px; }
.tile-stars i, .big-stars i { font-style: normal; color: #2e3850; }
.tile-stars i.on, .big-stars i.on { color: var(--gold); }
.tile-stars { font-size: 14px; }
.tile-best { font-size: 12px; color: var(--mute); font-variant-numeric: tabular-nums; }
.tile.locked { cursor: default; border-top-color: var(--line); }
.tile.locked > * { opacity: 0.4; }

/* ---------- cards ---------- */

.card {
  width: min(460px, 100%);
  margin: auto;
  padding: 26px 26px 24px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 14px;
  background: var(--panel);
}
.card.wide {
  width: min(820px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 28px;
  align-items: center;
}
.kicker {
  margin: 0 0 6px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.card-title {
  margin: 0 0 12px;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  line-height: 1.08;
  letter-spacing: -0.01em;
}
.card-text { margin: 0 0 18px; color: var(--ink); }
.card-text.small { font-size: 14px; color: var(--mute); min-height: 1.5em; margin-bottom: 14px; }
.card-btns { display: flex; flex-wrap: wrap; gap: 10px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0 0 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.stats > div { padding: 10px 12px; }
.stats > div + div { border-left: 1px solid var(--line); }
.stats dt { font-size: 12px; color: var(--mute); font-weight: 700; }
.stats dd { margin: 2px 0 0; font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }

.big-stars { font-size: 34px; line-height: 1; margin: 0 0 16px; }
.big-stars.none { display: none; }

.result-map { display: grid; justify-items: center; gap: 8px; }
#map { border: 1px solid var(--line); border-radius: 8px; display: block; max-width: 100%; }
.legend { margin: 0; font-size: 12px; color: var(--mute); display: flex; align-items: center; gap: 6px; }
.legend .k { display: inline-block; width: 14px; height: 0; border-top: 2px solid #dfe6f3; margin-left: 8px; }
.legend .k:first-child { margin-left: 0; }
.legend .k.glass { border-top: 2px dashed #58b8ff; }
.legend .k.shift { border-top-color: #ff7a1a; }

/* ---------- HUD ---------- */

.hud { position: fixed; inset: 0; z-index: 10; display: none; pointer-events: none; }
.hud.on { display: block; }
.hud-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 12px 0;
}
.hud-level {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(6, 8, 13, 0.82);
  min-width: 0;
}
.hud-num { font-family: var(--display); font-weight: 800; color: var(--accent); }
.hud-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-timer {
  min-width: 124px;
  padding: 4px 16px 6px;
  text-align: center;
  font-family: var(--display);
  font-weight: 800;
  font-size: 30px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(6, 8, 13, 0.82);
}
.hud-timer.low { color: var(--warn); border-color: var(--warn); }
.hud-btns { justify-self: end; display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(6, 8, 13, 0.82);
  color: var(--ink);
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn .slash { display: none; }
.icon-btn.off .slash { display: inline; }
.icon-btn.off .wave { display: none; }

.compass {
  position: absolute;
  left: 50%;
  top: calc(76px + env(safe-area-inset-top));
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 6px;
  border: 1px solid #7a4dff;
  border-radius: 999px;
  background: rgba(6, 8, 13, 0.82);
  color: #c9a8ff;
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.compass.on { display: flex; }
.compass svg { width: 34px; height: 34px; }

.toast {
  position: absolute;
  left: 50%;
  top: 24%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(6, 8, 13, 0.88);
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.18s;
}
.toast.on { opacity: 1; }

.dot {
  position: absolute; left: 50%; top: 50%;
  width: 4px; height: 4px; margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
}

.hud-bumps {
  position: absolute;
  right: 12px;
  bottom: calc(40px + env(safe-area-inset-bottom));
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 8, 13, 0.82);
  font-size: 13px;
  color: var(--mute);
  font-weight: 700;
}
.hud-bumps b { color: var(--ink); margin-left: 4px; font-variant-numeric: tabular-nums; }

/* Thumb stick: only on touch screens. */
.stick {
  position: absolute;
  left: 22px;
  bottom: calc(64px + env(safe-area-inset-bottom));
  width: 108px; height: 108px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(6, 8, 13, 0.3);
  display: none;
}
/* While a thumb is down the stick sits under it (input.js sets left/top). */
.stick.live { border-color: var(--accent); transform: translate(-50%, -50%); }
.knob {
  position: absolute; left: 50%; top: 50%;
  width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
}
body.touch .stick { display: block; }
body.touch .dot { display: none; }

/* ---------- credit ---------- */

.credit {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  padding: 0 8px calc(6px + env(safe-area-inset-bottom));
  pointer-events: none;
  font-size: 12px;
}
.credit a {
  pointer-events: auto;
  padding: 5px 10px;
  color: #b7c1d6;
  background: rgba(6, 8, 13, 0.86);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  white-space: nowrap;
}
.credit a:first-child { border-left: 1px solid var(--line); border-radius: 8px 0 0 8px; }
.credit a:last-child { border-right: 1px solid var(--line); border-left: 1px solid var(--line); border-radius: 0 8px 8px 0; }
.credit a:hover { color: #ffffff; }

.noscript { position: fixed; inset: auto 16px 60px; text-align: center; z-index: 40; }

/* ---------- smaller screens ---------- */

@media (max-width: 900px) {
  .menu-inner { grid-template-columns: minmax(0, 1fr); gap: 26px; align-items: start; margin: 0 auto; padding-bottom: 8px; }
  .title, .title-flip { font-size: clamp(2.6rem, 13vw, 4.4rem); }
  .title-flip { height: 0.6em; }
  .tag { max-width: none; }
  .options { max-width: none; }
  .card.wide { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .result-map { order: -1; }
}

@media (max-width: 620px) {
  .levels { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 10px 9px 8px; min-height: 104px; }
  .tile-name { font-size: 12px; }
  .card { padding: 20px 18px 18px; }
  .hud-name { display: none; }
  .hud-timer { font-size: 24px; min-width: 104px; padding: 6px 10px 8px; }
  .stats dd { font-size: 15px; }
  .card-btns .btn { flex: 1 1 auto; }
  input[type='range'] { width: 132px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .screen { padding-top: 12px; }
  .card { padding: 16px 20px; }
  .card-text { margin-bottom: 10px; }
  .stats { margin-bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
