/* One surface: her name, an orb, one line. Nothing else earns a place here. */

:root {
  --bg: #0b0b0d;
  --bg-lift: #141417;
  --ink: #ece7e1;
  --ink-dim: #8a8681;
  --ink-faint: #56534f;
  --warm: #e8c6a0;
  --warm-deep: #c98f5a;
  --edge: #22222899;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(120% 90% at 50% 8%, #15151a 0%, var(--bg) 62%);
  color: var(--ink);
  font: 400 16px/1.55 ui-rounded, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#stage {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  justify-items: center;
  gap: 0;
  padding: max(24px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

header {
  padding-top: 8vh;
}

h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: lowercase;
  color: var(--ink-dim);
  transition: color 0.6s var(--ease);
}

body[data-state='speaking'] h1 {
  color: var(--warm);
}

/* ---------------------------------------------------------------- the orb */

#orb {
  --size: min(46vw, 208px);
  position: relative;
  align-self: center;
  width: var(--size);
  height: var(--size);
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}

#orb:focus-visible {
  outline: 2px solid var(--warm);
  outline-offset: 14px;
}

.orb-core,
.orb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}

.orb-core {
  background: radial-gradient(circle at 38% 32%, #fff6ea 0%, var(--warm) 34%, var(--warm-deep) 72%, #6d4526 100%);
  box-shadow: 0 0 60px -12px var(--warm-deep);
  opacity: 0.28;
  transform: scale(0.9);
  transition: opacity 0.8s var(--ease), transform 0.8s var(--ease), box-shadow 0.8s var(--ease);
}

.orb-ring {
  border: 1px solid #ffffff14;
  transform: scale(1.18);
  opacity: 0;
  transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}

/* idle: barely there, breathing. she is present, not demanding */
body[data-state='idle'] .orb-core {
  animation: breathe 6.5s ease-in-out infinite;
}

body[data-state='ready'] .orb-core {
  opacity: 0.45;
  transform: scale(0.94);
  animation: breathe 5s ease-in-out infinite;
}

body[data-state='speaking'] .orb-core {
  opacity: 1;
  transform: scale(1);
  box-shadow: 0 0 90px -6px var(--warm-deep);
  animation: speak 1.9s ease-in-out infinite;
}

body[data-state='listening'] .orb-core {
  opacity: 0.55;
  transform: scale(0.92);
}

body[data-state='listening'] .orb-ring {
  opacity: 1;
  animation: listen 2.4s ease-out infinite;
}

body[data-state='thinking'] .orb-core {
  opacity: 0.7;
  animation: think 1.4s ease-in-out infinite;
}

body[data-state='lost'] .orb-core {
  opacity: 0.2;
  filter: grayscale(0.7);
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(0.9);
  }
  50% {
    transform: scale(0.97);
  }
}

@keyframes speak {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes think {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.85;
  }
}

@keyframes listen {
  0% {
    transform: scale(0.98);
    opacity: 0.7;
  }
  100% {
    transform: scale(1.32);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .orb-core,
  .orb-ring {
    animation: none !important;
  }
}

/* --------------------------------------------------------------- the line */

.line {
  margin: 26px 0 0;
  max-width: 30rem;
  min-height: 3.4em;
  text-align: center;
  text-wrap: balance;
  font-size: 17px;
  color: var(--ink);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}

.line.show {
  opacity: 1;
  transform: none;
}

.line.quiet {
  color: var(--ink-dim);
  font-size: 15px;
}

/* -------------------------------------------------------------- text input */

/* ------------------------------------------------------------------- tray */

#tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 18px;
  margin-top: 28px;
  opacity: 0;
  transition: opacity 1.2s var(--ease);
}

#tray.show {
  opacity: 1;
}

#tray button {
  border: 0;
  background: none;
  padding: 6px 2px;
  color: var(--ink-faint);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: color 0.3s var(--ease);
}

#tray button:hover,
#tray button:focus-visible {
  color: var(--ink-dim);
  outline: none;
}

/* ------------------------------------------------------------------ sheet */

dialog {
  border: 1px solid var(--edge);
  border-radius: 18px;
  background: var(--bg-lift);
  color: var(--ink);
  padding: 22px;
  width: min(26rem, calc(100vw - 32px));
}

dialog::backdrop {
  background: #000000b8;
  backdrop-filter: blur(3px);
}

dialog h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 500;
}

dialog p {
  margin: 0 0 12px;
  color: var(--ink-dim);
  font-size: 14px;
}

dialog ul {
  margin: 0 0 14px;
  padding-left: 18px;
  color: var(--ink);
  font-size: 14px;
}

dialog li {
  margin-bottom: 6px;
}

dialog input {
  width: 100%;
  margin-bottom: 10px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: #0e0e11;
  color: var(--ink);
  font: inherit;
}

dialog menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 16px 0 0;
  padding: 0;
}

dialog menu button {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: none;
  color: var(--ink-dim);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

dialog menu button#sheet-ok {
  background: var(--warm);
  border-color: var(--warm);
  color: #221609;
}

.error {
  color: #e0a08a;
  font-size: 13px;
}

/* --------------------------------------------------- the start affordance */

/*
 * The orb is self-explanatory once she is talking, and completely opaque before that.
 * The word sits inside it until the first tap and then never returns - `data-started`
 * is set in begin(), so a mute later on cannot bring it back and imply a restart.
 */
.orb-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 15px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  pointer-events: none;
  animation: label-in 900ms ease both;
}

body[data-started] .orb-label {
  display: none;
}

@keyframes label-in {
  from { opacity: 0; }
  to   { opacity: 0.85; }
}

@media (prefers-reduced-motion: reduce) {
  .orb-label { animation: none; opacity: 0.85; }
}

/* ------------------------------------------------------- the memory panel */

#sheet-body {
  max-height: min(62vh, 30rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet-note {
  font-size: 13px;
  color: var(--ink-dim);
}

#sheet-body h3 {
  margin: 18px 0 6px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

#sheet-body h3:first-of-type {
  margin-top: 10px;
}

.mem-count {
  color: var(--edge-strong, var(--ink-dim));
  opacity: 0.7;
}

.mem-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.mem-list li {
  padding: 7px 0;
  border-top: 1px solid var(--edge);
  font-size: 14px;
  line-height: 1.45;
}

.mem-text {
  display: block;
  color: var(--ink);
}

.mem-meta {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  opacity: 0.8;
}
