:root {
  --paper: #f8fbff;
  --ink: #101828;
  --muted: #667085;
  --line: rgba(26, 115, 232, 0.16);
  --panel: rgba(255, 255, 255, 0.78);
  --assistant: #ffffff;
  --user: #1769e0;
  --user-text: #ffffff;
  --accent: #1a73e8;
  --accent-soft: #d9ecff;
  --danger: #b42318;
  --shadow: 0 24px 80px rgba(32, 83, 148, 0.14);
  --app-top-offset: 0px;
  --app-height: 100dvh;
  --keyboard-lift: 0px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #ffffff;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family:
    ui-serif,
    "Iowan Old Style",
    "Palatino Linotype",
    Georgia,
    serif;
  overflow: hidden;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -2;
  content: "";
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 251, 255, 0.96) 42%, rgba(226, 242, 255, 0.84) 100%),
    linear-gradient(160deg, rgba(26, 115, 232, 0.12), transparent 38%),
    linear-gradient(20deg, transparent 54%, rgba(105, 196, 255, 0.18) 100%);
}

body::after {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  opacity: 0.35;
  background-image:
    linear-gradient(90deg, rgba(26, 115, 232, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(26, 115, 232, 0.026) 1px, transparent 1px);
  background-size: 56px 56px;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(100vw, 1180px);
  height: 100dvh;
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  background: rgba(255, 255, 255, 0.7);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: max(16px, env(safe-area-inset-top)) clamp(16px, 4vw, 36px) 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 118px;
  height: auto;
  display: block;
}

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

.model-pill {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid rgba(26, 115, 232, 0.2);
  border-radius: 999px;
  color: var(--muted);
  font-family:
    "Avenir Next",
    "Helvetica Neue",
    sans-serif;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.72);
}

.pulse {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.13);
}

.thread {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px clamp(14px, 4vw, 46px);
  overflow-y: auto;
  scroll-behavior: smooth;
}

.message {
  width: 100%;
  display: flex;
  animation: rise 220ms ease-out both;
}

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

.message.assistant {
  justify-content: flex-start;
}

.message-bubble {
  max-width: min(72ch, 78%);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--assistant);
  box-shadow: 0 12px 32px rgba(32, 83, 148, 0.08);
}

.message.user .message-bubble {
  color: var(--user-text);
  background: linear-gradient(135deg, #1769e0 0%, #48b8ff 100%);
  border-color: rgba(23, 105, 224, 0.24);
  box-shadow: 0 14px 34px rgba(26, 115, 232, 0.22);
}

.message.error .message-bubble {
  color: var(--danger);
  border-color: rgba(161, 60, 47, 0.28);
}

.message-bubble p {
  margin: 0;
  font-size: 17px;
  line-height: 1.52;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-bubble p + p {
  margin-top: 0.75em;
}

.typing .message-bubble {
  min-width: 76px;
  display: flex;
  gap: 7px;
  align-items: center;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0.48;
  animation: blink 1.1s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 120ms;
}

.typing-dot:nth-child(3) {
  animation-delay: 240ms;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 52px;
  gap: 10px;
  align-items: end;
  padding: 14px clamp(14px, 4vw, 36px) max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.site-footer {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 6px clamp(14px, 4vw, 36px) 0;
  color: var(--muted);
  background: var(--panel);
  font-family:
    "Avenir Next",
    "Helvetica Neue",
    sans-serif;
  font-size: 12px;
  line-height: 1;
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--ink);
}

.composer-field {
  min-height: 52px;
  display: flex;
  align-items: center;
  border: 1px solid rgba(26, 115, 232, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.composer-field:focus-within {
  border-color: rgba(26, 115, 232, 0.62);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.12);
}

textarea {
  width: 100%;
  max-height: 160px;
  min-height: 24px;
  padding: 14px 15px;
  display: block;
  color: var(--ink);
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-size: 17px;
  line-height: 1.42;
}

textarea::placeholder {
  color: rgba(125, 118, 107, 0.8);
}

.send-button {
  width: 52px;
  height: 52px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(26, 115, 232, 0.24);
  border-radius: 8px;
  color: var(--user-text);
  background: linear-gradient(135deg, #1769e0 0%, #48b8ff 100%);
  transition:
    transform 140ms ease,
    background 140ms ease,
    opacity 140ms ease;
}

.send-button:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #1158c7 0%, #28a8ff 100%);
}

.send-button:disabled {
  cursor: default;
  opacity: 0.44;
  transform: none;
}

.send-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink {
  0%,
  100% {
    opacity: 0.28;
    transform: translateY(0);
  }
  45% {
    opacity: 0.9;
    transform: translateY(-3px);
  }
}

@media (max-width: 720px) {
  .shell {
    position: fixed;
    top: var(--app-top-offset);
    right: 0;
    bottom: auto;
    left: 0;
    width: 100vw;
    height: var(--app-height);
    min-height: 0;
    border: 0;
    box-shadow: none;
    padding: 0;
    overflow: hidden;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }

  .topbar {
    min-height: 64px;
  }

  .brand-mark {
    width: 106px;
  }

  .model-pill {
    max-width: 142px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .thread {
    padding-top: 16px;
    padding-bottom: 14px;
  }

  body.keyboard-open .thread {
    padding-bottom: 8px;
  }

  .message-bubble {
    max-width: 88%;
  }

  .message-bubble p,
  textarea {
    font-size: 16px;
  }

  .composer {
    position: static;
    z-index: 30;
    grid-template-columns: 1fr 50px;
    gap: 9px;
    padding: 12px 16px calc(max(14px, env(safe-area-inset-bottom)) + var(--keyboard-lift));
    border-top: 1px solid rgba(26, 115, 232, 0.22);
    box-shadow: 0 -16px 42px rgba(32, 83, 148, 0.14);
    backdrop-filter: blur(18px);
    transition: padding-bottom 180ms ease;
  }

  .composer-field {
    min-height: 56px;
    border-color: rgba(26, 115, 232, 0.32);
    box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.08);
  }

  textarea {
    padding: 16px;
  }

  .send-button {
    width: 56px;
    height: 56px;
  }

  .site-footer {
    position: static;
    z-index: 29;
    min-height: 24px;
    gap: 12px;
    padding: 0 14px 4px;
    font-size: 11px;
    background: transparent;
  }

  body.keyboard-open .site-footer {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
