/* JARVIS — Apple design language (SF system stack, binary light/dark rhythm, single blue accent)
   Motion layer: spring physics, typing dots, streaming reveal, scroll-driven cinematic sections. */

:root {
  color-scheme: dark;
  --blue: #0071e3;
  --blue-bright: #2997ff;
  --link: #2997ff;
  --ink: #f5f5f7;
  --ink-secondary: rgba(255, 255, 255, 0.72);
  --ink-tertiary: rgba(255, 255, 255, 0.48);
  --surface-dark: #1d1d1f;
  --surface-elevated: #272729;
  --field: rgba(255, 255, 255, 0.07);
  --ease-apple: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --font: system-ui, -apple-system, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-family: var(--font);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
}

html, body { margin: 0; padding: 0; }

body {
  min-height: 100dvh;
  background: #000000;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.374px;
}

/* ---------- Glass navigation (the Apple signature) ---------- */

.glass-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 0 max(16px, env(safe-area-inset-left));
  background: rgba(22, 22, 23, 0.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.nav-mark {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: conic-gradient(from 210deg, #2997ff, #a6a6ad 55%, #2997ff);
  animation: markSpin 14s linear infinite;
}

@keyframes markSpin {
  to { transform: rotate(360deg); }
}

.nav-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.nav-status {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-tertiary);
  transition: color 0.4s var(--ease-apple);
}

.nav-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-tertiary);
  transition: background 0.4s var(--ease-apple);
}

.nav-status.online { color: var(--ink-secondary); }
.nav-status.online::before { background: #30d158; }
.nav-status.offline { color: #ff453a; }
.nav-status.offline::before { background: #ff453a; }

/* ---------- Cinematic hero: staged reveal, gentle float ---------- */

.shell {
  width: min(680px, 100%);
  min-height: calc(100dvh - 48px);
  margin: 0 auto;
  padding: 0 20px calc(210px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.hero {
  padding: 72px 0 48px;
  text-align: center;
}

.eyebrow,
.hero-title,
.hero-sub {
  opacity: 0;
  transform: translateY(26px) scale(0.97);
  filter: blur(6px);
  animation: heroReveal 0.9s var(--ease-apple) forwards;
}

.eyebrow { animation-delay: 0.05s; }
.hero-title { animation-delay: 0.15s; }
.hero-sub { animation-delay: 0.32s; }

@keyframes heroReveal {
  to { opacity: 1; transform: none; filter: blur(0); }
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue-bright);
}

.hero-title {
  margin: 0;
  font-size: 56px;
  font-weight: 600;
  line-height: 1.07;
  letter-spacing: -0.28px;
}

.hero-sub {
  margin: 12px 0 0;
  font-size: 21px;
  font-weight: 400;
  line-height: 1.19;
  letter-spacing: 0.231px;
  color: var(--ink-secondary);
}

@media (max-width: 480px) {
  .hero { padding: 48px 0 36px; }
  .hero-title { font-size: 40px; }
  .hero-sub { font-size: 17px; }
}

/* ---------- Messages: Apple iMessage choreography ---------- */

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 8px;
}

.message {
  max-width: 86%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 17px;
  line-height: 1.47;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(180deg, #0a84ff, #0071e3);
  color: #ffffff;
  border-bottom-right-radius: 6px;
  transform-origin: bottom right;
  animation: popUser 0.42s var(--ease-spring) both;
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface-elevated);
  color: var(--ink);
  border-bottom-left-radius: 6px;
  transform-origin: bottom left;
  animation: popAssistant 0.42s var(--ease-spring) both;
}

@keyframes popUser {
  from { opacity: 0; transform: translateY(14px) scale(0.86); }
  to { opacity: 1; transform: none; }
}

@keyframes popAssistant {
  from { opacity: 0; transform: translateY(14px) scale(0.92); }
  to { opacity: 1; transform: none; }
}

/* Scroll-driven fade for the whole thread (compositor-driven, no JS) */

@supports (animation-timeline: view()) {
  .messages .message {
    animation: scrollFade linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 60%;
  }
  .messages .message.user,
  .messages .message.assistant {
    animation-name: scrollFade;
  }
}

@keyframes scrollFade {
  from { opacity: 0.25; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Typing indicator: three breathing dots ---------- */

.typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  background: var(--surface-elevated);
  animation: popAssistant 0.42s var(--ease-spring) both;
}

.typing .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-tertiary);
  animation: dotBreathe 1.2s ease-in-out infinite;
}

.typing .dot:nth-child(2) { animation-delay: 0.18s; }
.typing .dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes dotBreathe {
  0%, 60%, 100% { transform: scale(0.82); opacity: 0.55; }
  30% { transform: scale(1.12); opacity: 1; background: var(--blue-bright); }
}

/* ---------- Streaming reveal for assistant answers ---------- */

.message.assistant.streaming {
  animation: popAssistant 0.42s var(--ease-spring) both;
}

.message.assistant.streaming .reveal {
  animation: lineUp 0.5s var(--ease-apple) both;
}

@keyframes lineUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Composer: floating glass dock ---------- */

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 auto;
  width: min(680px, 100%);
  padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  background: rgba(20, 20, 22, 0.74);
  backdrop-filter: saturate(160%) blur(24px);
  -webkit-backdrop-filter: saturate(160%) blur(24px);
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 -10px 34px rgba(0, 0, 0, 0.4);
  animation: dockUp 0.7s var(--ease-spring) 0.45s both;
}

@keyframes dockUp {
  from { transform: translateY(110%); }
  to { transform: none; }
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

textarea#message {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  padding: 11px 16px;
  border: none;
  border-radius: 22px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  letter-spacing: -0.374px;
  outline: none;
  transition: background 0.25s var(--ease-apple), box-shadow 0.25s var(--ease-apple);
}

textarea#message:focus {
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.55);
  background: rgba(255, 255, 255, 0.1);
}

textarea#message::placeholder { color: var(--ink-tertiary); }

button.cta {
  flex: 0 0 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--blue);
  color: #ffffff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.18s var(--ease-spring), background 0.2s var(--ease-apple);
}

button.cta:hover { background: #0077ed; }
button.cta:active { transform: scale(0.88); }
button.cta:disabled { opacity: 0.4; cursor: default; }

/* Circular progress ring while waiting */

button.cta.busy {
  background: transparent;
  border-radius: 50%;
  position: relative;
}

button.cta.busy::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--blue-bright);
  animation: ringSpin 0.9s linear infinite;
}

@keyframes ringSpin {
  to { transform: rotate(360deg); }
}

.composer-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
}

/* ---------- Pill toggle (Apple switch) ---------- */

.pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.pill-toggle input { position: absolute; opacity: 0; pointer-events: none; }

.pill-track {
  width: 40px;
  height: 24px;
  border-radius: 980px;
  background: rgba(255, 255, 255, 0.16);
  position: relative;
  transition: background 0.25s var(--ease-apple);
  flex: none;
}

.pill-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.25s var(--ease-spring);
}

.pill-toggle input:checked + .pill-track { background: #30d158; }
.pill-toggle input:checked + .pill-track .pill-knob { transform: translateX(16px); }
.pill-toggle input:focus-visible + .pill-track { outline: 2px solid var(--blue-bright); outline-offset: 2px; }

.pill-label {
  font-size: 14px;
  color: var(--ink-secondary);
  letter-spacing: -0.224px;
}

/* ---------- Text link + dev panel ---------- */

.text-link {
  border: none;
  background: none;
  padding: 4px 0;
  font: inherit;
  font-size: 14px;
  letter-spacing: -0.224px;
  color: var(--link);
  cursor: pointer;
}

.text-link:hover { text-decoration: underline; }

.dev-panel { font-size: 12px; color: var(--ink-tertiary); }

.dev-panel summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
  color: var(--ink-tertiary);
  letter-spacing: -0.14px;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s var(--ease-apple);
}

.dev-panel summary::after {
  content: "⌃";
  font-size: 10px;
  opacity: 0.6;
  transform: rotate(90deg);
  transition: transform 0.2s var(--ease-apple);
}

.dev-panel[open] summary::after { transform: rotate(270deg); }

.dev-panel summary:hover { color: var(--ink-secondary); }

.dev-panel summary::-webkit-details-marker { display: none; }

.dev-panel[open] summary { color: var(--ink-secondary); }

.dev-panel input {
  width: 100%;
  margin-top: 8px;
  padding: 9px 12px;
  border: none;
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: box-shadow 0.2s var(--ease-apple), background 0.2s var(--ease-apple);
}

.dev-panel input:focus { box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.5); background: rgba(255, 255, 255, 0.1); }

/* ---------- Reduced motion: everything settles instantly ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .nav-mark { animation: none; }
  .eyebrow, .hero-title, .hero-sub { opacity: 1; transform: none; filter: none; animation: none; }
  .message.user, .message.assistant { animation: none; }
  .typing, .typing .dot { animation: none; }
  .composer { animation: none; }
  @supports (animation-timeline: view()) {
    .messages .message { animation: none; }
  }
}
