:root {
  --bg-deep: #0f0620;
  --bg-card: #1a0a2e;
  --neon-purple: #b967ff;
  --neon-orange: #ff6b35;
  --neon-yellow: #ffe066;
  --mint: #00f5d4;
  --text: #f8f5ff;
  --muted: #9b8bb8;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "Space Mono", monospace;
  --radius: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #2d1b4e 0%, var(--bg-deep) 55%);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.hidden {
  display: none !important;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  background: rgba(5, 2, 12, 0.92);
  backdrop-filter: blur(8px);
}

.gate-card {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.gate-title {
  margin: 0 0 8px;
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--neon-yellow);
  text-align: center;
}

.gate-lead {
  margin: 0 0 16px;
  text-align: center;
  font-size: 0.85rem;
}

.gate-q {
  margin: 14px 0 8px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--neon-yellow);
}

.gate-loading {
  margin: 0;
  padding: 10px;
  text-align: center;
  font-size: 0.8rem;
}

.gate-boot-error {
  margin: 0 0 12px;
  padding: 10px;
  border-radius: 10px;
  background: rgba(214, 48, 49, 0.2);
  border: 1px solid #ff6b6b;
  color: #ffb3b3;
  font-size: 0.78rem;
}

.role-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.role-btn {
  padding: 14px 10px;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.85rem;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  cursor: pointer;
}

.role-btn--on {
  border-color: var(--neon-orange);
  background: rgba(255, 107, 53, 0.2);
  color: var(--neon-yellow);
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(15, 6, 32, 0.98), rgba(15, 6, 32, 0.85));
  border-bottom: 1px solid rgba(185, 103, 255, 0.25);
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.btn-ghost {
  flex-shrink: 0;
  margin-top: 2px;
  padding: 8px 12px;
  font-size: 0.7rem;
  font-weight: 800;
  font-family: inherit;
  letter-spacing: 0.04em;
  color: var(--mint);
  background: rgba(0, 245, 212, 0.08);
  border: 1px solid rgba(0, 245, 212, 0.35);
  border-radius: 999px;
  cursor: pointer;
}

.brand-icon {
  font-size: 1.85rem;
  line-height: 1.2;
  filter: drop-shadow(0 0 10px var(--neon-purple));
}

.brand-title {
  margin: 0;
  font-size: clamp(0.95rem, 4vw, 1.15rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.2;
  color: var(--neon-yellow);
  text-shadow: 0 0 14px rgba(255, 224, 102, 0.45);
}

.tagline {
  margin: 6px 0 0;
  font-size: 0.68rem;
  line-height: 1.35;
  color: var(--muted);
}

.panels {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  min-height: 0;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-section {
  flex: 1;
}

.chat-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: min(72dvh, 560px);
  padding: 12px;
}

.chat-messages {
  flex: 1;
  min-height: 200px;
  overflow-y: auto;
  padding: 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-placeholder {
  margin: 0;
  padding: 12px;
  font-size: 0.85rem;
  text-align: center;
}

.muted {
  color: var(--muted);
}

.bubble {
  display: flex;
  margin-bottom: 10px;
}

.bubble--user {
  justify-content: flex-end;
}

.bubble--model {
  justify-content: flex-start;
}

.bubble-inner {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble--user .bubble-inner {
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.35), rgba(185, 103, 255, 0.35));
  border: 1px solid rgba(255, 224, 102, 0.25);
}

.bubble--model .bubble-inner {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: rgba(26, 10, 46, 0.95);
  border: 1px solid rgba(0, 245, 212, 0.22);
  color: #e8fff9;
}

.chat-input {
  width: 100%;
  resize: none;
  padding: 12px;
  font-size: 0.95rem;
  font-family: inherit;
  border-radius: 12px;
  border: 1px solid rgba(185, 103, 255, 0.4);
  background: #12081f;
  color: var(--text);
}

.chat-input::placeholder {
  color: var(--muted);
}

.btn-primary {
  font-family: var(--font);
  font-weight: 800;
  font-size: 0.9rem;
  padding: 14px;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  width: 100%;
  background: linear-gradient(135deg, var(--neon-orange), var(--neon-purple));
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  box-shadow: 0 4px 24px rgba(255, 107, 53, 0.35);
}

.btn-primary:disabled {
  opacity: 0.75;
  cursor: not-allowed;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
