/* =====================================================================
   MALI'S ARCADE — "Modern × 16-bit", the same look as Merpy
   Tokens are copied token-for-token from Chamiz/merpy/index.html (:root and
   html[data-theme="dark"]); change them there and here together.
   Cream paper + dot grid, 2px ink outlines, hard "pressable" shadows, pastel
   sticker tiles. One type stack for EN/TH (Inter + SukhumvitSet for Thai).
   The canvases keep their own pixel art — only the page around them changed.
   Used by game.html, scoreboard.html, xo/snake/space-shooter/mali-warrior.
   ===================================================================== */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

@font-face { font-family: "SukhumvitSet"; font-weight: 400; font-display: swap; unicode-range: U+0E00-0E7F;
  src: url("/Fonts/SukhumvitSet-Text.woff2") format("woff2"), url("/Fonts/SukhumvitSet-Text.ttf") format("truetype"); }
@font-face { font-family: "SukhumvitSet"; font-weight: 600; font-display: swap; unicode-range: U+0E00-0E7F;
  src: url("/Fonts/SukhumvitSet-SemiBold.woff2") format("woff2"), url("/Fonts/SukhumvitSet-SemiBold.ttf") format("truetype"); }
@font-face { font-family: "SukhumvitSet"; font-weight: 700 800; font-display: swap; unicode-range: U+0E00-0E7F;
  src: url("/Fonts/SukhumvitSet-Bold.woff2") format("woff2"), url("/Fonts/SukhumvitSet-Bold.ttf") format("truetype"); }

:root {
  --bg: #fff3e4;
  --dot: rgba(43, 26, 18, 0.07);
  --surface: #fffaf2;
  --surface-soft: #ffe8cf;
  --ink: #2b1a12;
  --edge: #2b1a12;
  --text: #2b1a12;
  --muted: #8b6b5a;
  --accent: #ff4b2b;
  --accent-hover: #ec3717;
  --accent-2: #ff9a1f;
  --accent-soft: rgba(255, 75, 43, 0.14);
  --line: rgba(43, 26, 18, 0.14);
  --line-strong: rgba(43, 26, 18, 0.32);
  --gold: #ffc21a;
  --gold-dim: #b37a00;
  --good: #1fa45a;
  --good-soft: #d9f6e3;
  --bad: #e5322d;
  --t0: #ffd9c2; --t1: #ffd3de; --t2: #d3f3dc; --t3: #d4e8ff; --t4: #e7dcff; --t5: #fff0b3;
  --radius: 14px;
  --radius-lg: 20px;
  --hard: 0 4px 0 var(--ink);
  --hard-sm: 0 3px 0 var(--ink);
  --font-body: "Inter", "SukhumvitSet", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --nav-h: 60px;
}
html[data-theme="dark"] {
  --bg: #17110d;
  --dot: rgba(255, 230, 205, 0.05);
  --surface: #221913;
  --surface-soft: #2e2219;
  --ink: #000;
  --edge: rgba(255, 228, 200, 0.5);
  --text: #fbeee0;
  --muted: #b9a08e;
  --accent: #ff6645;
  --accent-hover: #ff7b5e;
  --accent-2: #ffab3d;
  --accent-soft: rgba(255, 102, 69, 0.2);
  --line: rgba(255, 228, 200, 0.14);
  --line-strong: rgba(255, 228, 200, 0.32);
  --gold: #ffcc3d;
  --gold-dim: #e0a92a;
  --good: #45d483;
  --good-soft: #193a27;
  --bad: #ff6b66;
  --t0: #4a2d20; --t1: #4a2434; --t2: #1f3d2b; --t3: #1f3347; --t4: #33294d; --t5: #463c18;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--text);
  display: flex; flex-direction: column;
  background: radial-gradient(var(--dot) 1.2px, transparent 1.4px) 0 0 / 16px 16px, var(--bg);
  background-attachment: fixed;
  font-family: var(--font-body); font-size: 17px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Sticker icons (images/arcade-icons/*.svg) — never stretched, faint light
   rim in dark mode so the ink outline doesn't vanish. */
.ic { display: inline-block; flex: none; object-fit: contain; vertical-align: -0.22em; pointer-events: none; }
html[data-theme="dark"] .ic { filter: drop-shadow(0 0 .6px rgba(255, 240, 225, .9)); }

/* ---------- Top bar — the same shape as Merpy's .mp-nav ---------- */
.ar-nav {
  position: sticky; top: 0; z-index: 10; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  height: var(--nav-h); padding: 0 clamp(12px, 4vw, 20px);
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--nav-h) + env(safe-area-inset-top, 0px));
  background: var(--surface); border-bottom: 2px solid var(--edge);
}
.ar-home { display: inline-flex; align-items: center; transition: transform .2s ease, opacity .2s ease; }
.ar-home:hover { opacity: .92; transform: translateY(-1px); }
.ar-home img { width: 38px; height: 38px; display: block; }
.ar-title {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-family: "Inter", sans-serif; font-size: clamp(22px, 3vw, 34px); font-weight: 800;
  letter-spacing: -0.01em; line-height: 1; color: var(--text); text-decoration: none; white-space: nowrap;
}
.ar-title span { color: var(--accent-2); }
.ar-links { display: flex; align-items: center; gap: 8px; }
.ar-pill {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  font-size: 13px; font-weight: 800; letter-spacing: .02em; color: var(--text); background: var(--surface);
  border: 2px solid var(--edge); border-radius: 10px; padding: 7px 10px; box-shadow: var(--hard-sm);
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), background 120ms var(--ease);
}
.ar-pill:hover { background: var(--surface-soft); }
.ar-pill:active { transform: translateY(3px); box-shadow: none; }
.ar-pill .ic { width: 20px; height: 20px; vertical-align: 0; }
@media (max-width: 520px) { .ar-pill .lbl { display: none; } .ar-title { font-size: 22px; } }

/* ---------- Page scaffolding ---------- */
.wrap { position: relative; width: 100%; flex: 1 0 auto; max-width: 1040px; margin: 0 auto; padding: 24px 16px 40px; }
.wrap.narrow { max-width: 620px; }

.hero { text-align: center; margin: 12px 0 26px; }
.hero-tile {
  width: 84px; height: 84px; margin: 0 auto 14px; display: grid; place-items: center;
  background: var(--t5); border: 2px solid var(--edge); border-radius: 24px; box-shadow: var(--hard);
}
.hero-tile .ic { width: 62px; height: 62px; vertical-align: 0; }
.hero-title { font-size: clamp(34px, 6vw, 52px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; margin-bottom: 8px; }
.hero-title span { color: var(--accent-2); }
.tagline { font-size: 17px; font-weight: 700; color: var(--muted); max-width: 46ch; margin: 0 auto; }

/* ---------- Section card (Merpy panel()) ---------- */
.panel {
  background: var(--surface); border: 2px solid var(--edge); border-radius: 22px;
  box-shadow: var(--hard); margin: 0 0 22px; overflow: hidden;
}
.panel-h {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--surface-soft); border-bottom: 2px solid var(--edge);
}
.panel-ic {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center;
  border-radius: 12px; border: 2px solid var(--edge); background: var(--t0);
}
.panel-ic .ic { width: 26px; height: 26px; vertical-align: 0; }
.panel-t { flex: 1; min-width: 0; display: grid; line-height: 1.3; }
.panel-t b { font-size: 16.5px; font-weight: 800; }
.panel-t small { font-size: 13px; font-weight: 600; color: var(--muted); }
.panel-b { padding: 14px 16px 16px; }

.t0 { background: var(--t0) !important; } .t1 { background: var(--t1) !important; } .t2 { background: var(--t2) !important; }
.t3 { background: var(--t3) !important; } .t4 { background: var(--t4) !important; } .t5 { background: var(--t5) !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  border: 2px solid var(--edge); background: var(--accent); color: #fff; padding: 11px 18px; border-radius: 12px;
  font-weight: 800; font-size: 15px; white-space: nowrap; box-shadow: var(--hard-sm);
  transition: background 120ms var(--ease), transform 120ms var(--ease), box-shadow 120ms var(--ease);
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn.big { padding: 14px 26px; font-size: 16.5px; border-radius: 14px; }
.btn.ghost { background: var(--surface); color: var(--text); }
.btn.ghost:hover { background: var(--surface-soft); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 10px; }
.btn .ic { width: 20px; height: 20px; vertical-align: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 800; padding: 2px 10px;
  border: 1.5px solid var(--line-strong); border-radius: 999px; color: var(--muted); background: var(--surface);
}
.chip.hot { border-color: var(--edge); color: var(--ink); background: var(--gold); }

/* ---------- Segmented control with a sliding pill (Merpy .segtabs) ---------- */
.segtabs {
  position: relative; display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); padding: 5px;
  background: var(--surface); border: 2px solid var(--edge); border-radius: 16px; box-shadow: var(--hard-sm);
}
.segtabs .tab {
  position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  background: transparent; border: none; border-radius: 11px; padding: 10px 4px; min-width: 0;
  font-size: 14.5px; font-weight: 800; color: var(--text); transition: color 520ms var(--ease);
}
.segtabs .tab .ic { width: 22px; height: 22px; vertical-align: 0; }
.segtabs .tab[aria-selected="true"] { color: #fff; }
.segtabs .tab .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-pill {
  position: absolute; z-index: 0; top: 5px; bottom: 5px; left: 5px;
  width: calc((100% - 10px) / var(--n, 3)); transform: translateX(calc(100% * var(--i, 0)));
  background: var(--accent); border: 2px solid var(--edge); border-radius: 11px;
  transition: transform 820ms cubic-bezier(.34, 1.15, .5, 1);
}
@media (max-width: 520px) { .segtabs .tab { flex-direction: column; gap: 2px; font-size: 12.5px; } }

/* ---------- Game selector cards ---------- */
.games { display: grid; gap: 22px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.gcard {
  position: relative; display: flex; flex-direction: column; gap: 12px; text-decoration: none; color: inherit;
  background: var(--surface); border: 2px solid var(--edge); border-radius: 22px; padding: 18px;
  box-shadow: var(--hard); transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}
.gcard:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.gcard:active { transform: translateY(4px); box-shadow: none; }
.gcard .top { display: flex; align-items: center; gap: 14px; }
.gicon {
  width: 72px; height: 72px; flex: none; display: grid; place-items: center;
  border: 2px solid var(--edge); border-radius: 20px; background: var(--t0); box-shadow: var(--hard-sm);
}
.gicon .ic { width: 54px; height: 54px; vertical-align: 0; }
.gcard h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; }
.gcard .sub { font-size: 13px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
html[lang="th"] .gcard .sub { letter-spacing: 0; }
.gcard .desc { font-size: 15px; color: var(--muted); font-weight: 600; line-height: 1.55; }
.gcard .desc b { color: var(--text); }
.gcard .pills { display: flex; flex-wrap: wrap; gap: 6px; }
.gcard .foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 12px; border-top: 1.5px dashed var(--line-strong); }
.gcard .best { font-size: 13.5px; font-weight: 800; color: var(--gold-dim); display: inline-flex; align-items: center; gap: 6px; }
.gcard .best .ic { width: 20px; height: 20px; vertical-align: 0; }
.gcard .play { pointer-events: none; }   /* the whole card is the link */
.gcard .flag {
  position: absolute; top: -12px; right: 16px; font-size: 12px; font-weight: 800; padding: 3px 10px;
  background: var(--gold); color: var(--ink); border: 2px solid var(--edge); border-radius: 999px; box-shadow: var(--hard-sm);
}
@media (min-width: 760px) {
  .gcard.featured { grid-column: 1 / -1; flex-direction: row; align-items: stretch; gap: 20px; }
  .gcard.featured .gicon { width: 120px; height: 120px; border-radius: 28px; align-self: center; }
  .gcard.featured .gicon .ic { width: 90px; height: 90px; }
  .gcard.featured .body { flex: 1; display: flex; flex-direction: column; gap: 10px; }
}
.gcard .body { display: contents; }
@media (min-width: 760px) { .gcard.featured .body { display: flex; } }

/* ---------- Leaderboard rows ---------- */
.lb { list-style: none; margin: 0; padding: 0; }
.lb li { display: flex; align-items: center; gap: 12px; padding: 11px 0; }
.lb li + li { border-top: 1.5px dashed var(--line-strong); }
.rank {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center; font-weight: 800; font-size: 15px;
  border: 2px solid var(--edge); border-radius: 12px; background: var(--surface-soft); font-variant-numeric: tabular-nums;
}
.rank .ic { width: 28px; height: 28px; vertical-align: 0; }
.rank.r1 { background: var(--gold); box-shadow: var(--hard-sm); }
.rank.r2 { background: var(--t3); }
.rank.r3 { background: var(--t0); }
.lb .who { flex: 1; min-width: 0; font-weight: 800; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .who .chip { margin-left: 6px; vertical-align: 2px; }
.lb .pts { font-weight: 800; font-size: 17px; color: var(--gold-dim); font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 6px; }
.lb .pts .ic { width: 20px; height: 20px; vertical-align: 0; }
.lb li.me { background: var(--accent-soft); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.status { text-align: center; padding: 26px 8px; color: var(--muted); font-weight: 700; font-size: 15.5px; }
.status .ic { width: 44px; height: 44px; display: block; margin: 0 auto 10px; }

/* ---------- Game pages ---------- */
body.game-page { height: 100dvh; min-height: 0; overflow: hidden; }
.gbar {
  flex-shrink: 0; display: flex; align-items: center; gap: 12px;
  width: 100%; max-width: 960px; margin: 0 auto; padding: 12px 16px 6px;
}
.backbtn {
  width: 42px; height: 42px; flex: none; display: inline-grid; place-items: center; padding: 0; text-decoration: none; color: var(--text);
  background: var(--surface); border: 2px solid var(--edge); border-radius: 12px; font-size: 18px; font-weight: 900;
  box-shadow: var(--hard-sm); transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}
.backbtn:active { transform: translateY(3px); box-shadow: none; }
.gbar-t { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.gbar-t .gicon { width: 42px; height: 42px; border-radius: 13px; box-shadow: none; }
.gbar-t .gicon .ic { width: 32px; height: 32px; }
.gbar-t h1 { font-size: 19px; font-weight: 800; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.stat {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px 5px 7px;
  background: var(--surface); border: 2px solid var(--edge); border-radius: 999px; box-shadow: var(--hard-sm);
  font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap;
}
.stat .ic { width: 20px; height: 20px; vertical-align: 0; }
.stat b { color: var(--text); font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .gbar { flex-wrap: wrap; padding-top: 10px; }
  .hud { width: 100%; justify-content: center; }
  .stat .lbl { display: none; }
}

.game-area {
  position: relative; flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center; overflow: hidden; padding: 10px 16px 18px;
}
#gameCanvas {
  display: block; image-rendering: pixelated; image-rendering: crisp-edges; touch-action: none;
  border: 3px solid var(--edge); border-radius: 18px; box-shadow: 0 6px 0 var(--ink);
  background: #0a0820;
}

/* Start / game-over card, laid over the playfield */
.overlay {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 16px;
  background: transparent;   /* the card sits right on the dark playfield */
}
.overlay.hidden { display: none; }
.ov-card {
  width: min(100%, 400px); text-align: center; display: grid; justify-items: center; gap: 12px;
  background: var(--surface); border: 2px solid var(--edge); border-radius: 24px; box-shadow: var(--hard);
  padding: 24px 22px 22px; animation: ovIn 420ms var(--ease);
}
@keyframes ovIn { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.ov-card .gicon { width: 76px; height: 76px; border-radius: 22px; }
.ov-title { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.ov-text { font-size: 15.5px; font-weight: 600; color: var(--muted); line-height: 1.55; }
.ov-text b { color: var(--accent); }
.ov-hint { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.ov-hint .ic { width: 24px; height: 24px; }
@media (prefers-reduced-motion: reduce) { .ov-card { animation: none; } .tab-pill { transition: none; } }

/* On-screen controls (touch devices only; shown by each game's JS) */
.touch {
  flex-shrink: 0; display: none; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 2px solid var(--edge);
}
.touch.center { justify-content: center; }
.dpad { display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 52px); gap: 6px; }
.key {
  display: grid; place-items: center; font-size: 18px; font-weight: 900; color: var(--text);
  background: var(--surface); border: 2px solid var(--edge); border-radius: 13px; box-shadow: var(--hard-sm);
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none;
  transition: transform 80ms var(--ease), box-shadow 80ms var(--ease), background 80ms var(--ease);
}
.key:active, .key.on { transform: translateY(3px); box-shadow: none; background: var(--accent-soft); }
.key.big { width: 66px; height: 66px; border-radius: 18px; }
.key.act { width: 70px; height: 70px; border-radius: 20px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 800; line-height: 1.2; text-align: center; }
.key.act:active { background: var(--accent-hover); }
.key.act.alt { background: var(--t5); color: var(--ink); }
.key .ic { width: 28px; height: 28px; vertical-align: 0; display: block; margin: 0 auto 2px; }
.pad { display: flex; gap: 10px; }
.pad.col { flex-direction: column; }

/* ---------- Nickname modal (scores.js) ---------- */
.ar-modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: rgba(23, 17, 13, .45);
}
.ar-modal .ov-card { font-family: var(--font-body); color: var(--text); }
.ar-modal input {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 2px solid var(--line-strong); border-radius: 12px; padding: 11px 13px; text-align: center;
}
.ar-modal input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ar-modal .row { display: flex; gap: 8px; width: 100%; }
.ar-modal .row .btn { flex: 1; }

/* ---------- Site footer — the same one every Chamiz site carries ---------- */
.site-footer {
  flex-shrink: 0; text-align: center; padding: 26px 16px calc(26px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 2px solid var(--edge); font-size: 14px; color: var(--muted);
}
.site-footer p { margin: 0; }
.site-footer span { color: var(--accent); font-weight: 800; }
.site-footer .links { margin-top: 8px; line-height: 1.9; }
.site-footer a { color: var(--accent); font-weight: 800; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.site-footer a[aria-current="page"] { color: var(--text); }
.site-footer .copy { margin-top: 8px; font-size: 13px; opacity: .75; }

/* the canvas border sits outside the size each game's fit function sets */
#gameCanvas { box-sizing: content-box; }
