/* GunnGPT — letterhead/hall-pass motif: serif masthead, mono utility text,
   a perforated ticket-stub rule under the header (the one signature flourish). */

:root {
  --paper: #faf7f2;
  --ink: #1b1918;
  --muted: #7a7267;
  --line: #ded6c9;
  --surface: #ffffff;
  --red: #8c1515;
  --red-deep: #5e0e0e;
  --red-text: #8c1515;
  --red-tint: rgba(140, 21, 21, 0.09);

  --font-display: ui-serif, Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15120e;
    --ink: #efe9e0;
    --muted: #a89c8c;
    --line: #332c24;
    --surface: #201b15;
    --red: #8c1515;
    --red-deep: #a83a2a;
    --red-text: #e2836a;
    --red-tint: rgba(226, 131, 106, 0.12);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  background: var(--paper);
}

@media (min-width: 641px) {
  body { background: var(--line); }
  .app { box-shadow: 0 0 0 1px var(--line), 0 24px 60px -24px rgba(0, 0, 0, 0.35); }
}

/* ---- masthead ---- */
.masthead { background: var(--paper); flex: none; }
.masthead__rule { height: 3px; background: var(--red); }
.masthead__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.55rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0.6rem 1rem 0;
}
.masthead__tagline {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.01em;
  margin: 0.2rem 1rem 0.7rem;
}
.masthead__perf {
  height: 9px;
  background-color: var(--red);
  background-image: radial-gradient(circle, var(--paper) 3px, transparent 3.3px);
  background-size: 14px 9px;
  background-position: 7px center;
  background-repeat: repeat-x;
}

/* ---- thread ---- */
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  -webkit-overflow-scrolling: touch;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 32ch;
  line-height: 1.5;
}

.bubble {
  max-width: 84%;
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble--user {
  align-self: flex-end;
  background: var(--red);
  color: #fff8f2;
  border-bottom-right-radius: 4px;
}

.bubble--assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.bubble--error {
  border-color: var(--red-text);
  background: var(--red-tint);
}

.bubble__thinking {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--muted);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

.bubble__sources {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.chip {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--red-text);
  text-decoration: none;
  background: var(--paper);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip:hover, .chip:focus-visible {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.bubble__error p { margin: 0 0 0.5rem; font-size: 0.9rem; }
.retry {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--red-text);
  background: transparent;
  color: var(--red-text);
  cursor: pointer;
}
.retry:hover { background: var(--red); border-color: var(--red); color: #fff; }

/* ---- composer ---- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.6rem;
  border-top: 1px solid var(--line);
  background: var(--paper);
  flex: none;
}
.composer__input {
  flex: 1;
  resize: none;
  max-height: 7rem;
  min-height: 2.5rem;
  padding: 0.6rem 0.9rem;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.3;
}
.composer__input:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-tint);
}
.composer__send {
  font-family: var(--font-body);
  font-weight: 700;
  padding: 0 1.15rem;
  height: 2.5rem;
  border: none;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}
.composer__send:hover:not(:disabled) { background: var(--red-deep); }
.composer__send:disabled { opacity: 0.5; cursor: default; }

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

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