:root {
  --paper: #f5f0e6;
  --paper-2: #ede6d8;
  --card: #fbf8f2;
  --ink: #24221f;
  --ink-2: #4a463f;
  --muted: #8a8275;
  --line: #e0d7c5;
  --gold: #a8834a;
  --gold-soft: #efe2c8;
  --allow: #3f6b4f;
  --deny: #9b4a3c;
  --mine: #2f2c28;
  --mine-ink: #f5f0e6;
  --code: #ebe4d4;
  --serif: "Songti TC", "Songti SC", "Noto Serif TC", "Noto Serif SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang TC", "PingFang SC", "Noto Sans TC", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1a1917;
    --paper-2: #23211e;
    --card: #24221f;
    --ink: #ece6da;
    --ink-2: #c9c1b2;
    --muted: #8f8778;
    --line: #36332e;
    --gold: #c9a467;
    --gold-soft: #3a3125;
    --allow: #7fae8c;
    --deny: #d38b7c;
    --mine: #ece6da;
    --mine-ink: #1a1917;
    --code: #2d2a26;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
code, pre { font-family: var(--mono); }

/* 印章 */
.seal {
  flex: none;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1.5px solid var(--gold);
  border-radius: 9px;
  color: var(--gold);
  font: 600 19px/1 var(--serif);
  background: var(--gold-soft);
}
.seal-lg { width: 64px; height: 64px; border-radius: 16px; font-size: 34px; margin: 0 auto 18px; }

/* 按钮 */
.btn {
  display: block; width: 100%;
  border-radius: 12px; padding: 12px 16px;
  font-weight: 600; border: 1px solid transparent;
}
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-line { background: transparent; border-color: var(--line); color: var(--deny); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: transparent; color: var(--ink-2);
  font-size: 22px; line-height: 1;
}
.icon-btn:active { background: var(--paper-2); }

/* ---------- 配对 ---------- */
.pair {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px max(24px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
}
.pair-card { width: 100%; max-width: 360px; text-align: center; }
.pair h1 { font: 600 24px/1.3 var(--serif); margin: 0; letter-spacing: .04em; }
.pair-sub { color: var(--muted); margin: 4px 0 28px; }
.pair form { text-align: left; display: grid; gap: 8px; }
.pair label { font-size: 14px; color: var(--ink-2); margin-top: 6px; }
.pair input {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: 17px/1.3 var(--sans);
}
#pair-code { font: 600 26px/1.2 var(--mono); letter-spacing: .35em; text-align: center; }
.pair input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.pair .btn { margin-top: 14px; }
.pair-error { color: var(--deny); min-height: 1.5em; margin: 4px 0 0; font-size: 14px; text-align: center; }
.pair-hint { color: var(--muted); font-size: 13px; margin-top: 24px; line-height: 1.8; }
.pair-hint code { background: var(--code); padding: 2px 6px; border-radius: 6px; color: var(--ink-2); }

/* ---------- 聊天 ---------- */
.chat {
  height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 760px; margin: 0 auto;
}
.top {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.who { flex: 1; min-width: 0; }
.who-name { font: 600 17px/1.3 var(--serif); letter-spacing: .05em; }
.who-status { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--allow); }
.dot.off { background: var(--deny); }

.log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.day {
  align-self: center;
  font-size: 12px; color: var(--muted);
  margin: 14px 0 6px; letter-spacing: .08em;
}
.empty {
  margin: auto; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.9;
}
.empty .seal { margin: 0 auto 12px; }

.row { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.row.mine { justify-content: flex-end; }
.row .seal { width: 28px; height: 28px; border-radius: 7px; font-size: 15px; margin-bottom: 18px; }
.row.cont .seal { visibility: hidden; }
.stack { display: flex; flex-direction: column; max-width: min(82%, 600px); min-width: 0; }
.row.mine .stack { align-items: flex-end; }
.bubble {
  padding: 9px 13px; border-radius: 16px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 15.5px;
}
.row.ake .bubble { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.row.mine .bubble { background: var(--mine); color: var(--mine-ink); border-bottom-right-radius: 5px; }
.time { font-size: 11px; color: var(--muted); margin: 3px 4px 0; }

.bubble code { background: var(--code); padding: 1px 5px; border-radius: 5px; font-size: .88em; }
.row.mine .bubble code { background: rgba(127,127,127,.25); }
.bubble pre {
  background: var(--code); border-radius: 10px; padding: 10px 12px; margin: 6px 0;
  overflow-x: auto; white-space: pre; font-size: 13px; line-height: 1.5;
}
.bubble pre code { background: none; padding: 0; font-size: inherit; }
.bubble a { color: var(--gold); }

.note {
  align-self: center; text-align: center;
  font-size: 12.5px; color: var(--muted);
  padding: 3px 12px; margin: 4px 0;
  border-radius: 999px; background: var(--paper-2);
  max-width: 90%; overflow-wrap: anywhere;
}
.note.allow::before { content: "✓ "; color: var(--allow); }
.note.deny::before { content: "✕ "; color: var(--deny); }

/* 审批卡片 */
.approvals { flex: none; padding: 0 12px; display: flex; flex-direction: column; gap: 10px; max-height: 55dvh; overflow-y: auto; }
.approvals:not(:empty) { padding-top: 10px; padding-bottom: 4px; border-top: 1px solid var(--line); }
.approval {
  background: var(--card);
  border: 1.5px solid var(--gold);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 6px 18px -12px rgba(0,0,0,.35);
}
.approval-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.approval-label { font-size: 12px; color: var(--gold); letter-spacing: .1em; }
.approval-tool { font: 600 16px/1.4 var(--serif); }
.approval-raw { font: 12px var(--mono); color: var(--muted); }
.approval-desc { margin: 4px 0 0; color: var(--ink-2); font-size: 14.5px; overflow-wrap: anywhere; }
.approval details { margin-top: 8px; }
.approval summary { font-size: 13px; color: var(--muted); cursor: pointer; }
.approval pre {
  margin: 6px 0 0; padding: 10px 12px; border-radius: 10px;
  background: var(--code); font-size: 12.5px; line-height: 1.5;
  max-height: 34dvh; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
}
.approval-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.approval-actions button { border-radius: 12px; padding: 11px 0; font-weight: 600; border: 1.5px solid; }
.deny-btn { background: transparent; border-color: var(--deny) !important; color: var(--deny); }
.allow-btn { background: var(--allow); border-color: var(--allow) !important; color: var(--paper); }
.approval.busy { opacity: .55; pointer-events: none; }
.approval-meta { font-size: 11.5px; color: var(--muted); margin-top: 8px; }

.thinking {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 18px; font-size: 13px; color: var(--muted);
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.composer {
  flex: none;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom)) 12px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.composer textarea {
  flex: 1; resize: none;
  max-height: 40dvh;
  padding: 9px 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: 16px/1.45 var(--sans);
}
.composer textarea:focus { outline: none; border-color: var(--gold); }
.send {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  border: none; background: var(--ink); color: var(--paper);
  display: grid; place-items: center;
}
.send:disabled { background: var(--line); color: var(--muted); cursor: default; }

/* 选单 */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(20,18,15,.38);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-panel {
  width: 100%; max-width: 520px;
  background: var(--paper); border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 8px;
}
.sheet h2 { font: 600 17px/1.3 var(--serif); margin: 0 0 6px; }
.devices { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.devices li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line);
}
.devices .dev-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.devices .dev-sub { font-size: 12px; color: var(--muted); }
.devices button { border: none; background: none; color: var(--deny); font-size: 14px; }
.devices .you { font-size: 12px; color: var(--gold); }
