/*
 * 主题：每个颜色用 light-dark(明亮, 暗色) 写一次。
 * 没有 data-theme 时跟随系统；app.js 按用户选择设置 data-theme="light" / "dark"。
 */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f3f1eb, #16171c);
  --panel: light-dark(#ffffff, #1f2128);
  --panel-2: light-dark(#eeebe3, #282b34);
  --line: light-dark(#dcd8ce, #343844);
  --line-strong: light-dark(#b9b3a5, #50566a);
  --text: light-dark(#23242b, #ecebe6);
  --muted: light-dark(#6c6e78, #9a9ca6);
  --red: light-dark(#d23c30, #e0463a);
  --red-2: light-dark(#b02c22, #b8322a);
  --gold: #f2c14e;
  --danger: light-dark(#c62828, #ff8a80);
  --badge-text: light-dark(#4b4d57, #c9cad1);
  --save-bg: light-dark(rgba(210,60,48,.12), rgba(224,70,58,.18));
  --save-text: light-dark(#b02c22, #ff9b91);
  --media: light-dark(#e2dfd6, #0d0e11);
  --code-bg: light-dark(#f0ede5, #0f1014);
  --notice-bg: light-dark(rgba(217,154,0,.12), rgba(242,193,78,.1));
  --notice-line: light-dark(rgba(190,135,0,.4), rgba(242,193,78,.35));
  --notice-text: light-dark(#7a5800, #f5d68a);
  --bar: light-dark(#ffffff, #111216);
  --bar-line: light-dark(#dcd8ce, #23252d);
  --bar-btn: light-dark(#f3f1eb, #1b1d23);
  --bar-btn-line: light-dark(#d2cdc1, #2e313b);
  --pop: light-dark(#ffffff, #1b1d23);
  --pop-line: light-dark(#dcd8ce, #2e313b);
  --shadow: light-dark(rgba(40,35,20,.16), rgba(0,0,0,.5));
  --toast-bg: light-dark(#2b2c33, #2b2e37);
  --toast-line: light-dark(#2b2c33, #3c4050);
  --radius: 10px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---------- 顶栏 ---------- */
#app { max-width: 1440px; margin: 0 auto; padding: 0 20px 24px; min-height: 100%; display: flex; flex-direction: column; }
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; padding: 18px 0 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .04em; }
.brand p { margin: 0; font-size: 12px; }
.logo {
  width: 40px; height: 28px; border-radius: 4px; flex: none;
  background: linear-gradient(#d9d4c7 0 55%, var(--red-2) 55% 72%, #2c2c2c 72%);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.25);
}
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search input {
  width: min(320px, 70vw); padding: 8px 12px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line); outline: none;
}
.search input:focus { border-color: var(--red); }
select, .ghost, .btn {
  padding: 8px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line);
}
.ghost:hover, select:hover { border-color: var(--line-strong); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-2); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.theme-btn { display: inline-flex; align-items: center; gap: 6px; }
/* 图标：明亮=空心圆，暗色=实心圆，跟随系统=半圆 */
.theme-btn .ico { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; flex: none; }
.theme-btn[data-mode="dark"] .ico { background: currentColor; }
.theme-btn[data-mode="auto"] .ico { background: linear-gradient(90deg, currentColor 50%, transparent 50%); }

/* ---------- 分类 ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: thin; }
.tab {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.tab .count { margin-left: 6px; font-size: 12px; opacity: .7; }

.notice {
  margin: 0 0 12px; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  background: var(--notice-bg); border: 1px solid var(--notice-line); color: var(--notice-text);
}

/* ---------- 游戏卡片 ---------- */
main { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.card {
  position: relative; display: flex; flex-direction: column; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  transition: transform .12s ease, border-color .12s ease;
}
.card:hover, .card:focus-within { transform: translateY(-2px); border-color: var(--line-strong); }
.card .open {
  display: flex; flex-direction: column; text-align: left; padding: 0; border: 0; background: none; width: 100%;
}
.card .open:focus-visible { outline: 2px solid var(--red); outline-offset: -2px; }
.media { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: var(--media); }
.media .blur { position: absolute; inset: -12px; background-size: cover; background-position: center; filter: blur(14px) brightness(.55); }
.media img { position: relative; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; display: block; }
.media img.cover { image-rendering: auto; }
.media .ph {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 44px; font-weight: 700; color: rgba(255,255,255,.88); text-shadow: 0 2px 0 rgba(0,0,0,.3);
}
.media .play {
  position: absolute; inset: 0; display: grid; place-items: center; opacity: 0;
  background: rgba(0,0,0,.35); transition: opacity .12s;
}
.media .play::after {
  content: ""; width: 0; height: 0; margin-left: 6px;
  border-left: 22px solid #fff; border-top: 14px solid transparent; border-bottom: 14px solid transparent;
}
.card:hover .play, .card .open:focus-visible .play { opacity: 1; }
.info { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.title { font-weight: 600; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
.meta { display: flex; flex-wrap: wrap; gap: 4px; font-size: 12px; color: var(--muted); }
.badge { padding: 0 6px; border-radius: 4px; background: var(--panel-2); font-size: 11px; line-height: 18px; color: var(--badge-text); }
.badge.save { background: var(--save-bg); color: var(--save-text); }
.fav {
  position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 16px; line-height: 30px; text-align: center;
  opacity: 0; transition: opacity .12s;
}
.card:hover .fav, .fav:focus-visible, .fav[aria-pressed="true"] { opacity: 1; }
.fav[aria-pressed="true"] { color: var(--gold); }
@media (hover: none) { .fav { opacity: 1; } }

/* ---------- 空状态 ---------- */
.empty { max-width: 640px; margin: 40px auto; padding: 24px; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h2 { margin: 0 0 8px; font-size: 18px; }
.empty pre { background: var(--code-bg); padding: 12px; border-radius: 8px; overflow: auto; font-size: 13px; }
.empty code { font-family: ui-monospace, Consolas, monospace; }

.foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding-top: 24px; font-size: 12px; }

/* ---------- 播放器 ---------- */
.player { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; background: #000; }
.player-bar {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  background: var(--bar); border-bottom: 1px solid var(--bar-line);
}
.player-bar button {
  padding: 5px 10px; border-radius: 6px; border: 1px solid var(--bar-btn-line); background: var(--bar-btn); font-size: 13px;
}
.player-bar button:hover { border-color: var(--line-strong); }
.player-bar button:disabled { opacity: .45; cursor: default; }
.player-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.player-actions { display: flex; gap: 6px; }
.stage { position: relative; flex: 1; min-height: 0; }
.stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: #000; }
.help {
  position: absolute; top: 46px; right: 10px; z-index: 2; width: 300px; padding: 12px 14px;
  background: var(--pop); border: 1px solid var(--pop-line); border-radius: 8px; box-shadow: 0 8px 24px var(--shadow);
}
.help table { width: 100%; border-collapse: collapse; }
.help th { text-align: left; font-weight: 500; color: var(--muted); padding: 3px 0; width: 45%; }
.help td { padding: 3px 0; }
.help p { margin: 8px 0 0; font-size: 12px; }
@media (max-width: 560px) {
  .player-actions button[data-wide] { display: none; }
  .player-bar { gap: 6px; }
}

/* ---------- 对话框 ---------- */
dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
.dlg { padding: 18px 20px 16px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-size: 17px; }
.dlg p { margin: 0; }
.choices { display: grid; gap: 8px; }
.choice {
  display: flex; align-items: center; gap: 12px; padding: 8px; text-align: left;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
}
.choice:hover, .choice:focus-visible { border-color: var(--red); outline: none; }
.choice img, .choice .thumb { width: 96px; height: 72px; flex: none; border-radius: 4px; object-fit: contain; background: var(--media); image-rendering: pixelated; }
.choice strong { display: block; }
.choice small { color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.list { display: grid; gap: 6px; max-height: 50vh; overflow: auto; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; background: var(--panel-2); }
.list .item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .item small { color: var(--muted); white-space: nowrap; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 40; transform: translate(-50%, 20px);
  padding: 8px 14px; border-radius: 8px; background: var(--toast-bg); border: 1px solid var(--toast-line); color: #f2f1ec;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
