@font-face { font-family: "IM Fell English"; src: url("/fonts/im-fell-english-latin-400-normal.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "IM Fell English SC"; src: url("/fonts/im-fell-english-sc-latin-400-normal.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Reenie Beanie"; src: url("/fonts/reenie-beanie-latin-400-normal.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Young Serif"; src: url("/fonts/young-serif-latin-400-normal.woff2") format("woff2"); font-display: swap; }

/* Codex: the Control Star parchment, written in blue ink. */
:root {
  --paper: #e8dfc8;
  --paper-lift: rgba(255, 255, 255, 0.3);
  --paper-press: rgba(38, 66, 109, 0.1);
  --ink: #16223b;
  --muted: #3f4a5e;
  --blue: #26426d;
  --pen: #23408f;
  --cream: #f3ecd9;
  --danger: #8f3220;
  --rule: 1px solid var(--ink);
  --serif: "IM Fell English", Georgia, serif;
  --caps: "IM Fell English SC", Georgia, serif;
  --hand: "Reenie Beanie", "Bradley Hand", cursive;
  --slab: "Young Serif", Georgia, serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--paper) url("/grain.png") 0 0 / 192px 192px; color: var(--ink); }
body { font-family: var(--serif); font-weight: 400; font-synthesis: none; font-size: 18px; line-height: 1.35; -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; border-radius: 0; }
input, textarea { font: inherit; color: inherit; border-radius: 0; -webkit-appearance: none; appearance: none; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
[hidden] { display: none !important; }
.caps, .sec h3, .field label, .field .lab, .count, .letter { font-family: var(--caps); font-weight: 400; letter-spacing: 0.14em; text-transform: uppercase; }

/* ---------- Shell ---------- */
#app { min-height: 100%; }
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; min-height: 100dvh; }
.book { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 5; background: var(--paper) url("/grain.png") 0 0 / 192px 192px; padding: calc(var(--safe-t) + 20px) 22px 12px; border-bottom: 3px double var(--ink); }
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wordmark { margin: 0; line-height: 0; }
.wordmark svg { display: block; width: 112px; height: 68px; overflow: visible; }
.wordmark text { font-family: var(--slab); font-size: 23px; fill: var(--blue); }
.status { font-family: var(--caps); font-size: 14px; letter-spacing: 0.1em; color: var(--muted); display: inline-flex; align-items: center; gap: 7px; padding: 8px 0 8px 8px; white-space: nowrap; }
.status i { width: 9px; height: 9px; border-radius: 50%; background: #2f5d3a; }
.status.off i { background: #a84a14; }
.status.busy i { background: var(--blue); animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: 0.25; } }

.search { position: relative; margin-top: 16px; }
.search input { width: 100%; height: 50px; border: var(--rule); background: var(--paper-lift); padding: 0 44px 0 46px; font-size: 19px; outline: none; }
.search input::placeholder { color: var(--muted); opacity: 0.85; }
.search input:focus { border-color: var(--pen); box-shadow: inset 0 0 0 1px var(--pen); }
.search input::-webkit-search-cancel-button { display: none; }
.search svg { position: absolute; left: 15px; top: 15px; width: 20px; height: 20px; stroke: var(--muted); fill: none; stroke-width: 1.8; stroke-linecap: round; }
.search .clear { position: absolute; right: 6px; top: 6px; width: 38px; height: 38px; color: var(--muted); font-size: 24px; line-height: 1; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 22px 2px; margin: 0 -22px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 12px; border: var(--rule); font-size: 16.5px; font-weight: 400; color: var(--ink); display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.chip small { font-family: var(--slab); font-size: 12px; color: var(--muted); font-weight: 400; }
.chip.place { border-color: var(--blue); color: var(--blue); }
.chip.on { background: var(--ink); color: var(--cream); }
.chip.on small { color: var(--cream); opacity: 0.8; }
.chip.place.on { background: var(--blue); border-color: var(--blue); color: var(--cream); }
.chip-sep { flex: none; width: 1px; background: var(--ink); margin: 4px 2px; }

/* ---------- List ---------- */
.list { flex: 1; padding: 6px 14px 24px; }
.letter { font-size: 15px; color: var(--blue); padding: 16px 8px 2px; }
.row { display: flex; align-items: center; gap: 15px; width: 100%; text-align: left; padding: 10px 8px; }
.row:hover, .row.sel { background: var(--paper-lift); }
.row:active { background: var(--paper-press); }
.avatar { flex: none; width: 50px; height: 50px; margin: 4px; border-radius: 50%; border: 2px solid var(--blue); outline: 1px dashed rgba(38, 66, 109, 0.6); outline-offset: 3px; display: grid; place-items: center; font-family: var(--slab); font-size: 18px; color: var(--blue); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row .who { min-width: 0; flex: 1; }
.row .name { font-weight: 400; font-size: 25px; line-height: 1.12; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 16.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .tags { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.row .tags b { font-weight: 400; color: var(--blue); }
.count { font-size: 14px; color: var(--muted); padding: 14px 8px 0; }

.empty { text-align: center; padding: 64px 28px; color: var(--muted); }
.empty h2 { font-weight: 400; font-size: 28px; color: var(--ink); margin: 0 0 6px; }
.empty p { margin: 0 auto; max-width: 28ch; font-family: var(--hand); font-size: 28px; line-height: 1.05; color: var(--pen); }

.fab { position: sticky; bottom: calc(var(--safe-b) + 22px); align-self: flex-end; margin: 0 22px calc(var(--safe-b) + 22px) 0; z-index: 6; flex: none; height: 54px; padding: 0 22px; background: var(--blue); color: var(--cream); font-family: var(--caps); font-size: 17px; letter-spacing: 0.1em; display: inline-flex; align-items: center; gap: 10px; box-shadow: 3px 3px 0 var(--ink); }
.fab span { font-family: var(--serif); font-size: 26px; line-height: 1; margin-top: -3px; }
.foot { text-align: center; padding: 0 0 6px; }
.foot button { font-family: var(--caps); font-size: 13.5px; letter-spacing: 0.1em; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; padding: 10px; }

/* ---------- Contact page ---------- */
.detail { position: fixed; inset: 0; z-index: 10; background: var(--paper) url("/grain.png") 0 0 / 192px 192px; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(var(--safe-t) + 10px) 22px calc(var(--safe-b) + 40px); }
.bar { display: flex; justify-content: space-between; align-items: center; min-height: 46px; }
.bar button { height: 44px; padding: 0 4px; font-family: var(--caps); font-size: 16px; letter-spacing: 0.14em; color: var(--blue); }
.hero { text-align: center; padding: 14px 0 4px; }
.hero .avatar { width: 124px; height: 124px; font-size: 42px; margin: 6px auto 18px; outline-offset: 5px; }
.hero h1 { font-weight: 400; font-size: 38px; line-height: 1; margin: 0; overflow-wrap: anywhere; }
.hero p { margin: 6px 0 0; color: var(--muted); font-size: 19px; }
.acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 20px 0 6px; }
.act { flex: 1 1 74px; max-width: 110px; height: 60px; padding: 0 8px; border: var(--rule); background: var(--paper-lift); display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 15.5px; font-weight: 400; text-decoration: none; color: var(--ink); }
.act svg { width: 20px; height: 20px; stroke: var(--blue); fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sec { border-top: var(--rule); padding: 13px 0 15px; margin-top: 16px; }
.sec + .sec { margin-top: 0; }
.sec h3 { font-size: 14px; color: var(--muted); margin: 0 0 7px; }
.sec .val { font-size: 20px; overflow-wrap: anywhere; }
.sec .note, .field textarea { font-family: var(--hand); font-weight: 400; font-size: 31px; line-height: 1.06; color: var(--pen); }
.sec .note { white-space: pre-wrap; overflow-wrap: anywhere; }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.kv { display: grid; grid-template-columns: 1fr; gap: 14px; }
.kv a { text-decoration: underline; text-decoration-color: var(--blue); text-underline-offset: 4px; }

/* ---------- Add / edit ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(22, 34, 59, 0.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 620px; max-height: 100%; height: 100%; background: var(--paper) url("/grain.png") 0 0 / 192px 192px; display: flex; flex-direction: column; }
.sheet .bar { padding: calc(var(--safe-t) + 8px) 18px 8px; border-bottom: 3px double var(--ink); flex: none; }
.sheet .bar strong { font-family: var(--caps); font-weight: 400; font-size: 17px; letter-spacing: 0.14em; }
.sheet .bar .save { color: var(--cream); background: var(--blue); padding: 0 20px; height: 40px; letter-spacing: 0.1em; }
.form { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 20px 20px calc(var(--safe-b) + 60px); }
.photo-pick { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; }
.photo-pick .avatar { width: 88px; height: 88px; font-size: 30px; cursor: pointer; }
.photo-pick .btns { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.link { color: var(--blue); font-weight: 400; font-size: 18px; padding: 6px 0; text-decoration: underline; text-underline-offset: 4px; }
.link.danger { color: var(--danger); }
.field { margin-bottom: 16px; }
.field label, .field .lab { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, .tagbox { width: 100%; border: var(--rule); background: var(--paper-lift); padding: 11px 13px; font-size: 19px; outline: none; }
.field input:focus, .field textarea:focus, .tagbox:focus-within { border-color: var(--pen); box-shadow: inset 0 0 0 1px var(--pen); }
.field textarea { min-height: 132px; resize: vertical; display: block; font-size: 31px; line-height: 1.06; padding: 8px 13px; }
.field textarea::placeholder { color: var(--pen); opacity: 0.5; }
.field input.big { font-weight: 400; font-size: 27px; padding: 11px 13px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tagbox { display: flex; flex-wrap: wrap; gap: 7px; padding: 7px; cursor: text; }
.tagbox input { flex: 1; min-width: 110px; border: 0; background: none; padding: 5px 6px; width: auto; box-shadow: none !important; }
.tagbox .chip { height: 32px; padding: 0 4px 0 11px; }
.tagbox .chip button { width: 26px; height: 26px; font-size: 20px; line-height: 1; }
.sugg { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.sugg .chip { height: 30px; font-size: 15.5px; border-style: dashed; color: var(--muted); }
.sugg .chip.place { color: var(--blue); }
.hints { margin-top: 6px; font-family: var(--hand); font-size: 24px; line-height: 1.05; color: var(--pen); display: grid; gap: 2px; }
.hints .warn { color: var(--danger); }
.form-err { color: var(--danger); font-weight: 400; font-size: 18px; margin: 0 0 14px; }

/* ---------- First run / sign in ---------- */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 28px; }
.gate-card { width: 100%; max-width: 380px; text-align: center; }
.cover { width: 200px; margin: 0 auto 26px; padding: 22px 0 18px; border-top: 3px double var(--ink); border-bottom: 3px double var(--ink); display: grid; place-items: center; }
.cover .wordmark svg { width: 140px; height: 85px; }
.gate h1 { font-family: var(--caps); font-weight: 400; letter-spacing: 0.14em; font-size: 19px; margin: 0 0 6px; }
.gate p { color: var(--muted); margin: 0 0 20px; font-size: 18px; }
.gate .field { text-align: left; }
.btn { width: 100%; height: 52px; background: var(--blue); color: var(--cream); font-family: var(--caps); font-size: 17px; letter-spacing: 0.12em; box-shadow: 3px 3px 0 var(--ink); }
.btn:disabled { opacity: 0.5; }

/* ---------- Confirm / message ---------- */
.dialog-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(22, 34, 59, 0.55); display: grid; place-items: center; padding: 28px; }
.dialog { width: 100%; max-width: 340px; background: var(--paper) url("/grain.png") 0 0 / 192px 192px; border: var(--rule); box-shadow: 4px 4px 0 var(--ink); padding: 24px; text-align: center; }
.dialog h2 { font-weight: 400; font-size: 25px; line-height: 1.1; margin: 0 0 8px; }
.dialog p { color: var(--muted); margin: 0 0 20px; }
.dialog .two button { height: 48px; border: var(--rule); font-family: var(--caps); letter-spacing: 0.1em; font-size: 15px; }
.dialog .two .go { background: var(--danger); border-color: var(--danger); color: var(--cream); }
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 96px); transform: translateX(-50%); z-index: 50; background: var(--ink); color: var(--cream); padding: 9px 18px; font-family: var(--caps); font-size: 15px; letter-spacing: 0.08em; max-width: calc(100% - 40px); text-align: center; }

/* ---------- Wide screens: book on the left, open page on the right ---------- */
@media (min-width: 900px) {
  .shell { grid-template-columns: minmax(360px, 430px) 1fr; height: 100vh; }
  .book { border-right: var(--rule); height: 100vh; overflow-y: auto; }
  .top { padding: 26px 24px 12px; }
  .chips { margin: 0 -24px; padding: 12px 24px 2px; flex-wrap: wrap; overflow: visible; }
  .page { height: 100vh; overflow-y: auto; position: relative; }
  .detail { position: static; inset: auto; padding: 22px 48px 60px; max-width: 720px; margin: 0 auto; background: none; overflow: visible; }
  .detail .back { visibility: hidden; }
  .page-empty { height: 100%; display: grid; place-items: center; text-align: center; font-family: var(--hand); font-size: 30px; color: var(--pen); }
  .sheet-wrap { align-items: center; }
  .sheet { height: auto; max-height: 92vh; border: var(--rule); box-shadow: 5px 5px 0 var(--ink); overflow: hidden; }
  .sheet .bar { padding-top: 12px; }
  .kv { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 899px) { .page-empty { display: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
