:root {
  --bg: #04050d;
  --bg2: #0a0d1f;
  --ink: #e9ecff;
  --ink-dim: #8b93b8;
  --ink-faint: #4b5275;
  --cyan: #5ef2ff;
  --violet: #9b6bff;
  --magenta: #ff5edb;
  --amber: #ffc46b;
  --glass: rgba(20, 24, 52, 0.42);
  --glass-hi: rgba(120, 140, 255, 0.14);
  --line: rgba(140, 160, 255, 0.16);
  --accent: var(--cyan);
  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  overflow: hidden;
  background:
    radial-gradient(1200px 700px at 50% -10%, rgba(91, 70, 255, 0.18), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(0, 220, 255, 0.10), transparent 60%),
    var(--bg);
}
#stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }
.screen { position: relative; z-index: 1; height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.wordmark {
  font-weight: 700; letter-spacing: 0.42em; margin: 0;
  background: linear-gradient(90deg, var(--cyan), var(--violet), var(--magenta), var(--cyan));
  background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 8s linear infinite;
}
.wordmark.small { font-size: 15px; }
@keyframes shimmer { to { background-position: 300% 0; } }

/* ---------- Giriş ---------- */
#login { align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; }
#login .wordmark { font-size: 34px; margin-top: 8px; }
.sub { color: var(--ink-dim); margin: 0 0 22px; letter-spacing: 0.04em; }
#loginForm { display: flex; flex-direction: column; gap: 12px; width: min(340px, 100%); }
#loginForm input {
  height: 52px; border-radius: 16px; border: 1px solid var(--line); background: var(--glass);
  color: var(--ink); padding: 0 18px; font: inherit; font-size: 17px; outline: none;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: border-color .25s, box-shadow .25s;
}
#loginForm input:focus { border-color: rgba(94, 242, 255, .5); box-shadow: 0 0 0 4px rgba(94, 242, 255, .1); }
.btn-primary {
  height: 52px; border-radius: 16px; font-weight: 600; font-size: 16px; letter-spacing: .04em; color: #050614;
  background: linear-gradient(120deg, var(--cyan), var(--violet)); box-shadow: 0 8px 30px rgba(110, 120, 255, .35);
  transition: transform .15s, filter .2s;
}
.btn-primary:active { transform: scale(.97); }
.err { color: #ff7a9a; min-height: 1.2em; margin: 4px 0 0; font-size: 14px; }

/* ---------- Üst bar ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 10px) 16px 8px; z-index: 3;
}
.brand { display: flex; align-items: center; gap: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 12px var(--cyan); transition: background .4s, box-shadow .4s; }
body[data-state="thinking"] .dot { background: var(--violet); box-shadow: 0 0 14px var(--violet); animation: blink 1s infinite; }
body[data-state="listening"] .dot { background: var(--magenta); box-shadow: 0 0 14px var(--magenta); }
body[data-state="speaking"] .dot { background: var(--amber); box-shadow: 0 0 14px var(--amber); }
@keyframes blink { 50% { opacity: .35; } }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--ink-dim); transition: color .2s, background .2s; }
.icon-btn:active { background: var(--glass-hi); }
.icon-btn[aria-pressed="true"] { color: var(--amber); }
.icon-btn[aria-pressed="false"] .wave { opacity: .25; }

/* ---------- Sahne (orb) ---------- */
.stage {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 0 20px; transition: flex .6s cubic-bezier(.2,.8,.2,1);
  min-height: 0;
}
.orb-wrap { position: relative; width: 300px; height: 300px; transition: width .6s cubic-bezier(.2,.8,.2,1), height .6s cubic-bezier(.2,.8,.2,1); }
.orb-wrap canvas, .login-orb canvas { width: 100%; height: 100%; display: block; }
.login-orb { width: 220px; height: 220px; }
.hero { text-align: center; transition: opacity .4s; }
.hero h2 { font-weight: 500; font-size: 24px; margin: 4px 0 6px; letter-spacing: -0.01em; }
.status-line {
  font-family: 'JetBrains Mono', monospace; font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); margin: 0; min-height: 1.4em; transition: color .4s;
}
.live-text { color: var(--ink-dim); margin: 6px 0 0; min-height: 1.2em; font-size: 15px; max-width: 520px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; max-width: 560px; }
.chip {
  padding: 10px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass);
  color: var(--ink); font-size: 14px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: border-color .2s, transform .15s; animation: rise .7s backwards;
}
.chip:nth-child(2) { animation-delay: .08s; } .chip:nth-child(3) { animation-delay: .16s; }
.chip:active { transform: scale(.96); border-color: rgba(94,242,255,.5); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* Sohbet başlayınca orb küçülür ve yukarı çıkar */
body.has-thread .stage { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 16px 6px; }
body.has-thread .orb-wrap { width: 64px; height: 64px; }
body.has-thread .hero { text-align: left; }
body.has-thread .hero h2, body.has-thread .chips, body.has-thread .live-text { display: none; }

/* ---------- Sohbet akışı ---------- */
.thread {
  flex: 1; overflow-y: auto; padding: 6px 16px 18px; display: none; flex-direction: column; gap: 14px;
  mask-image: linear-gradient(transparent, #000 18px, #000 calc(100% - 18px), transparent);
  -webkit-mask-image: linear-gradient(transparent, #000 18px, #000 calc(100% - 18px), transparent);
  scroll-behavior: smooth; overscroll-behavior: contain;
}
body.has-thread .thread { display: flex; }
.msg { max-width: min(680px, 92%); line-height: 1.55; font-size: 16px; animation: msgIn .45s cubic-bezier(.2,.8,.2,1) backwards; overflow-wrap: anywhere; }
@keyframes msgIn { from { opacity: 0; transform: translateY(12px) scale(.98); filter: blur(4px); } }
.msg.user {
  align-self: flex-end; padding: 11px 15px; border-radius: 20px 20px 6px 20px;
  background: linear-gradient(135deg, rgba(94,242,255,.16), rgba(155,107,255,.18)); border: 1px solid rgba(140,170,255,.22);
}
.msg.uzay {
  align-self: flex-start; padding: 14px 16px; border-radius: 6px 20px 20px 20px; background: var(--glass);
  border: 1px solid var(--line); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); position: relative;
}
.msg.uzay::before {
  content: ''; position: absolute; inset: -1px; border-radius: inherit; padding: 1px; pointer-events: none;
  background: linear-gradient(140deg, rgba(94,242,255,.45), transparent 40%, transparent 70%, rgba(255,94,219,.35));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
}
.msg.error { align-self: center; color: #ff8fab; font-size: 14px; text-align: center; }
.msg.system { align-self: center; color: var(--ink-dim); font-family: 'JetBrains Mono', monospace; font-size: 12px; letter-spacing: .04em; }
.msg p { margin: 0 0 .6em; } .msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: .2em 0 .6em; padding-left: 1.2em; }
.msg code { font-family: 'JetBrains Mono', monospace; font-size: .86em; background: rgba(140,160,255,.12); padding: .1em .35em; border-radius: 6px; }
.msg pre { background: rgba(0,0,0,.35); padding: 10px 12px; border-radius: 12px; overflow-x: auto; }
.msg pre code { background: none; padding: 0; }
.msg a { color: var(--cyan); }
.msg h3, .msg h4 { margin: .4em 0 .3em; font-size: 1.02em; }
.msg .wikilink { color: var(--violet); font-weight: 500; }
.typing { align-self: flex-start; display: flex; gap: 6px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--violet); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; background: var(--cyan); } .typing i:nth-child(3) { animation-delay: .3s; background: var(--magenta); }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-6px); opacity: 1; } }

/* ---------- Alt bar ---------- */
.composer { padding: 8px 12px calc(var(--safe-b) + 12px); z-index: 3; }
.mode { position: relative; display: inline-flex; margin: 0 0 8px 6px; padding: 3px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); }
.mode-btn { position: relative; z-index: 1; padding: 6px 14px; border-radius: 999px; font-size: 13px; color: var(--ink-dim); transition: color .3s; }
.mode-btn.active { color: #050614; font-weight: 600; }
.mode-glow { position: absolute; top: 3px; bottom: 3px; left: 3px; border-radius: 999px; background: linear-gradient(120deg, var(--cyan), var(--violet)); transition: transform .35s cubic-bezier(.2,.8,.2,1), width .35s; }
body[data-mode="note"] .mode-glow { background: linear-gradient(120deg, var(--amber), var(--magenta)); }
.bar {
  display: flex; align-items: flex-end; gap: 8px; padding: 6px; border-radius: 26px; background: var(--glass);
  border: 1px solid var(--line); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 10px 40px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.04); transition: border-color .3s, box-shadow .3s;
}
.bar:focus-within { border-color: rgba(94,242,255,.35); box-shadow: 0 10px 40px rgba(0,0,0,.35), 0 0 0 4px rgba(94,242,255,.06); }
#input {
  flex: 1; resize: none; border: 0; outline: none; background: transparent; color: var(--ink); font: inherit;
  font-size: 16.5px; line-height: 1.4; padding: 11px 6px 11px 12px; max-height: 160px;
}
#input::placeholder { color: var(--ink-faint); }
.send { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--ink-dim); transition: all .2s; }
.send:not(:disabled) { color: #050614; background: linear-gradient(120deg, var(--cyan), var(--violet)); }
.send:disabled { opacity: .35; }
.mic {
  position: relative; width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #050614;
  background: radial-gradient(circle at 35% 30%, #fff 0, var(--cyan) 30%, var(--violet) 75%);
  box-shadow: 0 0 24px rgba(94,242,255,.45), 0 0 60px rgba(155,107,255,.25); transition: transform .15s;
}
body[data-mode="note"] .mic { background: radial-gradient(circle at 35% 30%, #fff 0, var(--amber) 30%, var(--magenta) 80%); box-shadow: 0 0 24px rgba(255,196,107,.45), 0 0 60px rgba(255,94,219,.25); }
.mic svg { position: relative; z-index: 1; width: 24px; height: 24px; stroke-width: 2; }
.mic:active { transform: scale(.93); }
.mic-ring { position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid rgba(94,242,255,.6); animation: ring 2.6s ease-out infinite; }
.mic-ring.r2 { animation-delay: 1.3s; }
@keyframes ring { from { transform: scale(1); opacity: .7; } to { transform: scale(1.8); opacity: 0; } }
body[data-state="thinking"] .mic { filter: grayscale(.6) brightness(.7); }

/* ---------- Dinleme katmanı ---------- */
.listen {
  position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 24px 20px calc(var(--safe-b) + 28px); text-align: center; pointer-events: none;
}
.listen > * { pointer-events: auto; }
.listen-hint { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--magenta); margin: 0 0 10px; }
.listen-text { font-size: 22px; line-height: 1.4; min-height: 2.8em; max-width: 620px; margin: 0 0 22px; text-shadow: 0 2px 20px rgba(0,0,0,.6); }
.listen-actions { display: flex; gap: 12px; width: min(380px, 100%); }
.listen-actions > * { flex: 1; }
.ghost { height: 52px; border-radius: 16px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
body.listening .composer, body.listening .thread, body.listening .top, body.listening .hero, body.listening .chips { opacity: 0; pointer-events: none; }
body.listening .stage { flex: 1 !important; flex-direction: column !important; justify-content: center !important; }
body.listening .orb-wrap { width: min(360px, 80vw) !important; height: min(360px, 80vw) !important; }
.composer, .thread, .top, .hero, .chips { transition: opacity .35s; }

@media (min-width: 900px) {
  .thread, .composer { width: 760px; margin: 0 auto; }
  body.has-thread .stage { width: 760px; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
