/* Gnomogram: light, sage and white. iOS conventions; one green tint. */
:root {
  color-scheme: light;
  --bg:#f3f6ef; --surface:#ffffff; --surface2:#edf3e8; --surface3:#d9e3d2; --sep:rgba(60,90,55,.16);
  --label:#1f2b1c; --label2:#5f6e5a; --label3:#8a977f; --label4:#b4bfa9;
  --tint:#3f6b3a; --tint-strong:#365d31; --tint-dim:rgba(63,107,58,.12); --red:#c0392b; --gold:#b58a1c;
  --bar:rgba(243,246,239,.82); --bar-blur:blur(20px) saturate(160%);
  --r:14px; --r-bubble:18px; --shadow:0 1px 2px rgba(31,43,28,.06), 0 4px 14px rgba(31,43,28,.05);
  --body:17px; --sub:15px; --foot:13px; --cap:12px;
}
* { box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html, body { margin:0; height:100%; }
body { background:var(--bg); color:var(--label); font:var(--body)/1.35 -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing:antialiased; }
/* soft hills along the bottom edge, like the icon's ground */
body::after { content:""; position:fixed; left:0; right:0; bottom:0; height:22vh; z-index:-1; pointer-events:none; opacity:.9;
  background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 200' preserveAspectRatio='none'><path d='M0 120 C 150 60, 250 160, 400 110 C 550 60, 650 150, 800 100 L 800 200 L 0 200 Z' fill='%23dfe9d6'/><path d='M0 160 C 200 110, 300 190, 480 150 C 620 120, 700 170, 800 150 L 800 200 L 0 200 Z' fill='%23cfddc3'/></svg>") bottom/100% 100% no-repeat; }
main { max-width:640px; margin:0 auto; min-height:100%; display:flex; flex-direction:column; padding-top:env(safe-area-inset-top); }
.muted { color:var(--label2); font-size:var(--sub); }
.mono { font-family:ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.err { color:var(--red); }
.hidden { display:none !important; }
.glass { }

/* ---------- nav bar ---------- */
header { position:sticky; top:0; z-index:20; min-height:52px; padding:6px 16px; display:flex; align-items:center; gap:12px;
  background:var(--bar); -webkit-backdrop-filter:var(--bar-blur); backdrop-filter:var(--bar-blur); border-bottom:0.5px solid var(--sep); }
header h1 { font-size:17px; font-weight:600; margin:0; flex:1; display:flex; align-items:center; gap:8px; letter-spacing:-.01em; }
header .ver { font:var(--cap) ui-monospace, "SF Mono", Menlo, monospace; color:var(--label3); }
header #who { font-size:var(--sub); color:var(--label2); }
button.link, a.link { background:none; border:0; padding:0; color:var(--tint); font:inherit; font-size:var(--body); font-weight:500; text-decoration:none; cursor:pointer; }
#back { font-size:26px; line-height:1; padding-right:2px; }

/* ---------- controls ---------- */
button { font:inherit; font-size:var(--body); font-weight:600; padding:11px 18px; border-radius:999px; border:1px solid var(--surface3); cursor:pointer; color:var(--tint); background:var(--surface); }
button:active { opacity:.75; }
button.primary { background:var(--tint); border-color:var(--tint); color:#fff; }
button[disabled] { opacity:.45; cursor:default; }
input, textarea, select { font:inherit; font-size:var(--body); width:100%; padding:11px 14px; border-radius:12px; color:var(--label);
  background:var(--surface); border:1px solid var(--surface3); outline:none; box-shadow:inset 0 1px 1px rgba(31,43,28,.04); }
input::placeholder, textarea::placeholder { color:var(--label3); }
input:focus, textarea:focus { border-color:var(--tint); box-shadow:0 0 0 3px var(--tint-dim); }
textarea { resize:none; }
section.pad { padding:16px; }
.row { display:flex; gap:10px; } .row > * { flex:1; }
/* inputs with a leading icon */
.field { position:relative; }
.field svg { position:absolute; left:13px; top:50%; transform:translateY(-50%); width:17px; height:17px; color:var(--label3); pointer-events:none; }
.field input { padding-left:40px; }

/* ---------- sign in ---------- */
#auth { display:flex; flex-direction:column; align-items:center; padding:36px 20px 24px; }
#auth .brand { text-align:center; margin-bottom:22px; }
#auth .brand img { width:96px; height:96px; border-radius:24px; display:block; margin:0 auto 12px; }
#auth .brand .name { font-size:28px; font-weight:700; letter-spacing:-.02em; }
#auth .card { width:100%; max-width:360px; background:transparent; padding:0; }
#auth .card > div[style] { height:10px !important; }
#auth .row { margin-top:6px; flex-direction:column; }
#auth .row button { width:100%; }
#auth #authErr:empty { display:none; }
#auth #authErr { margin-top:10px; font-size:var(--sub); text-align:center; }
#auth .hint-text { display:none; }

/* ---------- grouped list (threads) ---------- */
.card, .group { background:var(--surface); border-radius:var(--r); overflow:hidden; box-shadow:var(--shadow); }
.card { padding:14px 16px; }
#threads { padding:12px 16px; display:flex; flex-direction:column; gap:18px; }
.newthread { background:var(--surface); border-radius:var(--r); padding:10px; box-shadow:var(--shadow); }
.newthread #newErr:empty { display:none; }
.newthread #newErr { margin-top:6px; }
#threadList { background:var(--surface); border-radius:var(--r); overflow:hidden; box-shadow:var(--shadow); }
#threadList:empty { display:none; }
.thread { display:flex; align-items:center; gap:14px; padding:12px 16px; cursor:pointer; position:relative; }
.thread + .thread::before { content:""; position:absolute; left:66px; right:0; top:0; height:0.5px; background:var(--sep); }
.thread:active { background:var(--surface2); }
.thread .count { flex:1; color:var(--label2); font-size:var(--sub); }
.thread::after { content:"\203A"; color:var(--label4); font-size:22px; line-height:1; margin-left:4px; }
.dot { width:10px; height:10px; border-radius:50%; background:var(--tint); flex:none; }
svg.sigil { display:block; flex:none; }
.footer-actions { display:flex; justify-content:space-between; padding:2px 6px; font-size:var(--sub); }
.footer-actions .link { font-size:var(--sub); }
.invite-card { background:var(--surface2); border-radius:var(--r); padding:14px 16px; }
.invite-card .code { font:600 28px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing:.14em; margin:6px 0 12px; color:var(--label); }

/* ---------- lens chips ---------- */
.lens-strip { position:sticky; top:52px; z-index:19; background:var(--bar); -webkit-backdrop-filter:var(--bar-blur); backdrop-filter:var(--bar-blur); border-bottom:0.5px solid var(--sep); padding:8px 16px; display:flex; flex-direction:column; gap:8px; }
.lens-strip #lensChips { display:flex; gap:8px; overflow-x:auto; scrollbar-width:none; }
.lens-strip #lensChips::-webkit-scrollbar { display:none; }
.lens-strip #lensChips:empty { display:none; }
.lens-strip .chip { display:inline-flex; align-items:center; gap:6px; padding:6px 12px; border-radius:999px; font-size:var(--sub); font-weight:500; background:var(--surface2); color:var(--label); border:1px solid var(--surface3); white-space:nowrap; cursor:pointer; }
.lens-strip .chip.active { background:var(--tint); border-color:var(--tint); color:#fff; }
.lens-strip .chip .x { opacity:.6; }
.lens-row { display:flex; align-items:center; gap:10px; }
.lens-row .ta { flex:1; display:flex; align-items:center; gap:8px; }
.lens-row .ta input { flex:1; min-width:0; padding:8px 12px; font-size:var(--sub); }
.lens-row .ta .hint { margin:0; min-height:0; white-space:nowrap; }
.lens-row #lock { font-size:var(--sub); flex:none; }

/* ---------- typeahead ---------- */
.ta { position:relative; }
.ta .sugg { position:absolute; left:0; right:0; top:100%; z-index:30; margin-top:6px; border-radius:var(--r); overflow:hidden; background:var(--surface); max-height:min(50vh, 360px); overflow-y:auto; -webkit-overflow-scrolling:touch; box-shadow:0 10px 30px rgba(31,43,28,.18); border:1px solid var(--surface3); }
.ta .sugg div { padding:11px 14px; cursor:pointer; position:relative; }
.ta .sugg div + div::before { content:""; position:absolute; left:14px; right:0; top:0; height:0.5px; background:var(--sep); }
.ta .sugg div:active { background:var(--surface2); }
.ta .sugg div small { display:block; color:var(--label2); font-size:var(--foot); }
.ta .hint { font-size:var(--foot); margin-top:4px; min-height:1.1em; text-align:right; }
.ta .hint .browse { font-size:var(--foot); color:var(--tint); }

/* ---------- conversation ---------- */
#msgs { flex:1; padding:12px 16px 8px; display:flex; flex-direction:column; gap:8px; }
.bubble { background:var(--surface); border:1px solid var(--surface3); border-radius:var(--r-bubble); padding:9px 13px; max-width:88%; align-self:flex-start; position:relative; cursor:pointer; box-shadow:var(--shadow); }
.bubble:active { opacity:.8; }
.bubble:has(.text) { background:var(--surface2); border-color:#cfe0c6; }
.bubble .coords { font-size:var(--sub); letter-spacing:.02em; word-break:break-word; color:var(--label2); }
.bubble.unread { margin-left:14px; }
.bubble.unread::before { content:""; position:absolute; top:50%; left:-14px; margin-top:-4px; width:8px; height:8px; border-radius:50%; background:var(--tint); }
.bubble .text { margin-top:6px; font-size:var(--body); color:var(--label); }
.bubble .meta { margin-top:5px; font-size:var(--cap); color:var(--label2); display:flex; gap:8px; flex-wrap:wrap; }
.bubble .meta b { color:var(--label); font-weight:600; }
.bubble .panel { margin-top:8px; padding-top:8px; border-top:0.5px solid var(--sep); }
.bubble .panel .ta input { font-size:var(--sub); padding:8px 12px; }

/* ---------- compose bar ---------- */
#composer { position:sticky; bottom:0; z-index:20; background:var(--bar); -webkit-backdrop-filter:var(--bar-blur); backdrop-filter:var(--bar-blur); border-top:0.5px solid var(--sep); padding:8px 12px calc(8px + env(safe-area-inset-bottom)); display:grid; grid-template-columns:1fr auto; grid-template-areas:"book book" "text send" "check check" "out out"; gap:8px; align-items:end; }
#composer #sendTa { grid-area:book; }
#composer #sendTa input { border-radius:999px; padding:8px 14px; font-size:var(--sub); }
#composer #sendTa .hint { position:absolute; right:12px; top:50%; transform:translateY(-50%); margin:0; min-height:0; }
#composer #text { grid-area:text; border-radius:20px; min-height:38px; padding:9px 14px; line-height:1.3; }
#composer #send { grid-area:send; width:36px; height:36px; padding:0; border-radius:50%; background:var(--tint); border-color:var(--tint); color:#fff; font-size:20px; line-height:1; display:flex; align-items:center; justify-content:center; }
#composer #send[disabled] { background:var(--surface3); border-color:var(--surface3); color:#fff; opacity:1; }
#check { grid-area:check; font-size:var(--foot); line-height:1.4; height:66px; overflow:hidden; color:var(--label2); }
#check .bad { color:var(--red); text-decoration:underline wavy var(--red); cursor:pointer; }
#check .fixes { margin-top:4px; white-space:nowrap; overflow-x:auto; scrollbar-width:none; }
#check .fix { display:inline-block; margin:0 6px 0 0; padding:3px 10px; border-radius:999px; cursor:pointer; font-size:var(--foot); background:var(--surface2); color:var(--tint); border:1px solid var(--surface3); }
#check .note { color:var(--label2); }
#check .line { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
#sendOut { grid-area:out; font-size:var(--foot); }
#sendOut:empty { display:none; }

/* ---------- lock screen ---------- */
#lockScreen { position:fixed; inset:0; z-index:50; background:var(--bg); display:flex; align-items:center; justify-content:center; padding:24px; }
.lock-card { width:min(100%, 320px); text-align:center; }
.lock-title { font-size:28px; font-weight:700; letter-spacing:-.02em; margin-bottom:20px; }

/* ======== refinements from the mockup ======== */
/* icons: thin line, inherit colour */
svg:not(.sigil) { stroke:currentColor; fill:none; stroke-width:1.9; stroke-linecap:round; stroke-linejoin:round; }
button svg, .rowbtn svg, .chip svg, .badge svg { width:18px; height:18px; flex:none; }
.link.icon { display:inline-flex; align-items:center; justify-content:center; width:36px; height:36px; border-radius:50%; }
.link.icon svg { width:22px; height:22px; }
#back svg { width:26px; height:26px; }

/* nav bar: three slots so the title stays centred */
header { display:grid; grid-template-columns:1fr auto 1fr; align-items:center; gap:0; padding:4px 8px; }
header .h-left { display:flex; align-items:center; justify-self:start; }
header .h-right { display:flex; align-items:center; gap:6px; justify-self:end; }
header h1 { justify-self:center; font-size:17px; font-weight:600; margin:0; display:flex; align-items:center; gap:8px; }
header .ver { position:absolute; right:12px; bottom:-14px; font:10px ui-monospace, "SF Mono", Menlo, monospace; color:var(--label4); }
header { position:sticky; }

/* sign in: hills framing the top, eye toggle */
#auth { position:relative; padding-top:28px; }
#auth .hills-top { position:absolute; left:0; right:0; top:0; height:150px; z-index:-1; opacity:.9;
  background:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 200' preserveAspectRatio='none'><path d='M0 0 L800 0 L800 90 C 650 140, 550 60, 400 100 C 250 140, 150 70, 0 110 Z' fill='%23e3ecdb'/><path d='M0 0 L800 0 L800 50 C 620 90, 520 30, 380 60 C 220 95, 120 40, 0 70 Z' fill='%23d4e2c8'/></svg>") top/100% 100% no-repeat; }
#auth .brand { margin-top:30px; }
#auth .brand img { width:104px; height:104px; border-radius:26px; box-shadow:var(--shadow); }
.field .eye { position:absolute; right:6px; top:50%; transform:translateY(-50%); width:34px; height:34px; padding:0; border:0; background:none; color:var(--label3); border-radius:50%; }
.field .eye.on { color:var(--tint); }
.field:has(.eye) input { padding-right:44px; }
#auth .card { max-width:360px; }
#auth .row button { display:flex; align-items:center; justify-content:center; gap:8px; }
#auth #register { border-color:#cfe0c6; background:#fff; }

/* threads: sigil tiles, action rows */
.thread .tile { width:40px; height:40px; border-radius:10px; background:var(--surface2); display:flex; align-items:center; justify-content:center; flex:none; }
.thread .tile svg { filter:none; }
.group.actions { padding:4px 0; }
.rowbtn { display:flex; align-items:center; gap:12px; width:100%; text-align:left; padding:12px 16px; border:0; border-radius:0; background:none; color:var(--tint); font-weight:500; }
.rowbtn + .rowbtn { border-top:0.5px solid var(--sep); }
.rowbtn:active { background:var(--surface2); }
.invite-card { position:relative; background:#e9f1e3; border:1px solid #d3e2c8; padding:16px 72px 16px 16px; }
.invite-card .badge { position:absolute; right:14px; top:14px; width:44px; height:44px; border-radius:50%; background:#fff; color:var(--tint); display:flex; align-items:center; justify-content:center; box-shadow:var(--shadow); }
.invite-card .badge svg { width:22px; height:22px; }
.invite-card .row { margin-top:4px; margin-right:-56px; }
.invite-card .row button { display:flex; align-items:center; justify-content:center; gap:8px; padding:10px 14px; }

/* lens strip: search-style field with a book button */
.ta.search { display:flex; align-items:center; position:relative; }
.ta.search .lead { position:absolute; left:11px; width:16px; height:16px; color:var(--label3); pointer-events:none; }
.ta.search input { padding-left:34px !important; padding-right:40px !important; }
.ta .browse { position:absolute; right:4px; top:50%; transform:translateY(-50%); width:32px; height:32px; padding:0; border:0; background:none; color:var(--tint); border-radius:50%; }
.ta .browse svg { width:19px; height:19px; }
.ta .hint { display:none; }
.ta:not(.search) .lead { display:none; }
.ta:not(.search) input { padding-right:40px; }
.ta .sugg div { display:flex; align-items:center; gap:10px; }
.ta .sugg .bk { width:18px; height:18px; color:var(--tint); flex:none; }
.lens-strip .chip { background:#e9f1e3; border-color:#cfe0c6; color:var(--tint-strong); font-weight:600; }
.lens-strip .chip svg { width:15px; height:15px; }
.lens-strip .chip.active { background:var(--tint); color:#fff; }
.lens-row #lock { color:var(--label2); }

/* bubbles: neutral and centred until decoded, then a side */
.bubble.veiled { align-self:center; max-width:94%; background:#eef2ea; border-color:#e2e9dc; box-shadow:none; }
.bubble.veiled .coords { color:var(--label2); text-align:center; }
.bubble.theirs { align-self:flex-start; background:#fff; border-color:#cfe0c6; }
.bubble.mine { align-self:flex-end; background:var(--tint); border-color:var(--tint); color:#fff; }
.bubble.mine .coords { color:rgba(255,255,255,.72); }
.bubble.mine .text { color:#fff; }
.bubble.mine .meta { color:rgba(255,255,255,.72); } .bubble.mine .meta b { color:#fff; }
.bubble.unread { margin-left:0; }
.bubble.veiled.unread::before { left:auto; right:-14px; } .bubble.veiled.unread { margin-right:14px; }

/* composer: book pill gets the icon treatment too */
#composer #sendTa { display:flex; align-items:center; }
#composer #sendTa .lead { display:block; position:absolute; left:12px; top:50%; transform:translateY(-50%); width:16px; height:16px; color:var(--label3); pointer-events:none; }
#composer #sendTa input { padding-left:36px !important; padding-right:40px !important; }
body.on-auth header { display:none; }
/* a bubble with an open decode panel sits above its siblings so its dropdown isn't covered */
.bubble { z-index:0; } .bubble:has(.panel) { z-index:5; }

/* ======== bookshelf: threads as covers on wooden shelves ======== */
#threadList { background:none; box-shadow:none; border-radius:0; overflow:visible;
  display:grid; grid-template-columns:repeat(3, 1fr); gap:30px 18px; padding:10px 14px 34px; }
.thread.cover { height:148px; padding:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:10px;
  background:linear-gradient(90deg, var(--c3) 0 7px, var(--c2) 7px 9px, var(--c) 9px 100%); border-radius:4px 9px 9px 4px;
  box-shadow:0 1px 0 rgba(255,255,255,.4) inset, 2px 3px 8px rgba(31,43,28,.22), 0 10px 0 -6px rgba(0,0,0,.08);
  position:relative; cursor:pointer; transform:translateY(0); transition:transform .12s; }
.thread.cover:active { transform:translateY(-3px); }
/* the plank: drawn from each cover and widened to meet its neighbours, so every row sits on a shelf */
.thread.cover::before { content:""; position:absolute; left:-18px; right:-18px; top:100%; margin-top:2px; height:9px;
  background:linear-gradient(#d4b991, #b9996e); border-radius:2px; box-shadow:0 4px 6px rgba(0,0,0,.12); z-index:-1; }
.thread.cover:nth-child(3n+1)::before { left:-14px; border-radius:3px 0 0 3px; }
.thread.cover:nth-child(3n)::before { right:-14px; border-radius:0 3px 3px 0; }
.thread.cover::after { content:none; }
.thread.cover .spine { position:absolute; left:11px; top:8px; bottom:8px; width:1px; background:rgba(255,255,255,.35); }
.thread.cover svg.sigil { margin-left:8px; filter:drop-shadow(0 1px 1px rgba(0,0,0,.2)); }
.thread.cover .count { flex:0; position:absolute; bottom:8px; right:10px; font:600 12px -apple-system, system-ui, sans-serif; color:rgba(31,43,28,.7); background:rgba(255,255,255,.55); padding:2px 7px; border-radius:999px; }
.thread.cover .dot { position:absolute; top:8px; right:8px; width:10px; height:10px; background:var(--tint); box-shadow:0 0 0 2px rgba(255,255,255,.8); }
.ta .sugg .none { color:var(--label2); font-size:var(--sub); }
