:root {
  --bg: #0a0d12;
  --bg-elev: #11161e;
  --fg: #e7ecf3;
  --muted: #8590a0;
  --accent: #7aa6ff;
  --accent-warm: #ffb98a;
  --speak: #a8ffd1;
  --listen: #7aa6ff;
  --think: #ffd47a;
  --danger: #ff7a7a;
  --border: #1f2632;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Inter", system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 50% -10%, #1a2438 0%, var(--bg) 60%);
  color: var(--fg);
  height: 100%;
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; min-width: 0; height: 100vh; overflow: hidden; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }
kbd {
  font-family: ui-monospace, "SF Mono", monospace;
  background: #1b2230; border: 1px solid #2a3344; border-bottom-width: 2px;
  border-radius: 6px; padding: 1px 6px; font-size: 12px;
}

/* Login */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  align-items: stretch;
  min-height: 100vh;
  background:
    linear-gradient(115deg, rgba(8, 12, 18, 0.94) 0%, rgba(8, 12, 18, 0.78) 52%, rgba(10, 13, 18, 0.98) 52%),
    linear-gradient(180deg, #172033 0%, #0a0d12 100%);
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
body.authenticated .login-screen {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}
body.auth-pending .login-screen {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}
body.auth-pending .topbar,
body.auth-pending .stage,
body.auth-pending .footbar,
body.auth-pending .debug-panel {
  pointer-events: none;
  visibility: hidden;
}
body:not(.authenticated):not(.auth-pending) .topbar,
body:not(.authenticated):not(.auth-pending) .stage,
body:not(.authenticated):not(.auth-pending) .footbar,
body:not(.authenticated):not(.auth-pending) .debug-panel {
  pointer-events: none;
  filter: blur(4px);
}
body:not(.authenticated) #logout { display: none; }

.login-visual {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
  padding: 48px 72px;
  min-width: 0;
}
.login-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #f1f5fb;
  font-weight: 700;
  font-size: 18px;
}
.login-mark .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-warm));
  box-shadow: 0 0 16px rgba(255,185,138,0.45);
}
.login-headline {
  max-width: 560px;
  color: #f4f7fb;
  font-size: 42px;
  font-weight: 700;
  line-height: 1.05;
}
.login-signal {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 86px;
}
.login-signal span {
  display: block;
  width: 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent-warm), var(--speak));
  box-shadow: 0 12px 28px rgba(168,255,209,0.14);
}
.login-signal span:nth-child(1) { height: 32px; }
.login-signal span:nth-child(2) { height: 64px; }
.login-signal span:nth-child(3) { height: 44px; }
.login-signal span:nth-child(4) { height: 78px; }
.login-signal span:nth-child(5) { height: 52px; }

.login-panel {
  align-self: center;
  justify-self: stretch;
  margin-right: 72px;
  padding: 28px;
  background: rgba(15, 20, 28, 0.86);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(0,0,0,0.44);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-title {
  color: var(--fg);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
.login-panel label {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.login-panel label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}
.login-panel input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #2c3545;
  border-radius: 8px;
  background: #0b1018;
  color: var(--fg);
  padding: 10px 12px;
  outline: none;
}
.login-panel input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122,166,255,0.18);
}
.login-panel button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #7aa6ff, #ffb98a);
  color: #081018;
  font-weight: 700;
  margin-top: 4px;
}
.login-panel button:disabled {
  cursor: wait;
  opacity: 0.68;
}
.login-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  min-width: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: 0.2px;
  min-width: 0;
}
.brand .name,
.brand .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand .dot { width: 10px; height: 10px; border-radius: 50%;
  flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-warm));
  box-shadow: 0 0 12px rgba(122,166,255,0.7);
}
.brand .sep, .brand .muted { color: var(--muted); font-weight: 400; }
.controls {
  display: flex; gap: 10px; align-items: center;
  min-width: 0;
}
.modeswitch {
  display: inline-flex; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px;
  min-width: 0;
}
.mode {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 500;
  transition: all 0.18s ease;
  min-width: 0;
  white-space: nowrap;
}
.mode.active {
  background: linear-gradient(180deg, #2c3a55, #1a2638);
  color: var(--fg);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
.ghost {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  padding: 7px 12px; border-radius: 10px; font-size: 13px;
  white-space: nowrap;
}
.ghost:hover { color: var(--fg); border-color: #2c3344; }
.ghost.small { padding: 4px 8px; font-size: 12px; }

/* Stage */
.stage {
  flex: 1; display: grid; grid-template-columns: 1fr 380px;
  gap: 0; min-height: 0;
}
.stage.no-transcript { grid-template-columns: 1fr 0; }
.orb-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; padding: 24px;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Orb */
.orb {
  position: relative; width: 240px; height: 240px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; user-select: none;
  transform: scale(1); transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.orb:hover { transform: scale(1.02); }
.orb-core {
  position: absolute; inset: 24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c8d6ff, #6c8be0 45%, #2a3a6f 80%);
  box-shadow:
    inset 0 0 30px rgba(255,255,255,0.18),
    inset 0 -20px 40px rgba(0,0,0,0.35),
    0 12px 60px rgba(60, 90, 200, 0.45);
  transition: box-shadow 0.3s ease, background 0.3s ease;
}
.orb-ring {
  position: absolute; inset: 0;
  border-radius: 50%; border: 1px solid rgba(122,166,255,0.25);
  background: radial-gradient(circle, transparent 60%, rgba(122,166,255,0.08) 70%, transparent 80%);
}
.orb-glow {
  position: absolute; inset: -30px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(122,166,255,0.18), transparent 65%);
  opacity: 0.6;
  filter: blur(16px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.orb.listening .orb-core {
  background: radial-gradient(circle at 35% 30%, #d6e0ff, var(--listen) 50%, #1f3170 85%);
  animation: pulseRing 1.6s ease-in-out infinite;
}
.orb.thinking .orb-core {
  background: radial-gradient(circle at 35% 30%, #fff0c8, var(--think) 55%, #5a4310 85%);
  animation: spin 5s linear infinite;
}
.orb.speaking .orb-core {
  background: radial-gradient(circle at 35% 30%, #d8ffe5, var(--speak) 55%, #114a30 85%);
  animation: speakPulse 0.55s ease-in-out infinite alternate;
}
.orb.error .orb-core {
  background: radial-gradient(circle at 35% 30%, #ffd3d3, var(--danger) 55%, #4a1212 85%);
}

@keyframes pulseRing {
  0%, 100% { box-shadow: inset 0 0 30px rgba(255,255,255,0.18), inset 0 -20px 40px rgba(0,0,0,0.35), 0 0 0 0 rgba(122,166,255,0.45), 0 12px 60px rgba(60,90,200,0.45); }
  50%      { box-shadow: inset 0 0 30px rgba(255,255,255,0.18), inset 0 -20px 40px rgba(0,0,0,0.35), 0 0 0 22px rgba(122,166,255,0), 0 12px 60px rgba(60,90,200,0.45); }
}
@keyframes speakPulse {
  from { transform: scale(1); }
  to   { transform: scale(1.04); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.status {
  margin-top: 28px;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.3px;
  min-height: 20px;
}
.ptt-hint { margin-top: 8px; color: var(--muted); font-size: 13px; }
.ptt-hint.hidden { display: none; }

/* Seed questions */
.seed-questions {
  margin-top: 32px;
  width: 100%;
  max-width: 640px;
  text-align: center;
}
.seed-title { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; margin-bottom: 10px; }
.seed-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.seed {
  background: var(--bg-elev); border: 1px solid var(--border); color: var(--fg);
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  transition: border-color 0.15s ease, background 0.15s ease;
  max-width: 100%;
}
.seed:hover { border-color: #344056; background: #161e2c; }

/* Transcript */
.transcript {
  border-left: 1px solid var(--border);
  background: rgba(10,12,16,0.6);
  display: flex; flex-direction: column; min-height: 0;
  transition: width 0.2s ease;
}
.stage.no-transcript .transcript { display: none; }
.transcript-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.transcript-head h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: 0.5px; color: var(--muted); text-transform: uppercase; }
.messages { flex: 1; overflow-y: auto; padding: 14px 18px 24px; }
.msg { margin-bottom: 16px; line-height: 1.5; font-size: 14px; }
.msg .role {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin-bottom: 4px;
}
.msg.user .role { color: var(--accent); }
.msg.assistant .role { color: var(--accent-warm); }
.msg .text { color: var(--fg); white-space: pre-wrap; }
.msg .citations { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.cite {
  background: #14202f; border: 1px solid #1e2c3f; color: #b6c4d4;
  padding: 4px 8px; border-radius: 6px; font-size: 11px;
  font-family: ui-monospace, "SF Mono", monospace;
  cursor: default;
}

/* Footbar */
.footbar {
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding: 8px 22px;
  font-size: 12px;
  min-width: 0;
}
#meta {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }

.debug-panel {
  position: fixed;
  right: 12px; bottom: 48px;
  width: 520px; max-width: calc(100vw - 24px);
  height: 320px;
  background: rgba(8, 11, 16, 0.96);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  display: flex; flex-direction: column;
  z-index: 1000;
  font-size: 11px;
}
.debug-panel.hidden { display: none; }
.debug-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  color: var(--muted); font-size: 12px;
}
.debug-panel pre {
  flex: 1; overflow: auto; margin: 0; padding: 8px 12px;
  font-family: ui-monospace, "SF Mono", monospace; font-size: 11px;
  line-height: 1.5; color: #c8d4e4;
  white-space: pre-wrap; word-break: break-word;
}
.debug-panel pre .lvl-warn { color: #ffc66e; }
.debug-panel pre .lvl-err  { color: #ff8a8a; }
.debug-panel pre .lvl-evt  { color: #7aa6ff; }
.debug-panel pre .lvl-ok   { color: #88e0a8; }

/* Responsive: stack on narrow */
@media (max-width: 900px) {
  .login-screen {
    grid-template-columns: 1fr;
    align-content: center;
    padding: 28px;
    min-height: 100dvh;
    overflow-y: auto;
  }
  .login-visual {
    padding: 0 0 24px;
    gap: 16px;
  }
  .login-headline {
    font-size: 30px;
    line-height: 1.1;
  }
  .login-signal { height: 52px; }
  .login-signal span { width: 9px; }
  .login-signal span:nth-child(1) { height: 22px; }
  .login-signal span:nth-child(2) { height: 44px; }
  .login-signal span:nth-child(3) { height: 30px; }
  .login-signal span:nth-child(4) { height: 52px; }
  .login-signal span:nth-child(5) { height: 36px; }
  .login-panel {
    margin: 0;
    width: 100%;
  }
  .stage { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .transcript { border-left: 0; border-top: 1px solid var(--border); max-height: 40vh; }
}

@media (max-width: 720px) {
  body {
    height: 100dvh;
    overflow-x: hidden;
  }
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    padding: 12px 14px;
  }
  .brand {
    width: 100%;
    gap: 8px;
    font-size: 17px;
  }
  .brand .muted {
    flex: 1 1 auto;
  }
  .controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    width: 100%;
    gap: 8px;
  }
  .modeswitch {
    display: flex;
    width: 100%;
  }
  .mode {
    flex: 1 1 0;
    padding: 8px 9px;
    font-size: 13px;
    text-align: center;
  }
  .ghost {
    padding: 8px 10px;
    font-size: 12px;
  }
  #transcript-toggle {
    display: none;
  }
  .stage,
  .stage.no-transcript {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    min-width: 0;
  }
  .transcript,
  .stage.no-transcript .transcript {
    display: none;
  }
  .orb-wrap {
    justify-content: flex-start;
    padding: 42px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
  }
  .orb {
    width: clamp(190px, 64vw, 260px);
    height: clamp(190px, 64vw, 260px);
  }
  .orb-core {
    inset: 22px;
  }
  .orb-glow {
    inset: -20px;
  }
  .status {
    margin-top: 24px;
    font-size: 15px;
  }
  .seed-questions {
    margin-top: 28px;
  }
  .seed-list {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 10px;
  }
  .seed {
    width: fit-content;
    max-width: min(100%, 360px);
    padding: 10px 16px;
    border-radius: 999px;
    line-height: 1.24;
    white-space: normal;
  }
  .footbar {
    padding: 8px max(14px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  }
}

@media (max-width: 420px) {
  .brand {
    font-size: 16px;
  }
  .brand .sep,
  .brand .muted {
    display: none;
  }
  .mode {
    padding-inline: 7px;
    font-size: 12px;
  }
  #logout {
    padding-inline: 9px;
  }
}

@media (max-width: 720px) and (max-height: 760px) {
  .orb-wrap {
    padding-top: 28px;
  }
  .orb {
    width: clamp(170px, 52vw, 220px);
    height: clamp(170px, 52vw, 220px);
  }
  .status {
    margin-top: 18px;
  }
  .seed-questions {
    margin-top: 22px;
  }
  .seed-title {
    margin-bottom: 8px;
  }
  .seed-list {
    gap: 8px;
  }
  .seed {
    padding-block: 8px;
  }
}
