:root {
  --bg: #f5f1ea;
  --surface: #fffdf9;
  --ink: #1f1b16;
  --muted: #6f675c;
  --line: #e3dccf;
  --accent: #c95a26;
  --accent-ink: #fff;
  --accent-soft: #f6e3d6;
  --danger: #b3261e;
  --ok: #2f6b3a;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --surface: #211e18;
    --ink: #f1ebe0;
    --muted: #a59c8e;
    --line: #353027;
    --accent: #e2703a;
    --accent-ink: #1a120c;
    --accent-soft: #3a2619;
    --danger: #f2867d;
    --ok: #8fcf98;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- shell ---------- */
.shell { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 18px 10px;
}
.brand { font-family: var(--serif); font-size: 26px; letter-spacing: .2px; margin: 0; }
.brand span { color: var(--accent); }
.main { flex: 1; overflow-y: auto; padding: 4px 18px 18px; }
.tabs {
  display: flex; gap: 4px; padding: 0 10px 10px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.tabs button {
  flex: 1; border: 0; background: none; padding: 9px 4px; border-radius: 10px;
  color: var(--muted); font-size: 14px; cursor: pointer;
}
.tabs button[aria-current="page"] { color: var(--ink); background: var(--surface); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }
@media (min-width: 720px) {
  .tabs { padding: 0 18px 10px; justify-content: flex-start; }
  .tabs button { flex: 0 0 auto; padding: 8px 14px; }
}

h2 { font-family: var(--serif); font-weight: 600; font-size: 22px; margin: 14px 0 6px; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 14px; }

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px;
  cursor: pointer; font-size: 15px;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
label.field, div.field { display: block; margin: 0 0 14px; }
label.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
label.field small { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], input[type=time], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.days label { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 14px; cursor: pointer; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.error { color: var(--danger); font-size: 14px; }
.ok { color: var(--ok); font-size: 14px; }

/* ---------- login ---------- */
.center { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 380px; }
.card .brand { margin-bottom: 4px; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: 100%; }
.thread { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 6px 2px 12px; }
.msg { max-width: 86%; padding: 10px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.error { align-self: flex-start; color: var(--danger); font-size: 14px; padding: 2px 4px; }
.activity { align-self: flex-start; color: var(--muted); font-size: 13px; padding: 0 4px; }
.divider { align-self: center; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; padding: 6px 0; }
.typing { align-self: flex-start; color: var(--muted); font-size: 14px; padding: 0 4px; }
.typing::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.empty-chat { color: var(--muted); text-align: center; margin: auto; max-width: 420px; padding: 20px; }
.empty-chat p { margin: 6px 0; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding-top: 8px; }
.composer textarea { min-height: 46px; max-height: 180px; resize: none; border-radius: 14px; }
.composer .btn { height: 46px; }

.form-card { align-self: stretch; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 14px 16px; }
.form-card h3 { margin: 0 0 4px; font-size: 16px; }
.form-card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; white-space: pre-wrap; }
.form-card.done { opacity: .7; border-left-color: var(--line); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.item h3 { margin: 0; font-size: 16px; }
.item .meta { color: var(--muted); font-size: 13px; margin: 3px 0 8px; word-break: break-all; }
.item .meta a { color: inherit; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--ink); margin-right: 6px; vertical-align: 1px; }
.badge.off { background: var(--line); color: var(--muted); }
audio { width: 100%; margin: 6px 0 4px; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
details .script { white-space: pre-wrap; font-family: var(--serif); font-size: 16px; line-height: 1.6; margin-top: 8px; }
.toolbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin: 8px 0 14px; flex-wrap: wrap; }
.notice { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }
.row.end { justify-content: flex-end; }
label.field.inline { gap: 10px; }
label.field.inline > span { display: inline; margin: 0; }
.field-title { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.grow { flex: 1; min-width: 200px; }
