/* ============================================================
   小霸王 · 在线红白机模拟器
   ============================================================ */
:root {
  --bg: #0a090d;
  --bg-2: #100e15;
  --panel: #15131c;
  --panel-2: #1c1925;
  --line: #2b2735;
  --line-soft: #221f2b;
  --red: #e4362b;
  --red-deep: #a51f17;
  --red-glow: rgba(228, 54, 43, 0.35);
  --cream: #f3e9d6;
  --cream-2: #e2d2b6;
  --ink: #1b1611;
  --text: #f5f0e7;
  --muted: #9c93a7;
  --green: #6fe3a4;
  --yellow: #f5c451;
  --mono: "SFMono-Regular", "JetBrains Mono", "Cascadia Mono", Consolas, "Courier New", monospace;
  --sans: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  --radius: 16px;
}

* { box-sizing: border-box; }
/* 移动端点击按钮/链接时禁掉浏览器默认的蓝色高亮方块 */
a, button, [role="button"], input, select, label { -webkit-tap-highlight-color: transparent; }
/* 游戏画面窗口：canvas 不在上面选择器内，点击画面会露出默认蓝色高亮方块；
   把整个画面窗口子树（canvas / 扫描线 / 覆光 / 开机 overlay 文案）一并禁掉 */
.screen-frame, .screen-frame * { -webkit-tap-highlight-color: transparent; }
button:focus:not(:focus-visible), a:focus:not(:focus-visible) { outline: none; }
button:focus-visible { outline: 2px solid rgba(228, 54, 43, 0.6); outline-offset: 2px; }
/* 卡带是 div[role=button][tabindex=0]，不是真 <button>，上面两条 button 规则不覆盖它：
   键盘回车会触发 :focus-visible，浏览器默认 outline:auto 在深色底上呈亮白，且画在 border 外侧；
   卡带与 .game-list（overflow-y:auto）四边贴齐，外侧焦点环被列表裁成残缺白边。
   这里给主题红环并用负 offset 画进卡片内部，避免被滚动容器裁剪；鼠标点击仍不显示环。 */
.game-card:focus:not(:focus-visible) { outline: none; }
.game-card:focus-visible { outline: 2px solid rgba(228, 54, 43, 0.75); outline-offset: -2px; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 18% -10%, rgba(228, 54, 43, 0.18), transparent 62%),
    radial-gradient(700px 420px at 88% 4%, rgba(120, 80, 255, 0.12), transparent 60%),
    linear-gradient(180deg, #0b0910 0%, #08070b 100%);
}
.ambient::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 50% 0%, #000 10%, transparent 75%);
}

/* ---------------- header ---------------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px clamp(16px, 3vw, 44px) 14px;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }

.logo-mark {
  width: 58px;
  height: 58px;
  flex: none;
  transform: rotate(-3deg);
  filter: drop-shadow(0 8px 14px rgba(228, 54, 43, 0.28));
}
.logo-mark img {
  display: block;
  width: 100%;
  height: 100%;
}

.brand-text h1 {
  margin: 0;
  font-size: clamp(20px, 2.4vw, 26px);
  letter-spacing: 1px;
  font-weight: 800;
  display: flex;
  align-items: baseline;
  gap: 9px;
  flex-wrap: wrap;
}
.brand-text h1 em {
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2.5px;
  color: var(--red);
  border: 1px solid rgba(228, 54, 43, 0.45);
  border-radius: 5px;
  padding: 3px 6px;
  background: rgba(228, 54, 43, 0.08);
}
.brand-text p {
  margin: 5px 0 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2.2px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions { display: flex; gap: 8px; flex: none; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 13px;
  font-size: 12.5px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s, color .18s;
  font-family: var(--sans);
}
.ghost-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.ghost-btn svg path:first-child { fill: currentColor; stroke: none; }
.ghost-btn:hover { background: rgba(255, 255, 255, 0.07); border-color: #3b3448; transform: translateY(-1px); }
.ghost-btn.is-off { color: #6e6579; }
.ghost-btn.is-off .wave { opacity: .25; }

/* ---------------- layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.95fr);
  gap: clamp(16px, 2.2vw, 26px);
  padding: 8px clamp(16px, 3vw, 44px) 40px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}

/* ---------------- console ---------------- */
.console {
  position: relative;
  background:
    linear-gradient(180deg, #f7eddb 0%, #ece0ca 62%, #ddcdb2 100%);
  border-radius: 22px;
  padding: 14px 14px 12px;
  color: var(--ink);
  box-shadow:
    0 40px 80px -40px rgba(0, 0, 0, 0.9),
    0 2px 0 rgba(255, 255, 255, 0.5) inset,
    0 -3px 0 rgba(120, 96, 66, 0.25) inset;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.console-top {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(180deg, #24202c, #171420);
  border-radius: 11px;
  padding: 8px 14px;
  color: var(--cream);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1.6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35) inset;
}
.power-unit { display: flex; align-items: center; gap: 7px; }
.led {
  width: 9px; height: 9px; border-radius: 50%;
  background: #4a1220;
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.8);
  transition: background .2s, box-shadow .2s;
}
.led.on { background: #ff4b3a; box-shadow: 0 0 10px #ff4b3a, 0 0 20px rgba(255, 75, 58, 0.5); }
.power-label { color: #b9b0c6; }
.console-badge {
  color: #7f768d;
  padding-left: 14px;
  border-left: 1px solid #383144;
  white-space: nowrap;
}
.cart-name {
  margin-left: auto;
  color: var(--red);
  font-weight: 700;
  letter-spacing: 1px;
  max-width: 46%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.screen-bay { padding: 14px 10px 8px; }

.screen-frame {
  position: relative;
  background: #0a0a0c;
  border-radius: 12px;
  padding: 12px;
  box-shadow:
    0 0 0 2px #b9a88d,
    0 0 0 4px #d9cab2,
    0 18px 30px -18px rgba(0, 0, 0, 0.65),
    inset 0 0 22px rgba(0, 0, 0, 0.9);
  overflow: hidden;
}
.screen-frame canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  height: auto;
  background: #000;
  border-radius: 6px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
}
.screen-frame.pixel-aspect canvas { aspect-ratio: 256 / 240; }
.screen-frame:fullscreen {
  border-radius: 0;
  padding: 0;
  display: grid;
  place-items: center;
  background: #000;
  box-shadow: none;
}
.screen-frame:fullscreen canvas {
  width: min(100vw, calc(100vh * 4 / 3));
  height: auto;
  max-width: 100vw;
  max-height: 100vh;
}
.screen-frame.pixel-aspect:fullscreen canvas {
  width: min(100vw, calc(100vh * 256 / 240));
}

/* 移动端全屏：画面铺满等比居中，手柄悬浮在两侧黑边，不占用画面高度。
   按键尺寸按黑边空间自适应（--fs-key 为方向键边长，AB 键取其 0.5）。 */
.screen-frame.with-pad:fullscreen {
  padding: 0;
  /* 与非全屏按键统一尺寸：直接复用 .dpad / .face 的固定档位公式，
     使全屏与非全屏在主流尺寸下按键大小完全一致。
     --fs-key 仍供下方定位公式（AB 中心对齐、胶囊避让）引用。
     矮屏/平板黑边不足时由媒体查询收缩，避免压住游戏画面。 */
  --fs-key: clamp(116px, 30vw, 136px);
  --fs-face: clamp(56px, 15vw, 66px);
}
.screen-frame.with-pad:fullscreen canvas {
  width: min(100vw, calc(100vh * 4 / 3));
  height: auto;
  max-height: 100vh;
}
.screen-frame.with-pad.pixel-aspect:fullscreen canvas {
  width: min(100vw, calc(100vh * 256 / 240));
}
.screen-frame.with-pad:fullscreen .scanlines,
.screen-frame.with-pad:fullscreen .screen-glare,
.screen-frame.with-pad:fullscreen .screen-overlay { inset: 0; }

/* 悬浮手柄层：铺满全屏但不拦截画面点击，仅按钮接收触摸 */
.screen-frame.with-pad:fullscreen .touch-deck {
  position: absolute;
  inset: 0;
  display: block;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
  z-index: 60;
}
.screen-frame.with-pad:fullscreen .touch-deck > * { pointer-events: auto; }
/* 方向键：贴左下（竖屏落在画面下方黑边，横屏落在画面左侧黑边） */
.screen-frame.with-pad:fullscreen .dpad {
  position: absolute;
  /* 左右留白从 16 拉到 24px：真机圆角/手势区不易误触，视觉也不贴边 */
  left: calc(24px + env(safe-area-inset-left));
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: var(--fs-key);
  height: var(--fs-key);
  opacity: .9;
}
/* AB 键：贴右下，随方向键等比。
   bottom 不再固定贴底，而是与摇杆中心对齐：摇杆中心距底 = 22 + fs-key/2，
   AB 组高 fs-face = fs-key/2，故 bottom = 22 + (fs-key-fs-face)/2 = 22 + fs-key*.25，
   避免 A 键中心比摇杆低约 38px 的"偏低"观感。 */
.screen-frame.with-pad:fullscreen .face-buttons {
  position: absolute;
  right: calc(28px + env(safe-area-inset-right));
  /* A 键中心与摇杆中心严格对齐：摇杆中心距底 = 22 + fs-key/2，
     AB 组高 = fs-face，故 bottom = 22 + (fs-key - fs-face)/2（fs-face 已是独立档位）。 */
  bottom: calc(22px + (var(--fs-key) - var(--fs-face)) / 2 + env(safe-area-inset-bottom));
  gap: 14px;
  opacity: .9;
}
.screen-frame.with-pad:fullscreen .face {
  width: var(--fs-face); height: var(--fs-face);
  font-size: 17px;
}
/* B 键错位与非全屏一致：固定 10px（原 fs-face*.18 在横屏 fs-face=66 时达 11.9px，偏大） */
.screen-frame.with-pad:fullscreen .face.b { transform: translateY(10px); }
.screen-frame.with-pad:fullscreen .face.b.active { transform: translateY(10px) scale(.96); }
/* 选择/开始：位置与非全屏竖屏完全一致（仅坐标系不同，几何等价）。
   非全屏手柄条是 flex space-between：dpad(左) / touch-middle(中) / face(右)，
   胶囊组水平落在中间项 = left24 + fs-key + 剩余空间/2，
   剩余 = 100vw - (左右 padding 24+28) - fs-key - 胶囊宽46 - AB组(2*fs-face+gap14)；
   垂直：手柄条 align-items:center 令胶囊组中心与 dpad 中心同高，
   故 bottom = 22(底padding) + (fs-key - 胶囊组高67)/2 = fs-key/2 - 11.5。
   四个尺寸(360/390/430/768)实测公式值与非全屏坐标逐个吻合。 */
.screen-frame.with-pad:fullscreen .touch-middle {
  position: absolute;
  left: calc(24px + var(--fs-key) + (100vw - 24px - 28px - var(--fs-key) - 46px - (2 * var(--fs-face) + 14px)) / 2 + env(safe-area-inset-left));
  bottom: calc(var(--fs-key) / 2 - 11.5px + env(safe-area-inset-bottom));
  transform: none;
  width: 46px;
  align-items: center;
  flex-direction: column;
  gap: 9px;
}
.screen-frame.with-pad:fullscreen .pill {
  padding: 8px 11px;
  font-size: 10px;
}
.touch-deck .fs-exit { display: none; }
.screen-frame.with-pad:fullscreen .fs-exit {
  display: block;
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  pointer-events: auto;
  background: rgba(34, 31, 43, .78);
}

@media (orientation: landscape) and (max-height: 520px) {
  /* 横屏按键尺寸同样与非全屏统一（固定档位 136px）。
     校验左右黑边：黑边宽=(100vw-100vh*4/3)/2，方向键 left(20)+136=156，
     AB 组 right(18)+2*66+gap(136*.07≈9.5)=159.5；844×390 黑边 162、932×430 黑边 179，
     均不压画面。gap 收紧到 .07 是为横屏黑边留余量（非全屏 gap 为 14px）。 */
  .screen-frame.with-pad:fullscreen {
    --fs-key: clamp(116px, 30vw, 136px);
  }
  .screen-frame.with-pad:fullscreen .dpad {
    left: calc(20px + env(safe-area-inset-left));
    bottom: calc(18px + env(safe-area-inset-bottom));
  }
  .screen-frame.with-pad:fullscreen .touch-middle {
    left: calc(20px + env(safe-area-inset-left));
    /* 摇杆底距 18px：bottom 取 fs-key+44px → 胶囊底与摇杆顶仍约 26px 间隙 */
    bottom: calc(var(--fs-key) + 44px + env(safe-area-inset-bottom));
    transform: none;
    width: var(--fs-key);
    align-items: center;
  }
  .screen-frame.with-pad:fullscreen .face-buttons {
    right: calc(18px + env(safe-area-inset-right));
    /* 摇杆横屏底距 18px，同竖屏逻辑与摇杆中心对齐：18 + (fs-key-face)/2 */
    bottom: calc(18px + (var(--fs-key) - var(--fs-face)) / 2 + env(safe-area-inset-bottom));
    /* AB 组内 gap 与非全屏统一为 14px（原 .07*fs-key≈9.5px 偏小） */
    gap: 14px;
  }
}

.scanlines {
  position: absolute;
  inset: 12px;
  border-radius: 6px;
  pointer-events: none;
  background: repeating-linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.16) 0px,
    rgba(0, 0, 0, 0.16) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0;
  transition: opacity .25s;
  mix-blend-mode: multiply;
}
.scanlines.on { opacity: 1; }
.screen-frame:fullscreen .scanlines { inset: 0; }

.screen-glare {
  position: absolute;
  inset: 12px;
  border-radius: 6px;
  pointer-events: none;
  background: radial-gradient(120% 70% at 20% 0%, rgba(255, 255, 255, 0.1), transparent 45%);
}
.screen-frame:fullscreen .screen-glare { inset: 0; }

.screen-overlay {
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  text-align: center;
  background: linear-gradient(180deg, rgba(6, 4, 9, 0.965), rgba(6, 4, 9, 0.985));
  backdrop-filter: blur(6px);
  border-radius: 6px;
  transition: opacity .25s, visibility .25s;
  z-index: 3;
}
.screen-overlay.hidden { opacity: 0; visibility: hidden; }
.overlay-card { max-width: 340px; padding: 16px; }
.overlay-kicker {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--red);
  margin: 0 0 10px;
}
.screen-overlay h2 { margin: 0 0 8px; font-size: 22px; letter-spacing: 1px; color: #fffaf2; text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8); }
.screen-overlay p { margin: 0 0 16px; font-size: 12.5px; line-height: 1.7; color: #b7aec3; }
.screen-overlay h2 { text-wrap: balance; }

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  background: linear-gradient(180deg, #ff5a48, var(--red) 60%, #c0271d);
  color: #fff;
  border: 0;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 8px 20px -8px var(--red-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform .15s, box-shadow .15s;
  font-family: var(--sans);
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 12px 24px -8px var(--red-glow); }
.primary-btn:active { transform: translateY(0); }

.fps-pill {
  position: absolute;
  right: 20px;
  top: 20px;
  z-index: 2;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 1px;
  color: #9be3b8;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(111, 227, 164, 0.2);
  border-radius: 4px;
  padding: 3px 6px;
  opacity: 0;
  transition: opacity .2s;
}
.fps-pill.visible { opacity: 1; }

/* deck */
.console-deck {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 12px 0;
  flex-wrap: wrap;
}
.deck-left, .deck-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.deck-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid #b5a488;
  border-bottom-width: 3px;
  background: linear-gradient(180deg, #fffaf0, #e4d4ba);
  color: #372c1d;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  cursor: pointer;
  box-shadow: 0 4px 10px -6px rgba(0, 0, 0, 0.5);
  transition: transform .12s, box-shadow .12s, filter .12s;
  font-family: var(--sans);
}
.deck-btn:hover { filter: brightness(1.03); }
.deck-btn:active { transform: translateY(2px); border-bottom-width: 1px; box-shadow: none; }
.deck-btn.small { padding: 8px 11px; font-size: 11.5px; }
.deck-btn .deck-icon { display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; flex: none; }
.deck-btn .deck-icon svg { width: 100%; height: 100%; display: block; }
.deck-btn.danger { color: var(--red-deep); }

.console-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 2px;
  font-size: 11px;
  color: #6d5f4c;
  font-family: var(--mono);
  flex-wrap: wrap;
}
.status-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.status-item b { color: #40342a; font-weight: 700; }
.status-sep { width: 1px; height: 11px; background: #c6b499; }
.status-spacer { flex: 1; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: #a99880; }
.dot.live { background: #26a65b; box-shadow: 0 0 6px rgba(38, 166, 91, 0.6); }
.dot.paused { background: #d99a27; }

.slider-wrap { display: inline-flex; align-items: center; gap: 6px; }
.slider-wrap svg { width: 14px; height: 14px; fill: currentColor; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 78px;
  height: 4px;
  border-radius: 4px;
  background: #c3b096;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: var(--red);
  border: 2px solid #fff6ea;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--red); border: 2px solid #fff6ea;
}

.toggle-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  letter-spacing: 1px;
  cursor: pointer;
  user-select: none;
}
.toggle-wrap input { accent-color: var(--red); width: 13px; height: 13px; margin: 0; }

/* ---------------- sidebar ---------------- */
.sidebar { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  box-shadow: 0 20px 40px -30px rgba(0, 0, 0, 0.9);
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-head h2 { margin: 0; font-size: 14px; letter-spacing: 1px; font-weight: 700; }
.panel-tag {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 2px;
  color: #6c6379;
}

.cat-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 11px; }
.cat-chip {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 1px;
  padding: 4px 9px;
  border-radius: 20px;
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.02);
  color: #9b91a9;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.cat-chip:hover { color: #d6cede; border-color: #463b59; }
.cat-chip.active {
  color: #ffd9d4;
  border-color: rgba(228, 54, 43, 0.55);
  background: rgba(228, 54, 43, 0.14);
}

.game-list-wrap { position: relative; min-width: 0; }
.game-list-wrap::after {
  content: "";
  position: absolute;
  left: 0; right: 4px; bottom: 0;
  height: 30px;
  pointer-events: none;
  background: linear-gradient(to top, var(--panel) 8%, rgba(21, 19, 28, 0));
  opacity: 1;
  transition: opacity .2s;
}
.game-list-wrap.at-end::after { opacity: 0; }

.game-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  max-height: 468px;
  overflow-y: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
}
.game-list::-webkit-scrollbar, .modal-inner::-webkit-scrollbar, dialog::-webkit-scrollbar { width: 6px; }
.game-list::-webkit-scrollbar-thumb, .modal-inner::-webkit-scrollbar-thumb, dialog::-webkit-scrollbar-thumb {
  background: #35303f;
  border-radius: 3px;
}
.game-list::-webkit-scrollbar-thumb:hover, .modal-inner::-webkit-scrollbar-thumb:hover, dialog::-webkit-scrollbar-thumb:hover { background: #4a4159; }
.game-list::-webkit-scrollbar-track, .modal-inner::-webkit-scrollbar-track, dialog::-webkit-scrollbar-track { background: transparent; }
/* 关闭原生上下箭头：默认 button 会顶在弹窗 18px 圆角缺口处露出来 */
.game-list::-webkit-scrollbar-button, .modal-inner::-webkit-scrollbar-button, dialog::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
  background: transparent;
  border: 0;
}
.game-list::-webkit-scrollbar-corner, .modal-inner::-webkit-scrollbar-corner, dialog::-webkit-scrollbar-corner { background: transparent; }
/* Firefox 无 webkit 伪元素：仅在其作用域补标准属性。
   Chromium/Edge 必须让 scrollbar-color 缺省，否则标准滚动条路径会架空上述 button 隐藏规则。 */
@supports not selector(::-webkit-scrollbar) {
  .game-list, .modal-inner, dialog {
    scrollbar-width: thin;
    scrollbar-color: #3a3346 transparent;
  }
}

.game-card {
  position: relative;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px;
  border-radius: 11px;
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.018);
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--text);
  transition: border-color .16s, background .16s, box-shadow .16s;
  font-family: var(--sans);
}
/* 不用 translateY：列表是滚动容器，上移会让卡片顶部被裁切（尤其圆角边） */
.game-card:hover { border-color: #4a4160; background: rgba(255, 255, 255, 0.055); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); }
.game-card.active { border-color: rgba(228, 54, 43, 0.55); background: rgba(228, 54, 43, 0.08); }
.game-card.active::after {
  content: "";
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 3px; border-radius: 3px;
  background: var(--red);
}
.cart-thumb {
  width: 36px;
  height: 44px;
  flex: none;
  border-radius: 4px 4px 3px 3px;
  background: linear-gradient(160deg, #f0e2c9, #cdb793 70%, #b29a74);
  position: relative;
  box-shadow: inset 0 -8px 0 rgba(80, 58, 34, 0.22), 0 2px 6px rgba(0, 0, 0, 0.4);
}
.cart-thumb::before {
  content: "";
  position: absolute;
  left: 5px; right: 5px; top: 5px; height: 19px;
  background: #2a2430;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.cart-thumb::after {
  content: "";
  position: absolute;
  left: 8px; right: 8px; top: 11px; height: 2px;
  background: var(--red);
  box-shadow: 0 4px 0 rgba(228, 54, 43, 0.55), 0 8px 0 rgba(228, 54, 43, 0.25);
}
.game-meta { min-width: 0; flex: 1; }
.game-name {
  display: block;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-sub {
  display: block;
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--muted);
  font-family: var(--mono);
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-badge {
  flex: none;
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 1px;
  padding: 3px 5px;
  border-radius: 4px;
  border: 1px solid #3a3346;
  color: #a99fb8;
}
.game-badge.free { color: #7fd7a4; border-color: rgba(111, 227, 164, 0.3); }
.game-badge.own { color: var(--yellow); border-color: rgba(245, 196, 81, 0.3); }
.game-del {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.35);
  color: #a99fb8;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, color .15s;
}
.game-card:hover .game-del { opacity: 1; }
.game-del:hover { color: var(--red); }

.upload-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px;
  border-radius: 10px;
  border: 1px dashed #3d3550;
  background: transparent;
  color: #b6acc6;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .16s, color .16s, background .16s;
  font-family: var(--sans);
}
.upload-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.upload-btn:hover { border-color: var(--red); color: #f0c6c0; background: rgba(228, 54, 43, 0.06); }

.hint { margin: 10px 0 0; font-size: 10.5px; line-height: 1.7; color: #7d748b; }

.key-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.key-list li {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: #b7aec4;
}
.key-list li > span { width: 58px; flex: none; color: #8b8197; font-size: 11px; }
.key-list em { font-style: normal; color: #6f6679; font-size: 10px; }
kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 4px;
  background: #221f2b;
  border: 1px solid #332e40;
  border-bottom-width: 2px;
  color: #ddd4e8;
  min-width: 20px;
  text-align: center;
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: #c7a9a3;
  font-size: 11px;
  cursor: pointer;
  letter-spacing: .5px;
  font-family: var(--sans);
}
.link-btn:hover { color: var(--red); }

.panel-note p { margin: 0 0 8px; font-size: 11.5px; line-height: 1.75; color: #a79db4; }
.panel-note p b { color: #d9d0e4; font-weight: 700; }
code {
  font-family: var(--mono);
  font-size: .92em;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.07);
  color: #e7dcc9;
}
.panel-note p.fine { font-size: 10px; color: #726a7e; margin-bottom: 0; }

/* ---------------- footer ---------------- */
.site-footer {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px clamp(16px, 3vw, 44px) 26px;
  border-top: 1px solid rgba(255, 255, 255, 0.045);
  text-align: center;
}
.site-footer p {
  margin: 0 0 5px;
  font-size: 10.5px;
  line-height: 1.7;
  color: #6f667a;
  letter-spacing: .3px;
}
.site-footer p.footer-brand {
  font-size: 11.5px;
  color: #a49aae;
  letter-spacing: 1.5px;
  margin-bottom: 7px;
}

/* ---------------- touch deck ---------------- */
.touch-deck { display: none; }

/* ---------------- modal ---------------- */
.modal {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  max-width: min(560px, calc(100vw - 28px));
  width: 100%;
  margin: auto;
}
.modal::backdrop { background: rgba(4, 3, 7, 0.72); backdrop-filter: blur(4px); }
#aboutDialog { max-width: min(780px, calc(100vw - 28px)); }
.modal-inner {
  background: linear-gradient(180deg, #1d1a26, #131119);
  border: 1px solid #332d40;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 40px 80px -30px #000;
  max-height: 86vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-head h2 { margin: 0; font-size: 17px; letter-spacing: 1px; }
.close-btn {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: #a99fb8;
  cursor: pointer;
  font-size: 12px;
}
.close-btn:hover { color: #fff; border-color: #4a4159; }
.modal-section { margin-top: 18px; }
.modal-section h3, .modal h3 { font-size: 12px; letter-spacing: 1.5px; color: #a99fb8; text-transform: uppercase; margin: 18px 0 8px; }
.modal-hint { font-size: 11px; color: #7d748b; line-height: 1.7; margin: 0 0 10px; }
.modal p { font-size: 12.5px; line-height: 1.8; color: #b6acC4; }
.modal .fine { color: #7d748b; font-size: 11px; }
.license-list { margin: 0; padding-left: 18px; font-size: 12px; color: #b6acc4; line-height: 1.9; }
.license-list b { color: #e8dfea; }
.modal a { color: #f0b8ae; text-decoration: underline; text-underline-offset: 2px; }
.modal a:hover { color: #ffd9d4; }

.remap-grid { display: grid; gap: 7px; }
.remap-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line-soft);
}
.remap-row span { font-size: 12px; color: #c2b8cf; }
.remap-key {
  min-width: 84px;
  padding: 5px 9px;
  border-radius: 6px;
  border: 1px solid #3b3448;
  border-bottom-width: 2px;
  background: #221f2b;
  color: #e7dfea;
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
}
.remap-key.listening { border-color: var(--red); color: #ffd1cb; animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px rgba(228, 54, 43, 0.18); } }

.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px;
  font-size: 12px;
  color: #bdb3c9;
  border-bottom: 1px solid var(--line-soft);
}
.option-row:last-child { border-bottom: 0; }
select {
  background: #221f2b;
  color: #e7dfea;
  border: 1px solid #3b3448;
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 11.5px;
  font-family: var(--sans);
  outline: none;
}
.switch { position: relative; width: 38px; height: 21px; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i {
  position: absolute;
  inset: 0;
  background: #2c2736;
  border-radius: 20px;
  transition: background .2s;
}
.switch i::after {
  content: "";
  position: absolute;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: #cfc4d8;
  top: 3px; left: 3px;
  transition: transform .2s, background .2s;
}
.switch input:checked + i { background: rgba(228, 54, 43, 0.7); }
.switch input:checked + i::after { transform: translateX(17px); background: #fff; }

.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
#aboutDialog .modal-foot { justify-content: flex-end; }

/* ---------------- toast ---------------- */
body.dragging .screen-frame { outline: 2px dashed var(--red); outline-offset: -10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  z-index: 100;
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(26, 22, 33, 0.95);
  border: 1px solid #3b3448;
  color: #f0eaf4;
  font-size: 12.5px;
  letter-spacing: .4px;
  box-shadow: 0 16px 40px -16px #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- responsive ---------------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
  .panel-note { grid-column: 1 / -1; }
  .game-list { max-height: none; overflow: visible; padding-right: 0; }
  .game-list-wrap::after { display: none; }
}
@media (max-width: 760px) {
  .site-header { padding: 16px 14px 10px; }
  .logo-mark { width: 48px; height: 48px; }
  .brand-text p { letter-spacing: 1.4px; font-size: 9px; }
  .header-actions .ghost-btn span { display: none; }
  .header-actions .ghost-btn { padding: 9px 10px; }
  .layout { padding: 6px 12px 176px; }
  .sidebar { grid-template-columns: 1fr; }
  .sidebar > .panel { min-width: 0; }
  .game-list { min-width: 0; }
  .console { padding: 10px 10px 8px; border-radius: 18px; }
  .console-top { gap: 9px; font-size: 8.5px; letter-spacing: 1px; padding: 7px 10px; }
  .console-badge { display: none; }
  .cart-name { max-width: 55%; }
  .screen-bay { padding: 10px 2px 6px; }
  .screen-frame { padding: 8px; }
  .scanlines, .screen-glare, .screen-overlay { inset: 8px; }
  .console-deck { padding: 2px 4px 0; }
  .deck-btn { padding: 8px 10px; font-size: 11px; }
  .deck-btn.small { padding: 7px 8px; font-size: 10.5px; }
  .console-status { gap: 8px; font-size: 10px; padding: 10px 4px 0; }
  .status-spacer { display: none; }
  .slider-wrap input { width: 54px; }
  .touch-deck { display: flex; }
  .toast { bottom: calc(172px + env(safe-area-inset-bottom)); }
  .site-footer { padding-bottom: calc(182px + env(safe-area-inset-bottom)); }
}

/* 宽屏触摸设备（平板竖/横、手机横屏）：宽度 >760px 时若只按 max-width 判定会被当桌面
   而隐藏手柄，导致非全屏无虚拟按键、只有全屏才有。这里改用触摸能力判定，与 JS 全屏
   逻辑一致（pointer:coarse），补齐与窄屏相同的手柄显示与底部留白，避免遮挡内容。 */
@media (pointer: coarse) and (min-width: 761px) {
  .layout { padding-bottom: 176px; }
  .touch-deck { display: flex; }
  .toast { bottom: calc(172px + env(safe-area-inset-bottom)); }
  .site-footer { padding-bottom: calc(182px + env(safe-area-inset-bottom)); }
}

/* touch deck layout */
.touch-deck {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  /* 离边距离与全屏统一：竖屏 左24 / 右28 / 底22（对齐全屏 .dpad/.face-buttons 边距）。
     flex 居中使 AB 键底边距 = padding-bottom + (dpad-face)/2，与全屏公式等价。
     横屏由下方 media query 覆盖为 左20 / 右18 / 底18。 */
  padding: 12px 28px calc(22px + env(safe-area-inset-bottom)) 24px;
  background: linear-gradient(180deg, rgba(10, 9, 13, 0.2), rgba(10, 9, 13, 0.95) 30%);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  user-select: none;
  -webkit-user-select: none;
  /* 防 iOS Safari 长按手柄弹出「存储图像/查找」菜单；安卓小米靠 JS 的 touchstart.preventDefault 拦截 */
  -webkit-touch-callout: none;
  touch-action: none;
}
/* 非全屏横屏离边距离与全屏统一：左20 / 右18 / 底18 */
@media (orientation: landscape) and (max-height: 520px) {
  .touch-deck {
    padding: 12px 18px calc(18px + env(safe-area-inset-bottom)) 20px;
  }
}
/* 摇杆：圆形底盘 + 跟手圆头 + 四向刻度 */
.dpad {
  position: relative;
  /* 随屏宽自适应：窄屏保底 116，主流 390 起放大，封顶 136 避免撑破手柄条 */
  width: clamp(116px, 30vw, 136px);
  height: clamp(116px, 30vw, 136px);
  flex: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  border-radius: 50%;
  --dpang: 0deg;
  background: radial-gradient(circle at 50% 34%, #2b2637, #1c1926 58%, #131119 100%);
  border: 1px solid #3a3448;
  box-shadow:
    inset 0 3px 9px rgba(0, 0, 0, 0.6),
    inset 0 -1px 0 rgba(255, 255, 255, 0.06),
    0 2px 6px -2px rgba(0, 0, 0, 0.55);
  /* 整块底盘是摇杆的触控面：指针事件统一交给 .dpad 处理，
     4 个箭头刻度只做视觉高亮，不各自接收触摸 */
  touch-action: none;
  cursor: pointer;
}
.dpad.dragging {
  box-shadow:
    inset 0 3px 9px rgba(0, 0, 0, 0.6),
    inset 0 -1px 0 rgba(255, 255, 255, 0.06),
    0 0 0 1px rgba(228, 54, 43, 0.4),
    0 0 14px -3px rgba(228, 54, 43, 0.55);
}
/* 外圈弧形指示：按哪个方向就点亮那一圈 45° 弧段（斜向时两段相邻 =
   90° 弧，圆头压不到外圈，斜向一眼可辨）。角度由 --dpang 驱动。 */
.dpad::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  /* conic-gradient 的 0° 在 12 点方向、顺时针递增；--dpang 的 0° 在 3 点方向，
     所以整体 +90°；再减 22.5° 让弧段以扇区中心居中（一段 = 45°）。 */
  background: conic-gradient(
    from calc(var(--dpang) + 67.5deg),
    rgba(255, 96, 76, 0.6) 0deg,
    rgba(255, 96, 76, 0.6) 45deg,
    rgba(255, 96, 76, 0) 45deg,
    rgba(255, 96, 76, 0) 360deg
  );
  /* 只保留最外一圈：内沿 78% 正好避开圆头（圆头半径 23% + 最大位移 55%），
     圆头压不到弧光 */
  -webkit-mask: radial-gradient(circle at 50% 50%, transparent 77%, #000 79%);
  mask: radial-gradient(circle at 50% 50%, transparent 77%, #000 79%);
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}
.dpad.dragging::after { opacity: 1; }
.pad {
  position: relative;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  background: none;
  pointer-events: none;
}
.pad::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 7px solid rgba(206, 192, 224, 0.36);
  transform: translate(-50%, -50%);
  transition: border-bottom-color 0.12s ease, filter 0.12s ease;
}
.pad.up { grid-area: 1 / 2; }
.pad.left { grid-area: 2 / 1; }
.pad.right { grid-area: 2 / 3; }
.pad.down { grid-area: 3 / 2; }
.pad.down::after { transform: translate(-50%, -50%) rotate(180deg); }
.pad.left::after { transform: translate(-50%, -50%) rotate(-90deg); }
.pad.right::after { transform: translate(-50%, -50%) rotate(90deg); }
.pad.active::after {
  border-bottom-color: #ff7161;
  filter: drop-shadow(0 0 5px rgba(255, 96, 76, 0.8));
}
/* 圆头：跟手移动，松手弹回中心 */
.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 46%;
  height: 46%;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 28%, #6b6389 0%, #4a4463 34%, #322d46 64%, #201c2b 100%);
  border: 1px solid #544c6e;
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.62),
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -3px 7px rgba(0, 0, 0, 0.42);
  transform: translate(-50%, -50%);
  transition: transform 0.18s cubic-bezier(0.22, 0.9, 0.3, 1.15);
  pointer-events: none;
}
.stick-knob::after {
  content: "";
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
}
.dpad.dragging .stick-knob { transition: none; }
/* 已出方向：圆头描边转红并外发光（竖直方向时箭头刻度会被圆头挡住，
   这个反馈在圆头本体上，始终可见） */
.dpad.engaging .stick-knob {
  border-color: rgba(255, 122, 104, 0.9);
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.62),
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 0 13px -1px rgba(255, 96, 76, 0.55);
}
.touch-middle { display: flex; flex-direction: column; gap: 9px; }
.pill {
  /* 字号放大到 10px，但横向 padding 收紧，控制胶囊宽度≈46px，
     避免 360 窄屏下挤占与摇杆/AB 之间的横向间距 */
  padding: 8px 11px;
  border-radius: 20px;
  border: 1px solid #3a3448;
  background: #221f2b;
  color: #cfc5da;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 1px;
  cursor: pointer;
}
.face-buttons { display: flex; gap: 14px; align-items: center; }
.face {
  width: clamp(56px, 15vw, 66px); height: clamp(56px, 15vw, 66px);
  border-radius: 50%;
  border: 1px solid #4a3a3a;
  background: radial-gradient(circle at 35% 30%, #e8503f, #b8271c 70%, #7c150e);
  color: #fff4ec;
  font-weight: 800;
  font-size: 17px;
  font-family: var(--mono);
  box-shadow: 0 6px 14px -6px rgba(228, 54, 43, 0.7), inset 0 2px 4px rgba(255, 255, 255, 0.25);
  cursor: pointer;
  touch-action: none;
}
.face.b { transform: translateY(10px); }
.pill.active, .face.active {
  filter: brightness(1.35);
  transform: scale(0.96);
}
.face.b.active { transform: translateY(10px) scale(0.96); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
