/* Study Ninja: graph-paper notebook by day, night desk by night */
:root {
  --paper: #f5f7fb;
  --grid-line: #e2e8f3;
  --card: #ffffff;
  --ink: #1b2440;
  --muted: #5a6683;
  --line: #d6deec;
  --pen: #2b54e8;
  --marker: #ffe45c;
  --marker-ink: #1b2440;
  --shadow: 0 1px 0 #d6deec, 0 6px 14px -10px rgba(27, 36, 64, 0.35);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #10182a;
    --grid-line: #18233a;
    --card: #17213a;
    --ink: #e7ecf8;
    --muted: #9eabc7;
    --line: #26324e;
    --pen: #9bb1ff;
    --marker: #ffd93d;
    --marker-ink: #10182a;
    --shadow: 0 1px 0 #0a1020, 0 8px 18px -12px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #10182a;
  --grid-line: #18233a;
  --card: #17213a;
  --ink: #e7ecf8;
  --muted: #9eabc7;
  --line: #26324e;
  --pen: #9bb1ff;
  --marker: #ffd93d;
  --marker-ink: #10182a;
  --shadow: 0 1px 0 #0a1020, 0 8px 18px -12px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, .logo, .play {
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
}
a { color: var(--pen); }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--pen); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px clamp(12px, 3vw, 28px);
  background: var(--card);
  border-bottom: 2px solid var(--line);
}
.logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 1.25rem; font-weight: 800; letter-spacing: -0.01em;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.logo-mark { font-size: 1.5rem; line-height: 1; }
.search { flex: 1; max-width: 460px; margin-left: auto; }
.search input {
  width: 100%; padding: 9px 14px;
  font: inherit; color: var(--ink);
  background: var(--paper); border: 2px solid var(--line); border-radius: 10px;
}
.search input:focus { outline: none; border-color: var(--pen); }
.theme-btn {
  flex: none; width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 1.15rem; cursor: pointer;
  color: var(--ink); background: var(--paper);
  border: 2px solid var(--line); border-radius: 10px;
}
.theme-btn span::before { content: "🌙"; }
:root[data-theme="dark"] .theme-btn span::before { content: "☀️"; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-btn span::before { content: "☀️"; }
}

/* Page */
.wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0 clamp(12px, 3vw, 28px) 48px; flex: 1; }
.intro { padding: 28px 0 8px; max-width: 60ch; }
.intro h1 { margin: 0 0 6px; font-size: clamp(1.7rem, 4vw, 2.6rem); line-height: 1.1; letter-spacing: -0.02em; }
.intro p { margin: 0; color: var(--muted); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 16px 0; scrollbar-width: thin; }
.chip {
  flex: none; padding: 6px 14px;
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.92rem;
  background: var(--card); border: 2px solid var(--line); border-radius: 999px;
}
.chip small { color: var(--muted); font-weight: 500; margin-left: 2px; }
.chip.on { background: var(--marker); border-color: var(--marker); color: var(--marker-ink); }
.chip.on small { color: var(--marker-ink); }

/* Game grid: index cards on graph paper */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 14px; }
.tile {
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow);
  text-decoration: none; color: var(--ink); overflow: hidden;
}
.tile img { width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; background: var(--grid-line); }
.tile-title {
  margin: 8px 10px 10px; font-weight: 600; font-size: 0.92rem; line-height: 1.3;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.tile:hover .tile-title, .tile:focus-visible .tile-title {
  background: linear-gradient(transparent 12%, var(--marker) 12%, var(--marker) 88%, transparent 88%);
  color: var(--marker-ink);
}
.tile[hidden] { display: none; }
.no-results { color: var(--muted); }

/* Game page */
.crumbs { padding-top: 20px; font-size: 0.9rem; color: var(--muted); }
.crumbs a { color: var(--muted); }
.game-title { margin: 6px 0 14px; font-size: clamp(1.5rem, 3.5vw, 2.2rem); line-height: 1.15; letter-spacing: -0.02em; }
.stage {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 10px;
}
.frame {
  position: relative; margin: 0 auto;
  aspect-ratio: var(--ar);
  width: min(100%, calc((100vh - 200px) * (var(--ar))));
  min-width: min(100%, 280px);
  background: #000; border-radius: 6px; overflow: hidden;
}
.frame img { width: 100%; height: 100%; object-fit: cover; opacity: 0.55; filter: blur(2px); }
.frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  max-width: 85%;
  padding: 14px 28px; font-size: 1.15rem; font-weight: 800;
  color: var(--marker-ink); background: var(--marker);
  border: 0; border-radius: 12px; cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.play:active { transform: translate(-50%, calc(-50% + 3px)); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.stage-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 4px 2px; font-size: 0.9rem; color: var(--muted);
}
.fs-btn {
  flex: none; padding: 7px 14px; font: inherit; font-weight: 600; cursor: pointer;
  color: var(--ink); background: var(--paper); border: 2px solid var(--line); border-radius: 8px;
}
.about { max-width: 70ch; }
.about h2, .more h2 { font-size: 1.3rem; margin: 32px 0 8px; }
.about p { margin: 0; }

/* Footer */
.foot {
  padding: 20px clamp(12px, 3vw, 28px);
  background: var(--card); border-top: 2px solid var(--line);
  color: var(--muted); font-size: 0.88rem;
}
.foot p { margin: 4px auto; max-width: 1280px; }

@media (max-width: 560px) {
  .logo span:last-child { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .frame { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
