/*
 * Still here? These are just colors and margins.
 * Nobody ever got hired for their margins. Keep scrolling anyway.
 */

/* ---------- Tokens ----------
 * Two looks: "knot" (the default) and "crab". Each has a light and a dark palette.
 * The dark palette follows the visitor's system setting, or data-theme when a host sets one. */

:root,
:root[data-look="knot"] {
  --bg: #FFFFFF;
  --fg: #0D0D0D;
  --reply: #0D0D0D;
  --muted: #6B6B6B;
  --bubble: #F4F4F4;
  --composer-bg: #FFFFFF;
  --composer-border: #E3E3E3;
  --composer-shadow: 0 4px 18px rgba(0, 0, 0, .06);
  --line: #E3E3E3;
  --send-bg: #0D0D0D;
  --send-fg: #FFFFFF;
  --hover: #F0F0F0;
  color-scheme: light;
}

:root[data-look="crab"] {
  --bg: #FAF9F5;
  --fg: #141413;
  --reply: #3D3929;
  --muted: #73726C;
  --bubble: #F0EEE6;
  --composer-bg: #FFFFFF;
  --composer-border: #E6E3D8;
  --composer-shadow: 0 4px 20px rgba(60, 50, 30, .07);
  --line: #E6E3D8;
  --send-bg: #D97757;
  --send-fg: #FFFFFF;
  --hover: #F0EEE6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]),
  :root:not([data-theme="light"])[data-look="knot"] {
    --bg: #212121;
    --fg: #ECECEC;
    --reply: #ECECEC;
    --muted: #A0A0A0;
    --bubble: #303030;
    --composer-bg: #303030;
    --composer-border: #3A3A3A;
    --composer-shadow: none;
    --line: #424242;
    --send-bg: #ECECEC;
    --send-fg: #0D0D0D;
    --hover: #2F2F2F;
    color-scheme: dark;
  }

  :root:not([data-theme="light"])[data-look="crab"] {
    --bg: #262624;
    --fg: #FAF9F5;
    --reply: #E8E6DC;
    --muted: #A3A198;
    --bubble: #141413;
    --composer-bg: #30302E;
    --composer-border: #3E3E3A;
    --composer-shadow: none;
    --line: #3E3E3A;
    --send-bg: #D97757;
    --send-fg: #FFFFFF;
    --hover: #30302E;
    color-scheme: dark;
  }
}

:root[data-theme="dark"],
:root[data-theme="dark"][data-look="knot"] {
  --bg: #212121;
  --fg: #ECECEC;
  --reply: #ECECEC;
  --muted: #A0A0A0;
  --bubble: #303030;
  --composer-bg: #303030;
  --composer-border: #3A3A3A;
  --composer-shadow: none;
  --line: #424242;
  --send-bg: #ECECEC;
  --send-fg: #0D0D0D;
  --hover: #2F2F2F;
  color-scheme: dark;
}

:root[data-theme="dark"][data-look="crab"] {
  --bg: #262624;
  --fg: #FAF9F5;
  --reply: #E8E6DC;
  --muted: #A3A198;
  --bubble: #141413;
  --composer-bg: #30302E;
  --composer-border: #3E3E3A;
  --composer-shadow: none;
  --line: #3E3E3A;
  --send-bg: #D97757;
  --send-fg: #FFFFFF;
  --hover: #30302E;
  color-scheme: dark;
}

:root {
  --code-bg: color-mix(in srgb, var(--fg) 5%, var(--bg));
  --error: #C5221F;
  --sans: ui-sans-serif, -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Page ---------- */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  transition: background-color .35s, color .35s;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

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

.app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 16px;
}

.model-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 18px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}

.model-picker:hover {
  background: var(--hover);
}

.model-picker svg {
  opacity: .55;
}

.chat-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity .6s;
}

.chat-title.is-visible {
  opacity: 1;
}

.topbar-actions {
  display: flex;
  gap: 6px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover {
  background: var(--hover);
  color: var(--fg);
}

.look-switch {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--composer-border);
  border-radius: 50%;
  background: var(--composer-bg);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: transform .25s;
}

.look-switch:hover {
  transform: rotate(-12deg) scale(1.08);
}

/* ---------- Layout ---------- */

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

.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 16px 0;
}

.messages,
.dock-inner {
  width: min(760px, 100%);
  margin-inline: auto;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding-bottom: 24px;
}

.dock {
  padding: 0 16px calc(12px + env(safe-area-inset-bottom, 0px));
}

.dock-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app.is-empty .thread {
  display: none;
}

.app.is-empty .main {
  justify-content: center;
  padding-bottom: 8vh;
}

.app:not(.is-empty) .hero {
  display: none;
}

/* ---------- Greeting ---------- */

.hero {
  --greeting-size: clamp(2rem, 5.2vw, 3.6rem);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: calc(var(--greeting-size) * 2.3);
  padding-bottom: 14px;
  text-align: center;
}

.greeting {
  display: inline-flex;
  align-items: center;
  gap: .3em;
  margin: 0;
  font-size: var(--greeting-size);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -.025em;
  text-wrap: balance;
}

.greeting-mark {
  display: none;
}

:root[data-look="crab"] .greeting {
  font-family: var(--serif);
  font-weight: 300;
  letter-spacing: -.015em;
  font-variation-settings: "opsz" 60;
}

:root[data-look="crab"] .greeting-mark {
  display: inline-block;
  font-size: .8em;
}

/* ---------- Limit banner ---------- */

.limit-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--code-bg);
  font-size: 14px;
  line-height: 1.4;
}

.limit-banner[hidden] {
  display: none;
}

/* ---------- Composer ---------- */

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "attach prompt send";
  align-items: end;
  gap: 6px;
  padding: 8px 8px 8px 10px;
  border: 1px solid var(--composer-border);
  border-radius: 28px;
  background: var(--composer-bg);
  box-shadow: var(--composer-shadow);
  transition: background-color .35s, border-color .35s, border-radius .35s;
  position: relative;
}

.composer textarea {
  grid-area: prompt;
  min-width: 0;
  max-height: 9em;
  padding: 7px 4px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--fg);
  font: 16px/1.5 var(--sans);
}

.composer textarea::placeholder {
  color: var(--muted);
}

.composer textarea:disabled {
  cursor: not-allowed;
}

.composer .attach {
  grid-area: attach;
}

.model-inline {
  grid-area: model;
  display: none;
  margin-bottom: 2px;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}

.model-inline:hover {
  background: var(--hover);
  color: var(--fg);
}

.send {
  grid-area: send;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--send-bg);
  color: var(--send-fg);
  cursor: pointer;
  transition: opacity .2s, border-radius .35s, background-color .35s;
}

.send:disabled {
  opacity: .3;
  cursor: default;
}

:root[data-look="crab"] .composer {
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas:
    "prompt prompt prompt prompt"
    "attach . model send";
  row-gap: 8px;
  padding: 12px 12px 10px 14px;
  border-radius: 20px;
}

:root[data-look="crab"] .model-inline {
  display: block;
}

:root[data-look="crab"] .send {
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

:root[data-look="crab"] .composer .attach {
  width: 32px;
  height: 32px;
  border: 1px solid var(--composer-border);
  border-radius: 9px;
}

/* The attach button's excuse, in a bubble above it */

.toast {
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  max-width: min(360px, 100%);
  margin: 0;
  padding: 9px 14px;
  border-radius: 14px;
  background: var(--fg);
  color: var(--bg);
  font-size: 13.5px;
  line-height: 1.4;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .18);
  pointer-events: none;
  animation: pop .2s ease-out;
}

.toast[hidden] {
  display: none;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(4px); }
}

/* The same switch, spelled out at the bottom of a brand-new chat */

.page-footer {
  display: flex;
  justify-content: center;
  padding: 0 16px calc(8px + env(safe-area-inset-bottom, 0px));
}

.app:not(.is-empty) .page-footer {
  display: none;
}

.look-switch-inline {
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
}

.look-switch-inline:hover {
  background: var(--hover);
  color: var(--fg);
}

/* ---------- Suggestions and disclaimer ---------- */

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.suggestions button {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  font-size: 14px;
  cursor: pointer;
  transition: background-color .2s;
}

.suggestions button:hover {
  background: var(--hover);
}

.suggestions button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

:root[data-look="crab"] .suggestions button {
  border-radius: 10px;
  color: var(--muted);
}

:root[data-look="crab"] .suggestions button:hover {
  color: var(--fg);
}

.disclaimer {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ---------- Messages ---------- */

.user-message {
  align-self: flex-end;
  max-width: 80%;
  padding: 10px 16px;
  border-radius: 20px;
  background: var(--bubble);
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transition: background-color .35s;
}

:root[data-look="crab"] .user-message {
  border-radius: 14px;
}

.bot-message {
  max-width: 68ch;
  color: var(--reply);
  overflow-wrap: anywhere;
}

.bot-message .body {
  font-size: 16px;
  line-height: 1.7;
}

.bot-message[data-look="crab"] .body {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.65;
}

.bot-message .body > * {
  margin: 0 0 .75em;
}

.bot-message .body > :last-child {
  margin-bottom: 0;
}

.bot-message .body h3 {
  margin-top: 1em;
  font-size: 1.1em;
  font-weight: 600;
}

.bot-message .body ul {
  padding-left: 1.3em;
}

.bot-message .body li + li {
  margin-top: .25em;
}

.system-note {
  align-self: center;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--muted);
}

/* Code blocks, used for the email recap */

.code {
  margin: 0 0 .75em;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--code-bg);
  font-family: var(--sans);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px 6px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}

.code-head button {
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
}

.code-head button:hover {
  background: var(--hover);
  color: var(--fg);
}

.code pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  color: var(--fg);
  font: 13.5px/1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Extras around a reply: memory note, reasoning, sources, buttons, errors */

.memory-note {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
}

.reasoning-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.reasoning-toggle:hover {
  color: var(--fg);
}

.reasoning {
  margin: 0 0 12px;
  padding-left: 12px;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 14px;
  font-style: italic;
  line-height: 1.55;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  font-family: var(--sans);
}

.sources span {
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
}

.sources .sources-label {
  padding-left: 0;
  border: 0;
  font-weight: 500;
}

.pill-button,
.limit-banner button {
  flex: none;
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--send-bg);
  color: var(--send-fg);
  font: 500 14px var(--sans);
  cursor: pointer;
}

.pill-button {
  margin-top: 12px;
}

:root[data-look="crab"] .pill-button,
:root[data-look="crab"] .limit-banner button {
  border-radius: 9px;
}

.error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--error) 35%, transparent);
  border-radius: 12px;
  color: var(--error);
  font-family: var(--sans);
  font-size: 14px;
}

.error button {
  padding: 4px 12px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
}

.actions {
  display: flex;
  gap: 2px;
  margin: 8px 0 0 -8px;
  opacity: 0;
  transition: opacity .3s;
}

.bot-message.is-done .actions {
  opacity: 1;
}

.actions .icon-button {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.actions .icon-button[aria-pressed="true"] {
  color: var(--fg);
}

/* ---------- Thinking indicators ---------- */

.thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 27px;
  font-size: 15px;
  color: var(--muted);
}

.thinking .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--fg);
  animation: pulse 1s ease-in-out infinite;
}

.thinking .shimmer {
  background: linear-gradient(90deg, var(--muted) 30%, var(--fg) 50%, var(--muted) 70%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 1.6s linear infinite;
}

.thinking .crab {
  display: inline-block;
  font-size: 20px;
  animation: scuttle .5s ease-in-out infinite alternate;
}

.thinking .verb {
  font-family: var(--serif);
  font-style: italic;
}

@keyframes pulse {
  50% { transform: scale(.6); opacity: .5; }
}

@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

@keyframes scuttle {
  from { transform: translateX(-3px) rotate(-8deg); }
  to { transform: translateX(3px) rotate(8deg); }
}

/* ---------- Model menu ---------- */

.model-menu {
  position: fixed;
  z-index: 20;
  width: min(300px, calc(100vw - 16px));
  padding: 6px;
  border: 1px solid var(--composer-border);
  border-radius: 16px;
  background: var(--composer-bg);
  box-shadow: 0 14px 44px rgba(0, 0, 0, .16);
  color: var(--fg);
}

.model-menu[hidden] {
  display: none;
}

.model-menu button {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "name check"
    "blurb check";
  align-items: center;
  gap: 1px 12px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.model-menu button:hover,
.model-menu button:focus-visible {
  background: var(--hover);
  outline: none;
}

.model-menu .name {
  grid-area: name;
  font-size: 14px;
  font-weight: 500;
}

.model-menu .blurb {
  grid-area: blurb;
  font-size: 12.5px;
  color: var(--muted);
}

.model-menu .check {
  grid-area: check;
  font-size: 14px;
}

/* ---------- Phones ----------
 * Like the real apps: greeting in the middle, input pinned to the bottom,
 * suggestions in one row you swipe sideways. */

@media (max-width: 640px) {
  .topbar {
    min-height: 52px;
    padding: 8px 10px;
  }

  .model-picker {
    font-size: 17px;
  }

  .app.is-empty .main {
    justify-content: flex-end;
    padding-bottom: 0;
  }

  .app.is-empty .dock {
    flex: 1;
    display: flex;
  }

  .app.is-empty .dock-inner {
    flex: 1;
  }

  .hero {
    flex: 1;
    align-items: center;
    min-height: 0;
  }

  .suggestions {
    order: 1;
    flex-wrap: nowrap;
    justify-content: flex-start;
    margin-inline: -16px;
    padding: 2px 16px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .suggestions::-webkit-scrollbar {
    display: none;
  }

  .suggestions button {
    flex: none;
    white-space: nowrap;
  }

  .limit-banner {
    order: 2;
    font-size: 13px;
  }

  .composer {
    order: 3;
  }

  .disclaimer {
    order: 4;
    font-size: 11px;
  }

  .user-message {
    max-width: 85%;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .thinking .dot,
  .thinking .shimmer,
  .thinking .crab,
  .toast {
    animation: none;
  }

  body,
  .composer,
  .send,
  .user-message {
    transition: none;
  }
}
