:root {
  --paper: #e6ece4;
  --paper-2: #d9e2d8;
  --ink: #1b2420;
  --ink-2: #566159;
  --line: #b6c4b7;
  --seal: #b23a22;
  --ok: #2f6b45;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161d19; --paper-2: #1f2823; --ink: #dfe6df; --ink-2: #93a097;
    --line: #34423a; --seal: #d9553e; --ok: #7fc39a;
  }
}
:root[data-theme="dark"] {
  --paper: #161d19; --paper-2: #1f2823; --ink: #dfe6df; --ink-2: #93a097;
  --line: #34423a; --seal: #d9553e; --ok: #7fc39a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--sans); line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
main, header, footer { max-width: 40rem; margin: 0 auto; padding: 0 16px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-top: 1.25rem; }
.brand { font-size: 1.1rem; white-space: nowrap; }
.hanzi { color: var(--seal); font-size: 1.5rem; margin-right: 0.35rem; vertical-align: -0.05em; }
.lockline { color: var(--ink-2); display: flex; gap: 0.6rem; align-items: center; }
.lockline .dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--ink-2); display: inline-block; }
.lockline.open .dot { background: var(--ok); }
.lockline button { min-height: 2.2rem; padding: 0.3rem 0.8rem; }

section { padding: 1.75rem 0 1rem; border-top: 1px solid var(--line); }
section:first-child, .notice { border-top: 0; }
h1 { font-size: 1.35rem; font-weight: 600; margin: 0 0 0.5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
.lede { color: var(--ink-2); margin: 0 0 1.2rem; }
.notice { background: var(--paper-2); padding: 1rem; margin-top: 1.5rem; border-radius: 6px; }

.row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 0.6rem 0; }
label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--ink-2); font-size: 0.9rem; margin: 0.5rem 0; }
input, textarea, select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--paper-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 0.65rem 0.7rem; min-width: 0; width: 100%;
}
textarea { font-family: var(--mono); }
button {
  font: inherit; font-size: 16px; cursor: pointer; min-height: 44px; padding: 0.55rem 1rem; border-radius: 6px;
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink);
  flex: 1 1 auto;
}
button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button:disabled { opacity: 0.45; cursor: default; }
button.danger { color: var(--seal); }
:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }
.panel { background: var(--paper-2); padding: 1rem; border-radius: 8px; margin: 0.8rem 0; }
.panel label { margin: 0 0 0.6rem; }

/* a key: the seal, then the facts */
.key { display: grid; grid-template-columns: auto 1fr; gap: 0.6rem 1rem; padding: 1rem 0; border-top: 1px solid var(--line); align-items: start; }
.key:first-child { border-top: 0; }
.seal {
  font-family: var(--mono); font-size: 0.78rem; line-height: 1.4; letter-spacing: 0.03em; margin: 0;
  color: var(--seal); border: 2px solid var(--seal); border-radius: 3px;
  padding: 0.45rem 0.55rem; white-space: pre; user-select: all; -webkit-user-select: all;
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 3px var(--seal);
}
.key .name { font-weight: 600; font-size: 1.05rem; }
.meta { color: var(--ink-2); font-size: 0.9rem; margin: 0 0 0.8rem; }
.key .meta { margin: 0; }
.key .row { grid-column: 1 / -1; margin: 0.2rem 0 0; }
.key .row button { flex: 1 1 30%; }
.empty { color: var(--ink-2); padding: 0.5rem 0 1rem; }

.out { background: var(--paper-2); padding: 0.8rem; border-radius: 6px; font-family: var(--mono); font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; min-height: 3rem; margin: 0.6rem 0 0; }
.out:empty::before { content: "nothing sent yet"; color: var(--ink-2); }
pre.seed { font-family: var(--mono); font-size: 0.95rem; word-break: break-all; white-space: pre-wrap; background: var(--paper); padding: 0.8rem; border-radius: 4px; user-select: all; -webkit-user-select: all; margin: 0 0 0.6rem; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: flex-end; justify-content: center; padding: 16px; z-index: 5; }
.modal .panel { max-width: 36rem; width: 100%; margin: 0; padding-bottom: calc(1rem + env(safe-area-inset-bottom)); }

footer { padding-bottom: calc(4rem + env(safe-area-inset-bottom)); }
#status {
  position: fixed; left: 16px; right: 16px; bottom: calc(12px + env(safe-area-inset-bottom));
  max-width: 40rem; margin: 0 auto; padding: 0.7rem 0.9rem; border-radius: 8px;
  background: var(--ink); color: var(--paper); box-shadow: 0 4px 16px rgba(0,0,0,0.25); z-index: 4;
  pointer-events: none;
}
#status:empty { display: none; }
#status.err { background: var(--seal); color: #fff4ef; }

@media (max-width: 480px) {
  .lockline .view + button, .lockline .view { padding: 0.3rem 0.7rem; }
  .lockline:has(.view) .state { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
@media (min-width: 600px) {
  button { flex: 0 1 auto; }
  input, textarea, select { width: auto; min-width: 18rem; }
  .modal { align-items: center; }
}

/* the chat: the page itself is the scrollback, newest at the bottom */
#chat { padding-top: 0.5rem; border-top: 0; padding-bottom: 5rem; }
.day { color: var(--ink-2); font-size: 0.85rem; text-align: center; margin: 1.2rem 0 0.4rem; }
.msg { padding: 0.45rem 0; }
.msg .who { font-weight: 600; }
.msg.me .who { color: var(--seal); }
.msg .to { color: var(--ink-2); font-weight: 400; }
.msg .stamp { color: var(--ink-2); font-size: 0.8rem; margin-left: 0.5rem; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 0.1rem; }
.line { color: var(--ink-2); font-size: 0.9rem; padding: 0.25rem 0; overflow-wrap: anywhere; }
.line .stamp { font-size: 0.8rem; margin-right: 0.5rem; }
.lockline .view { min-height: 2.2rem; padding: 0.3rem 0.8rem; }

/* the composer sits above the home indicator; the log scrolls under it */
#composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex; gap: 0.5rem; align-items: flex-end;
  padding: 0.6rem 16px calc(0.6rem + env(safe-area-inset-bottom));
  background: var(--paper); border-top: 1px solid var(--line);
}
#composer textarea { flex: 1 1 auto; font-family: var(--sans); resize: none; max-height: 8rem; line-height: 1.35; }
#composer button { flex: 0 0 auto; }
#chat ~ footer #status, body:has(#chat:not([hidden])) #status { bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
@media (min-width: 600px) {
  #composer { left: 50%; transform: translateX(-50%); width: 100%; max-width: 40rem; }
  #composer textarea { min-width: 0; width: auto; }
}
