:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --ink: #1d2421;
  --ink-2: #4b5551;
  --muted: #7c8581;
  --line: #e4e0d7;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --coach: #ffffff;
  --me: #1f6f5c;
  --me-ink: #ffffff;
  --warn: #9a3412;
  --warn-soft: #fdeee4;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(29, 36, 33, .06), 0 4px 16px rgba(29, 36, 33, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1b211e;
    --ink: #e8ece9;
    --ink-2: #b9c2be;
    --muted: #8a948f;
    --line: #2b3330;
    --accent: #4fb394;
    --accent-ink: #0d1411;
    --accent-soft: #1d2f28;
    --coach: #1b211e;
    --me: #2f7e68;
    --me-ink: #ffffff;
    --warn: #fdba8c;
    --warn-soft: #3a2418;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none; }
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn-small { min-height: 36px; padding: 0 14px; border-radius: 10px; font-size: 14px; }
.btn-danger { background: var(--warn); color: #fff; }

/* ───────── app shell ───────── */
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.top { display: flex; align-items: center; gap: 12px; padding: max(12px, env(safe-area-inset-top)) 16px 12px; border-bottom: 1px solid var(--line); background: var(--bg); }
.mark { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 11px; background: var(--accent); color: var(--accent-ink); }
.top h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 650; }
.top small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 12px; background: transparent; color: var(--ink-2); }
.icon-btn:hover { background: var(--accent-soft); }

.menu { position: absolute; right: 16px; top: 60px; z-index: 5; min-width: 220px; padding: 6px; border-radius: 14px; background: var(--surface); box-shadow: 0 0 0 1px var(--line), 0 12px 32px rgba(0, 0, 0, .16); }
.menu button, .menu a { display: block; width: 100%; padding: 11px 12px; border: 0; border-radius: 10px; background: none; text-align: left; color: var(--ink); text-decoration: none; font-size: 15px; }
.menu button:hover, .menu a:hover { background: var(--accent-soft); }
.menu .danger { color: var(--warn); }

/* ───────── screens (gate, not invited, declined) ───────── */
.screen { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.card { width: 100%; max-width: 460px; padding: 28px 24px; border-radius: 22px; background: var(--surface); box-shadow: var(--shadow), 0 0 0 1px var(--line); }
.card h2 { margin: 0 0 10px; font-size: 22px; line-height: 1.25; }
.card p { margin: 0 0 18px; color: var(--ink-2); }
.card .stack { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.card .fine { margin: 16px 0 0; font-size: 13px; color: var(--muted); }

/* ───────── chat ───────── */
.chat { flex: 1; overflow-y: auto; padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: var(--radius); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.coach { align-self: flex-start; background: var(--coach); box-shadow: var(--shadow), 0 0 0 1px var(--line); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.error { align-self: center; max-width: 100%; background: var(--warn-soft); color: var(--warn); font-size: 14px; text-align: center; }
.msg .att { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 13px; opacity: .85; }
.msg img.preview { display: block; max-width: 220px; max-height: 220px; margin-bottom: 6px; border-radius: 12px; }
.msg p { margin: 0 0 8px; }
.msg p:last-child, .msg ul:last-child, .msg ol:last-child, .msg table:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0 0 8px; padding-left: 20px; }
.msg h3, .msg h4 { margin: 6px 0; font-size: 15px; }
.msg code { padding: 1px 5px; border-radius: 6px; background: var(--accent-soft); font-size: 14px; }
.msg .tbl { overflow-x: auto; margin: 4px 0 8px; }
.msg table { border-collapse: collapse; font-size: 14px; }
.msg th, .msg td { padding: 5px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.msg th { font-weight: 600; }
.day { align-self: center; margin: 6px 0; font-size: 12px; color: var(--muted); }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .6; } }

.composer { position: relative; padding: 8px 12px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); }
.tip { position: absolute; left: 12px; right: 12px; bottom: calc(100% + 10px); z-index: 4; padding: 16px 16px 14px; border-radius: 16px; background: var(--surface); box-shadow: 0 0 0 1px var(--line), 0 12px 32px rgba(0, 0, 0, .16); font-size: 14px; }
.tip::after { content: ''; position: absolute; left: 76px; bottom: -7px; width: 14px; height: 14px; background: var(--surface); box-shadow: 1px 1px 0 var(--line); transform: rotate(45deg); }
.tip strong { display: block; margin-bottom: 6px; font-size: 15px; }
.tip ul { margin: 0 0 12px; padding-left: 18px; color: var(--ink-2); }
.tip li { margin-bottom: 6px; }
.tip b { color: var(--ink); font-weight: 600; }
.tip .btn { width: 100%; }
.chip { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; margin: 0 0 8px 4px; padding: 6px 8px 6px 6px; border-radius: 12px; background: var(--surface); box-shadow: 0 0 0 1px var(--line); font-size: 13px; }
.chip img { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { width: 26px; height: 26px; border: 0; border-radius: 8px; background: var(--accent-soft); }
.row { display: flex; align-items: flex-end; gap: 8px; }
.row textarea { flex: 1; min-height: 46px; max-height: 160px; padding: 11px 14px; border: 0; border-radius: 16px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); resize: none; outline: none; line-height: 1.4; }
.row textarea:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.round { width: 46px; height: 46px; flex: none; display: grid; place-items: center; border: 0; border-radius: 16px; }
.round.attach { background: var(--surface); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--line); }
.round.send { background: var(--accent); color: var(--accent-ink); }
.round:disabled { opacity: .45; cursor: default; }
.disclaimer { margin: 8px 4px 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ───────── plain pages ───────── */
.plain { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.note { max-width: 420px; text-align: center; }
.note h1 { font-size: 22px; }

/* ───────── admin ───────── */
.admin { max-width: 980px; margin: 0 auto; padding: 24px 16px 60px; }
.admin h1 { margin: 0 0 4px; font-size: 24px; }
.admin h2 { margin: 28px 0 10px; font-size: 18px; }
.admin .status { color: var(--muted); font-size: 14px; }
.admin .panel { padding: 16px; border-radius: 16px; background: var(--surface); box-shadow: 0 0 0 1px var(--line); }
.admin form.inline { display: flex; flex-wrap: wrap; gap: 8px; }
.admin input[type=text], .admin input[type=password] { flex: 1 1 220px; min-height: 44px; padding: 0 12px; border: 0; border-radius: 12px; background: var(--bg); box-shadow: inset 0 0 0 1px var(--line); }
.admin .newlink { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--accent-soft); font-size: 14px; word-break: break-all; }
.admin table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin th, .admin td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.admin th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.admin td .acts { display: flex; flex-wrap: wrap; gap: 6px; }
.admin .scroll { overflow-x: auto; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.pill.off { background: var(--warn-soft); color: var(--warn); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: 14px; z-index: 10; }
