:root {
  --void: #030304;
  --ink: #0b0c0f;
  --steel: #8b93a3;
  --silver: #d9dee8;
  --white: #f4f6fa;
  --accent: #b49cff;
  --accent-deep: #6f4ff0;
  --accent-rgb: 170, 140, 255;
  --on-accent: #0d0820;
  --red: #ff4d4d;
  --glass: rgba(16, 17, 21, .62);
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .16);
  --wide: "Archivo", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--void);
  color: var(--white);
  font-family: var(--wide);
  font-variation-settings: "wdth" 100;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }

/* ---------- atmosphere ---------- */
#field { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
.beam {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(60% 40% at 50% 34%, rgba(var(--accent-rgb), .055), transparent 70%),
    conic-gradient(from 180deg at 50% -8%, transparent 168deg, rgba(200, 210, 230, .045) 176deg,
                   rgba(200, 210, 230, .07) 180deg, rgba(200, 210, 230, .045) 184deg, transparent 192deg);
}
.grain {
  position: fixed; inset: -50%; z-index: 1; pointer-events: none; opacity: .07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); } 40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -1%); } 80% { transform: translate(3%, 3%); } 100% { transform: translate(0, 0); }
}

.kicker {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .32em; text-transform: uppercase; color: var(--steel);
}
.fine { font-size: 13px; line-height: 1.5; color: var(--steel); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 26px; border-radius: 999px;
  font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .2em; text-transform: uppercase;
  transition: transform .15s ease, background .2s ease, box-shadow .2s ease, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-solid {
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 0 0 1px rgba(var(--accent-rgb), .4), 0 10px 40px -8px rgba(var(--accent-rgb), .55);
}
.btn-ghost { border: 1px solid var(--line-strong); color: var(--silver); }
.btn.small { height: 44px; padding: 0 18px; }
.btn.danger { color: #ff8a8a; border-color: rgba(255, 77, 77, .28); }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid var(--line); background: rgba(10, 11, 14, .5);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  transition: border-color .2s, transform .15s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.small { width: 48px; height: 48px; flex: none; }
.ico { width: 20px; height: 20px; fill: none; stroke: var(--silver); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 5; display: flex; align-items: flex-end; justify-content: center;
  padding: calc(var(--safe-t) + 24px) 20px calc(var(--safe-b) + 36px);
}
.gate-inner { width: 100%; max-width: 440px; text-align: center; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; justify-items: center; }
.mega {
  font-family: var(--wide); font-weight: 850; font-variation-settings: "wdth" 125;
  font-size: clamp(38px, 12vw, 112px); line-height: .9; letter-spacing: -.035em;
  background: linear-gradient(180deg, #ffffff 0%, #c7ccd6 55%, #6f7685 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 60px rgba(255, 255, 255, .06);
}
#gate-step-send { display: grid; gap: 14px; justify-items: center; width: 100%; }
#gate-step-send .btn { width: 100%; }
.code-form { display: grid; gap: 14px; width: 100%; }
.code-input {
  width: 100%; height: 72px; text-align: center; border-radius: 18px;
  background: rgba(255, 255, 255, .04); border: 1px solid var(--line-strong);
  font-family: var(--mono); font-size: 32px; letter-spacing: .5em; text-indent: .5em; outline: none;
}
.code-input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(var(--accent-rgb), .12); }
.gate-msg { min-height: 20px; font-family: var(--mono); font-size: 12px; letter-spacing: .06em; color: var(--steel); }
.gate-msg.err { color: #ff8a8a; }

/* ---------- app ---------- */
.app {
  position: fixed; inset: 0; z-index: 3; display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 10px) 16px calc(var(--safe-b) + 14px);
  pointer-events: none;
}
.app > * { pointer-events: auto; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: grid; justify-items: center; gap: 6px; }
.wordmark {
  font-weight: 800; font-variation-settings: "wdth" 125; font-size: 15px; letter-spacing: .52em; text-indent: .52em;
  color: var(--white);
}
.status {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 9.5px; letter-spacing: .3em; text-transform: uppercase; color: var(--steel);
}
.status i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.status.busy i { animation: blink .9s ease-in-out infinite; }
.status.off i { background: var(--red); box-shadow: 0 0 10px var(--red); }
@keyframes blink { 50% { opacity: .2; } }

#voice-toggle .off { display: none; }
#voice-toggle[aria-pressed="false"] .on { display: none; }
#voice-toggle[aria-pressed="false"] .off { display: block; }

.stage {
  margin-top: auto; padding: 0 4px 18px; max-height: 42svh; overflow-y: auto;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22px); mask-image: linear-gradient(180deg, transparent 0, #000 22px);
  scrollbar-width: none; pointer-events: auto;
}
.stage::-webkit-scrollbar { display: none; }
.said {
  font-family: var(--mono); font-size: 12px; line-height: 1.6; color: var(--steel); letter-spacing: .02em;
  margin-bottom: 10px; padding-top: 22px;
}
.said:not(:empty)::before { content: "YOU — "; color: rgba(var(--accent-rgb), .8); letter-spacing: .2em; }
.reply {
  font-size: clamp(19px, 5.2vw, 26px); line-height: 1.38; font-weight: 380; letter-spacing: -.01em;
  color: var(--white); text-wrap: pretty; white-space: pre-wrap;
}
.reply.dim { color: var(--steel); }

.dock { display: flex; align-items: center; gap: 10px; }
.field {
  flex: 1; min-width: 0; height: 56px; display: flex; align-items: center;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(140%); backdrop-filter: blur(20px) saturate(140%);
  padding: 0 6px 0 20px;
}
.field:focus-within { border-color: rgba(var(--accent-rgb), .45); }
.field input { flex: 1; min-width: 0; height: 100%; background: none; border: 0; outline: none; font-size: 16px; }
.field input::placeholder { color: #6c7383; }
.send { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; opacity: .35; transition: opacity .2s; }
.field.has-text .send { opacity: 1; }
.field.has-text .send .ico { stroke: var(--accent); }

.mic {
  position: relative; flex: none; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 35%, #2a2c31, #0d0e11 70%);
  border: 1px solid var(--line-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 12px 30px -10px rgba(0, 0, 0, .9);
  transition: transform .15s;
}
.mic:active { transform: scale(.94); }
.mic .ico { width: 24px; height: 24px; }
.mic .stop-ico { display: none; }
.mic-ring {
  position: absolute; inset: -5px; border-radius: 50%; border: 1.5px solid rgba(var(--accent-rgb), .0);
  transition: border-color .25s;
}
.app.listening .mic { background: radial-gradient(circle at 50% 35%, #d9ccff, var(--accent-deep) 75%); border-color: transparent; }
.app.listening .mic .ico { stroke: #140d00; }
.app.listening .mic .mic-ico { display: none; }
.app.listening .mic .stop-ico { display: block; fill: #140d00; stroke: none; }
.app.listening .mic-ring { border-color: rgba(var(--accent-rgb), .55); transform: scale(var(--lvl, 1)); }
.app.speaking .mic .mic-ico { display: none; }
.app.speaking .mic .stop-ico { display: block; fill: var(--silver); stroke: none; }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; z-index: 8; background: rgba(0, 0, 0, .55); animation: fade .2s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; max-height: 82svh; overflow-y: auto;
  margin: 0 auto; max-width: 620px;
  padding: 22px 20px calc(var(--safe-b) + 24px);
  border-radius: 26px 26px 0 0; border: 1px solid var(--line-strong); border-bottom: 0;
  background: rgba(12, 13, 16, .86);
  -webkit-backdrop-filter: blur(28px) saturate(140%); backdrop-filter: blur(28px) saturate(140%);
  animation: rise .28s cubic-bezier(.2, .8, .2, 1);
  display: grid; gap: 16px; align-content: start;
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; }
.sheet h2 { font-weight: 800; font-variation-settings: "wdth" 125; font-size: 30px; letter-spacing: -.02em; margin-top: 4px; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.fact-form { display: flex; gap: 10px; }
.fact-form input {
  flex: 1; min-width: 0; height: 44px; padding: 0 16px; border-radius: 999px; font-size: 16px;
  background: rgba(255, 255, 255, .04); border: 1px solid var(--line-strong); outline: none;
}
.fact-form input:focus { border-color: rgba(var(--accent-rgb), .45); }
.facts { list-style: none; display: grid; gap: 8px; counter-reset: f; }
.facts li {
  counter-increment: f; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start;
  padding: 14px 6px 14px 14px; border-radius: 14px; background: rgba(255, 255, 255, .03); border: 1px solid var(--line);
  font-size: 15px; line-height: 1.45;
}
.facts li::before { content: counter(f, decimal-leading-zero); font-family: var(--mono); font-size: 11px; color: var(--accent); padding-top: 3px; }
.facts li button { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; margin-top: -5px; }
.facts li button .ico { width: 15px; height: 15px; stroke: var(--steel); }
.facts .empty { grid-template-columns: 1fr; color: var(--steel); }
.facts .empty::before { content: none; }

.log-list { display: grid; gap: 14px; }
.log-list .turn { display: grid; gap: 4px; }
.log-list .who { font-family: var(--mono); font-size: 10px; letter-spacing: .28em; text-transform: uppercase; color: var(--steel); }
.log-list .user .who { color: rgba(var(--accent-rgb), .8); }
.log-list .text { font-size: 15px; line-height: 1.5; white-space: pre-wrap; color: var(--silver); }
.log-list .assistant .text { color: var(--white); }

.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 74px); transform: translateX(-50%); z-index: 20;
  max-width: calc(100% - 32px); padding: 11px 18px; border-radius: 999px;
  background: rgba(16, 17, 21, .9); border: 1px solid var(--line-strong);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .04em; color: var(--silver); text-align: center;
  animation: fade .2s ease;
}

@media (min-width: 900px) {
  .app { padding-left: max(16px, calc(50% - 360px)); padding-right: max(16px, calc(50% - 360px)); }
  .stage { max-height: 34svh; }
}
@media (prefers-reduced-motion: reduce) {
  .grain { animation: none; }
}
