/* ---- Calm dark theme ---- */
:root {
  --bg: #14161a;
  --surface: #1c1f26;
  --surface-2: #232732;
  --border: #2a2f3a;
  --text: #dfe2e8;
  --muted: #8a909d;
  --accent: #6d8ab0;          /* muted slate-blue */
  --accent-soft: #6d8ab022;
  --fav: #cf8a96;             /* soft rose for favorites */
  --radius: 12px;
  --gap: 16px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win over component display rules below
   (a class selector would otherwise override the UA `[hidden]{display:none}`). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search {
  display: flex;
  flex: 1 1 320px;
  min-width: 220px;
  gap: 8px;
}
.search input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}
.search input:focus { border-color: var(--accent); }
.search button {
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #0e1116;
  font-weight: 600;
  cursor: pointer;
}
.search button:hover { filter: brightness(1.08); }

.topbar-actions { display: flex; gap: 8px; }

.ghost-btn {
  padding: 9px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); color: #fff; }
.ghost-btn.active { border-color: var(--accent); color: #fff; background: var(--surface-2); }

/* ---- Layout ---- */
main { padding: 22px 20px 60px; max-width: 1500px; margin: 0 auto; }

.shelf { margin-bottom: 38px; }
.shelf h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 14px;
  letter-spacing: 0.3px;
}

/* Responsive grid: scales with viewport width & aspect ratio automatically */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--gap);
}

/* ---- Game card ---- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
  display: flex;
  flex-direction: column;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }

.card-thumb {
  aspect-ratio: 4 / 3;
  width: 100%;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}
.card-title {
  padding: 10px 12px;
  font-size: 0.88rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.fav-toggle {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(10, 12, 16, 0.6);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
}
.fav-toggle:hover { background: rgba(10, 12, 16, 0.85); }
.fav-toggle.active { color: var(--fav); }

/* ---- Status / misc ---- */
.status { color: var(--muted); padding: 12px 2px; font-size: 0.9rem; }
.load-more {
  display: block;
  margin: 20px auto 0;
  padding: 11px 26px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.load-more:hover { border-color: var(--accent); }

/* ---- Player overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(8, 9, 12, 0.86);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.player-shell {
  width: min(900px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.player-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
#player-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.player-head-actions { display: flex; gap: 8px; flex-shrink: 0; }
.player-stage {
  position: relative;
  flex: 1;
  min-height: 480px;
  background: #000;
  display: grid;
  place-items: center;
}
.player-stage ruffle-player,
.player-stage > div[style] { width: 100%; height: 100%; }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .topbar { gap: 10px; }
}

/* ============ Shortcuts guide ============ */
.shortcuts-box {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.shortcuts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.shortcuts-list {
  margin: 0;
  padding: 8px 18px 18px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 18px;
  align-items: center;
}
.shortcuts-list dt { white-space: nowrap; }
.shortcuts-list dd { margin: 0; color: var(--muted); font-size: 0.92rem; }
.shortcuts-list kbd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 7px;
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
}

/* ============ Math cover (front page) ============ */
#math-cover {
  position: fixed;
  inset: 0;
  z-index: 9999;
  overflow-y: auto;
  background: #f6f7fb;
  color: #1d2433;
  font-family: Georgia, "Times New Roman", serif;
}
.m-banner {
  background: #2f6fb0;
  color: #fff;
  text-align: center;
  padding: 30px 20px 26px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.m-banner h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3rem);
  letter-spacing: 0.5px;
}
.m-banner p { margin: 8px 0 0; opacity: 0.9; font-size: 1.05rem; }

.m-main { max-width: 680px; margin: 0 auto; padding: 30px 22px 90px; }
#math-questions { margin: 0; padding-left: 24px; }
#math-questions li { margin-bottom: 14px; }

.m-q {
  background: #fff;
  border: 1px solid #e3e6ef;
  border-radius: 10px;
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.m-q .q-text { font-size: 1.06rem; line-height: 1.4; }
.m-q input {
  width: 96px;
  flex-shrink: 0;
  padding: 9px 11px;
  border: 1px solid #c7ccda;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  text-align: center;
}
.m-q input:focus { outline: none; border-color: #2f6fb0; }
.m-q.correct input { border-color: #3aa657; background: #eafaef; }
.m-q.wrong input { border-color: #d9534f; background: #fdecec; }

.m-actions { display: flex; align-items: center; gap: 18px; margin-top: 24px; }
#math-check {
  background: #2f6fb0;
  color: #fff;
  border: none;
  padding: 11px 24px;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
}
#math-check:hover { background: #2a6299; }
#math-score { font-weight: bold; font-size: 1.05rem; }

.m-foot {
  margin-top: 40px;
  text-align: center;
  color: #99a0ad;
  font-size: 0.85rem;
  font-family: system-ui, sans-serif;
}

/* Invisible click target in the bottom-right corner — aim there to enter games.
   No text, no cursor change, so it's not visible; you just know where it is. */
#math-back {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 72px;
  height: 72px;
  background: transparent;
  cursor: default;
}
