:root {
  --bg: #07080b;
  --ink: #f4f1ea;
  --muted: #9aa3ad;
  --accent: #19c3d6;
  --glass: rgba(12, 14, 18, 0.72);
  --glass-solid: rgba(12, 14, 18, 0.96);
  --line: rgba(255, 255, 255, 0.08);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 50% 45%, #0e1a1d 0%, #07080b 65%);
  color: var(--ink); font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#stage { position: fixed; inset: 0; }
#stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#gl { background: var(--bg); }
#overlay { cursor: crosshair; outline: none; }
#overlay:focus-visible { box-shadow: inset 0 0 0 2px rgba(25, 195, 214, 0.5); }
.noscript { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); max-width: 32em; text-align: center; color: var(--muted); font: 14px/1.6 var(--mono); padding: 0 20px; }

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

.glass {
  background: var(--glass-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
@supports ((backdrop-filter: blur(10px)) or (-webkit-backdrop-filter: blur(10px))) {
  .glass { background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
}

#ui { transition: opacity 0.3s; }
body.ui-hidden #ui { opacity: 0; pointer-events: none; }
body.ui-hidden #ui * { pointer-events: none !important; }

#brand {
  position: fixed; left: 20px; top: 18px; pointer-events: none;
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.32em;
}
.brand-title { font-size: 13px; color: var(--ink); opacity: 0.9; }
.brand-title, .brand-sub, #hud { text-shadow: 0 0 2px #07080b, 0 0 8px #07080b, 0 0 16px #07080b; }
.brand-sub { font-size: 9.5px; color: #b8c0c7; margin-top: 5px; letter-spacing: 0.24em; }
/* Soft scrims so labels stay legible over bright filaments. */
#brand::before, #hud::before {
  content: ''; position: absolute; inset: -14px -22px; z-index: -1; pointer-events: none;
  background: radial-gradient(closest-side, rgba(7, 8, 11, 0.72), rgba(7, 8, 11, 0.4) 60%, transparent);
}

#hud {
  position: fixed; left: 20px; bottom: calc(18px + var(--safe-b)); pointer-events: none;
  font: 11px/1.7 var(--mono); text-transform: uppercase; letter-spacing: 0.14em;
  color: #b3bcc4;
}
#hud3 { color: var(--accent); min-height: 1.7em; }

#topbar { position: fixed; top: 14px; right: 14px; display: flex; gap: 8px; z-index: 5; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  color: var(--ink); background: var(--glass-solid); border: 1px solid var(--line); border-radius: var(--radius);
  font: 15px var(--mono); cursor: pointer; transition: border-color 0.2s, color 0.2s;
}
@supports (backdrop-filter: blur(10px)) { .icon-btn { background: var(--glass); backdrop-filter: blur(10px); } }
.icon-btn:hover { border-color: rgba(255, 255, 255, 0.22); }
.icon-btn[aria-expanded="true"] { color: var(--accent); border-color: rgba(25, 195, 214, 0.45); }
.icon-btn.small { width: 32px; height: 32px; font-size: 18px; }

button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg button:focus-visible { outline-offset: -2px; }

#panel {
  position: fixed; top: 62px; right: 14px; width: 292px; max-height: calc(100vh - 80px); overflow: auto;
  padding: 12px 16px 16px; z-index: 4;
  font: 12px var(--mono); color: var(--ink);
  scrollbar-width: thin;
}
#panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.panel-head h2, .help-head h2 { font: 11px var(--mono); text-transform: uppercase; letter-spacing: 0.24em; color: var(--muted); margin: 0; font-weight: normal; }
.panel-grip { display: none; }
.group { margin: 10px 0 12px; }
.group-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.16em; color: var(--muted); margin-bottom: 7px; }

.chips, .seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { gap: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-wrap: nowrap; }
.chips button, .seg button, .actions button {
  font: 11px var(--mono); letter-spacing: 0.06em; color: #c9d0d6; background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; cursor: pointer; min-height: 32px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.seg button { flex: 1; border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.chips button:hover, .seg button:hover, .actions button:hover { background: rgba(255, 255, 255, 0.07); color: var(--ink); }
.chips button[aria-pressed="true"], .seg button[aria-pressed="true"], .actions button[aria-pressed="true"] {
  color: #041417; background: var(--accent); border-color: var(--accent);
}

.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 8px; margin: 2px 0; }
.slider label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.12em; color: #c3cad0; }
.slider output { font-size: 10.5px; color: var(--accent); font-variant-numeric: tabular-nums; }
.slider input { grid-column: 1 / -1; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 32px; padding: 0; margin: 0;
  background: transparent; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: rgba(255, 255, 255, 0.28); }
input[type=range]::-moz-range-track { height: 1px; background: rgba(255, 255, 255, 0.28); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; margin-top: -5.5px;
  background: var(--ink); border: 2px solid var(--bg); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4);
}
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); border: 2px solid var(--bg); }
input[type=range]:focus-visible { outline: none; }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent); }
input[type=range]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--accent); }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.mobile-only { display: none; }

.pill {
  position: fixed; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translateX(-50%);
  padding: 9px 16px; border-radius: 999px; pointer-events: none; white-space: nowrap;
  font: 11px var(--mono); letter-spacing: 0.08em; color: #d5dbe0;
  background: var(--glass-solid); border: 1px solid var(--line);
}
@supports (backdrop-filter: blur(10px)) { .pill { background: var(--glass); backdrop-filter: blur(10px); } }
/* Clear of the HUD (3 lines at the bottom left) at every width, and of the play button when shown. */
#hint { bottom: calc(80px + var(--safe-b)); }
body.play-visible #hint { bottom: calc(124px + var(--safe-b)); }
#hint { opacity: 0; transition: opacity 0.9s ease; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis; }
#hint.show { opacity: 1; }
#growing { bottom: 50%; color: var(--accent); letter-spacing: 0.24em; text-transform: uppercase; }

#playBtn {
  position: fixed; left: 50%; bottom: calc(64px + var(--safe-b)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 13px 22px; border-radius: 999px;
  font: 13px var(--mono); letter-spacing: 0.12em; text-transform: uppercase; cursor: pointer;
  color: #041417; background: var(--accent); border: 0; box-shadow: 0 6px 30px rgba(25, 195, 214, 0.3);
}
#playBtn[hidden] { display: none; }

#toasts { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; z-index: 6; }
.toast {
  font: 11px var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink);
  padding: 8px 14px; border-radius: 999px; background: var(--glass-solid); border: 1px solid var(--line);
  animation: toast 1.6s ease forwards;
}
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

dialog#help {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  padding: 20px 24px 24px; color: var(--ink); font: 13px/1.55 var(--sans);
}
dialog#help::backdrop { background: rgba(3, 4, 6, 0.55); }
.help-head { display: flex; justify-content: space-between; align-items: center; }
.help-head h2 { font-size: 12px; color: var(--ink); }
.lede { color: #c3cad0; font-size: 13px; margin: 12px 0 16px; max-width: 62em; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.help-cols h3 { font: 10.5px var(--mono); text-transform: uppercase; letter-spacing: 0.2em; color: var(--accent); margin: 0 0 8px; font-weight: normal; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 12px; }
dt { color: var(--ink); font-family: var(--mono); font-size: 11px; white-space: nowrap; }
dd { margin: 0; color: #b8c0c7; }
kbd { font: 10.5px var(--mono); padding: 1px 5px; border: 1px solid rgba(255, 255, 255, 0.18); border-bottom-width: 2px; border-radius: 4px; background: rgba(255, 255, 255, 0.04); }

@media (max-width: 699px) {
  #brand { left: 16px; top: 16px; }
  .brand-title { font-size: 12px; }
  #hud { left: 16px; bottom: calc(14px + var(--safe-b)); font-size: 10px; }
  #topbar { top: 12px; right: 12px; }
  #panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh;
    border-radius: 14px 14px 0 0; border-bottom: 0; padding: 6px 16px calc(16px + var(--safe-b));
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  }
  .panel-grip { display: block; width: 36px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.18); margin: 4px auto 6px; }
  .mobile-only { display: block; }
  .actions { grid-template-columns: repeat(3, 1fr); }
  .chips button, .seg button, .actions button { min-height: 40px; }
  .pill { bottom: calc(64px + var(--safe-b)); font-size: 10.5px; }
  #hint { bottom: calc(76px + var(--safe-b)); white-space: normal; text-align: center; border-radius: 14px; width: max-content; line-height: 1.5; }
  body.play-visible #hint { bottom: calc(170px + var(--safe-b)); }
  .help-cols { grid-template-columns: 1fr; gap: 16px; }
  #playBtn { bottom: calc(110px + var(--safe-b)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: 0.01ms !important; }
  .toast { animation: none; }
}
