:root {
  --bg: #04060d;
  --panel: rgba(12, 16, 28, 0.86);
  --line: rgba(160, 180, 255, 0.18);
  --text: #e6ebf7;
  --dim: #8f9ab5;
  --accent: #ffcf5c;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
#space { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.label { position: absolute; left: 0; top: 0; font-size: 12px; white-space: nowrap; color: #cfd8f0; text-shadow: 0 0 6px #000, 0 0 2px #000; will-change: transform, opacity; }
.label.hi { color: #fff; font-size: 13px; }
.label.ring { color: rgba(150, 170, 220, 0.55); font-size: 11px; }

#top { position: fixed; top: 0; left: 0; right: 0; padding: calc(10px + env(safe-area-inset-top)) 12px 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; pointer-events: none; }
#top > * { pointer-events: auto; }
#searchForm { position: relative; flex: 1 1 240px; max-width: 420px; }
#search { width: 100%; padding: 10px 36px 10px 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--panel); outline: none; }
#search:focus { border-color: rgba(255, 207, 92, 0.6); }
#clearSearch { position: absolute; right: 6px; top: 5px; width: 30px; height: 30px; border: 0; background: none; font-size: 20px; color: var(--dim); }
#realm { margin-left: auto; padding: 9px 14px; border-radius: 22px; background: var(--panel); border: 1px solid var(--line); font-size: 12px; }
#realm.on { border-color: rgba(255, 207, 92, 0.7); color: var(--accent); }
#stats { padding: 9px 12px; border-radius: 22px; background: var(--panel); border: 1px solid var(--line); font-size: 12px; color: var(--dim); }
#search::-webkit-search-cancel-button { display: none; }
#hits { position: absolute; top: calc(100% + 6px); left: 0; right: 0; max-height: 40vh; overflow-y: auto; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
#hits button { display: block; width: 100%; text-align: left; padding: 9px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; }
#hits button:last-child { border-bottom: 0; }
#hits button:hover { background: rgba(255, 255, 255, 0.06); }
#hits .tag { color: var(--dim); font-size: 11px; margin-right: 6px; }
#hits .tour { color: var(--accent); }

#top { z-index: 3; }
#advice { position: fixed; z-index: 2; left: 12px; top: calc(60px + env(safe-area-inset-top)); width: min(380px, calc(100vw - 24px)); border-radius: 16px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px); }
#adviceToggle { display: block; width: 100%; padding: 10px 14px; border: 0; background: none; text-align: left; font-size: 13px; line-height: 1.5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#adviceToggle[aria-expanded="true"] { color: var(--accent); }
#adviceBody { padding: 0 12px 12px; max-height: calc(100vh - 220px); overflow-y: auto; }
#adviceTabs { display: flex; gap: 6px; margin-bottom: 10px; }
#adviceTabs button { flex: 1; padding: 6px 0; border-radius: 10px; border: 1px solid var(--line); background: none; font-size: 12px; color: var(--dim); }
#adviceTabs button.on { color: var(--accent); border-color: rgba(255, 207, 92, 0.6); }
#adviceList .item { padding: 10px 0; border-top: 1px solid var(--line); }
#adviceList .item:first-child { border-top: 0; padding-top: 2px; }
#adviceList .tag { display: inline-block; padding: 1px 8px; border-radius: 9px; font-size: 11px; background: rgba(255, 207, 92, 0.16); color: var(--accent); }
#adviceList p { margin: 6px 0 8px; font-size: 14px; line-height: 1.7; }
#adviceList .acts { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#adviceList .acts button { padding: 5px 12px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-size: 12px; }
#adviceList .acts button:hover { background: rgba(255, 255, 255, 0.12); }
#adviceList .done, #adviceList .none { color: var(--dim); font-size: 12px; }
#advice[hidden], #adviceBody[hidden] { display: none; }
#detail { position: fixed; right: 12px; top: 64px; bottom: 96px; width: min(380px, calc(100vw - 24px)); padding: 18px 18px 14px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); overflow-y: auto; backdrop-filter: blur(8px); }
#closeDetail { position: absolute; right: 8px; top: 6px; width: 34px; height: 34px; border: 0; background: none; font-size: 22px; color: var(--dim); }
#detail h2 { margin: 0 28px 4px 0; font-size: 18px; }
#detail .meta { color: var(--dim); font-size: 12px; margin-bottom: 12px; }
#detail .raw { white-space: pre-wrap; line-height: 1.7; margin: 0 0 14px; }
#detail h3 { font-size: 12px; color: var(--dim); font-weight: normal; margin: 16px 0 6px; letter-spacing: 1px; }
#detail .energy { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#detail .energy div { padding: 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); text-align: center; font-size: 12px; color: var(--dim); }
#detail .energy b { display: block; font-size: 17px; color: var(--text); font-weight: 600; }
#detail .flow { display: flex; width: 100%; justify-content: space-between; gap: 8px; padding: 7px 10px; margin-bottom: 4px; border: 0; border-radius: 9px; background: rgba(255, 255, 255, 0.05); text-align: left; }
#detail .flow:hover { background: rgba(255, 255, 255, 0.1); }
#detail .flow span:last-child { color: var(--dim); font-size: 12px; white-space: nowrap; }
#detail .excerpt { margin: -2px 0 8px; padding: 6px 10px; border-left: 2px solid var(--line); color: var(--dim); font-size: 12px; line-height: 1.6; }
#detail a { color: #9fc4ff; word-break: break-all; }
body.drop::after { content: '松开，把这本书放进宇宙'; position: fixed; inset: 12px; display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 18px; background: rgba(4, 6, 13, 0.7); color: var(--accent); font-size: 18px; pointer-events: none; }
#detail .chip { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; background: rgba(255, 207, 92, 0.16); color: var(--accent); margin-right: 4px; }
#detail audio { width: 100%; margin-bottom: 10px; }

#composer { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); pointer-events: none; }
#composer > * { pointer-events: auto; max-width: 720px; margin: 0 auto; }
#composeRow { display: flex; gap: 8px; align-items: flex-end; padding: 8px; border-radius: 26px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(8px); }
#text { flex: 1; min-height: 40px; max-height: 30vh; padding: 9px 6px; border: 0; background: none; resize: none; outline: none; line-height: 1.5; }
#mic, #book, #paste, #send { flex: none; height: 42px; border-radius: 21px; border: 0; font-weight: 600; }
#book, #paste { width: 42px; background: rgba(255, 255, 255, 0.1); }
#mic { width: 42px; background: rgba(255, 255, 255, 0.1); user-select: none; -webkit-user-select: none; touch-action: none; }
#mic.rec { background: #ff5a4d; animation: pulse 1s infinite; }
#send { padding: 0 18px; background: var(--accent); color: #1a1405; }
#send:disabled { opacity: 0.5; }
#notice { margin-bottom: 8px !important; padding: 9px 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255, 90, 77, 0.25); } }

#login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
#login[hidden], #empty[hidden], #outbox[hidden], #logout[hidden], #loginNote[hidden], #detail[hidden], #hits[hidden], #notice[hidden], #clearSearch[hidden] { display: none; }
#loginForm { display: grid; gap: 12px; width: min(300px, 80vw); text-align: center; }
#loginForm h1 { font-size: 20px; font-weight: 500; letter-spacing: 4px; }
#loginForm input, #loginForm button { padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); }
#loginForm button { background: var(--accent); color: #1a1405; border: 0; font-weight: 600; }
#loginError { color: #ff8a80; min-height: 1.2em; margin: 0; font-size: 13px; }
#empty { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; color: var(--dim); pointer-events: none; line-height: 1.9; }
#empty p { margin: 0; }

@media (max-width: 640px) {
  #mic, #book, #paste { width: 38px; }
  #send { padding: 0 14px; }
  #detail { left: 8px; right: 8px; width: auto; top: auto; bottom: 84px; max-height: 52vh; }
  #stats { display: none; }
}
@media (prefers-reduced-motion: reduce) { #mic.rec { animation: none; } }

/* 待上传（先存在手机里、连上了再补传） */
#outbox { margin-bottom: 8px !important; padding: 8px 8px 8px 14px; border-radius: 14px; background: var(--panel); border: 1px solid rgba(255, 207, 92, 0.35); font-size: 13px; display: flex; gap: 10px; align-items: center; }
#outbox.offline { border-color: rgba(255, 138, 128, 0.45); }
#outbox.stale { border-color: #ff8a80; }
#outboxText { flex: 1; line-height: 1.5; }
#outboxRetry { flex: none; padding: 5px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); font-size: 12px; }
#notice { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#noticeText { flex: 1 1 200px; line-height: 1.5; }
#noticeActs { display: flex; gap: 6px; flex-wrap: wrap; }
#noticeActs button, #detail .act { padding: 5px 12px; border-radius: 12px; border: 1px solid rgba(255, 207, 92, 0.5); background: rgba(255, 207, 92, 0.12); color: var(--accent); font-size: 12px; }
/* 别的 App 分享过来：先问一句「留下 / 丢弃」 */
#shareConfirm { margin-bottom: 8px; padding: 9px 14px; border-radius: 14px; background: var(--panel); border: 1px solid rgba(255, 207, 92, 0.5); font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#shareConfirm .shareText { flex: 1 1 200px; line-height: 1.5; overflow-wrap: anywhere; }
#shareConfirm .shareActs { display: flex; gap: 6px; }
#shareConfirm button { padding: 5px 12px; border-radius: 12px; border: 1px solid rgba(255, 207, 92, 0.5); background: rgba(255, 207, 92, 0.12); color: var(--accent); font-size: 12px; }
#shareConfirm button.link { border-color: var(--line); background: transparent; color: var(--dim); }
#noticeActs button.rec, #detail .act.rec { background: #ff5a4d; color: #fff; border-color: #ff5a4d; }
#detail .acts { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
#logout { padding: 9px 12px; border-radius: 22px; background: var(--panel); border: 1px solid var(--line); font-size: 12px; color: var(--dim); }
#loginForm .hint { margin: -4px 0 0; font-size: 12px; color: var(--dim); }
#loginForm .link { background: none; border: 0; color: var(--dim); font-size: 12px; font-weight: normal; text-decoration: underline; padding: 4px; }
#loginForm button:disabled { opacity: 0.5; }
#mic.latched { background: #ff5a4d; animation: pulse 1s infinite; }
