:root {
  --bg: #faf7f2;
  --bg-soft: #f1ede4;
  --ink: #1a1a1a;
  --ink-soft: #4a4a4a;
  --ink-muted: #8a8a82;
  --accent: #c9a227;
  --accent-ink: #5a4a10;
  --user-bg: #e8dfce;
  --tutor-bg: #ffffff;
  --tutor-border: #e0dacc;
  --danger: #8b1a1a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-soft: 0 1px 2px rgba(0,0,0,0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  height: 100dvh;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--tutor-border);
  flex-shrink: 0;
}

.header-left { display: flex; flex-direction: column; gap: 2px; }
.logo { font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.subtitle { font-size: 11px; color: var(--ink-muted); }

.btn-icon {
  background: transparent;
  border: 1px solid var(--tutor-border);
  color: var(--ink-soft);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--bg-soft); }
.btn-icon:active { transform: scale(0.95); }

.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.welcome {
  padding: 24px 8px;
  text-align: center;
}
.welcome h1 {
  font-size: 28px;
  font-weight: 500;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}
.welcome-sub {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0 0 20px;
}
.quick-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.chip {
  background: var(--tutor-bg);
  border: 1px solid var(--tutor-border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.chip:hover { background: var(--bg-soft); border-color: var(--ink-muted); }
.chip:active { transform: scale(0.97); }

.message {
  max-width: 90%;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.55;
  word-wrap: break-word;
  animation: fadeIn 0.2s ease;
}

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

.message.user {
  align-self: flex-end;
  background: var(--user-bg);
  color: var(--ink);
  border-bottom-right-radius: 4px;
}

.message.tutor {
  align-self: flex-start;
  background: var(--tutor-bg);
  color: var(--ink);
  border: 1px solid var(--tutor-border);
  border-bottom-left-radius: 4px;
}

.message p { margin: 0 0 10px; }
.message p:last-child { margin-bottom: 0; }
.message strong { font-weight: 600; }
.message em { font-style: italic; }
.message code {
  background: var(--bg-soft);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 0.9em;
}
.message pre {
  background: var(--bg-soft);
  padding: 10px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 13px;
  margin: 10px 0;
}
.message blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 10px 0;
  color: var(--ink-soft);
  font-style: italic;
}
.message ul, .message ol {
  margin: 10px 0;
  padding-left: 22px;
}
.message li { margin: 4px 0; }

.message svg { max-width: 100%; height: auto; display: block; margin: 10px 0; }
.message .widget-container {
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 10px 0;
}

.typing-indicator {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--tutor-bg);
  border: 1px solid var(--tutor-border);
  border-radius: var(--radius);
  margin: 0 16px 12px;
  width: fit-content;
}
.typing-indicator .dot {
  width: 6px;
  height: 6px;
  background: var(--ink-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator .dot:nth-child(2) { animation-delay: 0.16s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--tutor-border);
  align-items: flex-end;
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  padding: 10px 12px;
  border: 1px solid var(--tutor-border);
  border-radius: var(--radius);
  background: var(--tutor-bg);
  color: var(--ink);
  resize: none;
  max-height: 140px;
  outline: none;
  transition: border-color 0.15s;
}
#message-input:focus {
  border-color: var(--accent);
}

.btn-send {
  background: var(--accent);
  color: white;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.btn-send:hover:not(:disabled) { background: #b38f1e; }
.btn-send:active:not(:disabled) { transform: scale(0.93); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.error-banner {
  background: #fae0e0;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin: 8px 16px;
  font-size: 13px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1814;
    --bg-soft: #252219;
    --ink: #eeeae0;
    --ink-soft: #b8b2a4;
    --ink-muted: #7a7468;
    --user-bg: #3a3320;
    --tutor-bg: #252219;
    --tutor-border: #3a3530;
  }
}
