* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #2c2c2c;
  --muted: #6f6c66;
  --accent: #6b8e7f;
  --accent-deep: #557467;
  --accent-soft: #e7eeea;
  --user-bubble: #e7eeea;
  --ai-bubble: #ffffff;
  --border: #e5e2dc;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a18;
    --surface: #232320;
    --text: #ece9e2;
    --muted: #9c988e;
    --accent: #8eae9f;
    --accent-deep: #b3cdc1;
    --accent-soft: #2d3a35;
    --user-bubble: #2d3a35;
    --ai-bubble: #232320;
    --border: #34332f;
    --shadow: 0 1px 3px rgba(0,0,0,0.2);
  }
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100svh;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h1 {
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.question {
  font-size: 1.05rem;
  margin-bottom: 4px;
  color: var(--text);
}

.hint {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  padding: 10px 14px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chip:active { transform: scale(0.96); }

.chip.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-deep);
  font-weight: 500;
}

textarea, input[type="password"], input[type="text"] {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
}

textarea {
  min-height: 80px;
  resize: vertical;
}

textarea:focus, input:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

button.primary {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
}

button.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.secondary {
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

.progress {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.progress .dot {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  transition: background 0.2s ease;
}

.progress .dot.done { background: var(--accent); }

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  padding: 12px 16px;
  border-radius: var(--radius);
  max-width: 88%;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 1rem;
  line-height: 1.55;
}

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

.msg.ai {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 10px 0 max(10px, env(safe-area-inset-bottom)) 0;
  background: var(--bg);
  margin-top: 12px;
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 12px;
  font-size: 1rem;
  resize: none;
  overflow-y: auto;
}

.composer button {
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  min-width: 64px;
}

.composer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error {
  background: #fdecec;
  color: #a23030;
  padding: 12px;
  border-radius: 12px;
  margin: 12px 0;
}

@media (prefers-color-scheme: dark) {
  .error { background: #3a1f1f; color: #f0b3b3; }
}

.token-prompt { display: flex; flex-direction: column; gap: 12px; }

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.summary {
  font-size: 0.85rem;
  color: var(--muted);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.icon-btn:active { transform: scale(0.96); }

.form-label {
  display: block;
  font-weight: 500;
  font-size: 0.95rem;
  margin-bottom: 6px;
}

.checkin-bubble {
  align-self: stretch;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 4px 0;
}

.checkin-head {
  font-size: 0.8rem;
  color: var(--accent-deep);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.checkin-body {
  white-space: pre-wrap;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
}
