/* ============================================
   行程手帐 — Artisanal Journal Interface
   ============================================ */

/* ---------- Design Tokens ---------- */
:root {
  --paper: #FBF8F3;
  --paper-warm: #F6F1E7;
  --paper-dim: #EFEAD8;
  --paper-note: #FFF3CB;
  --paper-note-shadow: #E6D69A;
  --ink: #2E2822;
  --ink-mid: #5C524A;
  --ink-light: #908478;
  --ink-fade: #B8B0A4;
  --line: #D8D2C6;
  --line-light: #E8E2D8;
  --line-faint: #F0EBE2;
  --accent: #7A8C6E;
  --accent-deep: #5A6E50;
  --accent-warm: #C07840;
  --accent-warm-light: #D89058;
  --highlight: #FFF9E6;
  --tape-yellow: rgba(255, 230, 150, 0.55);
  --tape-pink: rgba(240, 180, 170, 0.4);
  --tape-green: rgba(170, 210, 170, 0.35);
  --shadow-sm: 0 1px 3px rgba(46, 40, 34, 0.06);
  --shadow-md: 0 2px 8px rgba(46, 40, 34, 0.08), 0 1px 2px rgba(46, 40, 34, 0.04);
  --shadow-lg: 0 4px 16px rgba(46, 40, 34, 0.1), 0 2px 4px rgba(46, 40, 34, 0.06);
  --shadow-note: 2px 3px 12px rgba(46, 40, 34, 0.1);
  --radius-xs: 3px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-serif: 'Noto Serif SC', 'Georgia', serif;
  --font-sans: 'Noto Sans SC', 'PingFang SC', sans-serif;
  --font-hand: 'Caveat', 'Noto Sans SC', cursive;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="dark"] {
  --paper: #DAD4C8;
  --paper-warm: #CEC7B8;
  --paper-dim: #C2BBAC;
  --paper-note: #E4DABA;
  --paper-note-shadow: #CABC92;
  --ink: #2E2822;
  --ink-mid: #4C443A;
  --ink-light: #6C625A;
  --ink-fade: #8C847A;
  --line: #B0A89A;
  --line-light: #C0B8AA;
  --line-faint: #CAC2B4;
  --accent: #6A7E5E;
  --accent-deep: #526848;
  --accent-warm: #A06830;
  --accent-warm-light: #B88048;
  --highlight: #DAD0A8;
  --tape-yellow: rgba(220, 200, 120, 0.4);
  --tape-pink: rgba(200, 150, 140, 0.3);
  --tape-green: rgba(140, 180, 140, 0.25);
  --shadow-sm: 0 1px 3px rgba(46, 40, 34, 0.08);
  --shadow-md: 0 2px 8px rgba(46, 40, 34, 0.1), 0 1px 2px rgba(46, 40, 34, 0.06);
  --shadow-lg: 0 4px 16px rgba(46, 40, 34, 0.12), 0 2px 4px rgba(46, 40, 34, 0.08);
  --shadow-note: 2px 3px 12px rgba(46, 40, 34, 0.12);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- Paper Texture Layer ---------- */
.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.4'/%3E%3C/svg%3E");
  background-size: 200px 200px;
  mix-blend-mode: multiply;
}

/* ---------- Page Body ---------- */
body {
  font-family: var(--font-sans);
  color: var(--ink);
  font-weight: 400;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 10% 20%, rgba(122, 140, 110, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 90% 80%, rgba(192, 120, 64, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(255, 243, 203, 0.06) 0%, transparent 70%),
    /* Full-width notebook ruled lines */
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent 31px,
      rgba(213, 207, 196, 0.18) 31px,
      rgba(213, 207, 196, 0.18) 32px
    );
}

/* ---------- Right Binding Line ---------- */
.notebook-line {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 40px;
  width: 1px;
  background: repeating-linear-gradient(
    to bottom,
    var(--line) 0px,
    var(--line) 5px,
    transparent 5px,
    transparent 11px
  );
  pointer-events: none;
  z-index: 1;
  opacity: 0.4;
}

/* Right corner fold */
body::after {
  content: '';
  position: fixed;
  top: 20px;
  right: 20px;
  width: 22px;
  height: 22px;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  pointer-events: none;
  z-index: 1;
  opacity: 0.4;
}

/* ---------- App Container ---------- */
#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 860px;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 20px 24px 20px 56px;
  position: relative;
  z-index: 10;
}

/* Left margin binding dots — fixed to viewport */
body::before {
  content: '';
  position: fixed;
  top: 0;
  bottom: 0;
  left: 44px;
  width: 2px;
  background: repeating-linear-gradient(
    to bottom,
    var(--accent-warm) 0px,
    var(--accent-warm) 3px,
    transparent 3px,
    transparent 16px
  );
  pointer-events: none;
  z-index: 1;
  opacity: 0.2;
}

/* Page number */
#app::after {
  content: '\2014  1  \2014';
  position: absolute;
  bottom: 10px;
  right: 24px;
  font-family: var(--font-serif);
  font-size: 10px;
  color: var(--ink-fade);
  letter-spacing: 4px;
  opacity: 0.5;
}

/* ---------- Navbar (Page Header) ---------- */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  margin-bottom: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

.logo-icon:hover {
  opacity: 1;
}

.logo-icon svg {
  width: 20px;
  height: 20px;
}

.nav-title {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 1.5px;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Theme Toggle ---------- */
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line-light);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-light);
  transition: all 0.25s ease;
  padding: 0;
}

@media (hover: hover) {
  .theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--paper-dim);
    transform: rotate(15deg);
  }
}

.theme-toggle svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
}

.theme-toggle .icon-sun { display: block; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---------- New Chat Button ---------- */
.btn-new-chat {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line-light);
  background: transparent;
  color: var(--ink-light);
  font-size: 0.82rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  align-items: center;
  gap: 5px;
  line-height: 1.4;
}

@media (hover: hover) {
  .btn-new-chat:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--paper-dim);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
  }
}

.btn-new-chat.elastic-press:active {
  transform: scale(0.92);
}

.btn-new-chat svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* ---------- Chat Container ---------- */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  height: 0;
}

/* ---------- Messages Area ---------- */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 4px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 3px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0);
  border-radius: 4px;
  padding: 4px 0;
  background-clip: padding-box;
  transition: background 0.45s cubic-bezier(0.32, 0.72, 0, 1);
}

.messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.35);
}

.messages.scrolling::-webkit-scrollbar-thumb {
  background: var(--line);
  padding: 4px 0;
  background-clip: padding-box;
  transition: background 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Message Row ---------- */
.message {
  display: flex;
  flex-direction: column;
  animation: messageEnter 0.45s var(--ease-out-expo) both;
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
  max-width: 60%;
}

.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 82%;
}

/* ---------- Bubble Base ---------- */
.bubble {
  padding: 14px 18px;
  line-height: 1.75;
  font-size: 15px;
  word-break: break-word;
  overflow-wrap: break-word;
  text-wrap: pretty;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  user-select: text;
  -webkit-user-select: text;
}

/* ---------- Elastic Press (Mobile) ---------- */
.elastic-press {
  transition: transform 0.12s var(--ease-spring), box-shadow 0.15s ease;
  will-change: transform;
}

.elastic-press:active {
  transform: scale(0.96);
}

/* Bubbles: slightly softer spring */
.bubble.elastic-press:active {
  transform: scale(0.97);
}

.user-bubble.elastic-press:active {
  transform: scale(0.97) rotate(-1deg);
  box-shadow: 1px 2px 6px rgba(44, 38, 32, 0.08);
}

.assistant-bubble.elastic-press:active {
  transform: scale(0.97);
  box-shadow: var(--shadow-sm);
}

/* ---------- User Sticky Note ---------- */
.user-bubble {
  background: var(--paper-note);
  color: var(--ink);
  border: 1px solid var(--paper-note-shadow);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-note);
  transform: rotate(-1deg);
}

@media (hover: hover) {
  .user-bubble:hover {
    transform: rotate(-0.5deg) translateY(-1px);
    box-shadow: 3px 4px 14px rgba(44, 38, 32, 0.12);
  }
}

/* Washi tape decoration */
.tape {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.tape-left {
  top: -6px;
  left: 10px;
  width: 38px;
  height: 14px;
  background: var(--tape-yellow);
  transform: rotate(-3deg);
  border-radius: 1px;
  opacity: 0.9;
}

/* Alternate tape colors based on nth-child */
.message.user:nth-child(3n+1) .tape-left {
  background: var(--tape-yellow);
  transform: rotate(-3deg);
  left: 10px;
}

.message.user:nth-child(3n+2) .tape-left {
  background: var(--tape-pink);
  transform: rotate(2deg);
  left: 14px;
}

.message.user:nth-child(3n+3) .tape-left {
  background: var(--tape-green);
  transform: rotate(-1deg);
  left: 8px;
  width: 34px;
}

/* ---------- Assistant Journal Entry ---------- */
.assistant-bubble {
  background: var(--paper-warm);
  color: var(--ink);
  border: 1px solid var(--line-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transform-origin: left center;
}

@media (hover: hover) {
  .assistant-bubble:hover {
    transform: translateX(3px) rotate(0.3deg);
    box-shadow: var(--shadow-md);
  }
}

/* Pen flourish on assistant bubble */
.assistant-bubble::after {
  content: '';
  position: absolute;
  bottom: 8px;
  right: 12px;
  width: 20px;
  height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
  opacity: 0.4;
}

/* ---------- Markdown Rendering ---------- */
.text-block {
  margin: 0;
}

.text-block p {
  margin: 0 0 12px 0;
}

.text-block p:last-child {
  margin-bottom: 0;
}

.text-block h1,
.text-block h2,
.text-block h3 {
  margin: 18px 0 10px 0;
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--ink);
  position: relative;
}

.text-block h1 {
  font-size: 1.2rem;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-light);
}

.text-block h2 {
  font-size: 1.08rem;
  padding-left: 12px;
  border-left: 2px solid var(--accent);
}

.text-block h3 {
  font-size: 0.98rem;
  letter-spacing: 0.02em;
}

.text-block h1:first-child,
.text-block h2:first-child,
.text-block h3:first-child {
  margin-top: 0;
}

.text-block ul,
.text-block ol {
  margin: 8px 0 12px 22px;
}

.text-block li {
  margin: 4px 0;
  padding-left: 4px;
}

.text-block li::marker {
  color: var(--accent);
}

.text-block table {
  border-collapse: separate;
  border-spacing: 0;
  margin: 12px 0;
  width: 100%;
  font-size: 13px;
  border: 1px solid var(--line-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.text-block th,
.text-block td {
  border-bottom: 1px solid var(--line-light);
  border-right: 1px solid var(--line-light);
  padding: 8px 12px;
  text-align: left;
}

.text-block th:last-child,
.text-block td:last-child {
  border-right: none;
}

.text-block tr:last-child td {
  border-bottom: none;
}

.text-block th {
  background: var(--paper-note);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-mid);
}

.text-block code {
  background: var(--paper-note);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
  color: var(--accent-warm);
  font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
  border: 1px solid rgba(213, 207, 196, 0.4);
}

.text-block pre {
  background: var(--ink);
  color: var(--paper);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.55;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.text-block pre code {
  background: none;
  padding: 0;
  color: inherit;
  border: none;
}

.text-block blockquote {
  border-left: 2px solid var(--accent-warm);
  padding: 2px 0 2px 14px;
  margin: 12px 0;
  color: var(--ink-mid);
  font-style: italic;
  background: linear-gradient(90deg, rgba(192, 120, 64, 0.04), transparent);
}

.text-block a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.text-block a:hover {
  color: var(--accent-deep);
  text-decoration-color: var(--accent);
}

/* ---------- Tool Tags (Marginalia Style) ---------- */
.tool-line {
  margin: 10px 0 6px;
}

.tool-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px 3px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--ink-light);
  background: var(--paper);
  border: 1px solid var(--line-light);
  transition: all 0.35s var(--ease-out-expo);
}

.tool-tag-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-fade);
  opacity: 0.5;
  transition: all 0.35s ease;
}

.tool-tag.running {
  color: var(--accent-warm);
  background: rgba(192, 120, 64, 0.08);
  border-color: var(--accent-warm);
  border-style: solid;
}

.tool-tag.running .tool-tag-dot {
  background: var(--accent-warm);
  opacity: 1;
  animation: dotPulse 1.5s ease-in-out infinite;
}

.tool-tag.done {
  color: var(--accent);
  background: rgba(122, 140, 110, 0.08);
  border-color: var(--accent);
  border-style: solid;
}

.tool-tag.done .tool-tag-dot {
  background: var(--accent);
  opacity: 0.8;
}

.tool-tag-count {
  font-size: 9px;
  font-weight: 700;
  color: var(--ink-fade);
  background: var(--line-light);
  padding: 1px 4px;
  border-radius: 8px;
  margin-left: 2px;
  line-height: 1;
}

/* ---------- Tool Group (多工具横向排列) ---------- */
.tool-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 6px;
  padding: 8px 10px;
  background: var(--paper-warm);
  border: 1px solid var(--line-light);
  border-radius: var(--radius-md);
}

.tool-group .tool-tag {
  border: none;
  background: transparent;
  padding: 2px 10px 2px 6px;
  font-size: 11px;
}

.tool-group .tool-tag.running {
  color: var(--accent-warm);
}

.tool-group .tool-tag.done {
  color: var(--accent);
}

/* ---------- Loading Dots ---------- */
.loading-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 6px 0;
}

.loading-dots span {
  width: 5px;
  height: 5px;
  background: var(--ink-fade);
  border-radius: 50%;
  animation: dotBounce 1.4s ease-in-out infinite both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

/* ---------- Welcome Screen ---------- */
.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 48px 0;
  animation: welcomeFade 0.8s var(--ease-out-expo) both;
}

.welcome-card {
  text-align: left;
  max-width: 500px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

/* Location pin stamp */
.welcome-stamp {
  width: 52px;
  height: 52px;
  margin: 0 0 28px;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  opacity: 0.6;
  transition: all 0.4s ease;
}

@media (hover: hover) {
  .welcome-stamp:hover {
    opacity: 1;
    transform: scale(1.05);
  }
}

.welcome-stamp svg {
  width: 24px;
  height: 24px;
  stroke-width: 1.5;
}

.welcome-card h2 {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 14px;
  line-height: 1.25;
  letter-spacing: 0.5px;
}

.accent-text {
  color: var(--accent);
  position: relative;
}

.accent-text::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 0;
  right: 0;
  height: 6px;
  background: rgba(122, 140, 110, 0.12);
  border-radius: 2px;
  z-index: -1;
}

.welcome-card > p {
  color: var(--ink-light);
  margin-bottom: 36px;
  font-size: 1rem;
  line-height: 1.85;
  max-width: 420px;
}

.quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.quick-btn {
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-light);
  background: var(--paper);
  color: var(--ink);
  font-size: 0.88rem;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s var(--ease-out-expo);
  display: flex;
  align-items: center;
  gap: 7px;
  line-height: 1.4;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.quick-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(122, 140, 110, 0.06), transparent);
  opacity: 0;
  transition: opacity 0.25s ease;
}

@media (hover: hover) {
  .quick-btn:hover {
    border-color: var(--accent);
    color: var(--accent-deep);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }

  .quick-btn:hover::before {
    opacity: 1;
  }
}

 .quick-btn.elastic-press:active {
  transform: scale(0.95);
}

.quick-btn svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

/* ---------- Input Area ---------- */
.input-area {
  padding: 14px 0 10px;
  border-top: 1px solid var(--line-light);
  position: relative;
}

/* Decorative dashed line above input */
.input-area::before {
  content: '';
  position: absolute;
  top: -2px;
  left: 0;
  right: 0;
  height: 1px;
  background: repeating-linear-gradient(
    to right,
    var(--line-faint) 0px,
    var(--line-faint) 8px,
    transparent 8px,
    transparent 13px
  );
  opacity: 0.5;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--paper);
  border: 1.5px solid var(--line-light);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 18px;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s var(--ease-out-expo);
  position: relative;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

@media (hover: hover) {
  .input-wrapper:focus-within {
    box-shadow:
      0 0 0 3px rgba(122, 140, 110, 0.1),
      var(--shadow-md);
    transform: translateY(-1px);
  }
}

.input-wrapper textarea {
  flex: 1;
  min-height: 40px;
  max-height: 100px;
  height: 40px;
  padding: 8px 0;
  border: none;
  background: transparent;
  font-size: 15px;
  font-family: var(--font-sans);
  line-height: 1.55;
  color: var(--ink);
  resize: none;
  outline: none;
  overflow-y: hidden;
}

.input-wrapper textarea::placeholder {
  color: var(--ink-fade);
  font-style: italic;
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: all 0.25s var(--ease-spring);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

@media (hover: hover) {
  .send-btn:hover:not(:disabled) {
    background: var(--accent);
    transform: scale(1.08);
    box-shadow: 0 2px 8px rgba(122, 140, 110, 0.25);
  }
}

.send-btn.elastic-press:active:not(:disabled) {
  transform: scale(0.88);
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send-btn.stop {
  background: var(--accent-warm);
}

@media (hover: hover) {
  .send-btn.stop:hover {
    background: var(--accent-warm-light);
    box-shadow: 0 2px 8px rgba(192, 120, 64, 0.25);
  }
}

.send-btn svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Keyboard Adaptation ---------- */
.messages {
  transition: padding-bottom 0.35s var(--ease-out-expo);
}

.input-area {
  transition: transform 0.35s var(--ease-out-expo), padding-bottom 0.35s var(--ease-out-expo);
}

/* Input hint text */
.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--ink-fade);
  margin-top: 8px;
  letter-spacing: 0.02em;
  opacity: 0.6;
}

/* ---------- Dark Theme Overrides ---------- */
[data-theme="dark"] body {
  background-image:
    radial-gradient(ellipse at 10% 20%, rgba(106, 126, 94, 0.035) 0%, transparent 50%),
    radial-gradient(ellipse at 90% 80%, rgba(160, 104, 48, 0.025) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(218, 208, 168, 0.04) 0%, transparent 70%),
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent 31px,
      rgba(180, 172, 158, 0.18) 31px,
      rgba(180, 172, 158, 0.18) 32px
    );
}

[data-theme="dark"] .paper-grain {
  opacity: 0.2;
}

[data-theme="dark"] .assistant-bubble {
  background: #C8C0B2;
  border-color: var(--line);
  border-left: 1px solid var(--line);
}

[data-theme="dark"] .user-bubble {
  background: var(--paper-note);
  border-color: var(--paper-note-shadow);
}

[data-theme="dark"] .input-wrapper {
  background: var(--paper);
}

[data-theme="dark"] .quick-btn {
  background: var(--paper);
}

[data-theme="dark"] .text-block th {
  background: var(--paper-note);
}

[data-theme="dark"] .text-block pre {
  background: #2A2420;
}

/* ---------- Animations ---------- */
@keyframes messageEnter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes welcomeFade {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dotBounce {
  0%, 80%, 100% {
    transform: scale(0.4);
    opacity: 0.3;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes dotPulse {
  0%, 100% {
    opacity: 0.6;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.4);
  }
}

/* ---------- Responsive: Tablet (≤768px) ---------- */
@media (max-width: 768px) {
  #app {
    padding: 14px 14px 14px 32px;
  }

  body::before {
    left: 16px;
    opacity: 0.12;
  }

  #app::after {
    display: none;
  }

  .notebook-line,
  body::after {
    display: none;
  }

  .nav-title {
    font-size: 1rem;
    letter-spacing: 0.5px;
  }

  .navbar {
    padding: 8px 0 6px;
  }

  /* Touch-friendly: 44px minimum tap targets */
  .btn-new-chat {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
    font-size: 0;
    gap: 0;
    overflow: hidden;
    border-radius: 50%;
  }

  .btn-new-chat svg {
    width: 16px;
    height: 16px;
  }

  .theme-toggle {
    width: 40px;
    height: 40px;
  }

  .messages {
    padding: 12px 0;
    gap: 18px;
  }

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

  .message.assistant {
    max-width: 90%;
  }

  .welcome {
    padding: 20px 0;
  }

  .welcome-card h2 {
    font-size: 1.75rem;
    line-height: 1.3;
  }

  .quick-questions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .quick-btn {
    justify-content: center;
  }

  .input-hint {
    display: none;
  }

  .input-wrapper {
    padding: 6px 6px 6px 14px;
  }

  .send-btn {
    width: 44px;
    height: 44px;
  }

  .input-wrapper textarea {
    min-height: 44px;
    max-height: 100px;
    height: 44px;
    font-size: 16px; /* prevent iOS zoom on focus */
  }

  .bubble {
    font-size: 15px;
    line-height: 1.7;
  }

  /* Simplified tape on mobile */
  .tape-left {
    width: 30px;
    height: 10px;
    top: -5px;
  }
}

/* ---------- Responsive: Phone (≤480px) ---------- */
@media (max-width: 480px) {
  /* Allow browser to scroll input into view when keyboard opens */
  body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #app {
    padding: 10px 10px 10px 24px;
  }

  body::before {
    left: 10px;
    opacity: 0.08;
  }

  /* Minimize paper grain for performance on small devices */
  .paper-grain {
    opacity: 0.15;
  }

  .navbar {
    padding: 6px 0 4px;
    margin-bottom: 0;
  }

  .logo-icon {
    width: 20px;
    height: 20px;
  }

  .logo-icon svg {
    width: 18px;
    height: 18px;
  }

  .nav-title {
    font-size: 0.95rem;
  }

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

  .message.assistant {
    max-width: 94%;
  }

  .bubble {
    padding: 10px 14px;
    font-size: 14.5px;
    line-height: 1.72;
  }

  .user-bubble {
    border-radius: 14px;
  }

  .assistant-bubble {
    border-radius: 14px;
  }

  .welcome {
    padding: 16px 0;
    align-items: flex-start;
  }

  .welcome-card h2 {
    font-size: 1.5rem;
    line-height: 1.3;
    margin-bottom: 10px;
  }

  .welcome-card > p {
    font-size: 0.9rem;
    line-height: 1.75;
    margin-bottom: 24px;
    max-width: 100%;
  }

  .welcome-stamp {
    width: 44px;
    height: 44px;
    margin-bottom: 18px;
  }

  .welcome-stamp svg {
    width: 20px;
    height: 20px;
  }

  .input-area {
    padding: 10px 0 8px;
  }

  .input-wrapper {
    border-radius: 14px;
    padding: 6px 6px 6px 14px;
  }

  .input-wrapper textarea {
    font-size: 16px;
    min-height: 44px;
    height: 44px;
    max-height: 96px;
  }

  .send-btn {
    width: 44px;
    height: 44px;
  }

  /* Tool tags: smaller on phone */
  .tool-tag {
    font-size: 11px;
    padding: 2px 10px 2px 7px;
  }

  .tool-line {
    margin: 6px 0 4px;
  }

  .tool-group {
    gap: 4px;
    padding: 6px 8px;
  }

  .tool-group .tool-tag {
    font-size: 10.5px;
  }

  /* Tighter markdown spacing */
  .text-block h1 { font-size: 1.1rem; margin: 14px 0 8px; }
  .text-block h2 { font-size: 1rem; margin: 12px 0 6px; }
  .text-block h3 { font-size: 0.92rem; }
  .text-block p { margin-bottom: 8px; }
  .text-block ul, .text-block ol { margin: 6px 0 8px 18px; }
  .text-block table { font-size: 12px; }
  .text-block th, .text-block td { padding: 6px 8px; }

  /* Elastic press is handled by .elastic-press class */
  .theme-toggle.elastic-press:active {
    transform: scale(0.88);
  }

  .send-btn.elastic-press:active:not(:disabled) {
    transform: scale(0.88);
  }

  .quick-btn.elastic-press:active {
    transform: scale(0.95);
  }

  .btn-new-chat.elastic-press:active {
    transform: scale(0.92);
  }
}

/* ---------- Safe area for notched phones ---------- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  @media (max-width: 480px) {
    #app {
      padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .input-area {
      padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
  }
}
