/* Knock Knock. One night look. Both fonts are served from /fonts (SIL Open
   Font License, the licence files sit beside them), Latin set only, which
   holds every Spanish letter; Georgia and the system face stand in while
   they load. */
@font-face { font-family: 'IM Fell English'; src: url('/fonts/im-fell-english-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; src: url('/fonts/atkinson-hyperlegible-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Atkinson Hyperlegible'; src: url('/fonts/atkinson-hyperlegible-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }

:root {
  color-scheme: dark;
  --night: #111824;
  --night-top: #141d2c;
  --night-low: #0f1520;
  --ink: #eceaf2;
  --muted: #b7c1cf;
  --muted-2: #a9b5c5;
  --card: #1b2533;
  --second: #1d2735;
  --edge: #55647a;
  --field: #0c121c;
  --field-edge: #6a7a92;
  --lamp: #f0b866;
  --lamp-ink: #1a1206;
  --name: #f3e3c4;
  --warn-ground: #241f1a;
  --mine: #2a3446;
  --theirs: #1f2a3a;
  --head: 'IM Fell English', Georgia, 'Times New Roman', serif;
  --body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: linear-gradient(180deg, var(--night-top), var(--night-low)) fixed, var(--night);
  color: var(--ink);
  font: 16px/1.45 var(--body);
  -webkit-text-size-adjust: 100%;
}
#app { min-height: 100vh; min-height: 100dvh; }
h1, h2, h3 { font-family: var(--head); font-weight: 400; line-height: 1.15; text-wrap: balance; margin: 0 0 .4em; }
h1 { font-size: 2rem; color: var(--name); }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.2rem; }
h1:focus, h2:focus { outline: none; }
p { margin: 0 0 .7em; }
a { color: var(--lamp); }
.muted { color: var(--muted); }
.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
:focus-visible { outline: 3px solid var(--lamp); outline-offset: 2px; }

/* ---- Pages ---- */
.page, .group {
  max-width: 640px; margin: 0 auto;
  padding-block: calc(24px + env(safe-area-inset-top, 0px)) calc(32px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 14px; align-content: start;
}
.page.wideview { max-width: 900px; }
.page > *, .group > * { min-width: 0; }
.card { background: var(--card); border-radius: 16px; padding: 16px; display: grid; gap: 8px; min-width: 0; }
.card.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card.wide { width: 100%; text-align: left; color: var(--ink); border: 1px solid transparent; cursor: pointer; font: inherit; }
.card.wide strong { font-family: var(--head); font-weight: 400; font-size: 1.25rem; color: var(--name); }
.card.wide:hover { border-color: var(--edge); }
pre.card { white-space: pre-wrap; word-break: break-word; font: inherit; margin: 0; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; align-items: center; }
.row > * { min-width: 0; }
header.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
header.top h1 { margin: 0; }

/* ---- Buttons ---- */
button { font: inherit; cursor: pointer; }
button.main, button.second {
  border-radius: 12px; padding: 10px 18px; min-height: 44px;
}
button.main { background: var(--lamp); color: var(--lamp-ink); border: 0; font-weight: 700; min-height: 50px; }
button.second { background: var(--second); color: var(--ink); border: 1px solid var(--edge); }
button.small { min-height: 40px; padding: 6px 14px; font-size: .95rem; }
button:disabled { opacity: .55; cursor: progress; }
.pill { background: var(--second); color: var(--ink); border: 1px solid var(--edge); border-radius: 999px; padding: 6px 14px; min-height: 40px; }
.pill[aria-pressed='true'] { background: var(--lamp); color: var(--lamp-ink); border-color: var(--lamp); font-weight: 700; }
.langs { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent; padding: 8px 10px; min-height: 44px; }
.tab[aria-current='page'] { color: var(--ink); border-bottom-color: var(--lamp); }
.person { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--second); color: var(--ink); border: 1px solid var(--edge); border-radius: 12px; padding: 10px 14px; min-height: 44px; text-align: left; }
.new { background: var(--lamp); color: var(--lamp-ink); border-radius: 999px; padding: 2px 10px; font-size: .85rem; font-weight: 700; }

/* ---- Fields ---- */
input, textarea, select {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid var(--field-edge); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea { resize: vertical; }
input[type='checkbox'] { width: 22px; height: 22px; min-height: 0; accent-color: var(--lamp); flex: none; margin: 2px 0 0; }
.field { display: grid; gap: 6px; color: var(--muted); }
.tick { display: flex; gap: 10px; align-items: flex-start; }
.code { display: block; font: 700 1.6rem/1.3 ui-monospace, 'Cascadia Mono', Consolas, monospace; letter-spacing: .08em; color: var(--name); background: var(--field); border: 1px dashed var(--edge); border-radius: 12px; padding: 14px; text-align: center; word-break: break-all; user-select: all; }
.note { margin: 0; color: var(--muted); }
.note.warn { color: var(--ink); background: var(--warn-ground); border: 1px solid var(--lamp); border-radius: 12px; padding: 10px 12px; }
.warnbox { background: var(--warn-ground); border: 1px solid var(--lamp); border-radius: 16px; padding: 16px; display: grid; gap: 8px; }

/* ---- The front door ---- */
.door { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: 1fr auto; position: relative; overflow: hidden; }
.door .house { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: cover; object-position: center top; }
.door h1 { position: relative; text-align: center; font-size: 46px; margin: calc(40px + env(safe-area-inset-top, 0px)) 16px 0; text-shadow: 0 2px 12px #000; }
.sheet {
  position: relative; grid-row: 2; background: rgba(17, 24, 36, .94); border-radius: 22px 22px 0 0;
  padding-block: 20px calc(24px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 12px; max-width: 640px; width: 100%; margin: 0 auto;
}

/* ---- A conversation ---- */
.talk { display: grid; gap: 10px; }
.holder { display: grid; gap: 10px; }
.thread { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.thread li { max-width: 86%; padding: 10px 14px; border-radius: 16px; position: relative; overflow-wrap: anywhere; }
.thread li p { margin: 0 0 .3em; }
.thread .mine { justify-self: end; background: var(--mine); border-bottom-right-radius: 4px; }
.thread .theirs { justify-self: start; background: var(--theirs); border: 1px solid #2c3a4f; border-bottom-left-radius: 4px; }
.thread .who { display: block; font-size: .85rem; color: var(--name); margin-bottom: 2px; }
.thread time { display: block; font-size: .8rem; color: var(--muted-2); text-align: right; }
.thread .sealed { color: var(--muted-2); font-style: italic; }
.composer { position: sticky; bottom: 0; background: linear-gradient(180deg, transparent, var(--night-low) 30%); padding-block: 14px calc(8px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; }
.composer .row textarea { flex: 1; }
.knock { min-height: 0; }

/* ---- The ghostly part ---- */
.quiet { text-align: center; padding: 28px 8px; color: var(--muted); }
.eyes { display: flex; justify-content: center; gap: 18px; margin-bottom: 12px; }
.eyes i { width: 12px; height: 16px; border-radius: 50%; background: var(--name); animation: blink 6s infinite; }
.eyes.still i { animation: none; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
.heard { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); margin: 0; font-style: italic; animation: fade 2.6s forwards; }
.heard .ring { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--lamp); animation: ring 1.4s ease-out; }
.heard.still, .heard.still .ring { animation: none; }
@keyframes ring { from { transform: scale(.3); opacity: 1; } to { transform: scale(2.2); opacity: 0; } }
@keyframes fade { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
.peek { position: absolute; width: 34px; height: auto; top: -26px; left: -10px; animation: peek 4.2s ease-in-out forwards; pointer-events: none; }
@keyframes peek { 0% { transform: translateY(20px); opacity: 0; } 25%, 70% { transform: translateY(0); opacity: .9; } 100% { transform: translateY(20px); opacity: 0; } }
body.crooked .page, body.crooked .group { transform: rotate(-.6deg); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  body.crooked .page, body.crooked .group { transform: none; }
}

/* ---- The printed recovery key ---- */
@media print {
  body { background: #fff; color: #000; }
  body * { visibility: hidden; }
  .print, .print * { visibility: visible; }
  .print { position: absolute; top: 2cm; left: 1cm; right: 1cm; color: #000; background: #fff; border: 2px solid #000; font-size: 22pt; }
}
