/* GameStudio portal — dark-first, green accent echoing the duckmath.org palette */
:root {
  --bg: #0b1210;
  --bg-soft: #0f1814;
  --surface: #131e19;
  --surface-2: #18261f;
  --surface-3: #1e3027;
  --border: #24382c;
  --border-strong: #33523f;
  --text: #e9f5ec;
  --text-dim: #a7c2b1;
  --muted: #779486;
  --accent: #4ade80;
  --accent-soft: rgba(74, 222, 128, .12);
  --accent-2: #38bdf8;
  --warn: #fbbf24;
  --danger: #fb7185;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --radius: 14px;
  --header-h: 68px;
}
html[data-theme="light"] {
  --bg: #f3f8f4;
  --bg-soft: #eaf2ec;
  --surface: #ffffff;
  --surface-2: #f4f9f5;
  --surface-3: #e7f1e9;
  --border: #d9e8dd;
  --border-strong: #b9d6c3;
  --text: #15251c;
  --text-dim: #3d5c49;
  --muted: #6a8776;
  --accent: #16a34a;
  --accent-soft: rgba(22, 163, 74, .1);
  --accent-2: #0284c7;
  --warn: #b45309;
  --danger: #dc2626;
  --shadow: 0 18px 45px rgba(20, 50, 30, .13);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
::selection { background: var(--accent-soft); color: var(--text); }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; font-size: 19px;
  background: linear-gradient(145deg, var(--accent), #16a34a);
  box-shadow: 0 4px 14px var(--accent-soft);
}
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: .3px; white-space: nowrap; }
.brand-name small { display: block; font-size: 10px; font-weight: 500; color: var(--muted); letter-spacing: 1.4px; }

.search {
  flex: 1 1 auto; max-width: 520px; position: relative; margin-left: auto;
}
.search input {
  width: 100%; height: 40px; padding: 0 42px 0 42px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 11px;
  outline: none; transition: .18s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 15px; pointer-events: none; }
.search kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 10px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 5px; padding: 2px 5px; pointer-events: none;
}
.search.has-value kbd { display: none; }
.search .clear {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  display: none; width: 22px; height: 22px; border: 0; border-radius: 6px;
  background: var(--surface-3); color: var(--text-dim); line-height: 1;
}
.search.has-value .clear { display: block; }

.icon-btn {
  width: 38px; height: 38px; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-dim); font-size: 16px; transition: .18s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- layout ---------- */
.page { max-width: 1440px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 70px; }
.hero {
  padding: 46px 0 30px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap;
}
.hero h1 { margin: 0 0 10px; font-size: clamp(26px, 4vw, 40px); letter-spacing: -.6px; line-height: 1.15; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p { margin: 0; color: var(--text-dim); font-size: 14px; line-height: 1.7; max-width: 620px; }
.hero-stats { display: flex; gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 18px; text-align: center; min-width: 92px;
}
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 11px; letter-spacing: .5px; }

/* ---------- filters ---------- */
.filters {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 20px;
}
.filter-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter-row + .filter-row { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.filter-label { font-size: 11px; color: var(--muted); letter-spacing: .8px; min-width: 52px; }

.segmented { display: inline-flex; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 6px 13px; border-radius: 7px; font-size: 12.5px; transition: .15s; white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--accent); color: #07140c; font-weight: 700; }
html[data-theme="light"] .segmented button.active { color: #fff; }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text-dim);
  padding: 5px 11px; border-radius: 20px; font-size: 12px; transition: .15s; white-space: nowrap;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip .n { opacity: .6; font-size: 10px; margin-left: 4px; }

select.sort {
  margin-left: auto; background: var(--bg-soft); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 9px; padding: 7px 11px; font-size: 12.5px; outline: none;
}
select.sort:focus { border-color: var(--accent); }

.result-line { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 14px; gap: 12px; flex-wrap: wrap; }
.result-line .count { font-size: 13px; color: var(--muted); }
.result-line .count b { color: var(--text); }
.link-btn { background: none; border: 0; color: var(--accent); font-size: 12.5px; padding: 4px; }
.link-btn:hover { text-decoration: underline; }

/* ---------- game grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 16px; }
.card {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; transition: transform .2s, border-color .2s, box-shadow .2s;
  display: flex; flex-direction: column; cursor: pointer;
}
.card:hover { transform: translateY(-4px); border-color: var(--border-strong); box-shadow: var(--shadow); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cover {
  position: relative; aspect-ratio: 4 / 3; overflow: hidden;
  background: linear-gradient(140deg, var(--surface-2), var(--surface-3));
  display: grid; place-items: center;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .35s; }
.card:hover .cover img { transform: scale(1.06); }
.cover .emoji { font-size: 62px; filter: drop-shadow(0 8px 18px rgba(0,0,0,.35)); }
.cover .fallback {
  position: absolute; inset: 0; display: none; place-items: center;
  font-size: 30px; font-weight: 800; color: var(--muted);
  background: linear-gradient(140deg, var(--surface-2), var(--surface-3));
}
.cover.img-failed img { display: none; }
.cover.img-failed .fallback { display: grid; }
.cover .veil { position: absolute; inset: 0; background: linear-gradient(180deg, transparent 55%, rgba(0,0,0,.55)); pointer-events: none; }
.badge {
  position: absolute; top: 9px; left: 9px; z-index: 2;
  font-size: 10px; font-weight: 700; letter-spacing: .4px;
  padding: 4px 8px; border-radius: 6px; backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.14);
}
.badge.local { background: rgba(22, 163, 74, .9); color: #fff; }
.badge.external { background: rgba(15, 23, 42, .78); color: #cbd5e1; }
.fav {
  position: absolute; top: 7px; right: 8px; z-index: 3;
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid rgba(255,255,255,.16);
  background: rgba(10, 18, 14, .62); color: #fff; font-size: 14px;
  display: grid; place-items: center; backdrop-filter: blur(8px); transition: .15s;
}
.fav:hover { transform: scale(1.1); }
.fav.on { color: var(--warn); border-color: var(--warn); }
.play-hint {
  position: absolute; inset: 0; z-index: 2; display: grid; place-items: center;
  background: rgba(6, 14, 10, .5); opacity: 0; transition: .2s;
}
.card:hover .play-hint { opacity: 1; }
.play-hint span {
  background: var(--accent); color: #07140c; font-weight: 800; font-size: 13px;
  padding: 9px 18px; border-radius: 30px; transform: translateY(6px); transition: .2s;
}
.card:hover .play-hint span { transform: translateY(0); }
.card-body { padding: 11px 13px 13px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-title { font-size: 13.5px; font-weight: 700; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-zh { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 16px; }
.card-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.tag { font-size: 10px; color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 2px 6px; }
.tag.ads { color: #d9a441; background: rgba(217, 164, 65, .14); border-color: rgba(217, 164, 65, .42); font-weight: 600; }
.card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 8px; font-size: 11px; color: var(--muted); }
.card-foot .heat { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.card-foot .heat.hot { color: var(--accent); }

/* ---------- sections ---------- */
.section-head { display: flex; align-items: baseline; gap: 10px; margin: 34px 2px 14px; }
.section-head h2 { margin: 0; font-size: 17px; }
.section-head span { font-size: 12px; color: var(--muted); }
.recent-strip { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.recent-item {
  flex: 0 0 132px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; padding: 9px 11px; cursor: pointer; transition: .15s;
}
.recent-item:hover { border-color: var(--accent); }
.recent-item b { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item small { color: var(--muted); font-size: 10px; }

/* ---------- empty / loading ---------- */
.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty .big { font-size: 42px; margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.empty p { margin: 0 0 16px; font-size: 13px; }
.state-box { padding: 60px 20px; text-align: center; color: var(--muted); font-size: 14px; }
.state-box code { background: var(--surface-2); border: 1px solid var(--border); padding: 2px 7px; border-radius: 5px; color: var(--accent); font-size: 12px; }

/* ---------- player modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100; display: none;
  background: rgba(4, 10, 7, .88); backdrop-filter: blur(8px);
  padding: clamp(8px, 2vw, 26px);
}
.modal.open { display: flex; align-items: center; justify-content: center; }
.player {
  width: min(1100px, 100%); height: min(860px, 100%);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.player-head {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border-bottom: 1px solid var(--border); background: var(--bg-soft); flex: 0 0 auto;
}
.player-head .p-emoji { font-size: 20px; }
.player-head .p-title { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-head .p-sub { font-size: 11px; color: var(--muted); }
.player-tools { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.tool {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-dim);
  border-radius: 8px; padding: 6px 11px; font-size: 12px; white-space: nowrap; transition: .15s;
}
.tool:hover { border-color: var(--accent); color: var(--accent); }
.tool.primary { background: var(--accent); color: #07140c; border-color: var(--accent); font-weight: 700; }
html[data-theme="light"] .tool.primary { color: #fff; }
.tool.close { font-size: 16px; padding: 4px 10px; }
.player-frame { flex: 1 1 auto; position: relative; background: #0b1210; min-height: 0; }
.player-frame iframe { width: 100%; height: 100%; border: 0; display: block; background: #0b1210; }
.frame-loading {
  position: absolute; inset: 0; display: grid; place-items: center; gap: 10px;
  color: var(--muted); font-size: 13px; background: var(--bg-soft); text-align: center; padding: 20px;
}
.frame-loading.hidden { display: none; }
.frame-note {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  font-size: 11.5px; color: var(--muted); background: var(--surface-2);
  border-top: 1px solid var(--border); flex: 0 0 auto;
}
.frame-note b { color: var(--warn); font-weight: 600; }
body.modal-open { overflow: hidden; }

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid var(--border); margin-top: 46px; padding: 22px 0 0;
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--muted); line-height: 1.8;
}
.footer a { color: var(--accent); }
.footer a:hover { text-decoration: underline; }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  :root { --header-h: 60px; }
  .topbar { gap: 10px; }
  .brand-name small { display: none; }
  .brand-name { font-size: 14px; }
  .search { max-width: none; }
  .search kbd { display: none; }
  .hero { padding: 28px 0 22px; }
  .hero-stats { width: 100%; }
  .stat { flex: 1; min-width: 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 11px; }
  .cover .emoji { font-size: 46px; }
  .player-tools .tool span { display: none; }
  .filter-label { min-width: 100%; }
  select.sort { margin-left: 0; }
}
@media (max-width: 420px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .card-body { padding: 9px 10px 11px; }
}
