/* app.css — 遥控器界面（暗色、移动优先、无外链、无框架）
 *
 * 设计取向：一台放在床头的实体遥控器。哑光深色机身、发丝级分隔线、按键有真实
 * 的凹面与回弹，读数区像仪表面板（等宽等宽数字）。夜间用：不刺眼、不要花。
 *
 * 硬约束：
 *   - 只用系统字体（无 Google Fonts / CDN），字体栈里不带任何外链
 *   - 正文对比度 ≥ 4.5:1（--ink / --ink-dim 均按 #14171e 与 #0b0d11 底面验算）
 *   - 链路状态不只靠颜色：颜色 + 字形 + 文字三重区分
 *   - 安全区：env(safe-area-inset-*) 覆盖刘海与手势条
 */

:root {
  color-scheme: dark;

  /* 机身 */
  --bg: #0b0d11;
  --bg-deep: #07090c;
  --surface: #14171e;
  --surface-2: #1b1f28;
  --surface-3: #232834;
  --line: #2a3040;
  --line-soft: #1f242f;

  /* 文字（对照 --surface 均 ≥ 4.5:1） */
  --ink: #e9edf5;
  --ink-dim: #a7b0c2;
  --ink-mute: #8d97a9;

  /* 状态色：lan 绿 / relay 蓝 / connecting 琥珀 / offline 红 / idle 灰 */
  --lan: #3ddc97;
  --lan-dim: #12352a;
  --relay: #82aaff;
  --relay-dim: #16233d;
  --connecting: #f7c04a;
  --connecting-dim: #372c15;
  --offline: #ff7078;
  --offline-dim: #3a1a1e;
  --idle: #8d97a9;
  --idle-dim: #1e222b;

  --danger: #ff7078;

  /* 字体：全部本机字体，零外链 */
  --fb: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fm: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;

  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);

  --tap: 46px; /* 最小可点尺寸 */
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 420px at 50% -12%, rgba(60, 90, 160, .16), transparent 60%),
    radial-gradient(600px 300px at 100% 108%, rgba(61, 220, 151, .07), transparent 62%),
    var(--bg);
  color: var(--ink);
  font-family: var(--fb);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* 极细噪点，给哑光表面一点颗粒感（纯 CSS，无图片） */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .035;
  background-image:
    repeating-linear-gradient(0deg, #fff 0 1px, transparent 1px 2px),
    repeating-linear-gradient(90deg, #fff 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
}

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--surface-3); color: var(--ink); padding: 10px 14px; z-index: 99;
  border-radius: var(--r-sm);
}
.skip:focus { left: 12px; top: 12px; }

:focus-visible {
  outline: 2px solid var(--relay);
  outline-offset: 2px;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
code, kbd, .mono { font-family: var(--fm); }
kbd {
  display: inline-block; padding: 0 5px; border-radius: 4px;
  background: var(--surface-3); border: 1px solid var(--line);
  font-size: 12px; line-height: 1.6;
}

/* ───────────────────────── 骨架 ───────────────────────── */

.shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
}

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--sa-t)) calc(14px + var(--sa-r)) 10px calc(14px + var(--sa-l));
  border-bottom: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  position: sticky; top: 0; z-index: 20;
}

.brand { display: flex; align-items: center; gap: 9px; margin-right: auto; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(150deg, var(--lan), #1d7d6b);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18), 0 3px 10px rgba(61, 220, 151, .22);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 6px; border-radius: 3px;
  background: var(--bg-deep); opacity: .62;
}
.brand-text { font-size: 14.5px; font-weight: 600; letter-spacing: .04em; }
.brand-text em { font-style: normal; color: var(--ink-mute); font-weight: 500; margin-left: 2px; }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.link-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px 5px 8px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; letter-spacing: .01em;
  border: 1px solid var(--line);
  background: var(--idle-dim); color: var(--idle);
  white-space: nowrap;
}
.link-chip .link-glyph { font-size: 13px; line-height: 1; }
.link-chip[data-state="lan"]        { color: var(--lan);        background: var(--lan-dim);        border-color: color-mix(in srgb, var(--lan) 38%, var(--line)); }
.link-chip[data-state="relay"]      { color: var(--relay);      background: var(--relay-dim);      border-color: color-mix(in srgb, var(--relay) 38%, var(--line)); }
.link-chip[data-state="connecting"] { color: var(--connecting); background: var(--connecting-dim); border-color: color-mix(in srgb, var(--connecting) 38%, var(--line)); }
.link-chip[data-state="offline"]    { color: var(--offline);    background: var(--offline-dim);    border-color: color-mix(in srgb, var(--offline) 42%, var(--line)); }

.icon-btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-dim);
  border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.icon-btn:hover { color: var(--ink); border-color: var(--surface-3); }

.main {
  flex: 1;
  padding: 14px calc(14px + var(--sa-r)) calc(96px + var(--sa-b)) calc(14px + var(--sa-l));
}

.screen[hidden] { display: none; }

/* ───────────────────────── 通用块 ───────────────────────── */

.card {
  background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 88%, var(--bg)));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 10px 28px rgba(0, 0, 0, .28);
}

.card-truth { border-color: color-mix(in srgb, var(--connecting) 30%, var(--line)); }
.card-truth h2 { color: var(--connecting); }

.block-head {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.block-head h2 { font-size: 14px; font-weight: 650; letter-spacing: .02em; }
.block-head h3 { font-size: 13px; font-weight: 600; }
.hint { font-size: 12.5px; color: var(--ink-mute); line-height: 1.5; }
.subblock { padding: 12px 0; border-top: 1px solid var(--line-soft); }
.subblock:first-of-type { border-top: 0; padding-top: 2px; }
.subblock h3 { margin-bottom: 6px; }
.subblock .hint { margin-bottom: 10px; }

.truth-list { list-style: none; display: grid; gap: 9px; margin-top: 4px; }
.truth-list li {
  position: relative; padding-left: 20px; font-size: 13px; color: var(--ink-dim); line-height: 1.6;
}
.truth-list li::before {
  content: "→"; position: absolute; left: 0; top: 0; color: var(--ink-mute);
}
.truth-list b { color: var(--ink); }

.kv { display: grid; gap: 8px; }
.kv > div { display: flex; gap: 12px; align-items: baseline; }
.kv dt { flex: 0 0 88px; font-size: 12.5px; color: var(--ink-mute); }
.kv dd { font-size: 13px; color: var(--ink); word-break: break-all; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--ink-mute); margin-bottom: 6px; }

input[type="text"], input[type="email"], textarea {
  width: 100%;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 11px 12px;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #6b7587; }
input[type="text"]:focus, input[type="email"]:focus, textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--relay) 60%, var(--line));
  box-shadow: 0 0 0 3px rgba(130, 170, 255, .14);
}
textarea { resize: vertical; min-height: 68px; }

.code-input { letter-spacing: .12em; font-size: 16px; }

.text-row { display: flex; gap: 8px; align-items: stretch; margin-top: 10px; }
.text-row > input { flex: 1; min-width: 0; }

.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--r-md);
  padding: 11px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  min-height: var(--tap);
  transition: transform .06s, background .15s, border-color .15s, color .15s;
}
.btn:active { transform: translateY(1px); }
.btn:hover { border-color: var(--surface-3); background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, #2f7d68, #226251);
  border-color: #2f8a72;
  color: #eafff7;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .16) inset, 0 6px 16px rgba(35, 110, 90, .3);
}
.btn-primary:hover { background: linear-gradient(180deg, #37937a, #2a7663); border-color: #3aa286; }

.btn-ghost { background: transparent; color: var(--ink-dim); }
.btn-ghost:hover { color: var(--ink); background: var(--surface-2); }

.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn-danger:hover { background: var(--offline-dim); border-color: var(--danger); color: #ffd9db; }

.btn-block { width: 100%; margin-top: 4px; }
.btn-sm { padding: 6px 11px; font-size: 12px; min-height: 34px; margin-left: auto; }

.field-error {
  margin-top: 9px; padding: 9px 11px;
  font-size: 12.5px; line-height: 1.5;
  color: #ffd9db;
  background: var(--offline-dim);
  border: 1px solid color-mix(in srgb, var(--offline) 42%, var(--line));
  border-left-width: 3px;
  border-radius: var(--r-sm);
  white-space: pre-wrap;
}
.field-error[hidden] { display: none; }

.cooldown { font-size: 12.5px; color: var(--ink-mute); align-self: center; font-variant-numeric: tabular-nums; }

.badge {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 650; letter-spacing: .02em;
  border: 1px solid var(--line); background: var(--idle-dim); color: var(--idle);
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-off         { color: var(--idle);       background: var(--idle-dim); }
.badge-trial       { color: var(--connecting); background: var(--connecting-dim); border-color: color-mix(in srgb, var(--connecting) 36%, var(--line)); }
.badge-permanent   { color: var(--lan);        background: var(--lan-dim);        border-color: color-mix(in srgb, var(--lan) 36%, var(--line)); }
.badge-subscribed  { color: var(--relay);      background: var(--relay-dim);      border-color: color-mix(in srgb, var(--relay) 36%, var(--line)); }

.test-result {
  margin-top: 10px; padding: 9px 11px; border-radius: var(--r-sm);
  font-size: 12.5px; font-family: var(--fm);
  background: var(--bg-deep); border: 1px solid var(--line); color: var(--ink-dim);
  white-space: pre-wrap; word-break: break-all;
}
.test-result[data-tone="ok"]   { border-color: color-mix(in srgb, var(--lan) 40%, var(--line)); color: var(--lan); }
.test-result[data-tone="bad"]  { border-color: color-mix(in srgb, var(--offline) 40%, var(--line)); color: #ffd9db; }

.empty-note { font-size: 12.5px; color: var(--ink-mute); padding: 8px 2px 0; }

.footnote { margin-top: 16px; font-size: 11.5px; color: var(--ink-mute); line-height: 1.6; }

.switch { display: flex; gap: 10px; align-items: flex-start; margin-top: 12px; font-size: 12.5px; color: var(--ink-dim); }
.switch input { flex: 0 0 auto; width: 18px; height: 18px; margin-top: 2px; accent-color: #2f8a72; }

/* ───────────────────── 链路状态条（遥控器顶部） ───────────────────── */

.link-strip {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  border-left: 4px solid var(--idle);
  background: var(--idle-dim);
  margin-bottom: 12px;
}
.link-strip-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.link-strip-text strong { font-size: 13.5px; color: var(--idle); letter-spacing: .01em; }
.link-strip-text span { font-size: 11.5px; color: var(--ink-dim); }
.link-strip-device {
  margin-left: auto; font-family: var(--fm); font-size: 11px; color: var(--ink-mute);
  text-align: right; max-width: 42%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.link-strip[data-state="lan"]        { border-left-color: var(--lan);        background: var(--lan-dim);        border-color: color-mix(in srgb, var(--lan) 30%, var(--line)); }
.link-strip[data-state="lan"]        strong { color: var(--lan); }
.link-strip[data-state="relay"]      { border-left-color: var(--relay);      background: var(--relay-dim);      border-color: color-mix(in srgb, var(--relay) 30%, var(--line)); }
.link-strip[data-state="relay"]      strong { color: var(--relay); }
.link-strip[data-state="connecting"] { border-left-color: var(--connecting); background: var(--connecting-dim); border-color: color-mix(in srgb, var(--connecting) 30%, var(--line)); }
.link-strip[data-state="connecting"] strong { color: var(--connecting); }
.link-strip[data-state="connecting"] .link-strip-text strong::after {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 7px; border-radius: 50%;
  background: currentColor; animation: pulse 1.1s ease-in-out infinite;
}
.link-strip[data-state="offline"]    { border-left-color: var(--offline);    background: var(--offline-dim);    border-color: color-mix(in srgb, var(--offline) 34%, var(--line)); }
.link-strip[data-state="offline"]    strong { color: var(--offline); }

@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ───────────────────────── 画布舞台 ───────────────────────── */

.stage {
  position: relative;
  border-radius: var(--r-md);
  background:
    linear-gradient(180deg, #0a0c10, #05070a);
  border: 1px solid var(--line);
  overflow: hidden;
  aspect-ratio: 16 / 9;
  display: grid; place-items: center;
  margin-bottom: 14px;
  box-shadow: inset 0 0 42px rgba(0, 0, 0, .7);
}
.stage::after { /* 扫描线，让画面像屏幕而不是贴图 */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(180deg, rgba(255, 255, 255, .028) 0 1px, transparent 1px 3px);
}
#screen-canvas { width: 100%; height: 100%; display: block; object-fit: contain; }

.stage-empty {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 6px;
  text-align: center; padding: 18px; pointer-events: none;
}
.stage-empty-title { font-size: 13.5px; color: var(--ink-dim); font-weight: 600; }
.stage-empty-sub { font-size: 12px; color: var(--ink-mute); max-width: 32ch; margin: 0 auto; }
.stage[data-has-frame="1"] .stage-empty { display: none; }

.stats {
  position: absolute; left: 8px; bottom: 8px;
  display: flex; gap: 4px;
  font-family: var(--fm); font-size: 10.5px; letter-spacing: .02em;
}
.stat {
  display: inline-flex; align-items: baseline; gap: 4px;
  padding: 3px 7px; border-radius: 6px;
  background: rgba(6, 8, 11, .78);
  border: 1px solid rgba(255, 255, 255, .1);
  color: var(--ink-mute);
  backdrop-filter: blur(6px);
}
.stat b { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 600; }

/* ───────────────────────── D-pad ───────────────────────── */

.dpad-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.dpad {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  width: min(78vw, 292px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 14px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 30%, #262b36, #14171e 58%, #0e1116 100%);
  border: 1px solid var(--line);
  box-shadow:
    0 14px 30px rgba(0, 0, 0, .48),
    inset 0 1px 0 rgba(255, 255, 255, .07);
}
.dpad::before { /* 内圈凹槽 */
  content: ""; position: absolute; inset: 12%;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .045);
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, .55);
  pointer-events: none;
}

.key {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, #262c38, #191d25);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: grid; place-items: center;
  min-height: var(--tap);
  box-shadow: 0 2px 0 #0c0f14, 0 3px 9px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .09);
  transition: transform .06s, box-shadow .06s, background .12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
.key:active, .key[data-pressed="1"] {
  transform: translateY(2px);
  box-shadow: 0 0 0 #0c0f14, 0 1px 4px rgba(0, 0, 0, .5), inset 0 2px 6px rgba(0, 0, 0, .55);
  background: linear-gradient(180deg, #1f242e, #171b22);
}
.key:disabled { opacity: .42; cursor: not-allowed; transform: none; }

.key-up    { grid-area: 1 / 2; border-radius: var(--r-md) var(--r-md) 4px 4px; }
.key-left  { grid-area: 2 / 1; border-radius: var(--r-md) 4px 4px var(--r-md); }
.key-ok    {
  grid-area: 2 / 2;
  font-size: 13.5px; letter-spacing: .06em;
  background: linear-gradient(180deg, #2c6f5d, #1f5546);
  border-color: #2f8a72;
  color: #eafff7;
  box-shadow: 0 3px 0 #10241f, 0 6px 18px rgba(35, 110, 90, .34), inset 0 1px 0 rgba(255, 255, 255, .18);
  border-radius: 50%;
}
.key-ok:active { box-shadow: 0 0 0 #10241f, 0 1px 6px rgba(0, 0, 0, .5), inset 0 2px 7px rgba(0, 0, 0, .5); }
.key-right { grid-area: 2 / 3; border-radius: 4px var(--r-md) var(--r-md) 4px; }
.key-down  { grid-area: 3 / 2; border-radius: 4px 4px var(--r-md) var(--r-md); }

.key-rail {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.key-util { font-size: 12.5px; min-height: 42px; letter-spacing: .02em; }
.key-power {
  color: #ffd9db;
  border-color: color-mix(in srgb, var(--offline) 36%, var(--line));
  background: linear-gradient(180deg, #3a2126, #251518);
  box-shadow: 0 2px 0 #16090b, 0 3px 10px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .06);
}

/* ───────────────────────── 触摸板 ───────────────────────── */

.touchpad-block, .text-block { margin-bottom: 14px; }

.touchpad {
  position: relative;
  height: 132px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 50%, #1a1f28, #10141a 78%);
  box-shadow: inset 0 2px 14px rgba(0, 0, 0, .55);
  touch-action: none;
  overflow: hidden;
  display: grid; place-items: center;
  cursor: crosshair;
}
.touchpad-cross {
  position: absolute; left: 50%; top: 50%; width: 1px; height: 26px;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, .18), transparent);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.touchpad-cross::after {
  content: ""; position: absolute; left: -13px; top: 13px; width: 26px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .18), transparent);
}
.touchpad-hint {
  position: relative; font-size: 12px; color: var(--ink-mute); pointer-events: none;
  letter-spacing: .04em;
}
.touchpad[data-active="1"] { border-color: color-mix(in srgb, var(--relay) 55%, var(--line)); }
.touchpad[data-active="1"] .touchpad-hint { color: var(--relay); }

/* ───────────────────────── 设备列表 ───────────────────────── */

.device-list { list-style: none; display: grid; gap: 9px; margin-top: 8px; }

.device {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  padding: 11px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.device-main { min-width: 0; display: grid; gap: 4px; }
.device-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.device-name { font-size: 13.5px; font-weight: 600; }
.device-fp { font-family: var(--fm); font-size: 11.5px; color: var(--ink-mute); letter-spacing: .02em; }
.device-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11.5px; color: var(--ink-mute); }
.device-meta span { display: inline-flex; align-items: center; gap: 4px; }
.kind-tag {
  padding: 1px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 650;
  border: 1px solid var(--line); background: var(--surface-3); color: var(--ink-dim);
  letter-spacing: .03em;
}
.state-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--idle); }
.state-dot[data-state="lan"]     { background: var(--lan); }
.state-dot[data-state="relay"]   { background: var(--relay); }
.state-dot[data-state="offline"] { background: var(--offline); }
.state-dot[data-state="unknown"] { background: var(--idle); }

.device-actions { grid-column: 1 / -1; display: flex; gap: 7px; flex-wrap: wrap; }
.device-actions .btn { padding: 7px 12px; font-size: 12.5px; min-height: 36px; }

.usercode-slot { margin-top: 12px; text-align: center; }
.usercode {
  font-family: var(--fm);
  font-size: clamp(30px, 12vw, 46px);
  font-weight: 700;
  letter-spacing: .16em;
  line-height: 1.15;
  color: var(--lan);
  text-shadow: 0 0 26px rgba(61, 220, 151, .3);
  padding: 10px 0 4px;
  user-select: all;
}
.usercode-slot .hint { max-width: 34ch; margin: 0 auto; }

/* ───────────────────────── 标签栏 ───────────────────────── */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  max-width: 560px; margin: 0 auto;
  padding: 6px calc(8px + var(--sa-r)) calc(6px + var(--sa-b)) calc(8px + var(--sa-l));
  background: color-mix(in srgb, var(--bg-deep) 88%, transparent);
  border-top: 1px solid var(--line-soft);
  backdrop-filter: blur(16px);
}
.tab {
  display: grid; place-items: center; gap: 2px;
  padding: 7px 4px; border: 0; border-radius: var(--r-md);
  background: transparent; color: var(--ink-mute);
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  cursor: pointer; min-height: 50px;
  transition: color .15s, background .15s;
}
.tab-glyph { font-size: 16px; line-height: 1; }
.tab[aria-selected="true"] { color: var(--lan); background: rgba(61, 220, 151, .09); }
.tab:hover { color: var(--ink-dim); }
.tab[aria-selected="true"]:hover { color: var(--lan); }

/* ───────────────────────── 弹层 / 提示 ───────────────────────── */

.sheet {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  width: min(94vw, 480px);
  margin: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}
.sheet::backdrop { background: rgba(4, 6, 9, .72); backdrop-filter: blur(3px); }
.sheet-inner { padding: 18px; }
.sheet-inner h2 { font-size: 15px; margin-bottom: 6px; }
.sheet-inner .hint { margin-bottom: 10px; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(78px + var(--sa-b));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(90vw, 460px);
  padding: 10px 15px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-3) 94%, transparent);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12.5px;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
  animation: toast-in .18s ease-out;
}
.toast[data-tone="ok"]  { border-color: color-mix(in srgb, var(--lan) 45%, var(--line)); color: #d8fff0; }
.toast[data-tone="bad"] { border-color: color-mix(in srgb, var(--offline) 45%, var(--line)); color: #ffd9db; }
.toast[hidden] { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ───────────────────────── 响应式 / 动效偏好 ───────────────────────── */

/* 有横向空间时：D-pad 与功能键并排，遥控器更像一台真机 */
@media (min-width: 460px) {
  .dpad-wrap { grid-template-columns: auto minmax(112px, 1fr); align-items: center; }
  .dpad { width: 252px; margin: 0; }
  .key-rail { grid-template-columns: 1fr 1fr; }
  .key-power { grid-column: 1 / -1; }
}

@media (min-width: 700px) {
  .main { padding-bottom: calc(24px + var(--sa-b)); }
  .shell { max-width: 660px; }
  .tabbar { max-width: 660px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* 高对比模式：把发丝线加粗，别让层次靠亮度差撑着 */
@media (prefers-contrast: more) {
  :root { --line: #4a5468; --line-soft: #384152; --ink-dim: #c3cbda; --ink-mute: #b3bccc; }
}
