:root {
  --bg: #f6f2ea; --card: #fffdf8; --ink: #1f1d1a; --muted: #7a736a; --line: #e6dfd2;
  --accent: #1f4d3a; --accent-ink: #ffffff; --accent-soft: #e3ede6; --danger: #a33a2a;
  --bubble-me: #1f4d3a; --bubble-me-ink: #f6f2ea; --bubble-them: #ece6da; --bubble-them-ink: #1f1d1a;
  --radius: 16px; --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f; --card: #1f1d18; --ink: #ece7dc; --muted: #9b948a; --line: #2e2b25;
    --accent: #7fb89a; --accent-ink: #0f1d16; --accent-soft: #223129; --danger: #e07a6a;
    --bubble-me: #2f6b52; --bubble-me-ink: #f4f1ea; --bubble-them: #2a2822; --bubble-them-ink: #ece7dc;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); font: 17px/1.5 var(--sans); overscroll-behavior-y: none; }
body.chat-open { overflow: hidden; height: 100%; }
h1, h2, h3, .serif { font-family: var(--serif); font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
h1 { font-size: 2.1rem; margin: 0 0 .6em; }
h2 { font-size: 1.45rem; margin: 0 0 .5em; }
h3 { font-size: 1.15rem; margin: 0 0 .4em; }
p { margin: 0 0 1em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .92rem; }
.center { text-align: center; }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; font-size: 17px; outline: none;
  -webkit-appearance: none; appearance: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
label { display: block; font-weight: 600; margin: 18px 0 6px; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: .9rem; margin-top: 2px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; padding: 12px 18px;
  border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 17px; cursor: pointer;
  text-decoration: none; transition: transform .06s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--accent); min-height: 44px; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.inline { width: auto; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 0 0 16px; }
.card.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.card.accent .muted { color: color-mix(in srgb, var(--accent-ink) 75%, transparent); }
.card.accent a { color: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 15px; cursor: pointer; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.err { color: var(--danger); font-size: .95rem; margin: 10px 0 0; min-height: 1.2em; }
.ok { color: var(--accent); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: .85rem; font-weight: 600; }
.badge { display: inline-flex; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--danger); color: #fff; font-size: 13px; font-weight: 700; align-items: center; justify-content: center; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.switch:first-of-type { border-top: 0; }
.switch .t { font-weight: 600; }
.switch .d { color: var(--muted); font-size: .9rem; }
.toggle { flex: none; width: 52px; height: 32px; border-radius: 16px; background: var(--line); border: 0; position: relative; cursor: pointer; padding: 0; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.toggle.on { background: var(--accent); }
.toggle.on::after { left: 23px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }

/* layout */
.page { max-width: 560px; margin: 0 auto; padding: calc(var(--sat) + 18px) 18px calc(var(--sab) + 96px); min-height: 100vh; min-height: 100dvh; }
.page.bare { padding-bottom: calc(var(--sab) + 32px); }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; min-height: 40px; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.35rem; color: var(--accent); text-decoration: none; }
.brand small { display: block; font-family: var(--sans); font-weight: 500; font-size: .75rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 8px 8px calc(var(--sab) + 8px); z-index: 20; }
.tabs a { flex: 1; max-width: 140px; text-align: center; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; padding: 4px 0; position: relative; }
.tabs a .ic { display: block; font-size: 22px; line-height: 1.1; }
.tabs a.on { color: var(--accent); }
.tabs a .badge { position: absolute; top: -2px; right: 18%; }

/* landing */
.hero { padding: 30px 0 10px; }
.hero h1 { font-size: 2.5rem; }
.hero p.lead { font-size: 1.15rem; }
.steps { counter-reset: s; padding: 0; margin: 0 0 8px; list-style: none; }
.steps li { position: relative; padding: 0 0 18px 48px; counter-increment: s; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: flex; align-items: center; justify-content: center; font-family: var(--serif); }
.nots { columns: 2; column-gap: 18px; padding: 0; margin: 0; list-style: none; }
.nots li { padding: 6px 0; color: var(--muted); break-inside: avoid; }
.nots li::before { content: "— "; color: var(--accent); }
.stat { font-family: var(--serif); font-size: 1.05rem; }
.foot { margin-top: 40px; color: var(--muted); font-size: .85rem; }
.code-in { text-align: center; font-size: 30px; letter-spacing: .35em; font-variant-numeric: tabular-nums; padding-left: calc(14px + .35em); }

/* home cards */
.person { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.avatar { flex: none; width: 54px; height: 54px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-weight: 700; font-size: 24px; color: #fff; }
.person .n { font-family: var(--serif); font-weight: 700; font-size: 1.35rem; line-height: 1.15; }
.person .m { color: var(--muted); font-size: .9rem; }
.quote { font-family: var(--serif); font-size: 1.1rem; border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; margin: 12px 0 16px; }
.kv { margin: 0 0 12px; }
.kv .k { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.kv .v { white-space: pre-wrap; }
.countdown { display: flex; align-items: baseline; gap: 8px; margin: 8px 0 14px; }
.countdown b { font-family: var(--serif); font-size: 2rem; line-height: 1; }
.list a { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.list a:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .t { font-weight: 600; }
.list .s { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note { background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 12px 14px; font-size: .95rem; margin-bottom: 16px; }
.note.warn { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.tip { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 12px 14px; font-size: .92rem; margin-bottom: 16px; }
.tip button { background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; padding: 0 4px; cursor: pointer; }

/* chat */
.chat { position: fixed; left: 0; top: 0; width: 100%; height: 100%; display: flex; flex-direction: column; background: var(--bg); z-index: 30; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: calc(var(--sat) + 8px) 10px 8px; border-bottom: 1px solid var(--line); background: var(--bg); }
.chat-head .back { background: none; border: 0; font-size: 26px; padding: 4px 8px; color: var(--accent); cursor: pointer; }
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who .n { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .who .s { color: var(--muted); font-size: .8rem; }
.chat-head .more { background: none; border: 0; font-size: 24px; padding: 4px 10px; color: var(--accent); cursor: pointer; }
.msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 14px 8px; overscroll-behavior: contain; }
.msgs .day { text-align: center; color: var(--muted); font-size: .78rem; margin: 14px 0 10px; text-transform: uppercase; letter-spacing: .06em; }
.msg { max-width: 82%; margin: 3px 0; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.4; }
.msg.them { background: var(--bubble-them); color: var(--bubble-them-ink); border-bottom-left-radius: 6px; margin-right: auto; }
.msg.me { background: var(--bubble-me); color: var(--bubble-me-ink); border-bottom-right-radius: 6px; margin-left: auto; }
.msg time { display: block; font-size: .7rem; opacity: .6; margin-top: 3px; text-align: right; }
.msg.pending { opacity: .6; }
.sys { text-align: center; color: var(--muted); font-size: .9rem; margin: 18px 30px; }
.sys .ice { font-family: var(--serif); color: var(--ink); font-size: 1.05rem; margin-top: 6px; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(var(--sab) + 8px); border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { flex: 1; min-height: 44px; max-height: 140px; padding: 10px 14px; border-radius: 22px; resize: none; }
.composer .send { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.composer .send[disabled] { opacity: .4; }
.closed { text-align: center; padding: 14px 16px calc(var(--sab) + 14px); border-top: 1px solid var(--line); color: var(--muted); font-size: .95rem; }

/* sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: var(--card); border-radius: 20px 20px 0 0; padding: 14px 16px calc(var(--sab) + 16px); }
.sheet .h { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet .btn { margin-top: 8px; }

/* admin */
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { text-align: left; padding: 7px 6px; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; border-top: 0; }
.tbl { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stats b { display: block; font-family: var(--serif); font-size: 1.6rem; }
.stats span { color: var(--muted); font-size: .8rem; }

#toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 90px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .95rem; z-index: 60; max-width: 90vw; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (min-width: 700px) {
  .chat { left: 50%; transform: translateX(-50%); max-width: 640px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
