/* ========= 基础 ========= */
* { box-sizing: border-box; }
:root {
  --bg: #0a0d12;
  --panel: #12161d;
  --line: #232a36;
  --text: #e8edf4;
  --dim: #8b96a5;
  --accent: #ffd35c;
  --ok: #4ade80;
  --warn: #fbbf24;
}
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
code {
  background: #1b212c; border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 6px; font-size: 0.92em; color: var(--accent);
}
kbd {
  background: #1b212c; border: 1px solid #3a4353; border-bottom-width: 3px;
  border-radius: 6px; padding: 2px 8px; font-size: 0.9em; margin: 0 2px;
}
.dim { color: var(--dim); }

/* ========= 游戏库 index ========= */
.wrap { max-width: 1020px; margin: 0 auto; padding: 40px 20px 60px; }
header h1 { font-size: 34px; margin: 0 0 6px; letter-spacing: 1px; }
header p { margin: 0 0 30px; }

/* 主站 iframe 内嵌（body.embed）：标题与玩法说明交给外层工具页，只留游戏网格 */
body.embed .wrap { padding: 12px 14px 26px; }
body.embed header,
body.embed .howto { display: none; }

/* 独立访问（2026-10-08 站内多门户）：右上角「回首页」浮钮，embed 内嵌态隐藏 */
.home-fab {
  position: fixed; top: 14px; right: 16px; z-index: 90;
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(18, 22, 29, .55); border: 1px solid rgba(255, 255, 255, .18);
  color: var(--text); font-size: 20px; line-height: 1; text-decoration: none;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.home-fab:hover { background: var(--accent); color: #14171d; transform: scale(1.06); }
body.embed .home-fab { display: none; }
@media (pointer: coarse) { .home-fab { width: 44px; height: 44px; } }

/* 投币横幅：复古街机机台灯箱 */
.coin-strip {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-bottom: 16px; padding: 9px 14px;
  background: linear-gradient(180deg, #171d28, #10141c);
  border: 1px solid #2b3547; border-radius: 10px;
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 13px; font-weight: 700; letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 0 8px rgba(255, 211, 92, .45);
  box-shadow: inset 0 0 18px rgba(255, 211, 92, .06), 0 2px 10px rgba(0, 0, 0, .35);
}
.coin-strip .coin-ico { font-size: 11px; animation: coinSpin 2.4s linear infinite; }
.coin-strip .blink { animation: blink 1.1s steps(1) infinite; }
@keyframes coinSpin { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}

/* 卡片：街机卡带 */
.card {
  position: relative;
  display: flex; flex-direction: column;
  text-decoration: none; color: inherit;
  background: linear-gradient(180deg, #161c27, #0f131b);
  border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
  animation: cardIn .45s both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px); }
}
.card:hover {
  transform: translateY(-5px);
  border-color: rgba(255, 211, 92, .75);
  box-shadow: 0 16px 34px rgba(0, 0, 0, .5), 0 0 22px rgba(255, 211, 92, .12);
}

/* 封面屏：CRT 网格 + 扫描线 */
.thumb {
  position: relative;
  height: 122px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--g1, #334), var(--g2, #112));
}
.thumb::before {
  /* 透视网格地砖 */
  content: ""; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, .16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .16) 1px, transparent 1px);
  background-size: 17px 17px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.15), rgba(0,0,0,.75));
  -webkit-mask-image: linear-gradient(180deg, rgba(0,0,0,.15), rgba(0,0,0,.75));
  pointer-events: none;
}
.thumb::after {
  /* CRT 扫描线 + 顶部高光 */
  content: ""; position: absolute; inset: 0;
  background:
    repeating-linear-gradient(180deg, rgba(0, 0, 0, .16) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, rgba(255, 255, 255, .12), transparent 34%);
  pointer-events: none;
}
.thumb .emoji {
  position: relative; z-index: 1;
  font-size: 52px; line-height: 1;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, .45));
  transition: transform .22s cubic-bezier(.34, 1.56, .64, 1);
}
.card:hover .emoji { transform: scale(1.22) rotate(-5deg); }
.thumb .play-pill {
  position: absolute; right: 9px; bottom: 9px; z-index: 2;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--accent);
  background: rgba(8, 10, 15, .68); border: 1px solid rgba(255, 211, 92, .55);
  backdrop-filter: blur(2px);
  transition: all .18s ease;
}
.card:hover .play-pill {
  background: var(--accent); color: #1b1405;
  box-shadow: 0 0 14px rgba(255, 211, 92, .65);
  transform: scale(1.08);
}

/* 卡身 */
.card-body { padding: 11px 13px 13px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title {
  font-size: 15.5px; font-weight: 700; letter-spacing: .3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; min-height: 18px; }
.card-tags i {
  font-style: normal; font-size: 10.5px; line-height: 1;
  padding: 4px 8px; border-radius: 999px;
  color: #aab6c6; background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .09);
}
.card-foot { margin-top: auto; }

/* 状态徽标：绿灯就绪 / 黄灯待 ROM */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, .04); border: 1px solid var(--line); color: var(--dim);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.badge.ok { color: var(--ok); border-color: rgba(74, 222, 128, .35); }
.badge.ok .dot { background: var(--ok); box-shadow: 0 0 6px rgba(74, 222, 128, .8); }
.badge.wait { color: var(--warn); border-color: rgba(251, 191, 36, .35); }
.badge.wait .dot { background: var(--warn); }

/* 缺 ROM 卡带：整个变灰，像没插紧 */
.card.missing .thumb { filter: saturate(.3) brightness(.72); }
.card.missing .card-title { color: var(--dim); }

/* ========= 游戏库分页（2026-11-01）：200 款一页 ========= */
.fc-pager {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 8px; margin: 26px 0 6px;
}
.fc-pg-btn {
  font-family: ui-monospace, "Courier New", monospace;
  font-size: 13px; font-weight: 700; letter-spacing: 1px;
  color: var(--text); background: rgba(18, 22, 29, .8);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; min-width: 38px; cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.fc-pg-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.fc-pg-btn:disabled { opacity: .35; cursor: default; }
.fc-pg-btn.on { background: var(--accent); border-color: var(--accent); color: #1b1405; }
.fc-pg-gap { color: var(--dim); font-size: 13px; user-select: none; }
.fc-pg-info { font-size: 12px; color: var(--dim); margin-left: 6px; letter-spacing: 1px; }

/* 玩法说明（独立访问时才显示） */
.howto { margin-top: 46px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px 26px; }
.howto h2 { font-size: 18px; margin: 18px 0 10px; }
.howto h2:first-child { margin-top: 0; }
.howto ol { margin: 0; padding-left: 22px; line-height: 2; color: #c6cdd8; }
.howto .keys { line-height: 2.4; }
.dim-link { color: var(--dim); font-size: 13px; }

/* ========= 游戏页 play：整个视口都是游戏 ========= */
body.play-page { overflow: hidden; background: #000; }
#game {
  position: fixed; inset: 0; z-index: 1;
  background: #0a0d12;
}
#game canvas, #game video { width: 100%; height: 100%; }

#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,.7), transparent);
  transition: opacity .35s ease;
}
#topbar.idle { opacity: 0; pointer-events: none; }
#tb-title { font-weight: 700; letter-spacing: 1px; text-shadow: 0 1px 4px #000; position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; }
.tb-btn {
  display: inline-block; text-decoration: none; color: var(--text);
  background: rgba(18, 22, 29, .82); border: 1px solid var(--line);
  padding: 6px 14px; border-radius: 999px; font-size: 13.5px; cursor: pointer;
}
.tb-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ========= 弹层 ========= */
.modal {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 6, 10, .82); backdrop-filter: blur(3px);
}
.modal-card {
  text-align: center; max-width: 420px; padding: 34px 38px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
}
.modal-card h2 { margin: 8px 0 12px; }
.modal-card p { line-height: 1.8; }
.modal-emoji { font-size: 52px; }
#missing .modal-card button.primary {
  margin: 14px 0 10px; padding: 10px 26px; font-size: 15px;
  color: #10233a; background: var(--accent); border: 0; border-radius: 999px;
  cursor: pointer; font-weight: 700;
}
#missing .modal-card button.primary:hover { filter: brightness(1.08); }
.modal-card .dim-link { display: block; margin-top: 8px; }

#dropzone {
  position: fixed; inset: 14px; z-index: 60; display: none;
  border: 3px dashed var(--accent); border-radius: 18px;
  background: rgba(10, 13, 18, .75); pointer-events: none;
}
#dropzone.show { display: flex; }
.dz-inner {
  margin: auto; font-size: 26px; font-weight: 700; color: var(--accent); letter-spacing: 2px;
}

#toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%) translateY(20px);
  z-index: 70; background: rgba(18, 22, 29, .95); border: 1px solid var(--line);
  color: var(--text); padding: 10px 20px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .3s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ========= 小屏 ========= */
@media (max-width: 600px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 11px; }
  .thumb { height: 96px; }
  .thumb .emoji { font-size: 42px; }
  .thumb .play-pill { width: 24px; height: 24px; font-size: 10px; right: 7px; bottom: 7px; }
  .card-body { padding: 9px 11px 11px; gap: 6px; }
  .card-title { font-size: 14px; }
  .card-tags { min-height: 0; }
  .card-tags i { font-size: 9.5px; padding: 3px 6px; }
  .badge { font-size: 10.5px; padding: 3px 8px; }
  .coin-strip { font-size: 11px; letter-spacing: 1px; padding: 8px 10px; }
}

/* 游戏页 embed 内嵌（body.embed）：站外壳提供导航，游戏页只留标题与全屏 */
body.embed .tb-back,
body.embed .tb-home { display: none; }

/* ========= 云存档面板（登录用户每游戏 3 槽） ========= */
#cloud-panel .modal-card { max-width: 680px; width: calc(100vw - 48px); text-align: left; }
.cs-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.cs-title { margin: 0; font-size: 19px; }
.cs-tip { font-size: 12.5px; margin: 0 0 14px; }
/* 云存档面板样式已撤（2026-11-17 顶栏☁入口与面板删除，仅秘籍面板继续复用 cs-title/cs-btn/cs-tip） */
.cs-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 0;
  padding: 5px 13px; font-size: 12.5px; color: var(--text);
  background: transparent; border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
}
.cs-btn:hover { border-color: var(--accent); color: var(--accent); }
.cs-btn.primary { background: var(--accent); border-color: var(--accent); color: #10233a; font-weight: 700; }
.cs-btn.primary:hover { color: #10233a; filter: brightness(1.08); }
@media (max-width: 600px) {
  #cloud-slots { grid-template-columns: 1fr; }
  #cloud-panel .modal-card { max-height: 82vh; overflow: auto; }
}
#toast.err { background: rgba(120, 26, 30, .95); }

/* 连发设置面板 */
.turbo-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 4px; border-bottom: 1px solid var(--line);
}
.turbo-row span { font-size: 14px; }
.turbo-key {
  min-width: 52px; padding: 6px 14px; font-size: 15px; font-weight: 700;
  color: var(--text); background: rgba(255, 255, 255, .04);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.turbo-key:hover { border-color: var(--accent); color: var(--accent); }

/* 云存档面板内的连发键位区 */
.cs-divider { margin: 16px 0 10px; font-size: 12px; color: var(--dim); letter-spacing: 1px; border-top: 1px solid var(--line); padding-top: 12px; }
.turbo-foot { margin-top: 10px; text-align: center; }

/* 顶栏左右分组：中缝留给居中的游戏名，避免与按钮重叠 */
.tb-group { display: flex; gap: 8px; align-items: center; flex: 1; }
.tb-group.tb-right { justify-content: flex-end; }
/* 内嵌态：右侧预留外壳「⛶ 全屏沉浸模式」按钮位（约 160px），隐藏 iframe 内冗余全屏钮 */
body.embed #topbar { padding-right: 200px; }
body.embed #btn-full { display: none; }
/* 窄屏内嵌：空间不足时隐藏居中的游戏名（右侧 200px 预留保持不变，避免与外壳按钮碰撞） */
@media (max-width: 620px) {
  body.embed #tb-title { display: none; }
  body.embed #topbar { padding-right: 150px; }
  .tb-btn { padding: 5px 10px; font-size: 12.5px; }
  .tb-group { gap: 6px; }
}

/* 秘籍面板：条目卡（左信息右按钮） */
#cheat-list { display: grid; gap: 10px; }
.cheat-item {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
}
.cheat-desc { font-weight: 700; }
.cheat-when { font-size: 12px; color: var(--dim); margin-top: 2px; }
.cheat-item .cs-btn { white-space: nowrap; }
/* 秘籍按键序列键帽（2026-11-17 主理人拍板：每条写清怎么输入，后面跟自动输入按钮） */
.cheat-keys { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 7px; }
/* netplay 双人联机面板（2026-11-17 C 轮 MVP） */
.net-status {
  font-size: 13px; font-weight: 600; color: var(--accent, #ffd39c);
  background: rgba(255, 255, 255, .04); border: 1px solid var(--line, #2a3040);
  border-radius: 8px; padding: 9px 12px; margin: 10px 0; line-height: 1.7;
}
.net-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.net-code-input {
  flex: 1; min-width: 130px; padding: 6px 10px; font-size: 14px; letter-spacing: 2px;
  text-transform: uppercase; color: var(--text, #e8e6f0);
  background: rgba(255, 255, 255, .05); border: 1px solid var(--line, #2a3040); border-radius: 8px;
  outline: none;
}
.net-code-input:focus { border-color: var(--accent, #ffd39c); }
.cheat-key {
  display: inline-block; min-width: 22px; text-align: center;
  padding: 2px 7px; font-size: 12px; font-weight: 600;
  color: var(--text); background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px;
}
.cheat-key-p2 {
  font-size: 10px; font-weight: 700; color: var(--accent);
  border: 1px solid rgba(255, 211, 92, .4); border-radius: 4px; padding: 1px 4px;
  margin-left: 6px;
}
.cheat-keys + .cheat-badge-row { margin-top: 7px; }
/* 秘籍左下角悬浮入口（2026-11-17 主理人拍板；触屏虚拟手柄占左下角，coarse 指针隐藏走底部菜单） */
/* #cheat-fab 左下角悬浮「秘籍」已撤（2026-11-18）——秘籍入口收敛到底部控制条笑脸按钮，
   跨游戏检索走子站 /tools/retro/cheats */
/* 联机按钮换装（2026-11-18）：双人图标 + 常显「联机」绿字，一眼可辨是联机 */
#nes-netplay-btn { color: #7fe3a4; }
#nes-netplay-btn:hover { color: #a7f3cd; }
#nes-netplay-btn .ejs_menu_text {
  position: static !important; opacity: 1 !important; transform: none !important;
  background: none !important; box-shadow: none !important; color: inherit !important;
  padding: 0 !important; margin: 0 0 0 4px !important; font-size: 12px !important;
  bottom: auto !important; left: auto !important; pointer-events: none !important;
}
#nes-netplay-btn .ejs_menu_text::before { content: none !important; display: none !important; }
/* 时机徽标（2026-11-01 随底部唯一秘籍入口引入）：♻需重启 / 💀死亡画面 / ▶随时可用 */
.cheat-badge-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.cheat-badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  border: 1px solid var(--line); color: var(--dim);
}
.cheat-badge.badge-restart { color: var(--accent); border-color: rgba(255, 211, 92, .45); background: rgba(255, 211, 92, .08); }
.cheat-badge.badge-gameover { color: #ff8f8f; border-color: rgba(255, 143, 143, .4); background: rgba(255, 143, 143, .07); }
.cheat-badge.badge-anytime { color: #7fe3a4; border-color: rgba(127, 227, 164, .4); background: rgba(127, 227, 164, .07); }
