:root {
  --bg: #16181d;
  --panel: #20232a;
  --panel-2: #282c35;
  --line: #343946;
  --text: #eceef3;
  --muted: #9aa1b2;
  --accent: #ffcb3d;
  --accent-ink: #2a1f00;
  --danger: #ff6a6a;
  --ok: #58d39a;
  --lcd-bg: #b4bea2;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
#sheet-body a, .banner a { color: var(--accent); }
#sheet-body .about { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 12px; }

.view { display: none; min-height: 100%; }
.view.active { display: block; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px; background: rgba(22,24,29,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .2px; }
.brand p { margin: 0; font-size: 13px; }
/* a tiny brick game: pale shell, LCD, yellow buttons */
.brand-mark { width: 24px; height: 38px; border-radius: 5px; background: #e4e1d2; position: relative; flex: none; box-shadow: inset 0 -3px 0 #bdb9a6; }
.brand-mark::before { content: ""; position: absolute; left: 4px; top: 4px; width: 16px; height: 15px; border-radius: 2px; background: var(--lcd-bg); }
.brand-mark::after { content: ""; position: absolute; left: 5px; bottom: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); box-shadow: 9px -2px 0 1px var(--accent); }
.icon-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 40px;
  font-size: 20px; line-height: 1; display: grid; place-items: center; cursor: pointer; flex: none; }
.icon-btn:active { background: var(--panel-2); }

main { padding: 8px 16px calc(env(safe-area-inset-bottom) + 32px); max-width: 980px; margin: 0 auto; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 2px 10px; font-weight: 600; }
.banner { margin: 12px auto 0; padding: 14px; border-radius: var(--radius); background: #2c2a1c; border: 1px solid #5a5230;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-start; max-width: 948px; width: calc(100% - 32px); }
.banner-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600; text-decoration: none; }
.btn:active { background: var(--panel-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- library grid ---------- */
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 12px; }
.game { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px;
  display: flex; flex-direction: column; gap: 8px; cursor: pointer; position: relative; }
.game:active { transform: scale(.98); }
.game .thumb { width: 100%; aspect-ratio: 1; border-radius: 8px; background: radial-gradient(90% 90% at 50% 20%, #343a48, #23262e); overflow: hidden; position: relative; }
.game .thumb img { position: absolute; inset: 8px; width: calc(100% - 16px); height: calc(100% - 16px); object-fit: contain; }
.game.missing .thumb img { filter: grayscale(.7) brightness(.75); }
.game .name { font-weight: 650; font-size: 14px; line-height: 1.25; }
.game .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: #2b3140; color: #b9c2d6; }
.tag.warn { background: #3b2d14; color: #ffc864; }
.tag.good { background: #17352a; color: #7fe0b2; }
.game .more { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 8px; border: none; background: rgba(0,0,0,.45); color: #fff; font-size: 16px; cursor: pointer; }

/* ---------- filter: all / arcade / pets ---------- */
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 18px 2px 10px; }
.lib-head .section-title { margin: 0; }
.filter { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px; }
.filter button { border: 0; background: none; color: var(--muted); font: inherit; font-size: 14px; font-weight: 650; padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.filter button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }

/* phones: three across */
@media (max-width: 600px) {
  main { padding-left: 10px; padding-right: 10px; }
  .game-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .game { padding: 6px; gap: 5px; border-radius: 11px; }
  .game .thumb { border-radius: 7px; }
  .game .thumb img { inset: 5px; width: calc(100% - 10px); height: calc(100% - 10px); }
  .game .name { font-size: 12px; line-height: 1.2; }
  .game .meta { font-size: 10.5px; gap: 4px; }
  .game .meta + .meta { display: none; }                      /* the detail line: no room for it */
  .tag { font-size: 9.5px; padding: 1px 5px; }
  .game .more { top: 4px; right: 4px; width: 24px; height: 24px; font-size: 13px; border-radius: 6px; }
  .filter button { padding: 6px 11px; font-size: 13px; }
}

/* ---------- player ---------- */
#player { background: radial-gradient(120% 80% at 50% 0%, #2a2e38 0%, var(--bg) 70%); height: 100dvh; min-height: 0; display: none; flex-direction: column; }
#player.active { display: flex; }
html.in-player, html.in-player body { overflow: hidden; }
.player-bar { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 10px) 12px 6px; flex: none; }
.player-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.player-title span:first-child { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-title .muted { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage { flex: 1; min-height: 0; padding: 6px 10px calc(env(safe-area-inset-bottom) + 12px); display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none; touch-action: none; }
.stage svg { width: 100%; height: 100%; display: block; overflow: visible; }
.stage .bk-hit { fill: #fff; fill-opacity: 0; cursor: pointer; touch-action: none; }
.stage .bk-hit:hover { fill-opacity: .12; }
.stage .bk-hit.pressed { fill-opacity: .3; }
.stage .loading { color: var(--muted); }

/* phone held sideways: the bar floats over the corners so the handheld gets the full height */
@media (orientation: landscape) and (max-height: 560px) {
  .player-bar { position: absolute; top: 0; left: 0; right: 0; z-index: 3; padding: calc(env(safe-area-inset-top) + 6px) calc(env(safe-area-inset-right) + 10px) 0 calc(env(safe-area-inset-left) + 10px); pointer-events: none; }
  .player-bar > * { pointer-events: auto; }
  .player-title { visibility: hidden; }
  .stage { padding: 6px 56px calc(env(safe-area-inset-bottom) + 6px); }
}

/* ---------- sheet / toast ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel { width: 100%; max-width: 520px; background: var(--panel); border-radius: 18px 18px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px);
  border: 1px solid var(--line); max-height: 88dvh; overflow: auto; }
.sheet-panel h3 { margin: 0 0 8px; font-size: 17px; }
#sheet-body { color: var(--muted); font-size: 14px; }
#sheet-body p { margin: 6px 0 10px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.sheet-actions .btn { width: 100%; }
.field { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: var(--text); }
.field input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.keys { width: 100%; border-collapse: collapse; color: var(--text); }
.keys td { padding: 5px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.keys td:last-child { text-align: right; color: var(--muted); }
kbd { background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font: inherit; font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%); z-index: 30;
  background: #2d323d; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: 0 10px 30px rgba(0,0,0,.4); }

@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: 18px; }
}

/* ---------- catching up on time away (virtual pets) ---------- */
#player { position: relative; }
.catchup { position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 18px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0,0,0,.4);
  font-size: 14px; max-width: calc(100vw - 32px); }
.catchup.hidden { display: none; }
