/* tokens, locked from the avatar/banner (ballpoint pen on lined notebook paper) */
@font-face {
  font-family: 'Kalam';
  src: url('/assets/fonts/kalam-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Kalam';
  src: url('/assets/fonts/kalam-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/assets/fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/assets/fonts/jetbrains-mono-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f3ecd9;
  --paper-line: #bcd2ec;
  --paper-margin: #d98a8a;
  --ink: #1c2f5e;
  --ink-soft: #3a56a0;
  --stain: #8a5a2b;
  --paper-shadow: rgba(28, 47, 94, 0.18);
  --space-1: 0.5rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background:
    repeating-linear-gradient(
      var(--paper) 0px, var(--paper) 27px,
      var(--paper-line) 28px, var(--paper) 29px
    );
  color: var(--ink);
  font-family: 'Kalam', cursive, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.ruled-margin {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 56px;
  width: 2px;
  background: var(--paper-margin);
  opacity: 0.55;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-columns: 260px 1fr;
  padding: var(--space-4);
  gap: var(--space-4);
}

/* ---------- sidebar ---------- */
.sidebar {
  background: rgba(255, 252, 240, 0.55);
  border: 3px solid var(--ink);
  border-radius: 22px 8px 22px 8px / 8px 22px 8px 22px;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  transform: rotate(-0.35deg);
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 1.1rem;
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--ink);
}
.brand-mark { width: 26px; height: 26px; color: var(--ink); flex: none; }

.new-chat {
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: transparent;
  border: 2.5px dashed var(--ink);
  border-radius: 14px 4px 14px 4px;
  padding: var(--space-2) var(--space-3);
  cursor: not-allowed;
  text-align: left;
  opacity: 0.6;
}

.chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-item {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink-soft);
  background: none;
  border: none;
  text-align: left;
  padding: var(--space-1) var(--space-2);
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item:hover, .chat-item:focus-visible { background: rgba(28, 47, 94, 0.08); }
.chat-item:active { background: rgba(28, 47, 94, 0.15); }

.sidebar-footer {
  border-top: 2px solid var(--ink);
  padding-top: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.status-line {
  font-size: 0.85rem;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 6px;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #3a7d3a;
  box-shadow: 0 0 0 2px rgba(58,125,58,0.25);
  flex: none;
}

.ca-box {
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: rgba(255,255,255,0.6);
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
  color: var(--ink);
  text-align: left;
  width: 100%;
}
.ca-label { font-size: 0.75rem; opacity: 0.7; flex: none; }
.ca-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  word-break: break-all;
  line-height: 1.3;
}

.links-row { display: flex; gap: var(--space-2); }
.chrome-link { color: var(--ink); opacity: 0.75; }
.chrome-link:hover { opacity: 1; }

/* ---------- conversation ---------- */
.conversation {
  border: 3px solid var(--ink);
  border-radius: 8px 26px 8px 26px / 26px 8px 26px 8px;
  background: rgba(255, 252, 240, 0.4);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transform: rotate(0.2deg);
}

.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-5) var(--space-5) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.row { display: flex; }
.row.user { justify-content: flex-end; }
.row.bot { justify-content: flex-start; }

.bubble {
  max-width: 70%;
  padding: var(--space-2) var(--space-3);
  font-size: 1.15rem;
  line-height: 1.35;
}

.bubble.user {
  background: var(--ink);
  color: var(--paper);
  border-radius: 20px 20px 4px 20px;
  transform: rotate(0.6deg);
}

.bubble.bot {
  background: transparent;
  border: 2.5px solid var(--ink);
  color: var(--ink);
  border-radius: 4px 20px 20px 20px;
  transform: rotate(-0.5deg);
}

.bubble.thinking {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.bubble.thinking span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink);
  animation: think 1s infinite ease-in-out;
}
.bubble.thinking span:nth-child(2) { animation-delay: 0.15s; }
.bubble.thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes think {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--ink);
  margin-left: 2px;
  vertical-align: -0.15em;
  animation: blink 0.9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.composer {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  border-top: 2px solid var(--ink);
}
.composer input {
  flex: 1;
  font-family: 'Kalam', cursive;
  font-size: 1.05rem;
  color: var(--ink);
  background: rgba(255,255,255,0.6);
  border: 2px solid var(--ink);
  border-radius: 999px 8px 999px 8px;
  padding: var(--space-2) var(--space-4);
  outline: none;
}
.composer input::placeholder { color: var(--ink-soft); opacity: 0.6; }
.composer input:focus { box-shadow: 0 0 0 3px var(--paper-shadow); }
.composer button {
  width: 42px; height: 42px; flex: none;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.composer button:hover { background: var(--ink-soft); }

.reveal-toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: var(--paper);
  font-family: 'Kalam', cursive;
  font-size: 1rem;
  padding: 10px 18px;
  border-radius: 14px 4px 14px 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  max-width: 80vw;
  text-align: center;
}
.reveal-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.noscript-note {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Kalam', cursive;
  font-size: 1.3rem;
  padding: var(--space-5);
  text-align: center;
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    padding: var(--space-2);
    gap: var(--space-2);
  }
  .sidebar {
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: var(--space-2);
  }
  .brand span { display: none; }
  .chat-list { display: none; }
  .new-chat { display: none; }
  .sidebar-footer { flex-direction: row; align-items: center; border-top: none; flex: 1; }
  .status-line { display: none; }
  .ruled-margin { display: none; }
  .bubble { max-width: 86%; font-size: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  .dot, .caret, .bubble.thinking span { animation: none !important; }
  .bubble, .sidebar, .conversation { transform: none !important; }
  .reveal-toast { transition: none; }
}
