:root {
  --bg-top: #08131f;
  --bg-bottom: #071018;
  --surface: #0d1b2a;
  --card: rgba(18, 35, 52, 0.82);
  --accent: #4cc9f0;
  --accent-secondary: #3dd6b3;
  --accent-violet: #7f8cff;
  --text: #f3f8fc;
  --text-secondary: #95aabd;
  --border: rgba(255, 255, 255, 0.08);
  --success: #3dd6b3;
  --empty: #7f9bb0;
  --warning: #e3b341;
  --error: #f07178;
  --radius-card: 22px;
  --radius-control: 18px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  --motion: 180ms ease;
  --page-pad: 18px;
  --touch: 44px;
  --font: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  background: var(--bg-bottom);
  color: var(--text);
  font-family: var(--font);
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(
      900px 520px at 50% -8%,
      rgba(76, 201, 240, 0.16),
      transparent 58%
    ),
    radial-gradient(
      720px 420px at 100% 110%,
      rgba(127, 140, 255, 0.14),
      transparent 52%
    ),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  overflow-x: hidden;
}

/*
  Future Terry artwork (optional; UI is complete without these files):
  /static/terry-background.webp — faint hero/background wash
  /static/terry-logo.png — circular mark replacing the "T" fallback
*/
body.login::before,
body.has-terry-background::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: image-set(url("/static/terry-background.webp") type("image/webp"))
    center / cover no-repeat;
  opacity: 0.14;
  z-index: 0;
}

body > * {
  position: relative;
  z-index: 1;
}

a {
  color: var(--accent);
}

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

.AppShell {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: var(--page-pad) var(--page-pad) 32px;
}

.Header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.Header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.Header-name {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.Header-subtitle {
  margin: 0.1rem 0 0;
  color: var(--text-secondary);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.Header-titles {
  min-width: 0;
}

.Header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.TerryAvatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background:
    radial-gradient(
      circle at 30% 25%,
      rgba(243, 248, 252, 0.18),
      transparent 42%
    ),
    linear-gradient(160deg, var(--accent) 0%, var(--accent-violet) 70%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.12),
    0 8px 18px rgba(76, 201, 240, 0.18);
  overflow: hidden;
}

.TerryAvatar--hero {
  width: 88px;
  height: 88px;
  margin: 0 auto 18px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.1),
    0 16px 40px rgba(76, 201, 240, 0.22);
}

.TerryAvatar-fallback {
  font-size: 1.05rem;
  font-weight: 700;
  color: #071018;
}

.TerryAvatar--hero .TerryAvatar-fallback {
  font-size: 2.1rem;
}

.TerryAvatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.Online {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.78rem;
}

.Online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 10px rgba(61, 214, 179, 0.7);
}

.Header-menu {
  position: relative;
}

.Header-menuButton {
  list-style: none;
  width: var(--touch);
  height: var(--touch);
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(13, 27, 42, 0.7);
  color: var(--text);
  cursor: pointer;
}

.Header-menuButton::-webkit-details-marker {
  display: none;
}

.Header-menuPanel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 148px;
  padding: 8px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.Header-menuPanel button {
  width: 100%;
  min-height: var(--touch);
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.Header-menuPanel button:hover,
.Header-menuPanel button:focus-visible {
  background: rgba(255, 255, 255, 0.06);
}

.Greeting {
  margin: 12px 0 22px;
}

.Greeting h1 {
  margin: 0;
  font-size: clamp(1.7rem, 6vw, 2.15rem);
  font-weight: 650;
  letter-spacing: -0.03em;
}

.Greeting-prompt {
  margin: 8px 0 0;
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.Composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: end;
  gap: 10px;
  max-width: 100%;
  padding: 14px 12px 14px 16px;
  border-radius: var(--radius-card);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(18px);
}

.Composer:focus-within {
  border-color: rgba(76, 201, 240, 0.45);
  box-shadow:
    var(--shadow),
    0 0 0 3px rgba(76, 201, 240, 0.18);
}

.Composer textarea {
  width: 100%;
  min-width: 0;
  min-height: 76px;
  max-height: 180px;
  margin: 0;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.45;
  outline: none;
}

.Composer textarea::placeholder {
  color: #6f8799;
}

.Composer-send {
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--accent) 0%, #2aa8d6 100%);
  color: #071018;
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
}

.Composer-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.Thinking {
  margin: 12px 4px 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.Thinking-dots::after {
  content: "";
  animation: thinking-dots 1.1s steps(4, end) infinite;
}

.Chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 8px;
}

.Chip {
  min-height: var(--touch);
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(13, 27, 42, 0.62);
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.Chip:hover,
.Chip:focus-visible {
  color: var(--text);
  border-color: rgba(76, 201, 240, 0.35);
}

.AnswerCard,
.BriefCard,
.SourcesCard {
  margin-top: 18px;
  padding: 18px 18px 16px;
  border-radius: var(--radius-card);
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.AnswerCard h2 {
  margin: 0 0 12px;
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.AnswerCard-text {
  font-size: 1.0625rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.AnswerCard-text p {
  margin: 0 0 0.9em;
}

.AnswerCard-text p:last-child {
  margin-bottom: 0;
}

.AnswerCard-note,
.AnswerCard-notices {
  margin: 12px 0 0;
  color: var(--warning);
  font-size: 0.92rem;
}

.ResponseDetails,
.BriefCard,
.SourcesCard {
  overflow: hidden;
}

.ResponseDetails {
  margin-top: 14px;
}

.BriefCard > summary,
.SourcesCard > summary,
.ResponseDetails > summary {
  cursor: pointer;
  list-style: none;
  color: var(--text);
  font-weight: 650;
}

.BriefCard > summary::-webkit-details-marker,
.SourcesCard > summary::-webkit-details-marker,
.ResponseDetails > summary::-webkit-details-marker {
  display: none;
}

.BriefCard > summary::before,
.SourcesCard > summary::before,
.ResponseDetails > summary::before {
  content: "▸ ";
  color: var(--accent);
}

.BriefCard[open] > summary::before,
.SourcesCard[open] > summary::before,
.ResponseDetails[open] > summary::before {
  content: "▾ ";
}

.CardSummary-title {
  display: inline;
}

.CardSummary-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 0.84rem;
  font-weight: 400;
}

.BriefCard-body,
#answer-diagnostics,
.Sources-raw {
  margin-top: 12px;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.Sources-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
}

.Sources-account + .Sources-account {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.Sources-accountHead {
  min-width: 0;
  margin-bottom: 4px;
}

.Sources-accountLabel {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.Sources-accountMeta {
  margin: 2px 0 0;
  color: var(--text-secondary);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.Sources-accountStreams {
  list-style: none;
  margin: 0;
  padding: 0;
}

.Sources-list > li:not(.Sources-account),
.Sources-accountStreams li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.Sources-accountStreams li:last-child,
.Sources-list > li:last-child {
  border-bottom: 0;
}

.Badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 650;
}

.Badge-mark {
  font-size: 0.85rem;
}

.Badge--success {
  color: var(--success);
  background: rgba(61, 214, 179, 0.12);
}

.Badge--empty {
  color: var(--empty);
  background: rgba(127, 155, 176, 0.12);
}

.Badge--warning {
  color: var(--warning);
  background: rgba(227, 179, 65, 0.14);
}

.Badge--error {
  color: var(--error);
  background: rgba(240, 113, 120, 0.14);
}

.Sources-raw {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 14px;
  background: rgba(7, 16, 24, 0.45);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
}

.AppSecondary {
  display: grid;
  gap: 0;
}

.LoginScreen {
  min-height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 32px 20px;
}

.LoginScreen > * {
  min-width: 0;
  max-width: 100%;
}

.LoginScreen h1 {
  margin: 0;
  font-size: 2.1rem;
  letter-spacing: -0.03em;
}

.Login-lead {
  margin: 10px 0 0;
  color: var(--text);
  font-size: 1.05rem;
}

.Login-support {
  max-width: 18rem;
  width: 100%;
  margin: 10px 0 0;
  color: var(--text-secondary);
  line-height: 1.5;
  overflow-wrap: break-word;
}

#auth-error:not([hidden]) {
  margin: 14px 0 0;
  color: var(--error);
}

.Login-action {
  margin: 28px 0 0;
}

.LoginContinue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  min-width: 220px;
  padding: 0 22px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent) 0%, #2aa8d6 100%);
  color: #071018;
  text-decoration: none;
  font-weight: 700;
}

.LoginContinue:hover,
.LoginContinue:focus-visible {
  filter: brightness(1.06);
}

button,
summary,
a,
textarea {
  transition:
    background-color var(--motion),
    border-color var(--motion),
    box-shadow var(--motion),
    color var(--motion),
    filter var(--motion),
    opacity var(--motion);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.Composer:focus-within {
  outline: none;
}

@keyframes thinking-dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75% {
    content: "...";
  }
}

@media (max-width: 430px) {
  .Header-subtitle {
    display: none;
  }

  .Online span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .Online {
    position: relative;
  }
}

@media (min-width: 900px) {
  .AppShell {
    padding: 28px 32px 48px;
  }

  .AppSecondary {
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    align-items: start;
  }

  .BriefCard,
  .SourcesCard {
    margin-top: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .Thinking-dots::after {
    content: "...";
  }
}
