:root {
  --bg: #0a0a0b;
  --bone: #ece6d8;
  --bone-2: rgba(236, 230, 216, .78);
  --dim: rgba(236, 230, 216, .46);
  --faint: rgba(236, 230, 216, .22);
  --acid-g: #7cf09a;
  --acid: #bdf35c;
  --acid-y: #ecf76a;
  --acid-grad: linear-gradient(100deg, var(--acid-g), var(--acid-y));
  --violet: #8c7cff;
  --violet-2: #c4bbff;
  --m: clamp(16px, 2.6vw, 36px);
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--bone);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font: 400 12px/1.5 var(--mono);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

::selection { background: var(--acid); color: var(--bg); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

#over {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

#field {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}

/* ───────────── HUD ───────────── */

.hud {
  position: fixed;
  z-index: 2;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.dim { color: var(--dim); }
.tiny { font-size: 10px; }

.tl { top: var(--m); left: var(--m); }

.brand {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .02em;
}
.brand .ext {
  color: var(--acid);
  background: var(--acid-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.log {
  margin-top: 6px;
  min-height: 3lh;
  font-size: 11px;
  color: var(--dim);
}
.log div {
  white-space: nowrap;
  animation: logIn .35s ease-out;
}
.log div::before { content: "› "; color: var(--acid); }
.log div:nth-child(1) { color: var(--bone-2); }
.log div:nth-child(2) { opacity: .55; }
.log div:nth-child(3) { opacity: .28; }

@keyframes logIn {
  from { transform: translateY(-4px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.tr {
  top: var(--m);
  right: var(--m);
  text-align: right;
  font-size: 11px;
}
.tr .row { display: flex; gap: 8px; justify-content: flex-end; }
.tr .k { font-weight: 700; color: var(--violet-2); }
#nstep, #nloss { color: var(--bone); min-width: 6ch; text-align: left; font-variant-numeric: tabular-nums; }
#spark { display: block; width: 150px; height: 26px; margin: 6px 0 4px auto; }
.ghost-key { color: var(--violet); }

/* ───────────── REPL ───────────── */

#about {
  position: fixed;
  z-index: 2;
  left: var(--m);
  bottom: var(--m);
  pointer-events: none;
}

#repl {
  margin: 0;
  font: 400 13px/1.62 var(--mono);
  color: var(--bone-2);
  tab-size: 4;
}

#repl .ln {
  visibility: hidden;
  pointer-events: auto;
  border-radius: 2px;
  transition: background-color .15s, color .15s;
}
#repl .ln.on { visibility: visible; }
#repl .ln.in { color: var(--bone); }
#repl .pr { color: var(--acid-g); font-weight: 700; }
#repl .str { color: var(--violet-2); }
#repl .kw { color: var(--acid-y); }
#repl .cm { color: var(--dim); }
#repl a { color: inherit; text-decoration: none; }
#repl a .str { text-decoration: underline; text-decoration-color: rgba(196, 187, 255, .35); text-underline-offset: 3px; }
#repl a.fx { cursor: pointer; }

#repl .fx { cursor: default; }
#repl .fx:hover,
#repl .fx.active {
  background: var(--acid-grad);
  color: var(--bg);
  box-shadow: -3px 0 0 0 var(--acid-g), 3px 0 0 0 var(--acid-y), 0 0 18px rgba(189, 243, 92, .35);
}
#repl .fx:hover .str,
#repl .fx:hover .cm,
#repl .fx.active .str { color: var(--bg); }
#repl .fx:focus-visible { outline: 2px solid var(--violet); outline-offset: 3px; }
.noscript a { color: var(--acid); }

#repl .caret::after {
  content: "▍";
  color: var(--acid);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ───────────── controls ───────────── */

.br {
  right: var(--m);
  bottom: var(--m);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
}

.hint {
  margin: 0;
  font-size: 11px;
  display: grid;
  gap: 1px;
  transition: opacity .6s;
}
.hint div { display: flex; justify-content: flex-end; gap: 10px; }
.hint dt { color: var(--dim); }
.hint dd { margin: 0; min-width: 21ch; color: var(--bone-2); }
.hint.quiet { opacity: .35; }

.tray-wrap { display: flex; align-items: center; gap: 10px; }
.tray-label { font-size: 11px; }
.tray { display: flex; gap: 2px; }

.tray button,
.sound {
  pointer-events: auto;
  font: inherit;
  color: var(--dim);
  background: transparent;
  border: 1px solid var(--faint);
  border-radius: 0;
  cursor: pointer;
}
.tray button {
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
  font-family: "Apple Symbols", "Segoe UI Symbol", "DejaVu Sans", var(--mono);
  transition: background-color .15s, color .15s, border-color .15s;
}
.tray button:hover { color: var(--bone); border-color: var(--dim); }
.tray button[aria-pressed="true"] {
  background: var(--acid-grad);
  border-color: var(--acid);
  color: var(--bg);
}
.sound {
  height: 30px;
  padding: 0 10px;
  font-size: 11px;
}
.sound[aria-pressed="true"] { color: var(--bg); background: var(--violet); border-color: var(--violet); }
.tray button:focus-visible,
.sound:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }

.noscript {
  position: fixed; inset: 0; z-index: 9; padding: 10vh 8vw;
  background: var(--bg); font-size: 15px; line-height: 1.7;
}
.noscript h1 { font: 900 64px/1 "Big Shoulders Display", Impact, sans-serif; margin: 0 0 24px; }

/* ───────────── small screens ───────────── */

/* touch screens: no hover, no cursor to learn */
@media (hover: none) {
  #net, .hint { display: none; }
}

@media (max-width: 900px) {
  .hint { display: none; }
  #about { bottom: calc(var(--m) + 46px); }
  .br { left: var(--m); align-items: stretch; }
  .tray-wrap { justify-content: space-between; }
}

@media (max-width: 760px) {
  #net { display: none; }
  #repl { font-size: clamp(9px, 2.7vw, 12px); line-height: 1.5; }
  .tray button { width: 34px; height: 34px; }
  .sound { height: 34px; }
}

@media (max-width: 420px) {
  .tray-label { display: none; }
}

/* landscape phones: REPL moves to the right, the name takes the left */
@media (max-width: 760px) and (max-height: 520px) {
  #about { left: auto; right: var(--m); bottom: calc(var(--m) + 44px); }
  #repl { font-size: 9px; line-height: 1.36; }
  .log { min-height: 1lh; }
  .log div:nth-child(n+2) { display: none; }
  .tray button, .sound { height: 30px; }
  .tray button { width: 30px; }
}

@media (max-height: 560px) and (min-width: 761px) {
  .hint { display: none; }
  #repl { font-size: 11px; line-height: 1.45; }
}

@media (prefers-reduced-motion: reduce) {
  .log div { animation: none; }
  #repl .caret::after { animation: none; }
}
