@font-face {
  font-family: "Jimothy";
  src: url("../assets/Jimothy.woff2") format("woff2"),
       url("../assets/Jimothy.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --panel: #f7f7f8;
  --line: #ececf1;
  --text: #1f2023;
  --muted: #8a8a94;
  --user-bubble: #f0f2f5;
  --jimothy-bubble: #ffffff;
  --accent: #10a37f;
  --accent-ink: #ffffff;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --maxw: 760px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 16px;
}
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Mascot (pixel Jimothy) ---------- */
.mascot {
  position: relative;
  height: 64px;
  width: 74px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sprite-img {
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: center bottom;
  image-rendering: pixelated;
  transform-origin: 50% 100%;
  -webkit-user-drag: none;
  user-select: none;
}
/* The frames carry the animation; a whisper of transform adds life on top. */
.mascot[data-state="idle"] .sprite-img { animation: idle-bob 3.6s ease-in-out infinite; }
.mascot[data-state="thinking"] .sprite-img { animation: think-hop 1.1s ease-in-out infinite; }

@keyframes idle-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1.5px); }
}
@keyframes think-hop {
  0%, 100% { transform: translateY(0); }
  45% { transform: translateY(-5px); }
  70% { transform: translateY(0) scaleY(1.03); }
  85% { transform: translateY(0) scaleY(1); }
}

/* Thought bubble dots shown while thinking. */
.thought {
  position: absolute;
  top: -6px;
  left: -26px;
  display: none;
  gap: 3px;
  padding: 5px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.thought::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: -5px;
  width: 6px;
  height: 6px;
  background: #fff;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}
.mascot[data-state="thinking"] .thought { display: inline-flex; }
.thought span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: dot 1.1s infinite ease-in-out;
}
.thought span:nth-child(2) { animation-delay: 0.18s; }
.thought span:nth-child(3) { animation-delay: 0.36s; }
@keyframes dot {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Chat area ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 18px 8px;
}
.messages {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.row.user { justify-content: flex-end; }
/* Center Jimothy's avatar against his bubble (looks right for 1-line replies). */
.row.jimothy { align-items: center; }

.avatar {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background-image: url("../assets/sprites/avatar.png");
  background-size: cover;             /* face closeup fills the tile */
  background-position: center;
  background-repeat: no-repeat;
  background-color: var(--panel);
  image-rendering: pixelated;
  border: 0.5px solid var(--line);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
}

.bubble {
  max-width: 78%;
  padding: 11px 15px;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 15.5px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.row.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 5px;
}
.row.jimothy .bubble {
  background: var(--jimothy-bubble);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

/* The Jimothy font: chicken-scratch. Scaled up + spaced so it pairs with the
   sans-serif user text, which the little font would otherwise look tiny beside. */
.row.jimothy .bubble {
  font-family: "Jimothy", var(--sans);
  font-size: 40px;          /* 2x — the scratch glyphs render short, so this
                               brings their apparent height near the user's text */
  line-height: 0.95;
  letter-spacing: 0.5px;
  word-spacing: 2px;
  color: #2a2a2f;
  padding-top: 14px;
  padding-bottom: 12px;
}

/* ?translate=1 — turn the Jimothy font off, reveal plain text. */
body.translate .row.jimothy .bubble {
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.55;
  letter-spacing: normal;
  word-spacing: normal;
  color: var(--text);
}

/* Blinking caret while Jimothy types. */
.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 1px;
  background: var(--muted);
  vertical-align: text-bottom;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Composer ---------- */
.composer {
  padding: 8px 18px 14px;
  background: linear-gradient(to top, var(--bg) 70%, rgba(255,255,255,0));
}
.composer-form {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 8px 8px 8px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.composer-form:focus-within { border-color: #d3d3dc; }

#input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.5;
  max-height: 180px;
  color: var(--text);
  padding: 4px 0;
}

#send {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.05s;
}
#send:disabled { opacity: 0.35; cursor: default; }
#send:not(:disabled):active { transform: scale(0.92); }

.disclaimer {
  max-width: var(--maxw);
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------- Empty / welcome state ---------- */
.welcome {
  max-width: var(--maxw);
  margin: 8vh auto 0;
  text-align: center;
  color: var(--muted);
}
.welcome .big-sprite {
  width: 132px; height: 116px; margin: 0 auto 14px;
  background-image: url("../assets/sprites/stand-a.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center bottom;
  image-rendering: pixelated;
}
.welcome h1 {
  font-size: 24px;
  color: var(--text);
  margin: 0 0 6px;
  font-weight: 600;
}
.welcome p { margin: 0 auto; max-width: 440px; font-size: 14px; line-height: 1.5; }
.suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; margin-top: 22px;
}
.suggestions button {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 13px;
  cursor: pointer;
  transition: background 0.12s;
}
.suggestions button:hover { background: #eef0f3; }

@media (max-width: 520px) {
  .bubble { max-width: 85%; }
  .mascot { height: 52px; width: 60px; }
}
