:root {
  --bg: #F4F4F1; --card: #FFFFFF; --ink: #17191C; --ink2: #3A3F45; --muted: #5B6168;
  --line: #D9DAD6; --line2: #E6E7E3; --field: #A9ACA6; --accent: #C2410C; --accent-d: #9A3412;
  --ok: #166534; --ok-bg: #E3F1E6; --warn: #7C2D12; --warn-bg: #FDF1E3; --note-bg: #FBEAE0;
  --danger: #B42318; --radius: 12px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.4; -webkit-text-size-adjust: 100%;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
a:hover { color: var(--accent-d); }
:focus-visible { outline: 3px solid #2563EB; outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.screen { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; }
.top { display: flex; align-items: center; gap: 4px; min-height: 56px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); }
.top.pad { padding-left: 20px; padding-right: 16px; justify-content: space-between; }
.top.bar { background: var(--card); border-bottom: 1px solid var(--line); }
.top .title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top .title strong { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content { flex: 1; padding: 8px 20px 24px; display: flex; flex-direction: column; gap: 20px; }
.content.tight { padding: 4px 12px 12px; gap: 4px; }
.step { font-size: 13px; font-weight: 500; color: var(--muted); padding: 0 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }

h1 { margin: 0; font-size: 28px; line-height: 1.2; font-weight: 600; }
h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 4px; }
h3 { margin: 0; font-size: 16px; font-weight: 600; }
p { margin: 0; }
.lead { font-size: 15px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; line-height: 1.4; }
.mono { font-family: var(--mono); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack.lg { gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.push { margin-top: auto; }
.ok-text { color: var(--ok); font-weight: 500; }
.warn-text { color: var(--warn); font-weight: 500; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .legend { font-size: 14px; font-weight: 500; }
.field .hint { font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=tel], input[type=url], input[type=search], textarea {
  width: 100%; min-height: 50px; border: 1px solid var(--field); border-radius: 10px; padding: 12px 14px;
  background: var(--card); font-size: 16px;
}
textarea { resize: vertical; line-height: 1.5; }
input.mono, textarea.mono { font-family: var(--mono); }
.with-btn { position: relative; display: flex; }
.with-btn input { padding-right: 72px; }
.with-btn button { position: absolute; right: 4px; top: 3px; height: 44px; padding: 0 12px; border: 0; background: none; font-weight: 600; cursor: pointer; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
fieldset { border: 0; margin: 0; padding: 0; }
details summary { cursor: pointer; font-size: 14px; color: var(--muted); min-height: 32px; }
details[open] summary { margin-bottom: 8px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 52px;
  border: 0; border-radius: var(--radius); background: var(--accent); color: #fff; font-weight: 600; font-size: 16px;
  cursor: pointer; text-decoration: none; padding: 0 16px;
}
.btn:hover { background: var(--accent-d); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--field); min-height: 48px; font-weight: 500; font-size: 15px; }
.btn.secondary:hover { background: #ECECE8; color: var(--ink); }
.btn.danger { background: var(--card); color: var(--danger); border: 1px solid var(--danger); min-height: 48px; font-size: 15px; }
.btn.small { width: auto; min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 20px; }
.btn.dark { background: var(--ink); }
.btn.fab { width: auto; align-self: flex-end; border-radius: 26px; background: var(--ink); padding: 0 20px; font-size: 15px; }
.linkbtn { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 10px 4px; min-height: 44px; font-size: 15px; }
.linkbtn.danger { color: var(--danger); }
.iconbtn { width: 44px; height: 44px; border: 0; background: none; display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 22px; color: var(--ink); flex: none; }
.iconbtn:hover { background: #E8E8E4; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.card.pad { padding: 16px; }
.list { list-style: none; margin: 0; padding: 0; }
.card > .list > li + li, .card > .item + .item { border-top: 1px solid var(--line2); }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; background: none; border: 0; text-align: left; min-height: 48px; cursor: default; }
button.item { cursor: pointer; }
.note { background: var(--note-bg); color: var(--warn); border-radius: var(--radius); padding: 14px 16px; font-size: 14px; }
.info { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; color: var(--ink2); }
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 16px; font-size: 14px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #F1D7B8; }
.banner.ok { background: var(--ok-bg); color: #14532D; }

.pill { height: 32px; padding: 0 12px; border-radius: 16px; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer; text-decoration: none; }
.pill.ok { background: var(--ok-bg); color: #14532D; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 4px; background: currentColor; flex: none; }
.dot.on { background: var(--ok); width: 10px; height: 10px; border-radius: 5px; }
.dot.off { background: transparent; border: 2px solid #8A8F95; width: 10px; height: 10px; border-radius: 5px; }
.badge { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.tag { height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; flex: none; }
.tag.owner { background: var(--ink); color: #fff; height: 20px; font-weight: 600; font-size: 11px; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.met { color: var(--ok); }
.tag.plain { color: var(--muted); padding: 0; }

.avatar { width: 44px; height: 44px; border-radius: 22px; background: #E6E7E3; color: var(--ink); font-weight: 600; font-size: 15px; display: flex; align-items: center; justify-content: center; flex: none; }
.avatar.sq { border-radius: 12px; font-size: 18px; }
.avatar.dark { background: var(--ink); color: #fff; }
.avatar.ghost { background: var(--card); border: 1.5px dashed #8A8F95; color: var(--muted); }
.chanrow { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 12px; color: var(--ink); text-decoration: none; width: 100%; background: none; border: 1px solid transparent; text-align: left; cursor: pointer; }
.chanrow.unread { background: var(--card); border-color: var(--line); }
.chanrow .l1, .chanrow .l2 { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.chanrow .l1 strong { font-size: 16px; }
.chanrow .l2 span:first-child { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chanrow.unread .l2 span:first-child { color: var(--ink2); }
.section-label { padding: 16px 12px 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); font-size: 15px; }

.tabs {
  position: sticky; bottom: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { height: 64px; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 500; cursor: pointer; }
.tabs button[aria-current=page] { color: var(--accent); font-weight: 600; }

.chat { height: 100dvh; min-height: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.day { align-self: center; font-size: 12px; font-weight: 500; color: var(--muted); }
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 80%; }
.msg .who { font-size: 13px; font-weight: 600; color: var(--ink2); }
.msg .who span { font-weight: 400; color: var(--muted); }
.bubble { background: var(--card); border: 1px solid var(--line); border-radius: 4px 14px 14px 14px; padding: 10px 12px; font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.mine .bubble { background: var(--ink); color: #fff; border-color: var(--ink); border-radius: 14px 4px 14px 14px; }
.msg.mine.out .bubble { background: var(--card); color: var(--ink); border: 1.5px dashed #8A8F95; }
.msg .st { font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 4px; color: var(--ok); }
.msg.out .st { color: var(--warn); }
.compose { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; padding-bottom: max(14px, env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.compose textarea { min-height: 46px; max-height: 160px; border-radius: 23px; padding: 11px 16px; background: var(--bg); resize: none; }
.send { width: 46px; height: 46px; border-radius: 23px; border: 0; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; cursor: pointer; }

.words { list-style: none; margin: 0; padding: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; grid-auto-flow: column; grid-template-rows: repeat(4, auto); }
.words li { display: flex; gap: 10px; align-items: baseline; padding: 6px 4px; }
.words .n { width: 18px; font-size: 13px; color: var(--muted); text-align: right; }
.words .w { font-family: var(--mono); font-size: 17px; font-weight: 500; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.otp { font-family: var(--mono); font-size: 24px; font-weight: 500; letter-spacing: 1px; }
.fp { font-family: var(--mono); font-size: 18px; font-weight: 500; letter-spacing: 1px; }
.qr { display: flex; justify-content: center; }
.qr canvas { width: 208px; height: 208px; image-rendering: pixelated; }
.cam { width: 100%; border-radius: var(--radius); background: #000; aspect-ratio: 1; object-fit: cover; }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); background: #E6E7E3; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { min-height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 500; cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--card); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
ol.steps { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
ol.steps li { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; }
ol.steps .num { flex: none; width: 24px; height: 24px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.okmark { width: 56px; height: 56px; border-radius: 16px; background: var(--ok-bg); display: flex; align-items: center; justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); max-width: min(480px, calc(100vw - 32px));
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; z-index: 10;
  box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast.err { background: var(--danger); }
.update { position: fixed; top: 0; left: 0; right: 0; z-index: 9; display: flex; justify-content: center; gap: 12px; align-items: center; background: var(--ink); color: #fff; padding: 10px 16px; font-size: 14px; padding-top: max(10px, env(safe-area-inset-top)); }
.update button { background: var(--accent); color: #fff; border: 0; border-radius: 16px; height: 32px; padding: 0 14px; font-weight: 600; cursor: pointer; }

.gap2 { gap: 2px; } .gap8 { gap: 8px; } .fs17 { font-size: 17px; } .p8 { padding: 8px; } .px4 { padding: 0 4px; }
.pt-l { padding-top: 56px; } .pt-m { padding-top: 48px; } .h1sm { font-size: 22px; }

/* ---------- the app's own keyboard (app/js/keyboard.js) ---------- */
.chat { flex: none; height: calc(100dvh - var(--kb-h, 0px)); transition: height 300ms cubic-bezier(0.2, 0.8, 0.2, 1); }
html.kb-open .compose { padding-bottom: 10px; }
.kb {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; max-width: 520px; margin: 0 auto;
  background: #D1D4DA; padding: 8px 3px calc(8px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform 300ms cubic-bezier(0.2, 0.8, 0.2, 1);
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.kb.open { transform: translateY(0); box-shadow: 0 -1px 0 rgba(0,0,0,.08); }
.kb.instant { transition: none; }
.kb-rows { display: flex; flex-direction: column; gap: 11px; }
.kb-row { display: flex; gap: 6px; justify-content: center; }
.kb-row.inset { padding: 0 5%; }
.kb-key {
  flex: 1 1 0; min-width: 0; height: 43px; border: 0; border-radius: 5px; padding: 0;
  background: #FFFFFF; color: #000; font-size: 22px; font-family: inherit; line-height: 1;
  box-shadow: 0 1px 0 rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.kb-key.fn { background: #ADB2BB; font-size: 15px; }
.kb-key.wide { flex: 1.35 1 0; }
.kb-row:nth-child(3) .kb-key.wide:first-child { margin-right: 8px; }
.kb-row:nth-child(3) .kb-key.wide:last-child { margin-left: 8px; }
.kb-key.mode { flex: 1.2 1 0; }
.kb-key.space { flex: 4.6 1 0; font-size: 15px; }
.kb-key.ret { flex: 2.3 1 0; }
.kb-key.on, .kb-key.fn.down { background: #FFFFFF; }
.kb-key.space.down, .kb-key.char.down { background: #ADB2BB; }
.kb-preview {
  position: absolute; display: none; transform: translate(-50%, calc(-100% - 6px));
  min-width: calc(var(--key-w, 32px) * 1.45); height: 56px; padding: 0 6px; border-radius: 9px;
  background: #FFFFFF; color: #000; font-size: 32px; box-shadow: 0 2px 8px rgba(0,0,0,.28);
  align-items: center; justify-content: center; pointer-events: none;
}
.kb-preview.show { display: flex; }
@media (prefers-reduced-motion: reduce) { .kb, .chat { transition: none; } }
