:root {
  --bg: #050608; --fg: #f2f3f7; --dim: #6d7385; --faint: #3d4250; --acc: #b7ff5a; --acc2: #5ad1ff; --err: #ff8a95;
  --eo: cubic-bezier(0.23, 1, 0.32, 1);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--fg); }
body {
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid; grid-template-rows: auto 1fr auto; min-height: 100dvh; overflow: hidden;
  -webkit-font-smoothing: antialiased;
  background: radial-gradient(ellipse at 50% 40%, #0b0d12 0%, var(--bg) 60%);
}
button { font: inherit; color: inherit; }
a { color: inherit; }

header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  position: relative; z-index: 3;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 600; font-size: 15px; letter-spacing: -0.02em; }
.brand img { height: 18px; width: auto; display: block; opacity: 0.92; }
.brand span { padding-left: 10px; border-left: 1px solid rgba(255, 255, 255, 0.14); }

.seg { display: flex; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 999px; padding: 3px; }
.seg button {
  all: unset; cursor: pointer; padding: 6px 12px; border-radius: 999px; font-size: 13px; color: var(--dim);
  transition: background 0.2s, color 0.2s; white-space: nowrap;
}
.seg button[aria-checked="true"] { background: var(--fg); color: #0a0b0e; }
.seg button:focus-visible { outline: 2px solid var(--acc2); outline-offset: 2px; }

/* model choice (In browser tab only), top of the stage */
#models { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 2; }
.seg.mini { padding: 2px; }
.seg.mini button { padding: 4px 11px; font-size: 12px; }
.seg.mini small { font-size: 10.5px; opacity: 0.75; margin-left: 3px; }
.seg.mini button[disabled] { cursor: default; opacity: 0.55; }
body.local #models { display: none; }

main { display: grid; grid-template-rows: 1fr auto auto; min-height: 0; padding: 0 16px; }
#stage { position: relative; min-height: 220px; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#cube {
  position: absolute; border-radius: 50%; border: 0; background: transparent; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#cube:focus-visible { outline: 2px solid var(--acc2); outline-offset: 6px; }
#cube[disabled] { cursor: default; }

#setup {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(92%, 500px);
  text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center;
  background: rgba(5, 6, 8, 0.72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 16px; padding: 22px 20px;
}
#setup[hidden] { display: none; }
.setup-title { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.setup-sub { font-size: 12.5px; color: var(--dim); line-height: 1.5; }
.setup-sub a { color: var(--fg); }
.setup-sub code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--fg); user-select: all; white-space: nowrap; }
.cmd { display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 10px; padding: 6px 6px 6px 14px; }
.cmd { max-width: 100%; }
.cmd code { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--acc); user-select: all; text-align: left; overflow-wrap: anywhere; }

.ghost {
  all: unset; cursor: pointer; font-size: 12px; color: var(--fg); padding: 5px 10px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14); background: rgba(255, 255, 255, 0.04); transition: background 0.2s;
}
.ghost:hover { background: rgba(255, 255, 255, 0.1); }
.ghost:focus-visible, .icon:focus-visible { outline: 2px solid var(--acc2); outline-offset: 2px; }
.ghost[hidden], .icon[hidden] { display: none; }

/* live text: the last two lines, older lines fade out at the top */
#text {
  position: relative; height: calc(2 * 1.3em); overflow: hidden; text-align: center;
  font-size: clamp(19px, 2.4vw, 30px); font-weight: 500; letter-spacing: -0.02em; line-height: 1.3em;
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,.3) 0, #000 42%); mask-image: linear-gradient(to bottom, rgba(0,0,0,.3) 0, #000 42%);
  max-width: 980px; width: 100%; margin: 0 auto;
}
#lines { position: absolute; left: 0; right: 0; bottom: 0; }
.w { display: inline-block; margin: 0 0.12em; transition: color 0.6s ease; }
.p .w { color: var(--dim); }
.w.in { animation: rise 0.55s var(--eo) both; }
@keyframes rise { from { opacity: 0; transform: translateY(0.45em); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

#row {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  min-height: 44px; padding: 10px 0 4px; font-size: 14px; color: var(--dim);
}
#hint.err { color: var(--err); }
#chip {
  font-size: 11px; letter-spacing: 0.02em; color: var(--dim); border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px; padding: 3px 9px; white-space: nowrap;
}
.icon { all: unset; cursor: pointer; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.icon svg { width: 18px; height: 18px; fill: none; stroke: var(--dim); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon:hover svg { stroke: var(--fg); }
.icon[aria-pressed="true"] .off, .icon[aria-pressed="false"] .on { display: none; }
body:not(.demo) #chip, body:not(.demo) #sound { display: none; }

footer {
  text-align: center; font-size: 12px; color: var(--faint); letter-spacing: 0.01em;
  padding: 6px 16px max(14px, env(safe-area-inset-bottom));
}
footer b { color: var(--dim); font-weight: 500; }
.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; color: var(--dim); }

@media (max-width: 520px) {
  .seg.mini small { display: block; margin: 0; }
  .seg.mini button { text-align: center; line-height: 1.15; }
  .brand img { height: 15px; }
  .seg button { padding: 6px 10px; font-size: 12.5px; }
  #text { font-size: 19px; }
  #row { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .w.in { animation: fade 0.3s ease both; }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
  .w, .seg button { transition: none; }
}
