:root {
  --black: #050605;
  --black-soft: #0b0d0b;
  --white: #f2f4ef;
  --white-soft: rgba(242, 244, 239, 0.7);
  --white-muted: rgba(242, 244, 239, 0.44);
  --rule: rgba(242, 244, 239, 0.18);
  --green: #91ec67;
  --danger: #ff8d79;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-song: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html {
  min-width: 20rem;
  min-height: 100%;
  color-scheme: dark;
  background: var(--black);
}

body {
  min-width: 20rem;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow: hidden;
  color: var(--white);
  background: var(--black);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }

button,
input { font: inherit; }

button,
input {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(145, 236, 103, 0.2);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 4px;
}

.gate {
  width: min(32rem, 100%);
  height: 100vh;
  height: 100svh;
  margin-inline: auto;
  overflow-y: auto;
  padding: max(2rem, env(safe-area-inset-top)) max(1.5rem, env(safe-area-inset-right)) max(1.5rem, env(safe-area-inset-bottom)) max(1.5rem, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  align-items: center;
  gap: 2rem;
  animation: gate-in 700ms var(--ease) both;
}

.gate-copy { align-self: end; text-align: center; }

.eyebrow,
.call-head p {
  margin: 0;
  color: var(--white);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.eyebrow span,
.call-head p span { color: var(--white-muted); font-weight: 450; }

.call-head .voice-mode-badge {
  color: var(--green);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
}

h1 {
  margin: 1.4rem 0 0;
  font-family: var(--font-song);
  font-size: clamp(2.6rem, 9vw, 4.25rem);
  font-weight: 400;
  letter-spacing: -0.06em;
  line-height: 1;
  text-wrap: balance;
}

.gate-intro {
  margin: 1.25rem 0 0;
  color: var(--white-soft);
  font-family: var(--font-song);
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  line-height: 1.8;
}

.gate-form {
  width: min(22rem, 100%);
  margin-inline: auto;
  display: grid;
  gap: 0.75rem;
}

.auth-fields > label,
.voice-mode legend {
  color: var(--white-muted);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
}

.auth-fields {
  display: grid;
  gap: 0.55rem;
}

.auth-fields > input,
.code-row > input {
  width: 100%;
  min-height: 3.25rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 0;
  color: var(--white);
  background: transparent;
  letter-spacing: 0.08em;
  transition: border-color 180ms ease, background 180ms ease;
}

.auth-fields > input:hover,
.auth-fields > input:focus,
.code-row > input:hover,
.code-row > input:focus { border-color: rgba(242, 244, 239, 0.52); background: rgba(255, 255, 255, 0.025); }
.auth-fields > input::placeholder,
.code-row > input::placeholder { color: var(--white-muted); letter-spacing: 0; }

.code-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7.25rem;
}

.send-code {
  min-height: 3.25rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--rule);
  border-left: 0;
  border-radius: 0;
  color: var(--white);
  background: transparent;
  cursor: pointer;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
  transition: color 180ms ease, background 180ms ease, border-color 180ms ease;
}

.send-code:hover { color: var(--black); background: var(--white); border-color: var(--white); }
.send-code:disabled { color: var(--white-muted); background: transparent; border-color: var(--rule); cursor: wait; }

.auth-status {
  min-height: 1.1rem;
  margin: -0.1rem 0 0;
  color: var(--green);
  font-size: 0.68rem;
  line-height: 1.5;
  text-align: center;
}

.voice-mode {
  min-width: 0;
  margin: 0.15rem 0 0;
  padding: 0;
  border: 0;
}

.voice-mode legend { margin-bottom: 0.55rem; }

.voice-mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--rule);
}

.voice-mode-options label {
  position: relative;
  min-height: 2.65rem;
  display: grid;
  place-items: center;
  color: var(--white-muted);
  cursor: pointer;
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  transition: color 160ms ease, background 160ms ease;
}

.voice-mode-options label + label { border-left: 1px solid var(--rule); }
.voice-mode-options input { position: absolute; opacity: 0; pointer-events: none; }
.voice-mode-options label:has(input:checked) { color: var(--black); background: var(--white); }
.voice-mode-options label:has(input:focus-visible) { outline: 2px solid var(--green); outline-offset: 3px; }
.voice-mode-options label:hover:not(:has(input:checked)) { color: var(--white); background: rgba(255, 255, 255, 0.04); }

.voice-mode small {
  display: block;
  margin-top: 0.45rem;
  color: var(--white-muted);
  font-size: 0.62rem;
  line-height: 1.5;
  text-align: center;
}

.enter-button {
  min-height: 3.25rem;
  margin-top: 0.25rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--white);
  border-radius: 0;
  color: var(--black);
  background: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.86rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  transition: color 180ms ease, background 180ms ease, transform 120ms ease;
}

.enter-button:hover { color: var(--white); background: transparent; }
.enter-button:active { transform: translateY(1px); }
.enter-button:disabled { color: var(--white-muted); background: transparent; border-color: var(--rule); cursor: wait; }

.gate-error {
  min-height: 1.2rem;
  margin: 0;
  color: var(--danger);
  font-size: 0.75rem;
  line-height: 1.6;
  text-align: center;
}

.gate-note {
  align-self: end;
  margin: 0;
  color: var(--white-muted);
  font-size: 0.68rem;
  line-height: 1.7;
  text-align: center;
}

.call {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  isolation: isolate;
  background: var(--black);
  animation: call-in 900ms var(--ease) both;
}

#particleCanvas,
.veil {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#particleCanvas { z-index: -2; }

.veil {
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 48%, transparent 0 42%, rgba(5, 6, 5, 0.16) 68%, rgba(5, 6, 5, 0.82) 100%),
    linear-gradient(180deg, rgba(5, 6, 5, 0.72) 0%, transparent 18%, transparent 72%, rgba(5, 6, 5, 0.72) 100%);
}

.call-head {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  right: 0;
  min-height: 4.5rem;
  padding: max(1.25rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 1rem max(1.25rem, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.session-meta {
  color: var(--white-soft);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

.session-meta i {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(145, 236, 103, 0.4);
}

.session-meta i[data-state="speaking"],
.session-meta i[data-state="thinking"],
.session-meta i[data-state="connecting"] { animation: status-pulse 1.15s ease-in-out infinite; }

.session-meta time {
  margin-left: 0.4rem;
  color: var(--white-muted);
}

.conversation {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: max(7.6rem, calc(env(safe-area-inset-bottom) + 6.4rem));
  width: min(48rem, calc(100% - 3rem));
  height: min(42vh, 24rem);
  overflow: hidden;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  perspective: 34rem;
  perspective-origin: 50% 100%;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.86) 22%, #000 46%, #000 100%);
  mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.86) 22%, #000 46%, #000 100%);
  pointer-events: none;
}

.transcript {
  width: min(40em, 100%);
  max-height: none;
  margin: 0;
  color: rgba(246, 247, 243, 0.9);
  font-family: var(--font-song);
  font-size: clamp(0.94rem, 1.7vw, 1.08rem);
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 1.9;
  text-align: center;
  text-wrap: pretty;
  transform: rotateX(15deg) translateZ(0);
  transform-origin: 50% 100%;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 1), 0 6px 26px rgba(0, 0, 0, 0.94);
  transition: color 220ms ease, opacity 220ms ease;
}

.transcript.placeholder { color: var(--white-muted); }

.call-actions {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

.end-call {
  position: relative;
  width: 3.65rem;
  height: 3.65rem;
  padding: 0;
  border: 1px solid rgba(145, 236, 103, 0.86);
  border-radius: 50%;
  color: var(--green);
  background: rgba(5, 6, 5, 0.72);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 0.35rem rgba(145, 236, 103, 0.06), 0 0 2rem rgba(145, 236, 103, 0.12);
  transition: transform 160ms var(--ease), background 160ms ease, color 160ms ease;
}

.end-call:hover { color: var(--black); background: var(--green); transform: scale(1.04); }
.end-call:active { transform: scale(0.98); }
.end-call svg { width: 1.35rem; height: 1.35rem; fill: currentColor; }

.call-actions > span {
  color: var(--white-muted);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
}

#remoteAudio { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

@keyframes gate-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes call-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes status-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(145, 236, 103, 0.38); }
  50% { box-shadow: 0 0 0 0.42rem rgba(145, 236, 103, 0); }
}

@media (max-width: 40rem) {
  .gate { padding-inline: max(1.25rem, env(safe-area-inset-left)); }
  .call-head { align-items: flex-start; }
  .call-head p .agent-kind { display: none; }
  .session-meta { gap: 0.4rem; }
  .session-meta time { margin-left: 0.2rem; }
  .conversation {
    width: calc(100% - 2rem);
    height: min(38vh, 18rem);
    bottom: max(7rem, calc(env(safe-area-inset-bottom) + 6.1rem));
    perspective: 28rem;
  }
  .transcript { font-size: 0.92rem; line-height: 1.82; transform: rotateX(12deg) translateZ(0); }
}

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