:root {
  --ground: #0d0b16;
  --violet: #a78bfa;
  --violet-strong: #8b5cf6;
  --text: #ece9f7;
  --text-muted: #a9a3c2;
  --glass: rgba(24, 19, 42, 0.72);
  --glass-border: rgba(167, 139, 250, 0.22);
  --chip: rgba(255, 255, 255, 0.05);
  --chip-on: rgba(167, 139, 250, 0.22);
  --bubble-me: rgba(167, 139, 250, 0.18);
  --bubble-it: rgba(255, 255, 255, 0.06);
  --orb: #cfe8ea;
  --orb-core: #a78bfa;
  --wave: rgba(207, 232, 234, 0.35);
  --live: #f3a6b0;
  --danger: #f3a6b0;
  --ok: #7bc96f;
  --glow: rgba(139, 92, 246, 0.45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ground);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
.small { color: var(--text-muted); font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }

/* No double-tap zoom on the face: a double tap there is a grimace. */
#stage { position: fixed; inset: 0; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
#hint {
  position: fixed; left: 50%; top: calc(var(--stage-h, 100vh) * 0.78); transform: translateX(-50%);
  padding: 5px 12px; border-radius: 999px; font-size: 12px; white-space: nowrap; pointer-events: none;
  color: var(--text); background: var(--glass); border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); animation: hintIn 0.3s ease-out;
}
@keyframes hintIn { from { opacity: 0; transform: translateX(-50%) translateY(6px); } }
@media (prefers-reduced-motion: reduce) { #hint { animation: none; } }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; transition: opacity 0.6s ease; }

#brand { position: fixed; top: 20px; left: 24px; pointer-events: none; }
.wordmark { font-weight: 700; letter-spacing: 0.22em; font-size: 18px; }
.wordmark span { color: var(--violet); }
.tagline { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

#takeHome {
  /* As wide as the eight icons of the link row (the eighth, "full page", shows inside the Hub's frame). */
  position: fixed; top: 92px; left: 24px; width: 332px; padding: 14px 16px;
  background: var(--glass); border: 1px solid var(--glass-border); border-radius: 16px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 13px;
}
#takeHome h2 { margin: 0 0 6px; font-size: 15px; }
#takeHome p { margin: 0 0 12px; color: var(--text-muted); }

/* The link row: one round icon per place, the download first and lit. */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icons { display: flex; align-items: center; gap: 5px; }
.icons a {
  position: relative; flex: none; display: grid; place-items: center; width: 32px; height: 32px;
  border-radius: 50%; border: 1px solid var(--glass-border); background: var(--chip); color: var(--text-muted);
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.15s;
}
.icons a[hidden] { display: none; }
.icons svg { width: 15px; height: 15px; }
.icons a:hover, .icons a:focus-visible { color: var(--text); border-color: var(--violet); background: var(--chip-on); transform: translateY(-1px); outline: none; }
.icons a.get {
  width: 36px; height: 36px; color: var(--text); background: var(--violet-strong); border-color: var(--violet-strong);
  box-shadow: 0 0 0 3px var(--chip-on), 0 0 18px var(--glow);
}
.icons a.get svg { width: 17px; height: 17px; }
.icons a.get:hover, .icons a.get:focus-visible { background: var(--violet-strong); filter: brightness(1.12); }
/* The name of each icon, under it, where a pointer can hover (a phone has no hover: its screen reader reads the label). */
@media (hover: hover) {
  .icons a::after {
    content: attr(aria-label); position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(-3px);
    padding: 3px 8px; border-radius: 6px; white-space: nowrap; font-size: 11px; color: var(--text);
    background: var(--ground); border: 1px solid var(--glass-border); opacity: 0; pointer-events: none;
    transition: opacity 0.12s, transform 0.12s; z-index: 2;
  }
  .icons a:hover::after, .icons a:focus-visible::after { opacity: 1; transform: translateX(-50%) translateY(0); }
  /* The first name starts at its icon: centred, it would leave the screen on the left. */
  .icons a:first-child::after { left: 0; transform: translateY(-3px); }
  .icons a:first-child:hover::after, .icons a:first-child:focus-visible::after { transform: translateY(0); }
}
.narrow-only { display: none; }

#orbBox { position: fixed; left: 24px; bottom: 112px; display: flex; align-items: center; gap: 12px; pointer-events: none; }
#phase { color: var(--text-muted); font-size: 13px; letter-spacing: 0.04em; }

button, select, input[type="text"] {
  font: inherit; color: var(--text); background: var(--chip);
  border: 1px solid var(--glass-border); border-radius: 999px; padding: 6px 14px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--violet); }
button:disabled { opacity: 0.6; cursor: default; }
button[aria-pressed="true"], button[aria-selected="true"] { background: var(--chip-on); border-color: var(--violet); }
button.primary { background: var(--violet-strong); border-color: var(--violet-strong); font-weight: 600; }
button.primary.live { background: var(--live); border-color: var(--live); color: var(--ground); animation: breathe 1.2s ease-in-out infinite; }
@keyframes breathe { 50% { filter: brightness(1.15); } }
select { border-radius: 10px; padding: 5px 8px; }
select option, select optgroup { background: var(--ground); color: var(--text); }
input[type="text"] { border-radius: 10px; width: 100%; }
input[type="range"] { accent-color: var(--violet); }

#panel {
  position: fixed; top: 20px; right: 24px; bottom: 96px; width: 380px;
  display: flex; flex-direction: column; gap: 10px; padding: 16px;
  background: var(--glass); border: 1px solid var(--glass-border); border-radius: 16px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  font-size: 14px;
}
#panel h2 { margin: 0 0 6px; font-size: 18px; }
#panel h3 { margin: 14px 0 6px; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; }
#panel p { margin: 0 0 8px; }
#wake { overflow-y: auto; }
#wakeBtn { margin-top: 6px; padding: 9px 20px; }
#brains { border: 1px solid var(--glass-border); border-radius: 12px; padding: 8px 12px 10px; margin: 0 0 10px; }
#brains legend { padding: 0 4px; }
#brains label { display: flex; align-items: baseline; gap: 6px; margin: 4px 0; cursor: pointer; }
#brains input { accent-color: var(--violet); }
/* Bring your model: a quiet link under the two brains, opening a prefilled Community discussion. */
#brains .bring { display: inline-block; margin-top: 6px; color: var(--violet); text-decoration: none; border-bottom: 1px dashed currentColor; }
#brains .bring:hover { border-bottom-style: solid; }
#awake { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#tabs { display: flex; gap: 6px; margin-bottom: 10px; }
#tabs button { padding: 5px 12px; font-size: 13px; }
#tabs button.pulse { animation: pulse 0.9s ease-out 2; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(167, 139, 250, 0.25); } }
.tab { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; }

.prog { margin-top: 10px; font-size: 12px; color: var(--text-muted); }
.bar { height: 4px; background: var(--chip); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--violet); transition: width 0.3s ease; }

#log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 4px; min-height: 120px; }
.bubble { padding: 8px 12px; border-radius: 14px; max-width: 88%; white-space: pre-wrap; }
.bubble.me { align-self: flex-end; background: var(--bubble-me); }
.bubble.it { align-self: flex-start; background: var(--bubble-it); }
.bubble.thinking::after, .bubble.waiting::after { content: '● ● ●'; font-size: 9px; letter-spacing: 3px; color: var(--text-muted); animation: thinking 1.2s ease-in-out infinite; }
.bubble.waiting::after { margin-left: 6px; }
@keyframes thinking { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .bubble.thinking::after, .bubble.waiting::after { animation: none; } }
.note { align-self: center; color: var(--text-muted); font-size: 12px; text-align: center; }
a.note { color: var(--violet); }
#tab-studio a { color: var(--violet); }
#talkBar { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
#textForm { flex: 1; }
#micNote { margin-top: 6px; }

#mixer .row, .row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
#mixer select { width: 120px; }
#mixer input[type="range"] { flex: 1; }
.share { width: 40px; text-align: right; color: var(--text-muted); font-size: 12px; }
#tryForm input { flex: 1; }
.steps { list-style: none; padding: 0; margin: 0 0 8px; font-size: 12px; color: var(--text-muted); }
.steps li { display: flex; gap: 8px; align-items: center; margin: 3px 0; }
.steps li > span:first-child { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--chip-on); color: var(--text); font-size: 11px; }
#words { font-size: 13px; margin: 6px 0 4px; }
#words span { color: var(--text-muted); transition: color 0.15s; }
#words span.said { color: var(--text); }
#phonemes { font-size: 12px; color: var(--violet); word-break: break-word; min-height: 1.4em; }
#wave { width: 100%; height: 90px; margin-top: 6px; background: var(--chip); border-radius: 10px; }

#memList { list-style: none; padding: 0; margin: 4px 0 10px; }
#memList li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; margin: 6px 0; background: var(--chip); border: 1px solid var(--glass-border); border-radius: 10px; }
#memList button { padding: 3px 10px; font-size: 12px; }
.note { margin-top: auto; }
#tab-memory .note { text-align: left; align-self: stretch; margin-top: 14px; }


#gallery {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px 16px;
  display: flex; gap: 18px; justify-content: center; flex-wrap: wrap;
  background: linear-gradient(to top, rgba(13, 11, 22, 0.92), rgba(13, 11, 22, 0));
}
.group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.group-label { color: var(--text-muted); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; margin-right: 4px; }

#loading, #error {
  /* In the middle of the face's room: on a phone that room ends where the panel begins (app.js sets --stage-h). */
  position: fixed; left: 50%; top: calc(var(--stage-h, 100vh) / 2); transform: translate(-50%, -50%);
  color: var(--text-muted); pointer-events: none;
}
#error { color: var(--danger); max-width: 520px; text-align: center; }

@media (max-width: 1100px) and (min-width: 761px) {
  #gallery { right: 420px; justify-content: flex-start; }
}
@media (max-width: 760px) {
  /* The face is drawn in the room above the panel (app.js sets its height), never under it. */
  #stage { bottom: auto; height: var(--stage-h, 100%); }
  #brand { left: 14px; top: 10px; }
  .wordmark { font-size: 15px; letter-spacing: 0.2em; }
  .tagline { font-size: 11px; margin-top: 0; }
  /* A phone keeps the link row only, under the brand: the panel and the face need the room. */
  #takeHome { top: 54px; left: 14px; right: 14px; width: auto; padding: 0; background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none; }
  #takeHome h2, #takeHome p { display: none; }
  .icons { gap: 6px; }
  #orbBox { top: 6px; right: 10px; left: auto; bottom: auto; flex-direction: row-reverse; gap: 6px; }
  #orb { width: 44px; height: 44px; }
  #phase { font-size: 12px; }
  #panel { left: 8px; right: 8px; top: auto; bottom: 60px; width: auto; height: 46vh; padding: 12px; gap: 6px; }
  /* Before the wake the panel is as tall as what it says, so the face keeps the most room. */
  #panel:has(#awake[hidden]) { height: auto; max-height: 46vh; }
  .wide-only { display: none; }
  .narrow-only { display: block; }
  #panel h2 { font-size: 16px; margin-bottom: 4px; }
  #brains { padding: 4px 10px 6px; margin-bottom: 6px; }
  #brains legend { display: none; }
  #brains label { margin: 2px 0; }
  #brains .bring { margin-top: 2px; }
  #wake .narrow-only { margin-bottom: 6px; }
  #wakeBtn { margin-top: 2px; }
  /* While it wakes, the choices are made: the panel shows the downloads only. */
  #wake.waking #brains, #wake.waking .narrow-only { display: none; }
  #micNote { display: none; }
  /* The typing field keeps the room: the button and the language take what their text needs. */
  #talkBar { gap: 6px; }
  #micBtn { flex: none; padding: 6px 12px; white-space: nowrap; }
  #textForm { min-width: 0; }
  #lang { flex: none; max-width: 104px; }
  #gallery {
    flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; gap: 14px;
    padding: 10px 16px 14px; scrollbar-width: none;
  }
  #gallery::-webkit-scrollbar { display: none; }
  .group { flex-wrap: nowrap; flex: none; }
  #gallery button { padding: 5px 11px; font-size: 13px; white-space: nowrap; }
}

/* The film, in the page: as tall as the screen allows, never wider than it. */
#film { padding: 0; border: 1px solid var(--glass-border); border-radius: 14px; background: var(--ground); color: var(--text); max-width: 92vw; }
#film::backdrop { background: rgba(0, 0, 0, 0.72); }
#filmVideo { display: block; height: min(80vh, 160vw); max-width: 92vw; aspect-ratio: 9 / 16; background: var(--ground); }
#film .filmBar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 12px; font-size: 13px; }
#film .filmBar a { color: var(--violet); }
#film .filmBar button { background: var(--chip); color: var(--text); border: 1px solid var(--glass-border); border-radius: 8px; padding: 4px 12px; cursor: pointer; }
