:root {
  color-scheme: dark;
  --ink: #ece9df;
  --muted: #77756f;
  --dim: #242522;
  --line: #383a36;
  --accent: #b7ff5a;
  --danger: #ff765f;
  --background: #0b0c0a;
  --panel: rgba(19, 20, 17, 0.78);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 42%, rgba(183, 255, 90, 0.045), transparent 36rem),
    var(--background);
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.app {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(1.25rem, 4vw, 3rem);
}

.unlock {
  width: min(100%, 28rem);
}

.identity {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: clamp(3rem, 10vh, 7rem);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.24em;
}

.identity-mark {
  width: 0.52rem;
  height: 0.52rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 1.4rem rgba(183, 255, 90, 0.55);
}

.unlock-form {
  display: grid;
  gap: 1.15rem;
}

.unlock-form h1 {
  margin: 0 0 1.7rem;
  font-size: clamp(2.6rem, 8vw, 4.7rem);
  font-weight: 520;
  letter-spacing: -0.065em;
}

.unlock-form label {
  display: grid;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 650;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.unlock-form input {
  width: 100%;
  min-height: 3.6rem;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  outline: none;
  padding: 0 1rem;
  color: var(--ink);
  background: var(--panel);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.unlock-form input:focus {
  border-color: rgba(183, 255, 90, 0.72);
  box-shadow: 0 0 0 3px rgba(183, 255, 90, 0.09);
}

.unlock-form button {
  min-height: 3.6rem;
  margin-top: 0.35rem;
  border: 0;
  border-radius: 0.85rem;
  cursor: pointer;
  color: #10120d;
  background: var(--accent);
  font-weight: 760;
  transition: opacity 160ms ease, transform 160ms ease;
}

.unlock-form button:hover {
  transform: translateY(-1px);
}

.unlock-form button:disabled {
  cursor: wait;
  opacity: 0.48;
  transform: none;
}

.unlock-status {
  min-height: 1.3rem;
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
}

.unlock-status[data-state="error"] {
  color: var(--danger);
}

.conversation {
  width: min(92vw, 62rem);
  display: grid;
  place-items: center;
}

.waveform-surface {
  position: relative;
  width: min(100%, 46rem);
  height: clamp(10rem, 32vh, 20rem);
  border: 1px solid rgba(236, 233, 223, 0.1);
  border-radius: clamp(1.5rem, 5vw, 3rem);
  outline: none;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: rgba(236, 233, 223, 0.018);
  -webkit-tap-highlight-color: transparent;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.waveform-surface::before {
  content: "";
  position: absolute;
  inset: 50% 14%;
  height: 1px;
  background: rgba(236, 233, 223, 0.08);
  transform: translateY(-50%);
}

.waveform-surface:focus-visible {
  box-shadow: 0 0 0 2px rgba(236, 233, 223, 0.32);
}

.waveform-surface:hover {
  border-color: rgba(236, 233, 223, 0.2);
  background: rgba(236, 233, 223, 0.028);
}

.app[data-mode="listening"] .waveform-surface {
  border-color: rgba(183, 255, 90, 0.68);
  background: rgba(183, 255, 90, 0.045);
  transform: scale(0.985);
}

#waveformCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hold-label {
  position: absolute;
  left: 50%;
  bottom: 1.35rem;
  z-index: 1;
  color: var(--muted);
  font-size: 0.61rem;
  font-weight: 720;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  transform: translateX(-50%);
  white-space: nowrap;
}

.app[data-mode="listening"] .hold-label {
  color: var(--accent);
}

.conversation-status {
  margin: 1.3rem 0 0;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 680;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.conversation-message {
  min-height: 1.4rem;
  max-width: 34rem;
  margin: 0.8rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
  text-align: center;
}

.conversation-message:empty {
  display: none;
}

.conversation-message[data-state="error"] {
  color: var(--danger);
}

.conversation-message:not([data-state="error"]) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.text-mode-button {
  position: fixed;
  right: max(1.25rem, env(safe-area-inset-right));
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  z-index: 4;
  width: 3.25rem;
  height: 3.25rem;
  display: grid;
  place-items: center;
  border: 1px solid rgba(236, 233, 223, 0.16);
  border-radius: 50%;
  outline: none;
  cursor: pointer;
  color: var(--ink);
  background: rgba(18, 19, 16, 0.94);
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.42);
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.text-mode-button svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-mode-button:hover,
.text-mode-button:focus-visible,
.text-mode-button[aria-expanded="true"] {
  border-color: rgba(183, 255, 90, 0.6);
  color: var(--accent);
  background: rgba(26, 29, 21, 0.98);
  transform: translateY(-1px);
}

.text-mode-button:focus-visible {
  box-shadow: 0 0 0 3px rgba(183, 255, 90, 0.12), 0 1rem 3rem rgba(0, 0, 0, 0.42);
}

.text-chat-panel {
  position: fixed;
  top: max(1.25rem, env(safe-area-inset-top));
  right: max(1.25rem, env(safe-area-inset-right));
  bottom: max(5.25rem, calc(env(safe-area-inset-bottom) + 5.25rem));
  z-index: 3;
  width: min(28rem, calc(100vw - 2.5rem));
  min-height: 24rem;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid rgba(236, 233, 223, 0.14);
  border-radius: 1.4rem;
  background: rgba(15, 16, 13, 0.96);
  box-shadow: 0 1.5rem 5rem rgba(0, 0, 0, 0.56);
  backdrop-filter: blur(22px);
}

.text-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(236, 233, 223, 0.08);
}

.text-chat-kicker {
  margin: 0 0 0.28rem;
  color: var(--accent);
  font-size: 0.58rem;
  font-weight: 740;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.text-chat-header h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 620;
  letter-spacing: -0.025em;
}

.text-chat-close {
  width: 2.3rem;
  height: 2.3rem;
  border: 0;
  border-radius: 50%;
  outline: none;
  cursor: pointer;
  color: var(--muted);
  background: rgba(236, 233, 223, 0.055);
  font-size: 1.45rem;
  line-height: 1;
}

.text-chat-close:hover,
.text-chat-close:focus-visible {
  color: var(--ink);
  background: rgba(236, 233, 223, 0.1);
}

.text-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  min-height: 0;
  overflow-y: auto;
  padding: 1.15rem 1.25rem;
  overscroll-behavior: contain;
}

.text-chat-empty {
  margin: auto 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
  text-align: center;
}

.text-chat-message {
  max-width: 88%;
  margin: 0;
  padding: 0.72rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.86rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.text-chat-message[data-role="user"] {
  align-self: flex-end;
  border-bottom-right-radius: 0.3rem;
  color: #12140e;
  background: var(--accent);
}

.text-chat-message[data-role="rat"] {
  align-self: flex-start;
  border: 1px solid rgba(236, 233, 223, 0.09);
  border-bottom-left-radius: 0.3rem;
  background: rgba(236, 233, 223, 0.055);
}

.text-chat-message[data-state="error"] {
  border-color: rgba(255, 118, 95, 0.25);
  color: var(--danger);
}

.text-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 0.65rem;
  padding: 0.85rem;
  border-top: 1px solid rgba(236, 233, 223, 0.08);
}

.text-composer textarea {
  width: 100%;
  min-height: 3rem;
  max-height: 9rem;
  resize: vertical;
  border: 1px solid rgba(236, 233, 223, 0.14);
  border-radius: 1rem;
  outline: none;
  padding: 0.78rem 0.9rem;
  color: var(--ink);
  background: rgba(236, 233, 223, 0.045);
  line-height: 1.4;
}

.text-composer textarea:focus {
  border-color: rgba(183, 255, 90, 0.55);
}

.text-composer textarea:disabled {
  opacity: 0.58;
}

.text-composer button {
  min-height: 3rem;
  border: 0;
  border-radius: 0.9rem;
  padding: 0 1rem;
  cursor: pointer;
  color: #10120d;
  background: var(--accent);
  font-size: 0.76rem;
  font-weight: 760;
}

.text-composer button:disabled {
  cursor: wait;
  opacity: 0.45;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

@media (max-width: 560px) {
  .app {
    padding: 1.2rem;
  }

  .identity {
    margin-bottom: 4rem;
  }

  .waveform-surface {
    height: 12rem;
  }

  .text-chat-panel {
    inset: max(0.75rem, env(safe-area-inset-top)) 0.75rem max(4.75rem, calc(env(safe-area-inset-bottom) + 4.75rem));
    width: auto;
    min-height: 0;
    border-radius: 1.2rem;
  }

  .text-mode-button {
    right: max(0.9rem, env(safe-area-inset-right));
    bottom: max(0.9rem, env(safe-area-inset-bottom));
  }
}

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