/* xiaoxi portal — 冷色、克制、可读性优先的终端界面。 */
:root {
  color-scheme: dark;
  --bg: #070a0c;
  --bg-raised: #0c1114;
  --bg-dock: rgba(10, 16, 19, .94);
  --fg: #cbd6d3;
  --dim: #70817e;
  --dimmer: #40514e;
  --her: #83e3c6;
  --her-soft: #58bda4;
  --warn: #d6ab68;
  --err: #d17c80;
  --ok: #79d6a0;
  --rule: rgba(143, 178, 169, .13);
  --rule-strong: rgba(143, 178, 169, .24);
  --fs: 15px;
  --lh: 1.75;
  --maxw: 1040px;
  --pad: clamp(18px, 4vw, 44px);
  --mono: "Cascadia Mono", "JetBrains Mono", "SF Mono", Consolas,
          "Noto Sans Mono CJK SC", "Microsoft YaHei Mono", monospace;
}
html[data-fs="big"] { --fs: 17px; }
html[data-fs="small"] { --fs: 13.5px; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 280px;
  background:
    radial-gradient(ellipse at 75% -10%, rgba(74, 131, 119, .07), transparent 48%),
    var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: var(--fs);
  line-height: var(--lh);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, #screen:focus-visible {
  outline: 1px solid var(--her-soft);
  outline-offset: 4px;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

#crt { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; position: relative; }

/* ── 顶栏 ───────────────────────────────────────────── */
#bar {
  position: sticky; top: 0; z-index: 8;
  display: flex; align-items: center; justify-content: flex-end; gap: 18px;
  min-height: 58px; padding: 10px var(--pad);
  border-bottom: 1px solid var(--rule);
  background: rgba(7, 10, 12, .86);
  backdrop-filter: blur(14px);
}
.bar-status { display: flex; align-items: center; gap: 16px; min-width: 0; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; color: var(--dim); font-size: 11px; white-space: nowrap; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--dim); flex: 0 0 auto; }
.dot.ok { background: var(--ok); box-shadow: 0 0 9px rgba(121, 214, 160, .5); }
.dot.bad { background: var(--err); }
.dot.wait { background: var(--warn); animation: pulse 1.6s ease-in-out infinite; }
#conn.ok { color: var(--ok); }
#conn.bad { color: var(--err); }
@keyframes pulse { 50% { opacity: .35; } }
button.ghost {
  display: grid; place-items: center; width: 27px; height: 27px; padding: 0;
  color: var(--dim); background: transparent; border: 1px solid var(--rule-strong);
  border-radius: 4px; font-size: 12px; cursor: pointer;
}
button.ghost:hover { color: var(--her); border-color: var(--her-soft); }

.volume-strip {
  display: flex; justify-content: space-between; gap: 16px;
  width: min(100%, var(--maxw)); margin: 0 auto; padding: 14px var(--pad) 0;
  color: var(--dimmer); font-size: 10px; letter-spacing: .04em;
}
.volume-k { color: var(--dim); margin-right: 12px; font-size: 9px; letter-spacing: .16em; }
.volume-right { white-space: nowrap; }
.tiny-square { display: inline-block; width: 4px; height: 4px; margin: 0 7px 2px; background: var(--her-soft); opacity: .65; }
#sid { color: var(--dimmer); }

/* ── 上下文余量 ─────────────────────────────────────── */
.vital { display: inline-flex; align-items: center; gap: 8px; }
.vital-label { color: var(--dimmer); font-size: 10px; white-space: nowrap; }
.vital-track { display: inline-block; width: 66px; height: 3px; background: var(--rule-strong); border-radius: 4px; overflow: hidden; }
.vital-fill { display: block; height: 100%; width: 100%; background: var(--her-soft); transition: width .65s cubic-bezier(.2,.8,.2,1), background .6s; }
.vital-fill.low { background: var(--warn); }
.vital-fill.crit { background: var(--err); }
.vital-num { min-width: 2ch; color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ── 输出 ───────────────────────────────────────────── */
#screen {
  flex: 0 0 auto; width: min(100%, var(--maxw)); margin: 0 auto;
  padding: 30px var(--pad) 40px;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
}
.ln { min-height: calc(var(--fs) * var(--lh)); max-width: 88ch; }
.ln.dim { color: var(--dim); }
.ln.her { color: var(--her); text-shadow: 0 0 16px rgba(131, 227, 198, .12); }
.ln.err { color: var(--err); }
.ln.warn { color: var(--warn); }
.ln.echo { color: #91a7a1; }
.ln.sys { color: var(--dimmer); font-size: .92em; }
.ln.blank { min-height: calc(var(--fs) * .72); }
.ln.echo .prompt, .prompt { color: var(--her-soft); user-select: none; }
/* 取件行：链接本身就在终端里，不用另开面板。下划线只在这里出现 ——
 * 整页只有这一处东西是可以拿走的。 */
.ln.link { padding-left: 1.6em; }
.ln.link a {
  color: var(--her); text-decoration: none;
  border-bottom: 1px dashed rgba(131, 227, 198, .45);
  transition: border-color .25s, color .25s;
}
.ln.link a:hover, .ln.link a:focus-visible { color: #a5f2db; border-bottom-color: var(--her); }
.ln.link a::after { content: " ↓"; color: var(--her-soft); opacity: .7; }
/* Tab 补全的候选。故意做成一个个带框的小块，而不是空格连成一行 ——
 * `cat   clear` 挤成一行会被读成一条命令，玩家以为那是补进去的字。 */
.ln.cands { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-left: 1.6em; }
.ln.cands .cand { color: var(--her-soft); }
.ln.cands .cand::before { content: "·"; margin-right: 5px; color: var(--dimmer); }
::selection { color: #e4f4ed; background: rgba(88, 189, 164, .28); }

/* ── 固定输入坞 ─────────────────────────────────────── */
#console-dock {
  position: sticky; bottom: 0; z-index: 7; margin-top: auto;
  padding: 0 var(--pad) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(7,10,12,.65), var(--bg-dock) 22%);
  border-top: 1px solid var(--rule);
  backdrop-filter: blur(16px);
}
#console-dock > * { width: min(100%, calc(var(--maxw) - 2 * var(--pad))); margin-left: auto; margin-right: auto; }
/* 光标槽恒占 6px，不随聚焦/输入法变宽窄 —— 宽度一变，整行正文就横跳
 * （上一版把宽度归零，实测聚焦瞬间正文左移 17px，比双光标还显眼）。 */
#caret-line { display: flex; align-items: center; gap: 5px; min-height: 47px; }
#caret { display: inline-block; width: 6px; height: 1.1em; flex: 0 0 auto; background: var(--her); opacity: .85; }
#caret.blink { animation: blink 1.1s step-end infinite; }
/* 一个光标就够了。
 *
 * 输入框里本来就有浏览器画的插入符（#hidden-input 的 caret-color），
 * 这里再自绘一个块光标、两者同时闪，页面上就是两个光标：桌面端和移动端
 * 一模一样，因为 DOM 是同一套。
 *
 * 分工按「有没有字」分，不按「有没有焦点」分 —— 这样任何时刻只画一个：
 *   空行 → 自绘块光标出在槽里（它就是这一行的光标），原生插入符设成透明
 *          （不这么做，那个竖条会压在 placeholder 第一个字上）；
 *   有字 → 自绘的让位，交给原生插入符（caret-shape: block，同款方块），
 *          因为它才跟得上光标移动、点选和删改。
 * 两种状态只换"谁画"，槽位尺寸不动，所以正文位置始终不跳。 */
#caret-line.filled #caret { background: transparent; animation: none; }
#caret-line:not(.filled) #hidden-input { caret-color: transparent; }
@keyframes blink { 50% { opacity: 0; } }
#hidden-input {
  min-width: 0; flex: 1; height: 38px; padding: 0;
  color: var(--fg); caret-color: var(--her); caret-shape: block;
  background: transparent; border: 0; outline: none;
  font-size: 16px; line-height: 1.4;
}
#hidden-input::placeholder { color: var(--dimmer); opacity: 1; }
#hidden-input:disabled { cursor: not-allowed; }
#queue-state { flex: 0 0 auto; color: var(--dimmer); font-size: 10px; }
#queue-state.active { color: var(--dim); }
.dock-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 20px; }
.hint { color: var(--dim); font-size: 11px; opacity: 0; transition: opacity .7s; }
.hint.show { opacity: 1; }
.key-help { flex: 0 0 auto; color: var(--dimmer); font-size: 10px; white-space: nowrap; }
kbd { padding: 0 3px; color: var(--dim); font: inherit; }
.key-sep { margin: 0 8px; }
#jump-latest {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: 104px; z-index: 9;
  padding: 5px 11px; border: 1px solid var(--rule-strong); border-radius: 4px;
  color: var(--her-soft); background: var(--bg-raised); font-size: 11px; cursor: pointer;
  box-shadow: 0 5px 20px rgba(0,0,0,.25);
}

/* ── CRT 覆盖层：很轻，不牺牲文字对比度 ─────────────── */
#scanlines, #vignette, #flicker { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
#scanlines { background: repeating-linear-gradient(to bottom, rgba(255,255,255,.014) 0, rgba(255,255,255,.014) 1px, transparent 1px, transparent 4px); }
#vignette { background: radial-gradient(ellipse at 50% 40%, transparent 55%, rgba(0,0,0,.4)); }
#flicker { background: rgba(131,227,198,.009); animation: flick 9s steps(1) infinite; }
@keyframes flick { 0%, 96%, 100% { opacity: 0; } 96.5% { opacity: 1; } 97.5% { opacity: 0; } }

@media (max-width: 700px) {
  :root { --fs: 14px; --lh: 1.72; --pad: 16px; }
  #bar { min-height: 53px; gap: 10px; }
  .vital-label { display: none; }
  .bar-status { gap: 11px; }
  .volume-strip { padding-top: 12px; font-size: 9px; }
  .volume-right { font-size: 0; }
  #sid { font-size: 9px; }
  #screen { padding-top: 23px; padding-bottom: 27px; }
  .vital-track { width: 48px; }
  #console-dock > * { width: 100%; }
  .key-help { display: none; }
  #jump-latest { bottom: 100px; }
}
@media (max-height: 480px) {
  #screen { padding-top: 14px; }
  .volume-strip { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  #flicker, #caret.blink, .dot.wait { animation: none; }
  .vital-fill { transition: none; }
}
