/* ---------------------------------------------------------------- tokens */

:root {
  --ink: #0a1211;
  --ink-2: #0e1917;
  --ink-3: #14211e;
  --paper: #f2ece2;
  --paper-soft: #cbc5bb;
  --muted: #8c9a94;
  --line: rgba(242, 236, 226, 0.1);
  --line-strong: rgba(242, 236, 226, 0.18);
  --amber: #e9b164;
  --amber-dim: rgba(233, 177, 100, 0.16);
  --mint: #8fd9c4;
  --mint-dim: rgba(143, 217, 196, 0.14);
  --warn: #e08d7c;

  --display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --ui: "Instrument Sans", "Helvetica Neue", system-ui, sans-serif;

  --pad: clamp(20px, 3.6vw, 52px);
  --cap-h: 104px;
  --ease: cubic-bezier(0.22, 0.68, 0.24, 1);
}

/* ---------------------------------------------------------------- reset */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
  border-radius: 4px;
}

::selection {
  background: rgba(233, 177, 100, 0.28);
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------------------------------------------------------------- shell */

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(340px, 0.74fr);
  height: 100dvh;
}

.stage {
  display: flex;
  flex-direction: column;
  padding: 26px var(--pad) 20px;
  position: relative;
  min-width: 0;
  background:
    radial-gradient(120% 90% at 18% -10%, rgba(143, 217, 196, 0.07), transparent 58%),
    radial-gradient(90% 70% at 80% 108%, rgba(233, 177, 100, 0.07), transparent 60%),
    var(--ink);
}

/* ---------------------------------------------------------------- header */

.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  color: var(--amber);
  display: grid;
  place-items: center;
  opacity: 0.9;
}

.brand-name {
  font-family: var(--display);
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0.01em;
}

.head-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
  padding: 6px 12px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 100px;
  transition: color 240ms var(--ease), border-color 240ms var(--ease);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 240ms var(--ease), box-shadow 240ms var(--ease);
}

.status[data-mode="listening"] {
  color: var(--mint);
  border-color: rgba(143, 217, 196, 0.3);
}
.status[data-mode="listening"] .status-dot {
  background: var(--mint);
  box-shadow: 0 0 0 0 rgba(143, 217, 196, 0.5);
  animation: halo 1.8s ease-out infinite;
}
.status[data-mode="speaking"] {
  color: var(--amber);
  border-color: rgba(233, 177, 100, 0.32);
}
.status[data-mode="speaking"] .status-dot {
  background: var(--amber);
  animation: blink 1.3s ease-in-out infinite;
}
.status[data-mode="thinking"] {
  color: var(--paper-soft);
  border-color: var(--line-strong);
}
.status[data-mode="thinking"] .status-dot {
  background: var(--paper-soft);
  animation: blink 0.9s ease-in-out infinite;
}

@keyframes halo {
  0% { box-shadow: 0 0 0 0 rgba(143, 217, 196, 0.45); }
  70%, 100% { box-shadow: 0 0 0 8px rgba(143, 217, 196, 0); }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  border: 1px solid transparent;
  transition: color 200ms var(--ease), border-color 200ms var(--ease), background 200ms var(--ease);
}

.icon-btn:hover {
  color: var(--paper);
  border-color: var(--line);
  background: rgba(242, 236, 226, 0.03);
}

/* ---------------------------------------------------------------- intro */

.intro {
  margin-top: clamp(28px, 6vh, 68px);
  max-width: 46ch;
}

.intro h1 {
  font-family: var(--display);
  font-optical-sizing: auto;
  font-weight: 300;
  font-size: clamp(2.55rem, 5.2vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: -0.018em;
  margin: 0 0 18px;
  color: var(--paper);
}

.intro p {
  margin: 0;
  max-width: 36ch;
  font-size: 15px;
  line-height: 1.62;
  color: var(--muted);
}

/* ---------------------------------------------------------------- instrument */

.instrument {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  align-content: center;
  gap: clamp(10px, 1.6vh, 20px);
  padding: 8px 0 4px;
  margin-top: 4px;
}

.orb {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 470px;
  min-height: 0;
  justify-self: center;
  align-self: center;
}

#viz {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.mic {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 104px;
  height: 104px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--paper);
  background: radial-gradient(circle at 50% 32%, rgba(242, 236, 226, 0.1), rgba(242, 236, 226, 0.02) 62%);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(2px);
  transition:
    color 260ms var(--ease),
    border-color 260ms var(--ease),
    background 260ms var(--ease),
    box-shadow 260ms var(--ease),
    width 260ms var(--ease),
    height 260ms var(--ease);
}

.mic:hover {
  border-color: rgba(242, 236, 226, 0.3);
  background: radial-gradient(circle at 50% 32%, rgba(242, 236, 226, 0.16), rgba(242, 236, 226, 0.03) 62%);
}

.mic-label {
  font-size: 11.5px;
  letter-spacing: 0.02em;
  color: var(--muted);
  transition: color 260ms var(--ease);
}

.mic .i-stop {
  display: none;
}

.mic[data-mode="listening"] {
  color: var(--mint);
  border-color: rgba(143, 217, 196, 0.6);
  background: radial-gradient(circle at 50% 32%, rgba(143, 217, 196, 0.2), rgba(143, 217, 196, 0.03) 64%);
  box-shadow: 0 0 70px -12px rgba(143, 217, 196, 0.55);
  width: 108px;
  height: 108px;
}
.mic[data-mode="listening"] .mic-label {
  color: var(--mint);
}

.mic[data-mode="speaking"] {
  color: var(--amber);
  border-color: rgba(233, 177, 100, 0.5);
  background: radial-gradient(circle at 50% 32%, rgba(233, 177, 100, 0.18), rgba(233, 177, 100, 0.02) 64%);
  box-shadow: 0 0 60px -12px rgba(233, 177, 100, 0.5);
}

.mic[data-mode="listening"] .i-mic,
.mic[data-mode="speaking"] .i-mic {
  display: none;
}

.mic[data-mode="listening"] .i-stop,
.mic[data-mode="speaking"] .i-stop {
  display: block;
}

.caption {
  width: min(100%, 30ch);
  margin: 0;
  text-align: center;
  font-family: var(--display);
  font-weight: 300;
  font-size: clamp(1.02rem, 1.35vw, 1.3rem);
  line-height: 1.45;
  color: var(--paper);
  opacity: 0.92;
  min-height: 2.9em;
  max-height: 4.4em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  text-wrap: balance;
}

.caption[data-tone="idle"] {
  color: var(--muted);
  font-size: clamp(0.95rem, 1.1vw, 1.05rem);
  max-width: 27ch;
}

/* ---------------------------------------------------------------- foot */

.stage-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11.5px;
  color: rgba(140, 154, 148, 0.75);
  letter-spacing: 0.02em;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* ---------------------------------------------------------------- ledger */

.ledger {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, #0d1816 0%, #0a1312 100%);
}

.ledger-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 26px var(--pad) 16px;
  border-bottom: 1px solid var(--line);
}

.ledger-head h2 {
  font-family: var(--display);
  font-weight: 300;
  font-size: 1.12rem;
  letter-spacing: 0.005em;
  margin: 0;
  color: var(--paper-soft);
}

.quiet-btn {
  font-size: 12.5px;
  color: var(--muted);
  padding: 2px 0;
  border-bottom: 1px solid transparent;
  transition: color 180ms var(--ease), border-color 180ms var(--ease);
  white-space: nowrap;
}

.quiet-btn:hover {
  color: var(--paper);
  border-color: var(--line-strong);
}

.quiet-btn.inline {
  align-self: flex-start;
  margin-top: 2px;
  color: var(--paper-soft);
  border-bottom: 1px solid var(--line-strong);
  padding-bottom: 1px;
}

.quiet-btn.inline:hover {
  color: var(--amber);
  border-color: rgba(233, 177, 100, 0.5);
}

.ledger-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 26px var(--pad) 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(242, 236, 226, 0.16) transparent;
  overscroll-behavior: contain;
}

.ledger-body::-webkit-scrollbar {
  width: 6px;
}
.ledger-body::-webkit-scrollbar-thumb {
  background: rgba(242, 236, 226, 0.14);
  border-radius: 99px;
}

.empty {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-top: 4px;
}

.empty-lead {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.68;
  max-width: 34ch;
}

.empty-label {
  margin: 8px 0 -4px;
  font-size: 12.5px;
  color: rgba(140, 154, 148, 0.72);
}

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

.starters li + li {
  border-top: 1px solid rgba(242, 236, 226, 0.055);
}

.starters button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 2px;
  font-family: var(--display);
  font-weight: 300;
  font-size: 16.5px;
  line-height: 1.35;
  color: var(--paper-soft);
  transition: color 200ms var(--ease), padding-left 240ms var(--ease);
}

.starters button:hover {
  color: var(--amber);
  padding-left: 7px;
}

.msg {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  padding: 15px 0;
}

.msg + .msg {
  border-top: 1px solid rgba(242, 236, 226, 0.055);
}

.msg .who {
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
  padding-top: 1px;
}

.msg.assistant .who {
  color: var(--amber);
}

.msg .text {
  margin: 0;
  font-size: 15px;
  line-height: 1.58;
  color: var(--paper-soft);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg.assistant .text {
  color: var(--paper);
  font-family: var(--display);
  font-weight: 300;
  font-size: 16px;
  line-height: 1.55;
}

.msg.interim .text {
  opacity: 0.55;
}

.msg .cursor::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.85em;
  margin-left: 3px;
  vertical-align: -0.06em;
  background: var(--amber);
  animation: blink 1s steps(2, start) infinite;
}

.msg.error .text {
  color: var(--warn);
  font-family: var(--ui);
  font-size: 13.5px;
}

/* ---------------------------------------------------------------- composer */

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px var(--pad) calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(10, 19, 18, 0.7);
  backdrop-filter: blur(8px);
}

.composer input {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
  border: 0;
  padding: 9px 2px;
  font-size: 14.5px;
  color: var(--paper);
}

.composer input::placeholder {
  color: rgba(140, 154, 148, 0.8);
}

.composer input:focus {
  outline: none;
}

.composer:focus-within {
  border-top-color: var(--line-strong);
}

.composer button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  color: var(--paper);
  transition: background 200ms var(--ease), border-color 200ms var(--ease), color 200ms var(--ease);
}

.composer button:hover {
  background: rgba(233, 177, 100, 0.14);
  border-color: rgba(233, 177, 100, 0.5);
  color: var(--amber);
}

.composer button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(4, 9, 8, 0.6);
  backdrop-filter: blur(3px);
  z-index: 40;
  opacity: 0;
  transition: opacity 320ms var(--ease);
}

.scrim.open {
  opacity: 1;
}

.sheet {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 50;
  width: min(410px, 94vw);
  height: 100dvh;
  overflow-y: auto;
  padding: 24px clamp(22px, 3vw, 32px) 40px;
  background: var(--ink-2);
  border-left: 1px solid var(--line);
  transform: translateX(103%);
  transition: transform 420ms var(--ease);
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.sheet.open {
  transform: translateX(0);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 2px;
}

.sheet-head h2 {
  font-family: var(--display);
  font-weight: 300;
  font-size: 1.55rem;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0;
  max-width: 12ch;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.field:last-child {
  border-bottom: 0;
}

.field label {
  font-size: 13px;
  color: var(--paper-soft);
  letter-spacing: 0.01em;
}

.field select {
  appearance: none;
  width: 100%;
  background: rgba(242, 236, 226, 0.045);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 36px 11px 13px;
  font-size: 14px;
  color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238c9a94' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}

.field select:hover {
  border-color: var(--line-strong);
}

.hint {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

.switch-field {
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
}

.switch-field > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.switch {
  flex: 0 0 auto;
  width: 46px;
  height: 26px;
  border-radius: 99px;
  border: 1px solid var(--line-strong);
  background: rgba(242, 236, 226, 0.05);
  padding: 2px;
  transition: background 240ms var(--ease), border-color 240ms var(--ease);
}

.switch .knob {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 260ms var(--ease), background 260ms var(--ease);
}

.switch[aria-checked="true"] {
  background: rgba(143, 217, 196, 0.18);
  border-color: rgba(143, 217, 196, 0.4);
}

.switch[aria-checked="true"] .knob {
  transform: translateX(20px);
  background: var(--mint);
}

.about p {
  margin: 0;
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
}

.about em {
  color: var(--paper-soft);
  font-style: normal;
  border-bottom: 1px solid var(--line-strong);
}

/* ---------------------------------------------------------------- gate */

.gate {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(70% 55% at 50% 18%, rgba(233, 177, 100, 0.09), transparent 70%),
    var(--ink);
}

.gate-card {
  width: min(390px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.brand-mark.large {
  color: var(--amber);
  margin-bottom: 6px;
}

.gate-card h1 {
  font-family: var(--display);
  font-weight: 300;
  font-size: 2.1rem;
  line-height: 1.05;
  letter-spacing: -0.015em;
  margin: 0;
}

.gate-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  max-width: 34ch;
}

.gate-card input {
  background: rgba(242, 236, 226, 0.045);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 13px 14px;
  font-size: 15px;
  letter-spacing: 0.06em;
}

.gate-card input:focus {
  outline: none;
  border-color: rgba(233, 177, 100, 0.55);
}

.primary {
  background: var(--amber);
  color: #1a1206;
  font-weight: 600;
  font-size: 14px;
  padding: 13px 16px;
  border-radius: 10px;
  transition: filter 180ms var(--ease), transform 180ms var(--ease);
}

.primary:hover {
  filter: brightness(1.06);
}

.primary:active {
  transform: translateY(1px);
}

.gate-error {
  min-height: 1.2em;
  font-size: 13px;
  color: var(--warn);
}

/* ---------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 8px);
  z-index: 80;
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(20, 33, 30, 0.96);
  color: var(--paper);
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------------------------------------------------------- responsive */

@media (min-width: 961px) and (max-height: 820px) {
  .intro {
    margin-top: 20px;
  }

  .intro h1 {
    font-size: clamp(2.2rem, 4vw, 3.3rem);
    margin-bottom: 12px;
  }

  .intro p {
    font-size: 14px;
    max-width: 42ch;
  }

  .orb {
    max-width: 400px;
  }

  .mic {
    width: 92px;
    height: 92px;
  }

  .caption {
    min-height: 2.6em;
  }
}

@media (max-width: 960px) {  body {
    overflow: auto;
  }

  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100dvh;
  }

  .stage {
    min-height: 100dvh;
    padding-bottom: 14px;
  }

  .intro {
    margin-top: clamp(22px, 5vh, 44px);
  }

  .intro h1 {
    font-size: clamp(2.4rem, 10vw, 3.6rem);
  }

  .intro p {
    font-size: 14.5px;
  }

  .instrument {
    min-height: 340px;
  }

  .ledger {
    border-left: 0;
    border-top: 1px solid var(--line);
    min-height: 70dvh;
  }

  .ledger-body {
    max-height: 58dvh;
  }
}

@media (max-width: 520px) {
  :root {
    --cap-h: 96px;
  }

  .stage-head {
    gap: 8px;
  }

  .status {
    padding: 5px 10px 5px 9px;
    font-size: 12px;
  }

  .brand-name {
    font-size: 15.5px;
  }

  .mic {
    width: 86px;
    height: 86px;
  }

  .mic[data-mode="listening"] {
    width: 94px;
    height: 94px;
  }

  .msg {
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 10px;
  }

  .msg .who {
    font-size: 11.5px;
  }

  .msg .text,
  .msg.assistant .text {
    font-size: 15px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
