/* BudgetGames — layout and neutral defaults. Themes (/theme.css) set the tokens and decoration.
   Elements marked .retro-only are hidden unless a theme opts in. */
:root {
  --bg: #f5f6f8; --fg: #1c2230; --muted: #5d6878; --card: #fff; --line: #e2e5ea; --field: #fff;
  --accent: #4c46d6; --accent-fg: #fff; --accent-soft: #ecebff; --danger: #c62828; --ok: #1b7f3a;
  --radius: 12px; --radius-s: 8px; --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 6px 18px rgb(0 0 0 / .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; --font-head: var(--font);
  --gutter: 16px; --maxw: 1240px;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--font); min-height: 100vh; overflow-x: hidden; }
body.modal-open { overflow: hidden; }
img { max-width: 100%; display: block; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--card); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }
.retro-only { display: none; }
.deco { display: none; }          /* optional decoration hooks a theme can switch on (e.g. .menubar) */
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* buttons & fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border: 1px solid var(--line);
  border-radius: var(--radius-s); background: var(--card); color: var(--fg); cursor: pointer; text-decoration: none; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn-big { min-height: 48px; padding: 10px 22px; font-size: 16px; }
.linkish { background: none; border: 0; padding: 4px 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--field); font-size: 16px; }
textarea { resize: vertical; min-height: 90px; }
.field { display: grid; gap: 4px; margin: 0 0 14px; border: 0; padding: 0; min-width: 0; }
.label { font-weight: 650; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin-top: 8px; }
.hp { position: absolute !important; left: -5000px; width: 1px; height: 1px; overflow: hidden; }
.form-error { color: var(--danger); font-weight: 600; margin: 8px 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* header */
.site-header { max-width: var(--maxw); margin: 0 auto; padding: 20px var(--gutter) 8px; }
.header-inner { display: flex; align-items: center; gap: 12px 18px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--fg); }
.logo { width: 38px; height: 38px; background: url(/static/favicon.svg) center/contain no-repeat; flex: none; }
.brand-name { font: 800 26px/1.1 var(--font-head); letter-spacing: -.02em; }
.tagline { margin: 0; color: var(--muted); flex: 1 1 260px; }
.add-btn { margin-left: auto; }

/* toolbar + tags */
.toolbar { max-width: var(--maxw); margin: 0 auto; padding: 8px var(--gutter); display: flex; gap: 10px; }
.toolbar .search { flex: 1; }
.toolbar .sort { flex: 0 0 auto; width: 150px; }
.tagbar { max-width: var(--maxw); margin: 0 auto; padding: 4px var(--gutter) 6px; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; color: var(--fg); }
.chip.active, .chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.chip-n { opacity: .65; }
.chip-small { padding: 3px 10px; font-size: 12px; }

/* grid + cards */
main { max-width: var(--maxw); margin: 0 auto; padding: 4px var(--gutter) 40px; }
.result-line { color: var(--muted); font-size: 14px; margin: 6px 0 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }
.card { min-width: 0; }
.card-link { display: flex; flex-direction: column; height: 100%; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; color: inherit; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s; }
.card-link:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgb(0 0 0 / .08), 0 12px 28px rgb(0 0 0 / .1); }
.card.featured .card-link { border-color: var(--accent); }
.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--line); overflow: hidden; }
.thumb > img, .thumb > .ph { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ph { display: grid; place-items: center; background: linear-gradient(135deg, hsl(var(--h, 220) 70% 55%), hsl(calc(var(--h, 220) + 50) 70% 40%)); color: #fff;
  font: 800 34px/1 var(--font-head); letter-spacing: .04em; text-shadow: 0 2px 8px rgb(0 0 0 / .25); }
.sticker { position: absolute; top: 8px; left: 8px; background: rgb(0 0 0 / .72); color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  padding: 3px 8px; border-radius: 999px; }
.sticker.inline { position: static; display: inline-block; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-title { margin: 0; font: 700 16px/1.3 var(--font-head); }
.card-desc { margin: 0; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { margin-top: auto; display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); padding-top: 4px; }
.card-tags { display: flex; gap: 6px; overflow: hidden; white-space: nowrap; }
.card-count { flex: none; }
.empty { text-align: center; padding: 40px 0; color: var(--muted); }

/* dialogs */
.dialog { border: 0; padding: 0; background: var(--card); color: var(--fg); border-radius: var(--radius); box-shadow: 0 20px 60px rgb(0 0 0 / .35);
  width: min(880px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: hidden; display: none; flex-direction: column; }
.dialog[open] { display: flex; animation: pop .18s ease-out; }
.dialog-add { width: min(620px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgb(10 12 20 / .6); backdrop-filter: blur(2px); }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog > .win-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--line); flex: none; }
.win-title-text { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.win-close { flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; font-size: 24px; line-height: 1; cursor: pointer; color: var(--fg); }
.win-close:hover { background: var(--line); }
.win-body { padding: 18px; overflow-y: auto; overscroll-behavior: contain; }
.card-wintitle { display: none; }

/* detail */
.detail { display: grid; gap: 16px; }
.hero { position: relative; background: #000; border-radius: var(--radius-s); overflow: hidden; aspect-ratio: 16 / 9; display: grid; place-items: center; }
.hero img { width: 100%; height: 100%; object-fit: contain; }
.hero .ph { width: 100%; height: 100%; font-size: 56px; }
.hero iframe { width: 100%; height: 100%; border: 0; background: #000; }
.hero-game { aspect-ratio: auto; height: min(70dvh, 640px); display: flex; flex-direction: column; }
.hero-game iframe { flex: 1; }
.game-bar { display: flex; gap: 8px; justify-content: flex-end; padding: 6px; background: #111; width: 100%; }
.play-here { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 18px; min-height: 54px; padding: 10px 26px; box-shadow: 0 6px 24px rgb(0 0 0 / .4); }
.gallery { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.gal { flex: none; width: 96px; aspect-ratio: 16 / 9; padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; background: var(--line); }
.gal img { width: 100%; height: 100%; object-fit: cover; }
.gal.active { border-color: var(--accent); }
.detail-kind { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.detail-title { margin: 6px 0 2px; font: 800 26px/1.2 var(--font-head); overflow-wrap: anywhere; }
.detail-sub { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.desc { white-space: pre-line; overflow-wrap: anywhere; margin-bottom: 12px; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.comments { border-top: 1px solid var(--line); padding-top: 14px; }
.comments-title { margin: 0 0 10px; font: 700 18px/1.3 var(--font-head); }
.comment-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 10px; }
.comment { background: var(--bg); border-radius: var(--radius-s); padding: 10px 12px; }
.comment-head { font-size: 13px; margin-bottom: 2px; }
.comment-when { color: var(--muted); }
.comment-body { white-space: pre-line; overflow-wrap: anywhere; }
.comment-form { background: var(--bg); border-radius: var(--radius-s); padding: 14px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* human check */
.human-check { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 12px; background: var(--card); margin: 4px 0 8px; }
.hc-head { font-weight: 700; font-size: 14px; margin-bottom: 8px; }
.hc-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hc-pic { background: #fff; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); line-height: 0; }
.hc-img { height: 56px; width: auto; max-width: 240px; }
.hc-answer { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.hc-answer input { width: 84px !important; text-align: center; font-size: 18px !important; }
.hc-tick { display: flex; align-items: center; gap: 10px; margin-top: 10px; cursor: pointer; user-select: none; }
.hc-box { width: 24px; height: 24px; accent-color: var(--ok); cursor: pointer; }
.hc-label { font-weight: 600; }
.hc-status { color: var(--muted); font-size: 13px; }
.human-check.verified .hc-status { color: var(--ok); font-weight: 700; }
.human-check.working .hc-status::after { content: ''; display: inline-block; width: 10px; height: 10px; margin-left: 6px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* add game */
.url-row { display: flex; gap: 8px; }
.url-row input { flex: 1; min-width: 0; }
.status-line { min-height: 1.5em; margin: 4px 0 8px; font-size: 14px; color: var(--muted); }
.status-line.busy::before { content: ''; display: inline-block; width: 12px; height: 12px; margin-right: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -1px; }
.step-details { border-top: 1px dashed var(--line); padding-top: 14px; margin-top: 6px; }
.image-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin: 4px 0 10px; }
.img-opt { aspect-ratio: 16 / 10; padding: 0; border: 2px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg); cursor: pointer; font-size: 13px; color: var(--muted); }
.img-opt img { width: 100%; height: 100%; object-fit: cover; }
.img-opt[aria-pressed=true] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.upload-own { min-height: 34px; font-size: 13px; padding: 4px 12px; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 14px; }

/* footer */
.site-footer { max-width: var(--maxw); margin: 0 auto; padding: 24px var(--gutter) 40px; text-align: center; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.counter { margin-bottom: 8px; }
.odometer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--fg); }
.fineprint a { color: inherit; }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1c2230; color: #fff; padding: 12px 18px;
  border-radius: 10px; box-shadow: 0 10px 30px rgb(0 0 0 / .3); z-index: 100; max-width: calc(100vw - 32px); font-weight: 600; }

/* 404 */
.page-404 { display: grid; place-items: center; padding: 16px; }
.notfound { width: min(460px, 100%); background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); text-align: center; overflow: hidden; }
.notfound > .win-title { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.notfound .big { font: 900 72px/1 var(--font-head); margin: 10px 0; }

@media (max-width: 640px) {
  :root { --gutter: 12px; }
  .site-header { padding-top: 14px; }
  .brand-name { font-size: 22px; }
  .tagline { font-size: 14px; flex-basis: 100%; order: 3; }
  .add-btn { margin-left: auto; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card-body { padding: 9px 10px 10px; }
  .card-title { font-size: 14px; }
  .card-desc { font-size: 13px; }
  .card-tags { display: none; }
  .toolbar .sort { width: 128px; }
  .dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  .dialog-add { width: 100vw; }
  .win-body { padding: 14px 12px calc(24px + env(safe-area-inset-bottom)); }
  .detail-title { font-size: 22px; }
  .hero-game { height: 62dvh; }
  .url-row { flex-direction: column; }
}
@media (max-width: 360px) { .grid { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
