@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&family=DM+Mono:wght@400;500&display=swap');

@font-face {
  font-family: "Intuitize Serif";
  src: url("./intuitize-serif.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #fffefa;
  --surface-subtle: #f0efe9;
  --text: #252722;
  --muted: #777970;
  --line: #e2e0d8;
  --line-strong: #d3d1c7;
  --accent: #496b59;
  --accent-soft: #e9eee9;
  --danger: #a33b33;
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#top-controls {
  position: fixed;
  inset: 0 0 auto;
  z-index: 120;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: opacity 160ms ease, transform 160ms ease;
}

.brand {
  font-family: "Intuitize Serif", Georgia, serif;
  font-size: 24px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.035em;
}

#top-controls-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.icon-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 140;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 7px;
  background: #292927;
  box-shadow: 0 4px 12px rgba(20, 20, 18, .18);
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -3px);
  transition: opacity 110ms ease, transform 110ms ease, visibility 0s linear 110ms;
  visibility: hidden;
  white-space: nowrap;
}

.icon-btn:hover::after,
.icon-btn:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
  transition-delay: 450ms;
  visibility: visible;
}

.icon-btn:focus-visible::after { transition-delay: 100ms; }

.icon-btn img {
  width: 19px;
  height: 19px;
  display: block;
  opacity: .58;
  filter: grayscale(1);
  pointer-events: none;
}

.icon-btn svg {
  width: 19px;
  height: 19px;
  display: block;
  opacity: .58;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.nav-label { display: none; }

.icon-btn:hover { background: var(--surface-subtle); }
.icon-btn.active {
  background: var(--accent-soft);
  border-color: #c8ded2;
}

body.overlay-open #top-controls {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

@media (min-width: 901px) {
  body { padding-left: 260px; }

  #top-controls {
    inset: 0 auto 0 0;
    width: 260px;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 18px 14px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    background: var(--surface-subtle);
  }

  .brand {
    min-height: 48px;
    display: flex;
    align-items: center;
    padding: 0 12px 8px;
  }

  #top-controls-right {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
  }

  .icon-btn {
    width: 100%;
    height: 44px;
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 12px;
    border-radius: 11px;
  }

  .icon-btn::after { display: none; }
  .icon-btn img { flex: 0 0 auto; }
  .nav-label { display: inline; font-size: 14px; }

  body.overlay-open #top-controls {
    opacity: 1;
    transform: none;
    pointer-events: auto;
  }

}

#app {
  width: min(768px, calc(100% - 32px));
  min-height: 0;
  height: 100%;
  margin: 0 auto;
  padding: 84px 0 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 24px;
}

.eco-mission {
  width: min(768px, calc(100% - 32px));
  min-height: 78px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 22px;
  margin: 0 auto 18px;
  padding: 16px 0;
  border-top: 1px solid var(--line-strong);
  color: inherit;
  text-decoration: none;
  transition: border-color 160ms ease, color 160ms ease;
}

.eco-mission > span {
  color: var(--accent);
  font-family: "DM Mono", monospace;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.eco-mission p { max-width: 660px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.eco-mission i { color: var(--accent); font-size: 20px; font-style: normal; transition: transform 160ms ease; }
.eco-mission:hover { border-color: var(--accent); }
.eco-mission:hover p { color: var(--text); }
.eco-mission:hover i { transform: translateX(4px); }
body.overlay-open .eco-mission { visibility: hidden; }

.hero-copy { text-align: center; }

#main-model-picker {
  position: fixed;
  top: 72px;
  left: 20px;
  z-index: 110;
  transition: opacity 140ms ease, transform 140ms ease;
}

#main-model-picker label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#model-select {
  height: 40px;
  padding: 0 32px 0 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  background-color: transparent;
  color: var(--text);
  font-family: "Intuitize Serif", Georgia, serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: background 140ms ease, border-color 140ms ease;
}

#model-select:hover { background-color: var(--surface-subtle); }
#model-select:focus-visible { border-color: var(--line-strong); background-color: var(--surface); }

/* Firefox's native select renderer distorts some custom-font glyphs. */
@-moz-document url-prefix() {
  #model-select {
    appearance: none;
    -moz-appearance: none;
    line-height: 1;
    background-image:
      linear-gradient(45deg, transparent 50%, currentColor 50%),
      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position:
      calc(100% - 14px) 18px,
      calc(100% - 10px) 18px;
    background-size: 4px 4px, 4px 4px;
    background-repeat: no-repeat;
  }
}

body.overlay-open #main-model-picker {
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

.hero-copy h1 {
  margin: 14px 0 0;
  font-family: "Intuitize Serif", Georgia, serif;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 400;
}

#model-badge {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
}

#composer,
#overlay-composer {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
}

#input,
#overlay-input {
  width: 100%;
  height: 64px;
  min-height: 64px;
  max-height: 180px;
  padding: 18px 64px 17px 64px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  outline: none;
  overflow-y: hidden;
  resize: none;
  box-shadow: 0 2px 8px rgba(20, 28, 23, .06);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

#input::placeholder,
#overlay-input::placeholder { color: #888e87; }

#input:focus,
#overlay-input:focus {
  border-color: #8daa9b;
  box-shadow: 0 0 0 3px rgba(23, 107, 77, .09);
}

.send-btn {
  position: absolute;
  right: 10px;
  bottom: 11px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #d8ded8;
  border-radius: 50%;
  background: #e9ede8;
  color: #35483e;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

.send-btn:hover { background: #dde5de; }
.send-btn:active { transform: scale(.96); }
.send-btn:disabled { opacity: .45; cursor: default; transform: none; }
.send-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.attach-btn {
  position: absolute;
  left: 10px;
  bottom: 11px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #d8ded8;
  border-radius: 50%;
  background: #e9ede8;
  color: #35483e;
  cursor: pointer;
  transition: background 140ms ease, transform 140ms ease;
}

.attach-btn:hover { background: #dde5de; }
.attach-btn:active { transform: scale(.96); }
.attach-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

#overlay-composer .attach-btn { width: 36px; height: 36px; left: 9px; bottom: 9px; }
#overlay-composer .attach-btn svg { width: 19px; height: 19px; }
#overlay-input { padding-left: 54px; }
#overlay-input:focus { padding-left: 54px; }

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 8px;
}

.attachments[hidden] { display: none; }

#overlay-footer .attachments { margin: 8px 0 6px; }

.attach-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  max-width: 100%;
}

.attach-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 9px;
  flex: 0 0 auto;
}

.attach-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.attach-name {
  max-width: 180px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-status {
  font-size: 11.5px;
  color: var(--muted);
}

.attach-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.attach-detail,
.attach-remove {
  border: 1px solid #d8ded8;
  background: #e9ede8;
  color: #35483e;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  transition: background 140ms ease, transform 140ms ease;
}

.attach-detail { padding: 5px 10px; }
.attach-remove {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}
.attach-detail:hover,
.attach-remove:hover { background: #dde5de; }
.attach-detail:active,
.attach-remove:active { transform: scale(.96); }

#gen-status,
#pending {
  min-height: 20px;
  color: var(--muted) !important;
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 12px !important;
  opacity: 0;
  transition: opacity 160ms ease;
}

#gen-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

#gen-status.visible { opacity: 1; }
#gen-status .gen-text { opacity: 0; transition: opacity 180ms ease; }
#gen-status .gen-text.visible { opacity: 1; }

.generation-face {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 50%;
  background: #3478f6;
  box-shadow: 0 2px 6px rgba(52, 120, 246, .22);
}

.generation-eye {
  width: 4px;
  height: 6px;
  border-radius: 999px;
  background: #fff;
  transform-origin: center;
  animation: generation-blink 4.8s ease-in-out infinite;
}

.generation-eye:last-child { animation-delay: 35ms; }

@keyframes generation-blink {
  0%, 88%, 92%, 96%, 100% { transform: scaleY(1); }
  90%, 94% { transform: scaleY(.08); }
}

@media (prefers-reduced-motion: reduce) {
  .generation-eye { animation: none; }
}

/* Conversation */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  justify-content: center;
  background: var(--bg);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 180ms ease, visibility 0s linear 180ms;
}

#overlay.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

#overlay-panel {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

#overlay-header {
  flex: 0 0 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid transparent;
  background: var(--bg);
}

#close-overlay,
#close-history,
#close-sources,
#close-personalize {
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}

#close-overlay:hover,
#close-history:hover,
#close-sources:hover,
#close-personalize:hover { background: var(--surface-subtle); color: var(--text); }

#overlay-content {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  margin: 0 auto;
  padding: 32px max(20px, calc((100vw - 768px) / 2)) 16px;
  overflow: hidden;
  outline: none;
}

.messages {
  width: 100%;
  max-width: 768px;
  margin: 0 auto;
  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 36px;
  padding: 0 0 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.bubble.user {
  align-self: flex-end;
  max-width: min(72%, 620px);
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 16px 16px 5px 16px;
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user .meta { display: none; }

.assistant-plain {
  align-self: flex-start;
  width: 100%;
  color: var(--text);
  font-size: 16px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.assistant-plain .meta { display: none; }
.assistant-plain.is-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 13px;
}

.assistant-plain:not(.is-loading) > .generation-face { display: none; }
.assistant-content > :first-child { margin-top: 0; }
.assistant-content > :last-child { margin-bottom: 0; }
.assistant-content.plain-fallback { white-space: pre-wrap; }
.assistant-content p { margin: 0 0 1em; }
.assistant-content h1,
.assistant-content h2,
.assistant-content h3 { margin: 1.5em 0 .65em; line-height: 1.25; letter-spacing: -.02em; }
.assistant-content h1 { font-size: 24px; }
.assistant-content h2 { font-size: 20px; }
.assistant-content h3 { font-size: 17px; }
.assistant-content ul,
.assistant-content ol { margin: .75em 0 1em; padding-left: 1.4em; }
.assistant-content li { margin: .35em 0; }
.assistant-content a { color: var(--accent); text-underline-offset: 3px; }
.assistant-content blockquote { margin: 1em 0; padding-left: 16px; border-left: 2px solid var(--line-strong); color: var(--muted); }

.assistant-actions {
  display: flex;
  align-items: center;
  margin-top: 14px;
}

.sources-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 130ms ease, border-color 130ms ease, color 130ms ease;
}

.sources-button:hover,
.sources-button:focus-visible {
  border-color: #c8d0c9;
  background: var(--surface-subtle);
  color: var(--text);
}

#overlay-footer {
  flex: 0 0 auto;
  padding: 12px max(20px, calc((100vw - 768px) / 2)) max(14px, env(safe-area-inset-bottom));
  border-top: 0;
  background: linear-gradient(to bottom, rgba(247, 246, 242, 0), var(--bg) 18px);
}

#overlay-composer { max-width: 768px; margin: 0 auto; }
#overlay-attachments { max-width: 768px; margin: 0 auto; }
#overlay-input { height: 56px; min-height: 56px; padding-block: 15px 14px; border-radius: 18px; }
#overlay-composer .send-btn { width: 36px; height: 36px; right: 9px; bottom: 9px; }

#overlay-disclaimer {
  margin-top: 9px !important;
  padding: 0 !important;
  color: var(--muted) !important;
  font-size: 11px !important;
}

/* Code and generated content */
pre,
pre.code-block {
  position: relative;
  max-width: 100%;
  overflow: auto;
  margin: 1em 0;
  padding: 18px;
  border: 1px solid #2d3430;
  border-radius: 12px;
  background: #1e2421;
  color: #edf1ee;
  font-family: "DM Mono", ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.6;
}

code,
code.inline-code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #e9ece7;
  font-family: "DM Mono", ui-monospace, monospace;
  font-size: .88em;
}

pre code { padding: 0; background: transparent; }

.code-block .copy-btn {
  position: absolute;
  top: 9px;
  right: 9px;
  padding: 6px 8px;
  border: 1px solid #46504b;
  border-radius: 7px;
  background: #29302c;
  color: #d9dfdb;
  font-size: 11px;
  cursor: pointer;
}

.copy-flash {
  position: absolute;
  top: 10px;
  right: 70px;
  padding: 5px 7px;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  opacity: 0;
  transition: opacity 140ms ease;
}
.copy-flash.visible { opacity: 1; }

/* Intuitize Canvas */
.intuitize-canvas {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--surface);
}

.canvas-header {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 11px 9px 17px;
  border-bottom: 1px solid var(--line);
}

.canvas-title {
  font-family: "Intuitize Serif", Georgia, serif;
  font-size: 17px;
  letter-spacing: -.015em;
}

.canvas-actions { display: flex; align-items: center; gap: 3px; }

.canvas-action,
.canvas-change-submit {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.canvas-action:hover { background: var(--surface-subtle); color: var(--text); }

.canvas-change-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
}

.canvas-change-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.canvas-body { padding: 18px; }
.canvas-body > :first-child { margin-top: 0; }
.canvas-body > :last-child { margin-bottom: 0; }

.intuitize-canvas pre,
.intuitize-canvas pre.code-block {
  margin: 0;
  border-color: var(--line);
  background: #f2f1ec;
  color: #30322d;
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.65;
}

.intuitize-canvas.canvas-code pre,
.intuitize-canvas.canvas-code pre.code-block { font-family: "DM Mono", ui-monospace, monospace; font-size: 13px; line-height: 1.6; }

.canvas-editor {
  width: calc(100% - 28px);
  min-height: 320px;
  display: block;
  margin: 14px;
  padding: 16px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: #f8f7f3;
  color: var(--text);
  font-family: "DM Mono", ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.6;
  outline: none;
}

.canvas-editor:focus { border-color: #9eaea4; box-shadow: 0 0 0 3px rgba(73, 107, 89, .08); }

.canvas-change-form {
  display: flex;
  gap: 8px;
  padding: 11px;
  border-top: 1px solid var(--line);
  background: #faf9f5;
}

.canvas-change-form[hidden] { display: none; }

.canvas-change-input {
  min-width: 0;
  flex: 1;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.canvas-change-input:focus { border-color: #9eaea4; }
.canvas-change-submit { min-height: 40px; border-color: var(--line-strong); background: var(--surface-subtle); color: var(--text); }
.canvas-change-submit:disabled { opacity: .55; cursor: wait; }

.intuitize-canvas > .copy-flash { top: 12px; right: 250px; }

/* Sources */
#sources-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(18, 22, 19, .32);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 160ms ease, visibility 0s linear 160ms;
}

#sources-modal.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

#sources-panel {
  width: min(620px, 100%);
  max-height: min(720px, calc(100dvh - 48px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(17, 25, 20, .18);
  transform: translateY(10px) scale(.985);
  transition: transform 180ms ease;
}

#sources-modal.visible #sources-panel { transform: translateY(0) scale(1); }

#sources-header {
  flex: 0 0 auto;
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.sources-heading h2 {
  margin: 0;
  font-family: "Intuitize Serif", Georgia, serif;
  font-size: 25px;
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -.025em;
}

.sources-heading p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

#sources-content {
  min-height: 120px;
  padding: 4px 22px 12px;
  overflow: auto;
  outline: none;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.source-item {
  padding: 18px 2px 19px;
  border-bottom: 1px solid var(--line);
}

.source-item:last-child { border-bottom: 0; }
.source-name { color: #858b85; font-size: 11px; line-height: 1.3; }
.source-item h3 { margin: 5px 0 7px; color: var(--text); font-size: 15px; font-weight: 500; line-height: 1.4; }
.source-item p { margin: 0 0 10px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.source-link {
  display: block;
  overflow: hidden;
  color: var(--accent);
  font-size: 11px;
  line-height: 1.4;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* Personalization */
#personalize-modal {
  position: fixed;
  inset: 0;
  z-index: 410;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(18, 22, 19, .32);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 160ms ease, visibility 0s linear 160ms;
}

#personalize-modal.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

#personalize-panel {
  width: min(440px, 100%);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(17, 25, 20, .18);
  transform: translateY(10px) scale(.985);
  transition: transform 180ms ease;
}

#personalize-modal.visible #personalize-panel { transform: translateY(0) scale(1); }

#personalize-header {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.personalize-heading h2 {
  margin: 0;
  font-family: "Intuitize Serif", Georgia, serif;
  font-size: 25px;
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -.025em;
}

.personalize-heading p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

#personalize-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 22px 0;
}

.personalize-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
}

.personalize-field input,
.personalize-field select {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 400;
  outline: none;
}

.personalize-field input:focus,
.personalize-field select:focus {
  border-color: #8daa9b;
  box-shadow: 0 0 0 3px rgba(23, 107, 77, .09);
}

#personalize-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 4px -22px 0;
  padding: 15px 22px;
  border-top: 1px solid var(--line);
}

#personalize-footer span { color: var(--muted); font-size: 11px; font-weight: 400; }
#personalize-footer button {
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
#personalize-footer button:hover { filter: brightness(.96); }

/* History */
#history-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
  background: rgba(18, 22, 19, .32);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 160ms ease, visibility 0s linear 160ms;
}

#history-modal.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

#history-panel {
  width: min(460px, calc(100% - 48px));
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 0;
  border-right: 1px solid var(--line-strong);
  border-radius: 0 22px 22px 0;
  background: var(--surface);
  box-shadow: 16px 0 48px rgba(17, 25, 20, .12);
  transform: translateX(-22px);
  transition: transform 190ms ease;
}

#history-modal.visible #history-panel { transform: translateX(0); }

#history-header,
#history-footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

#history-header { min-height: 86px; }
.history-heading h2 {
  margin: 0;
  font-family: "Intuitize Serif", Georgia, serif;
  font-size: 27px;
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -.025em;
}
.history-heading p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

#history-footer {
  justify-content: space-between;
  gap: 16px;
  border: 0;
  border-top: 1px solid var(--line);
  padding-block: 14px;
}

#history-storage-note { color: var(--muted); font-size: 11px; }

#history-content {
  flex: 1 1 auto;
  min-height: 160px;
  padding: 20px 14px 28px;
  overflow: auto;
  color: var(--muted);
  outline: none;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.history-group + .history-group { margin-top: 24px; }
.history-group-title {
  margin: 0 10px 8px;
  color: #888e87;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
}

.history-list { display: flex; flex-direction: column; gap: 3px; }

.history-row {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 16px;
  padding: 13px 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 130ms ease, border-color 130ms ease;
}

.history-row:hover,
.history-row:focus-visible { background: var(--surface-subtle); border-color: var(--line); }
.history-row-main { min-width: 0; }
.history-row-title {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-row-preview {
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; }
.history-row-time { color: #8b908a; font-size: 11px; white-space: nowrap; }
.history-row-count { color: #969b95; font-size: 10px; white-space: nowrap; }

.history-empty {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 44px 28px;
  text-align: center;
}
.history-empty-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  margin-bottom: 17px;
  border-bottom: 1px solid var(--line-strong);
  color: var(--accent);
  font-family: "Intuitize Serif", Georgia, serif;
  font-size: 22px;
}
.history-empty-icon {
  width: 42px;
  height: 42px;
  margin-bottom: 17px;
  opacity: .72;
}
.history-empty h3 { margin: 0; color: var(--text); font-size: 15px; font-weight: 500; }
.history-empty p { max-width: 260px; margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

#history-clear {
  padding: 8px 11px;
  border: 1px solid #e0c8c5;
  border-radius: 9px;
  background: transparent;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
}
#history-clear:hover { background: #fbf1f0; }
#history-clear.armed { border-color: var(--danger); background: var(--danger); color: white; }
#history-clear:disabled { opacity: .45; cursor: default; }

/* Incognito and settings */
#incognito-banner {
  position: fixed;
  top: 82px;
  left: 50%;
  z-index: 310;
  transform: translateX(-50%);
  pointer-events: none;
}

#incognito-banner-inner {
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--text);
  color: white;
  font-size: 12px;
  opacity: 0;
  transform: translateY(-5px);
  transition: opacity 160ms ease, transform 160ms ease;
}

#incognito-banner.show #incognito-banner-inner { opacity: 1; transform: none; }

body.incognito-on:not(.overlay-open) #input {
  background: #222825;
  color: #f3f5f2;
  border-color: #222825;
}
body.incognito-on:not(.overlay-open) #input::placeholder { color: #a8aea9; }

#settings-dropdown {
  position: fixed !important;
  min-width: 164px !important;
  padding: 6px !important;
  border: 1px solid var(--line-strong) !important;
  border-radius: 12px !important;
  background: var(--surface) !important;
  color: var(--text) !important;
  box-shadow: 0 12px 32px rgba(17, 25, 20, .12) !important;
}

#settings-dropdown button {
  padding: 9px 10px !important;
  border: 0 !important;
  border-radius: 8px !important;
  background: transparent !important;
  color: var(--text);
  font-size: 13px;
}
#settings-dropdown button:hover { background: var(--surface-subtle) !important; }

.suggestions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 80;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: 0 12px 32px rgba(17, 25, 20, .1);
}
.suggestion-item { padding: 10px 11px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; }
.suggestion-item:hover { background: var(--surface-subtle); }
.suggestion-item small { display: block; margin-top: 3px; color: var(--muted); }

@media (max-width: 640px) {
  #top-controls { height: 56px; padding: 0 12px; }
  .brand { font-size: 21px; }
  .icon-btn { width: 38px; height: 38px; }
  #main-model-picker { top: 62px; left: 8px; }

  #app {
    width: min(100% - 24px, 768px);
    min-height: 0;
    padding: 70px 0 24px;
    gap: 22px;
  }
  .eco-mission { width: calc(100% - 24px); grid-template-columns: 1fr auto; gap: 8px 16px; margin-bottom: 10px; padding-inline: 0; }
  .eco-mission p { grid-column: 1 / -1; grid-row: 2; }
  .eco-mission i { grid-column: 2; grid-row: 1; }
  .hero-copy h1 { margin-top: 15px; font-size: 34px; }
  #input { height: 58px; min-height: 58px; padding-block: 16px 15px; }

  #overlay-header { flex-basis: 56px; padding: 0 12px; }
  #overlay-content { padding: 22px 14px 8px; }
  .messages { gap: 28px; padding-bottom: 20px; }
  .bubble.user { max-width: 88%; }
  .assistant-plain { font-size: 15px; line-height: 1.65; }
  #overlay-footer { padding: 10px 12px max(10px, env(safe-area-inset-bottom)); }
  #overlay-disclaimer { display: none !important; }

  .canvas-header { align-items: flex-start; flex-direction: column; gap: 7px; padding: 13px; }
  .canvas-actions { width: 100%; }
  .canvas-action { flex: 1; }
  .canvas-change-button { justify-content: center; }
  .canvas-body { padding: 12px; }
  .canvas-change-form { flex-direction: column; }
  .canvas-change-submit { width: 100%; }
  .canvas-editor { width: calc(100% - 20px); min-height: 260px; margin: 10px; }

  #history-panel { width: 100%; border: 0; border-radius: 0; box-shadow: none; }
  #history-header { min-height: 78px; padding: 18px; }
  #history-footer { padding-inline: 18px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  #history-content { padding-inline: 8px; }
}

.mobile-mode #app { min-height: 0; }
.mobile-mode #overlay-panel { min-height: 100dvh; }

@media (min-width: 901px) {
  #overlay { left: 260px; }
  #incognito-banner { left: calc(50% + 130px); }
  #main-model-picker { top: 14px; left: 278px; }

  .eco-mission {
    position: fixed;
    left: 14px;
    bottom: 14px;
    z-index: 121;
    width: 232px;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    margin: 0;
    padding: 14px 12px 10px;
  }

  .eco-mission p {
    grid-column: 1 / -1;
    font-size: 11px;
    line-height: 1.45;
  }

  .eco-mission i { grid-column: 2; grid-row: 1; }
  body.overlay-open .eco-mission { visibility: visible; }
}

/* Mobile: floating chat button */
#chat-fab { display: none; }

@media (max-width: 900px) {
  /* Attachments are desktop-only; on phones hide the plus button, the file
     inputs, and any chips, and give the inputs back their original padding. */
  .attach-btn,
  #file-input,
  #overlay-file-input,
  #attachments,
  #overlay-attachments {
    display: none !important;
  }

  #input,
  #overlay-input,
  #overlay-input:focus { padding-left: 20px; }

  /* Floating chat button in the corner */
  #chat-fab {
    position: fixed;
    right: 16px;
    bottom: calc(env(safe-area-inset-bottom) + 16px);
    z-index: 150;
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 10px 26px rgba(17, 25, 20, .24);
    transition: transform 160ms ease, opacity 160ms ease, background 140ms ease;
  }

  #chat-fab:hover { background: #3d5d4c; }
  #chat-fab:active { transform: scale(.94); }

  #chat-fab svg {
    width: 24px;
    height: 24px;
    opacity: 1;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  body.overlay-open #chat-fab {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
  }

  /* Keep the mission link clear of the floating button */
  .eco-mission { margin-bottom: 84px; }
}

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