:root {
  color-scheme: light dark;
  --background: light-dark(#edf0e8,#171d19);
  --surface: light-dark(#fcfbf6,#242c25);
  --muted-surface: light-dark(#eef1e7,#323e33);
  --text: light-dark(#202f24,#e9efe4);
  --muted: light-dark(#516355,#b9c7ba);
  --border: light-dark(#cbd3c3,#48584b);
  --axis: light-dark(#8a9b8c,#788c7d);
  --strong: light-dark(#28583e,#9cd6ac);
  --inverse: light-dark(#fffdf5,#162b1d);
  --red: light-dark(#a12a3e,#f29aa7);
  --yellow: light-dark(#795600,#ebcc6f);
  --green: light-dark(#215a3a,#a1dda5);
  font: 16px/1.4 system-ui, sans-serif;
  background: var(--background);
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
.app { max-width: 585px; margin: auto; padding: 20px 14px max(24px,env(safe-area-inset-bottom)); }
.header, .contact-bar, .dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.header { margin: 2px 0 18px; }
h1, h2, p { margin: 0; }
h1 { font: 600 clamp(27px,6vw,39px)/.99 Georgia, serif; letter-spacing: -.035em; }
h2 { font-size: 18px; }
p, label { overflow-wrap: anywhere; }
.panel, dialog { border: 1px solid var(--border); background: var(--surface); border-radius: 15px; }
.gate, .conversation { padding: 14px; }
.gate, #unlock-form, #workspace { display: grid; gap: 12px; }
#vault-guide, .hint { color: var(--muted); font-size: 14px; }
#unlock-form label, dialog > label { display: grid; gap: 4px; }
input, select, textarea, button, .button-like { font: inherit; color: var(--text); }
button, .button-like {
  display: inline-flex; justify-content: center; align-items: center;
  min-height: 43px; padding: 6px 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; text-decoration: none; cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--strong); color: var(--inverse); border-color: var(--strong); font-weight: 650; }
button.quiet { background: transparent; }
input:not([type=checkbox]), select, textarea {
  min-width: 0; width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
input:not([type=checkbox]), select { min-height: 44px; }
textarea { display: block; resize: vertical; min-height: 52px; }
.contact-bar > div { display: flex; align-items: center; flex: 1; gap: 10px; min-width: 0; }
.contact-bar select { flex: 1; }
.presence { font-size: 12px; color: var(--muted); white-space: nowrap; }
.presence[data-online=true] { color: var(--green); font-weight: 700; }
.presence[data-online=true]::before { content: "●"; margin-right: 4px; }
.conversation { display: grid; }
.intention { justify-self: center; color: var(--strong); font-size: 13px; font-weight: 680; margin-bottom: 3px; }
#intention { text-align: center; }
.messages { max-height: 31vh; min-height: 110px; padding: 10px 1px; margin: 0; overflow: auto; list-style: none; display: grid; align-content: start; gap: 7px; }
.messages li { max-width: 86%; width: fit-content; padding: 5px 8px; border-radius: 9px; overflow-wrap: anywhere; white-space: pre-wrap; }
.messages .in { background: var(--muted-surface); }
.messages .out { background: var(--strong); color: var(--inverse); justify-self: end; }
.messages time { display: block; font-size: 11px; opacity: .88; margin-top: 2px; }
.messages .empty { max-width: 100%; color: var(--muted); justify-self: center; align-self: center; text-align: center; font-size: 14px; }
.send-form { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 7px; align-items: end; }
.compose { overflow: hidden; }
.tabs { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); border-bottom: 1px solid var(--border); }
.tabs button { border: 0; border-radius: 0; padding-inline: 3px; font-size: 14px; }
.tabs button[aria-selected=true] { color: var(--strong); background: var(--muted-surface); font-weight: 700; box-shadow: inset 0 -2px var(--strong); }
.tabs button:focus-visible { outline-offset: -3px; }
#board { padding: 8px 13px 13px; }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.graph { position: relative; border: 1px solid var(--border); min-height: 218px; }
.cells { display: grid; grid-template: repeat(6,1fr)/repeat(6,1fr); position: absolute; inset: 0; }
.cell { border: 0; border-radius: 0; min-height: 0; padding: 2px 3px; justify-content: end; align-items: start; background: transparent; color: var(--muted); font-size: 11px; }
.cells .cell:not(:nth-child(6n)) { border-right: 1px solid var(--border); }
.cells .cell:nth-child(-n+30) { border-bottom: 1px solid var(--border); }
.cells .cell:nth-child(6n+3) { border-right-color: var(--axis); }
.cells .cell:nth-child(n+13):nth-child(-n+18) { border-bottom-color: var(--axis); }
.quadrants { position: absolute; inset: 0; display: grid; grid-template: repeat(2,1fr)/repeat(2,1fr); pointer-events: none; }
.quadrants span { align-self: center; justify-self: center; color: var(--muted); background: var(--surface); padding: 1px 4px; border-radius: 4px; font-size: 12px; }
button.cell[aria-pressed=true] { background: var(--muted-surface); outline: 2px solid var(--strong); outline-offset: -2px; }
.point { position: absolute; transform: translate(-50%,-50%); border: 0; background: transparent; padding: 2px; white-space: nowrap; }
.point span { background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: 2px 4px; color: var(--ink); font-size: 12px; font-weight: 700; }
.point[aria-pressed=true] span { border-color: currentColor; }
.axis.top-axis { margin-bottom: 2px; }
.axis.bottom-axis { margin-top: 2px; }
.axis.bottom-axis span:nth-child(2) { text-align: center; }
.insight { display: grid; gap: 5px; padding-top: 9px; min-height: 33px; font-size: 14px; }
.insight p:first-child { color: var(--muted); }
.insight button { justify-self: start; }
.status { color: var(--red); font-size: 14px; margin-top: 7px; }
dialog { width: min(490px, calc(100% - 20px)); max-height: 90dvh; padding: 14px; overflow: auto; color: var(--text); }
dialog::backdrop { background: #0b1d14a0; }
dialog > * + * { margin-top: 10px; }
dialog > label.check { display: flex; align-items: center; flex-wrap: wrap; }
.check input { width: 20px; height: 20px; accent-color: var(--strong); }
.check span { font-size: 12px; color: var(--muted); }
.pair-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.qr-line { display: flex; justify-content: center; }
canvas { width: min(240px,100%); height: auto; image-rendering: pixelated; }
#export > * + *, #verify > * + * { margin-top: 7px; }
#verify { border-top: 1px solid var(--border); padding-top: 7px; }
#verify-key { display: block; overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.button-like:has(+ input:focus-visible) { outline: 2px solid var(--strong); outline-offset: 2px; }

.header-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 6px; }
.security-form { display: grid; gap: 7px; }
.security-form > button, .security-form > .pair-actions { justify-self: start; }
.security-form details { min-width: 0; }
.security-form details > * + * { margin-top: 6px; }
.security-form summary { cursor: pointer; font-weight: 620; }
.security-form .check { display: flex; align-items: center; gap: 6px; }
.recovery-list {
  display: grid; grid-template-columns: repeat(auto-fit,minmax(155px,1fr)); gap: 5px 8px;
  padding-left: 0; list-style: none; font: 13px/1.5 ui-monospace, monospace;
}

#qr { width: min(320px,100%); }
.camera-panel, .linked-pairing { display: grid; gap: 7px; }
.camera-panel video { width: 100%; max-height: min(40vh,320px); background: #121613; border-radius: 7px; }
.camera-panel button, .linked-pairing button { justify-self: start; }
