:root {
  --paper: #f6e8cb;
  --ink: #2b1b33;
  --x: #d8483f;
  --y: #3f9a45;
  --z: #3c63cf;
  --w: #c98512;
  --cy: #20c4de;
  --mg: #f0479f;
  --mono: ui-monospace, "DejaVu Sans Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --hand: "Comic Neue", "Comic Sans MS", "Chalkboard SE", "Segoe Print", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--ink);
  font-family: var(--hand);
  -webkit-user-select: none;
  user-select: none;
}

#gl {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud.bare { display: none; }

.panel {
  position: absolute;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 10px 14px 9px 13px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 8px 12px;
}

#stats { top: 14px; left: 14px; transform: rotate(-1deg); min-width: 200px; max-width: 320px; }
#stats .lvl { font-size: 15px; letter-spacing: 1px; }
#stats .lvl span { margin-left: 8px; }
#stats .row { display: flex; justify-content: flex-start; gap: 18px; margin-top: 4px; font-size: 12.5px; letter-spacing: 1px; }
#stats b { font-family: var(--mono); font-size: 15px; }
#hint { margin-top: 6px; padding-top: 6px; border-top: 2px dashed rgba(43, 27, 51, 0.35); font-size: 13px; line-height: 1.4; }
#hint:empty { display: none; }
.free-only { display: none; }
#hud.machines .free-only { display: block; }

#orient { top: 14px; right: 16px; transform: rotate(0.8deg); text-align: center; }
#orient .cap { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; opacity: 0.7; }
#orient .vec, #orient .axes { display: grid; grid-template-columns: 14px repeat(3, 78px) 14px; align-items: center; }
#orient .vec { font-family: var(--mono); font-size: 21px; font-weight: 700; margin-top: 2px; }
#orient .vec i { font-style: normal; font-weight: 400; font-size: 26px; line-height: 1; }
#orient .vec span { text-align: right; padding-right: 8px; font-variant-numeric: tabular-nums; white-space: pre; }
#orient .axes { font-family: var(--mono); font-size: 12px; font-weight: 700; }
#orient .axes span { text-align: right; padding-right: 14px; }
#ow, #orient .axes .ax-w { display: none; }
#hud.free #ow, #hud.free #orient .axes .ax-w, #hud.engaged #ow, #hud.engaged #orient .axes .ax-w { display: block; }
#hud.free #orient .vec, #hud.free #orient .axes, #hud.engaged #orient .vec, #hud.engaged #orient .axes { grid-template-columns: 14px repeat(4, 72px) 14px; }
#hud.engaged #orient { box-shadow: 4px 4px 0 var(--mg); }
#orient .pos { margin-top: 4px; font-family: var(--mono); font-size: 11px; opacity: 0.65; white-space: pre; }
#orient .mach { margin-top: 5px; padding-top: 5px; border-top: 2px dashed rgba(43, 27, 51, 0.35); font-family: var(--mono); font-size: 12.5px; font-weight: 700; text-align: left; }
#orient .mach:empty { display: none; }
#orient .mach div { display: flex; justify-content: space-between; gap: 14px; }
#orient .mach div > span:first-child { font-weight: 400; }
#orient .mach .tip { font-weight: 400; opacity: 0.6; }
.ax-x { color: var(--x); } .ax-y { color: var(--y); } .ax-z { color: var(--z); } .ax-w { color: var(--w); }

#compass { right: 16px; bottom: 16px; padding: 6px 6px 2px; transform: rotate(-0.6deg); }
#globe { display: block; width: 250px; height: 260px; }

#help { left: 14px; bottom: 16px; font-size: 13px; line-height: 1.75; transform: rotate(0.6deg); }
#help .dim { opacity: 0.7; font-size: 12px; }

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 5px;
  margin: 0 2px;
  font-family: var(--mono);
  font-size: 0.85em;
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
  background: #fffaf0;
  border: 2px solid var(--ink);
  border-bottom-width: 3px;
  border-radius: 5px;
}

#cross {
  position: absolute; left: 50%; top: 50%;
  width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border: 2.5px solid var(--paper);
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px var(--ink), inset 0 0 0 1.5px var(--ink);
  opacity: 0.85;
}
#cross::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 4px; height: 4px; margin: -2px 0 0 -2px;
  background: var(--ink); border-radius: 50%;
}

#target {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, 24px);
  padding: 0 8px;
  font-size: 12.5px; font-weight: 700; letter-spacing: 0.5px; line-height: 1.6;
  white-space: nowrap;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 9px;
  opacity: 0.92;
}
#target:empty { display: none; }
#prompt {
  position: absolute; left: 50%; bottom: 9%;
  transform: translateX(-50%);
  padding: 4px 14px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.5px; white-space: pre;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 10px;
  box-shadow: 3px 3px 0 var(--ink);
}
#prompt:empty { display: none; }

#banner {
  position: absolute; left: 0; right: 0; top: 20%;
  text-align: center;
  font-size: clamp(34px, 6vw, 72px);
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--paper);
  text-shadow: 3px 3px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 6px 6px 0 var(--ink);
  opacity: 0;
  transform: rotate(-2deg) scale(0.9);
  transition: opacity 0.25s, transform 0.25s;
}
#banner.on { opacity: 1; transform: rotate(-2deg) scale(1); }
#banner small { display: block; font-size: 0.3em; letter-spacing: 2px; margin-top: 8px; text-shadow: 2px 2px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); }

/* ---------- overlays ---------- */
#overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
#overlay.hidden { display: none; }

.card {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 14px 20px 12px 18px;
  box-shadow: 8px 8px 0 var(--ink);
  padding: 18px 30px 16px;
  max-width: 640px;
  max-height: 96vh;
  overflow: auto;
  transform: rotate(-0.6deg);
  font-size: 15.5px;
  line-height: 1.5;
}
.card.small { text-align: center; min-width: 320px; }
.card h1 { margin: 0; font-size: 54px; letter-spacing: 7px; line-height: 1; text-shadow: 4px 4px 0 var(--mg), -3px -3px 0 var(--cy); }
.card h2 { margin: 0 0 6px; font-size: 40px; letter-spacing: 2px; }
.card .sub { margin: 6px 0 12px; letter-spacing: 3px; text-transform: uppercase; font-size: 12.5px; opacity: 0.75; }
.card p { margin: 10px 0; }
.card table { border-collapse: collapse; margin: 8px 0; width: 100%; }
.card td { padding: 2.5px 0; vertical-align: baseline; }
.card td:first-child { white-space: nowrap; padding-right: 16px; width: 1%; }
.card .dim { opacity: 0.6; font-size: 0.9em; }
.card .tip { font-size: 14px; background: #fff7e2; border: 2px dashed var(--ink); border-radius: 8px; padding: 8px 10px; }
.card .tip:empty { display: none; }
.card.small .tip { max-width: 440px; margin: 12px auto; text-align: left; }
.card .keys { display: grid; grid-template-columns: repeat(3, auto); gap: 4px 16px; margin: 8px 0 4px; font-size: 14px; }
.card .keys .wide { grid-column: span 2; }
.card .go { text-align: center; font-weight: 800; font-size: 18px; margin: 14px 0 0; animation: pulse 1.1s ease-in-out infinite; }

/* menu: one button per level */
#card-title { max-width: 820px; padding: 12px 28px 12px; }
#card-title h1 { font-size: 46px; }
#card-title .sub { margin: 4px 0 6px; }
#card-title p { margin: 7px 0; }
#card-title .tip { padding: 5px 10px; }
#card-title .go { margin: 8px 0 0; }
#card-title .foot { display: flex; align-items: baseline; justify-content: center; gap: 22px; }
#card-title .foot .dim { margin: 0; white-space: nowrap; }
#card-title .foot .dim:empty { display: none; }
/* three columns, one for each zone of the climb (the number of rows is set from the longest zone) */
#levels { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(9, auto); grid-auto-flow: column; gap: 4px 10px; margin: 8px 0 2px; }
#levels .zone { font-family: var(--mono); font-size: 11.5px; letter-spacing: 3px; text-transform: uppercase; opacity: 0.7; padding-left: 4px; }
#levels .lvl {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 8px;
  font-family: inherit; font-size: 13.5px; color: var(--ink); text-align: left; white-space: nowrap; overflow: hidden;
  background: #fffaf0; border: 3px solid var(--ink); border-radius: 9px;
  box-shadow: 3px 3px 0 var(--ink); cursor: pointer;
}
#levels .lvl b {
  flex: none; width: 23px; height: 23px; line-height: 19px; text-align: center;
  font-family: var(--mono); font-size: 12.5px;
  background: #ffd23f; border: 2px solid var(--ink); border-radius: 50%;
}
#levels .lvl.z0 { background: #f1f8e4; }
#levels .lvl.z1 { background: #e6f1fb; }
#levels .lvl.z2 { background: #e9e2f6; }
#levels .lvl.done b { background: var(--y); color: #fff; }
#levels .lvl.done span::after { content: " \2713"; color: var(--y); font-weight: 800; }
#levels .lvl em { margin-left: auto; padding-left: 6px; font-style: normal; color: #d99a12; }
#lvl-shard { color: #ffd23f; }
#levels .lvl:hover { background: #fff3d4; }
#levels .lvl:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
#levels .lvl:focus-visible { outline: 3px solid var(--z); outline-offset: 2px; }
.card.small .dim { margin: 8px 0 0; }
.sw { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--ink); border-radius: 50%; vertical-align: -2px; }
.sw.cy { background: var(--cy); } .sw.mg { background: var(--mg); } .sw.gd { background: #f2b21c; }

@keyframes pulse { 50% { transform: scale(1.05); } }
@media (prefers-reduced-motion: reduce) { .card .go { animation: none; } #banner { transition: none; } }

#err {
  position: fixed; inset: 20px;
  margin: 0; padding: 16px;
  background: #fff5f2; color: #7a1010;
  border: 3px solid #7a1010; border-radius: 8px;
  font: 13px/1.5 var(--mono);
  white-space: pre-wrap; overflow: auto; z-index: 10;
  -webkit-user-select: text; user-select: text;
}

@media (max-height: 620px), (max-width: 900px) {
  #help { display: none; }
  #globe { width: 170px; height: 177px; }
  #orient .vec, #orient .axes { grid-template-columns: 12px repeat(3, 64px) 12px; }
  #orient .vec { font-size: 17px; }
}

/* a short window: tighten the menu so every level still fits without scrolling */
@media (max-height: 800px) {
  #card-title { padding: 8px 28px 9px; }
  #card-title h1 { font-size: 36px; }
  #card-title .sub { margin: 2px 0 3px; font-size: 11px; }
  #card-title p { margin: 4px 0; }
  #card-title .keys { gap: 2px 16px; margin: 4px 0 2px; font-size: 13.5px; }
  #card-title .tip { padding: 3px 10px; font-size: 13.5px; }
  #card-title .go { margin: 5px 0 0; font-size: 17px; }
  #levels { gap: 3px 10px; margin: 6px 0 2px; }
  #levels .lvl { padding: 1px 8px; border-width: 2px; box-shadow: 2px 2px 0 var(--ink); font-size: 13px; }
  #levels .lvl b { width: 21px; height: 21px; line-height: 17px; }
}

#sign-card { position: absolute; width: min(460px, 65vw); box-sizing: border-box;
  opacity: 0; transition: opacity 0.2s; pointer-events: none; line-height: 1.35; }
#sign-card.on { opacity: 1; }
#sign-card strong { display: block; margin-bottom: 4px; }

.sign-equation { text-align: center; font: italic 1.12em Georgia, serif; margin-bottom: 4px; }

.tutorial-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
#levels .tutorial-row button { justify-content: center; font-weight: bold; }
#levels .tutorial-row .done { background: var(--y); color: white; }
