/* Games by 313bits — styles. Plain CSS, no build step.
   Brand tokens are copied from 313bits-site/public/assets/styles.css. */

:root {
  --bg: #f6f7f5;
  --bg-alt: #eef1ee;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --ink: #0f172a;
  --text: #334155;
  --muted: #5b6678;
  --border: #e2e7e4;
  --border-strong: #cfd7d3;
  --accent: #0f766e;
  --accent-hover: #0c625b;
  --accent-soft: #e3f2ef;
  --accent-ink: #0b5f58;
  --gold: #d4a017;
  --gold-soft: #fbf1d3;
  --gold-ink: #8a6508;
  --on-accent: #ffffff;
  --board: #bbada0;
  --cell: rgba(238, 228, 218, .35);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -6px rgba(15, 23, 42, .10);
  --shadow-lg: 0 2px 4px rgba(15, 23, 42, .04), 0 24px 56px -12px rgba(15, 23, 42, .18);
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --container: 1100px;
  --header-h: 60px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --bg-alt: #0e1628;
    --surface: #121b2e;
    --surface-2: #162036;
    --ink: #f1f5f9;
    --text: #cbd5e1;
    --muted: #94a3b8;
    --border: #223049;
    --border-strong: #2e3d59;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-soft: rgba(45, 212, 191, .12);
    --accent-ink: #5eead4;
    --gold: #e9b93a;
    --gold-soft: rgba(233, 185, 58, .14);
    --gold-ink: #f3cd66;
    --on-accent: #042f2c;
    --board: #2a3550;
    --cell: rgba(255, 255, 255, .06);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -8px rgba(0, 0, 0, .5);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 28px 60px -14px rgba(0, 0, 0, .65);
  }
}

*, *::before, *::after { box-sizing: border-box; }
/* .btn and friends set display, which would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}
img, svg { display: block; max-width: 100%; }
h1, h2, h3 { color: var(--ink); line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.025em; font-weight: 750; }
p { margin: 0 0 1em; }
a { color: var(--accent-ink); text-underline-offset: 3px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -100px; z-index: 100; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; text-decoration: none; }
.skip-link:focus { top: 12px; color: var(--bg); }

.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 18px; }
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 16px; height: 16px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 12px;
  font: 600 15px/1 var(--font); text-decoration: none;
  border: 1px solid transparent; cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s, transform .12s;
  white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); }
.badge-soon { background: var(--gold-soft); color: var(--gold-ink); }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.header-inner { height: var(--header-h); display: flex; align-items: center; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); font-weight: 800; letter-spacing: -.03em; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.wordmark { font-size: 17px; }
.wordmark span { color: var(--accent-ink); }
.brand-sub { font-size: 12px; font-weight: 650; color: var(--muted); border-left: 1px solid var(--border-strong); padding-left: 9px; margin-left: 1px; letter-spacing: 0; }
.header-spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  background: transparent; border: 1px solid transparent; color: var(--ink);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent-ink); }
.icon-btn .i-off { display: none; }
.icon-btn[aria-pressed="false"] .i-on { display: none; }
.icon-btn[aria-pressed="false"] .i-off { display: block; }
.game-title { font-size: 17px; font-weight: 750; color: var(--ink); letter-spacing: -.02em; }

/* ---------- hub ---------- */
.hub-hero { padding: 34px 0 20px; text-align: center; }
.hub-hero h1 { font-size: clamp(28px, 7vw, 40px); margin-bottom: 10px; }
.hub-hero p { color: var(--muted); max-width: 46ch; margin: 0 auto; }
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 14px; padding: 10px 0 28px; }
.game-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); text-decoration: none; color: inherit;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
a.game-card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); color: inherit; }
.game-card .thumb { width: 46px; height: 46px; border-radius: 12px; margin-bottom: 8px; display: grid; place-items: center; font-weight: 800; font-size: 15px; letter-spacing: -.03em; background: var(--accent-soft); color: var(--accent-ink); }
.game-card h2 { font-size: 16px; margin: 0; }
.game-card p { font-size: 13px; color: var(--muted); margin: 0; line-height: 1.45; }
.game-card .best { margin-top: 8px; font-size: 12px; font-weight: 650; color: var(--gold-ink); }
.game-card.soon { opacity: .72; }

/* ---------- game page ---------- */
.page-game { overscroll-behavior: none; }
.game-main { padding: 14px 0 28px; }
.game-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.score-box { flex: 1; min-width: 0; padding: 8px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); text-align: center; }
.score-box span { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.score-box strong { display: block; font-size: 20px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.25; }
.game-stage { max-width: 440px; margin: 0 auto; }
.game-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.game-hint { text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0 0; }

/* ---------- 2048 board ---------- */
.board { position: relative; aspect-ratio: 1; width: 100%; padding: var(--gap, 10px); background: var(--board); border-radius: var(--radius); touch-action: none; user-select: none; -webkit-user-select: none; }
.board-cells { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: var(--gap, 10px); height: 100%; }
.board-cells div { background: var(--cell); border-radius: 8px; }
.tile {
  position: absolute; top: var(--gap, 10px); left: var(--gap, 10px);
  width: var(--tile, 70px); height: var(--tile, 70px);
  display: grid; place-items: center; border-radius: 8px;
  font-weight: 800; letter-spacing: -.04em; font-variant-numeric: tabular-nums;
  background: #eee4da; color: #6b6257;
  transform: translate(calc(var(--c) * (var(--tile) + var(--gap))), calc(var(--r) * (var(--tile) + var(--gap))));
  transition: transform .11s ease-in-out;
  will-change: transform;
}
.tile.v4 { background: #ede0c8; }
.tile.v8 { background: #f2b179; color: #fff; }
.tile.v16 { background: #f59563; color: #fff; }
.tile.v32 { background: #f67c5f; color: #fff; }
.tile.v64 { background: #f65e3b; color: #fff; }
.tile.v128 { background: #edcf72; color: #fff; font-size: .82em; }
.tile.v256 { background: #edcc61; color: #fff; font-size: .82em; }
.tile.v512 { background: #edc850; color: #fff; font-size: .82em; }
.tile.v1024 { background: var(--gold); color: #fff; font-size: .66em; }
.tile.v2048 { background: #0f766e; color: #fff; font-size: .66em; box-shadow: 0 0 0 3px rgba(212, 160, 23, .6); }
.tile.vbig { background: #0b5f58; color: #fff; font-size: .58em; }
.tile.new { animation: tile-in .13s ease-out .09s backwards; }
.tile.pop { animation: tile-pop .16s ease-out; }
@keyframes tile-in { from { transform: translate(calc(var(--c) * (var(--tile) + var(--gap))), calc(var(--r) * (var(--tile) + var(--gap)))) scale(.3); opacity: 0; } }
@keyframes tile-pop { 50% { transform: translate(calc(var(--c) * (var(--tile) + var(--gap))), calc(var(--r) * (var(--tile) + var(--gap)))) scale(1.16); } }

/* ---------- round-end screen (the only in-game ad slot) ---------- */
.round-end {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: none; flex-direction: column;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  overflow-y: auto; overscroll-behavior: contain;
}
.round-end[data-open="true"] { display: flex; animation: fade-in .18s ease-out; }
@keyframes fade-in { from { opacity: 0; } }
.round-end-inner { width: 100%; max-width: 420px; margin: auto; text-align: center; }
.round-end .result { font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.round-end h2 { font-size: clamp(26px, 8vw, 34px); margin-bottom: 14px; }
.round-end .stats { display: flex; gap: 10px; margin-bottom: 18px; }
.round-end .stats .score-box { flex: 1; }
.round-end .actions { display: grid; gap: 10px; margin-top: 4px; }

/* ---------- ads ---------- */
.ad-slot { margin: 24px auto 0; max-width: 336px; }
.ad-slot[hidden] { display: none; }
.ad-slot .ad-label { font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; text-align: center; }
.ad-slot ins { display: block; min-height: 250px; }
.hub-ad { margin: 8px auto 28px; max-width: 728px; }

/* ---------- prose (how to play / FAQ — the SEO text) ---------- */
.prose { max-width: 70ch; margin: 36px auto 0; padding-top: 28px; border-top: 1px solid var(--border); }
.prose h2 { font-size: 21px; margin-top: 30px; }
.prose h3 { font-size: 16px; margin-top: 22px; margin-bottom: .3em; }
.prose ul, .prose ol { padding-left: 20px; margin: 0 0 1em; }
.prose li { margin-bottom: .35em; }
.prose .lead { font-size: 17px; color: var(--text); }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--bg-alt); padding: 26px 0 max(22px, env(safe-area-inset-bottom)); margin-top: 36px; font-size: 14px; }
.footer-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 22px; }
.footer-brand p { color: var(--muted); font-size: 13px; max-width: 32ch; margin: 8px 0 0; }
.footer-col h2 { font-size: 12px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.footer-col ul { list-style: none; margin: 0; padding: 0; }
.footer-col li { margin-bottom: 5px; }
.footer-col a { color: var(--text); text-decoration: none; }
.footer-col a:hover { color: var(--accent-ink); text-decoration: underline; }
.footer-bottom { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between; color: var(--muted); font-size: 12.5px; }
.footer-bottom p { margin: 0; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); z-index: 60; background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast[data-open="true"] { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 420px) {
  .game-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
}

/* Keep the ad clear of the buttons the player actually taps (AdSense policy). */
.round-end .ad-slot { margin-top: 36px; }
