/* =========================================================
   MiniPlay Arcade - shared styles (MOBILE-FIRST)
   Base rules target phones (default). Desktop enhancements
   live inside @media (min-width: 900px).
   ========================================================= */
:root {
  --bg: #0f1222;
  --bg-soft: #171b33;
  --bg-card: #1d2240;
  --bg-card-hover: #252b52;
  --border: rgba(255,255,255,0.08);
  --text: #eef0ff;
  --text-dim: #9aa0c3;
  --text-faint: #6a7094;
  --accent: #7c6cff;
  --accent-2: #38d9c0;
  --accent-3: #ff7ac3;
  --gold: #ffc857;
  --danger: #ff6b6b;
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tap-min: 46px; /* minimum touch target height */
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  scroll-behavior: smooth;
  /* prevent iOS double-tap zoom on games */
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100dvh;
  background-image:
    radial-gradient(900px 480px at 85% -10%, rgba(124,108,255,0.16), transparent 60%),
    radial-gradient(700px 420px at -10% 20%, rgba(56,217,192,0.10), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1060px; margin: 0 auto; padding: 0 12px; }

/* ---------- top bar (compact on mobile, safe-area aware) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15,18,34,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.topbar-inner {
  max-width: 1060px; margin: 0 auto; padding: 9px 12px;
  display: flex; align-items: center; gap: 10px;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; letter-spacing: 0.2px; color: var(--text); white-space: nowrap; }
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; color: #fff;
}
.nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--text-dim); font-size: 13.5px; padding: 7px 12px;
  border-radius: 999px; white-space: nowrap;
  min-height: var(--tap-min);
  display: inline-flex; align-items: center;
  touch-action: manipulation;
}
.nav a:hover { color: var(--text); text-decoration: none; background: rgba(255,255,255,0.06); }
.nav a.active { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

/* ---------- hero / headers ---------- */
.hero { padding: 30px 6px 18px; text-align: center; }
.hero h1 { font-size: 27px; font-weight: 700; letter-spacing: -0.4px; line-height: 1.18; }
.hero p { color: var(--text-dim); font-size: 15px; margin-top: 10px; max-width: 640px; margin-left: auto; margin-right: auto; }
.page-head { padding: 22px 0 10px; }
.page-head h1 { font-size: 25px; font-weight: 700; }
.page-head p { color: var(--text-dim); margin-top: 6px; font-size: 14.5px; }

/* ---------- cards / grids (single column on mobile) ---------- */
.grid { display: grid; gap: 14px; padding: 8px 0 30px; }
.grid.games { grid-template-columns: 1fr; }

.game-card {
  position: relative; display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.game-card:hover { transform: translateY(-2px); border-color: rgba(124,108,255,0.5); background: var(--bg-card-hover); text-decoration: none; }
.game-thumb {
  aspect-ratio: 16/9;
  display: flex; align-items: center; justify-content: center;
  font-size: 44px;
  position: relative;
}
.game-thumb svg { width: 56px; height: 56px; }
.game-card-body { padding: 13px 15px 15px; }
.game-card-body h2 { font-size: 18px; font-weight: 600; color: var(--text); }
.game-card-body p { color: var(--text-dim); font-size: 13.5px; margin-top: 3px; }
.game-tag {
  position: absolute; top: 10px; right: 10px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px; color: #fff;
  background: rgba(0,0,0,0.35); backdrop-filter: blur(4px);
}
.play-hint {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 10px; font-size: 13.5px; font-weight: 600; color: var(--accent-2);
  min-height: var(--tap-min);
}

/* ---------- game page layout (mobile: game fills the screen) ---------- */
.game-wrap { display: grid; grid-template-columns: 1fr; gap: 16px; padding: 6px 0 34px; }
.game-stage { min-width: 0; }
.game-frame {
  position: relative;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 10px 14px;
  display: flex; flex-direction: column; align-items: center;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}
.game-frame h1 { font-size: 19px; font-weight: 700; align-self: flex-start; margin-bottom: 2px; }
.game-sub { color: var(--text-faint); font-size: 12.5px; align-self: flex-start; margin-bottom: 10px; }

/* canvas: fill phone width, keep aspect ratio */
.canvas-wrap { position: relative; width: 100%; display: flex; justify-content: center; }
canvas.game-canvas {
  display: block;
  width: 100%;
  max-width: 480px;
  height: auto;
  border-radius: var(--radius-sm);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- HUD (compact score strip) ---------- */
.hud { display: flex; gap: 8px; width: 100%; margin-bottom: 10px; }
.hud-item {
  flex: 1; text-align: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 4px;
}
.hud-item .label { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.6px; }
.hud-item .value { font-size: 21px; font-weight: 700; color: var(--text); margin-top: 1px; }

/* ---------- controls & buttons (big touch targets) ---------- */
.controls { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; justify-content: center; align-items: center; width: 100%; }
.controls .hint-text { color: var(--text-faint); font-size: 12px; }
.btn {
  font-family: var(--font); font-size: 15.5px; font-weight: 600;
  border: none; border-radius: 999px; cursor: pointer;
  padding: 12px 26px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transition: transform 0.12s ease, opacity 0.12s ease;
  min-height: var(--tap-min);
  touch-action: manipulation;
}
.btn:hover { transform: translateY(-1px); opacity: 0.92; }
.btn:active { transform: translateY(0) scale(0.97); }
.btn.ghost { background: rgba(255,255,255,0.08); border: 1px solid var(--border); }
.btn.small { padding: 8px 16px; font-size: 13.5px; min-height: 42px; }
.btn.icon { padding: 0; width: var(--tap-min); height: var(--tap-min); display: inline-flex; align-items: center; justify-content: center; font-size: 19px; border-radius: 12px; }

/* ---------- game over overlay (fullscreen on mobile) ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(10,12,26,0.92); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 28px 20px calc(28px + var(--safe-bottom));
  text-align: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.overlay.show { display: flex; }
.overlay h2 { font-size: 28px; font-weight: 800; letter-spacing: -0.3px; }
.overlay .score-big { font-size: 44px; font-weight: 800; color: var(--gold); margin: 4px 0 2px; line-height: 1.1; }
.overlay .score-label { color: var(--text-dim); font-size: 13px; }
.overlay .new-record { color: var(--accent-2); font-size: 13px; font-weight: 600; margin-top: 2px; min-height: 18px; }
.overlay .btn-row { display: flex; gap: 10px; margin-top: 14px; width: 100%; max-width: 340px; }
.overlay .btn-row .btn { flex: 1; }

/* ---------- ad slot (full width on mobile) ---------- */
.ad-slot {
  width: 100%; min-height: 100px;
  margin: 14px auto 2px;
  background: rgba(255,255,255,0.04);
  border: 1px dashed rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  max-width: 100%;
}
.ad-slot .ad-placeholder { color: var(--text-faint); font-size: 11.5px; }
/* CRITICAL: the <ins> is a flex item of .ad-slot; without flex-basis it collapses
   to 0 width and AdSense sees a zero-size slot -> No Fill (empty ad). Force it
   to occupy the full content width so the ad network can size the creative. */
.ad-slot ins.adsbygoogle {
  display: block;
  flex: 1 0 100%;
  max-width: 100%;
  min-height: 100px;
}
.share-row { display: flex; gap: 8px; margin-top: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- game info / how-to (collapsible on mobile) ---------- */
.game-info { color: var(--text-dim); font-size: 14px; }
.game-info h2 { color: var(--text); font-size: 16.5px; margin: 16px 0 6px; }
.game-info p { margin-bottom: 8px; }
.game-info ul { padding-left: 20px; margin-bottom: 10px; }
.game-info li { margin-bottom: 4px; }
.howto {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-top: 14px; overflow: hidden;
}
.howto summary {
  cursor: pointer; list-style: none;
  padding: 13px 16px; font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--tap-min); user-select: none; -webkit-user-select: none;
}
.howto summary::-webkit-details-marker { display: none; }
.howto summary::after {
  content: "+"; font-size: 19px; color: var(--text-faint); font-weight: 500;
  transition: transform 0.18s ease;
}
.howto[open] summary::after { transform: rotate(45deg); }
.howto ul { padding: 0 16px 14px 32px; color: var(--text-dim); font-size: 13.5px; }
.howto h3 { display: none; }

/* ---------- snake D-pad (mobile only) ---------- */
.dpad { display: none; }
@media (max-width: 899px) {
  .dpad {
    display: grid;
    grid-template-columns: repeat(3, 58px);
    grid-template-rows: repeat(2, 54px);
    gap: 8px;
    margin: 14px auto 0;
  }
  .dpad .dpad-btn {
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-dim);
    border-radius: 14px;
    font-size: 22px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; user-select: none; -webkit-user-select: none;
    touch-action: none;
    -webkit-touch-callout: none;
    transition: background 0.1s ease, transform 0.08s ease;
  }
  .dpad .dpad-btn:active, .dpad .dpad-btn.pressed {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff; transform: scale(0.93);
  }
  .dpad .d-up    { grid-column: 2; grid-row: 1; }
  .dpad .d-left  { grid-column: 1; grid-row: 2; }
  .dpad .d-down  { grid-column: 2; grid-row: 2; }
  .dpad .d-right { grid-column: 3; grid-row: 2; }
}

/* ---------- side rail (desktop only) ---------- */
.rail { display: none; }
.rail-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.rail-card h3 { font-size: 14px; color: var(--text); margin-bottom: 12px; }
.rail-card .game-thumb { aspect-ratio: 16/9; font-size: 30px; border-radius: var(--radius-sm); }
.rail-card .game-thumb svg { width: 40px; height: 40px; }
.rail-card a { color: var(--text); font-size: 14px; font-weight: 600; display: block; margin-top: 10px; }
.rail-card a:hover { color: var(--accent-2); text-decoration: none; }
.rail-card .rail-sub { color: var(--text-faint); font-size: 12.5px; margin-top: 2px; }

/* ---------- footer ---------- */
footer { border-top: 1px solid var(--border); padding: 22px 0 calc(26px + var(--safe-bottom)); margin-top: 16px; }
.footer-inner { max-width: 1060px; margin: 0 auto; padding: 0 12px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; color: var(--text-faint); font-size: 12.5px; }
.footer-inner a { color: var(--text-faint); min-height: var(--tap-min); display: inline-flex; align-items: center; }
.footer-inner a:hover { color: var(--text-dim); }
.footer-inner .spacer { margin-left: auto; }

/* ---------- 2048 board (fits any phone width) ---------- */
.board-2048 {
  --cell: min(84px, calc((100vw - 108px) / 4));
  --gap: 8px;
  display: grid;
  grid-template-columns: repeat(4, var(--cell));
  grid-template-rows: repeat(4, var(--cell));
  gap: var(--gap);
  background: rgba(0,0,0,0.28);
  border-radius: 12px;
  padding: var(--gap);
  touch-action: none;
}
.tile {
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cell) * 0.34);
  font-weight: 800;
  color: #f7f7ff;
  background: rgba(255,255,255,0.06);
  transition: transform 0.09s ease;
}
.tile.t2   { background: #3b3f68; color: #eef0ff; }
.tile.t4   { background: #4a4f85; color: #eef0ff; }
.tile.t8   { background: #7c6cff; }
.tile.t16  { background: #6a5ae0; }
.tile.t32  { background: #5347b7; }
.tile.t64  { background: #3d8bfd; }
.tile.t128 { background: #38d9c0; color: #0d2b24; }
.tile.t256 { background: #2fbda7; color: #0d2b24; }
.tile.t512 { background: #ffb03a; color: #3a2400; }
.tile.t1024{ background: #ff8c42; color: #3a2400; }
.tile.t2048{ background: #ff5d8f; color: #3a0000; }
.tile.t4096,.tile.t8192 { background: #ffd166; color: #3a2400; font-size: calc(var(--cell) * 0.26); }

/* ---------- misc ---------- */
.noselect { user-select: none; -webkit-user-select: none; }
.mt { margin-top: 18px; }
.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.centered { text-align: center; }

/* ---------- desktop overrides (>=900px) ---------- */
@media (min-width: 900px) {
  .container { padding: 0 16px; }
  .topbar-inner { padding: 12px 16px; }
  .logo { font-size: 17px; gap: 10px; }
  .logo-mark { width: 30px; height: 30px; font-size: 15px; }
  .nav { gap: 4px; }
  .nav a { font-size: 14px; padding: 7px 13px; }

  .hero { padding: 44px 0 26px; }
  .hero h1 { font-size: clamp(30px, 5vw, 44px); letter-spacing: -0.5px; }
  .hero p { font-size: clamp(15px, 2.2vw, 17px); }
  .page-head { padding: 30px 0 14px; }
  .page-head h1 { font-size: clamp(24px, 4vw, 34px); }

  .grid.games { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
  .game-thumb svg { width: 72px; height: 72px; }

  /* game page: stage + side rail */
  .game-wrap { grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; padding: 8px 0 44px; }
  .game-frame { padding: 18px 16px 16px; }
  .game-frame h1 { font-size: 20px; }
  .game-sub { margin-bottom: 14px; }
  .hud { gap: 10px; margin-bottom: 14px; }
  .hud-item { padding: 8px 6px; }
  .hud-item .value { font-size: 22px; }
  canvas.game-canvas { max-width: 480px; }
  .controls { gap: 10px; margin-top: 14px; }
  .btn { padding: 10px 22px; font-size: 14.5px; }
  .btn.small { padding: 7px 15px; font-size: 13px; }

  /* overlay: contained within the game frame on desktop */
  .overlay {
    position: absolute; inset: 0;
    border-radius: var(--radius);
    padding: 24px 18px;
    z-index: 20;
  }
  .overlay h2 { font-size: 30px; }
  .overlay .score-big { font-size: 46px; }
  .overlay .btn-row { max-width: none; width: auto; }
  .overlay .btn-row .btn { flex: none; }

  .ad-slot { max-width: 336px; min-height: 90px; }
  .game-info h2 { font-size: 17px; margin: 18px 0 6px; }
  .howto { padding: 0; margin-top: 18px; }
  .howto summary { display: none; } /* always open on desktop */
  .howto h3 { display: block; font-size: 14px; color: var(--text); padding: 14px 16px 0; }
  .howto ul { display: block; padding: 6px 16px 14px 34px; }
  details.howto:not([open]) > *:not(summary) { display: block; }

  .rail { display: flex; flex-direction: column; gap: 16px; }
  .dpad { display: none !important; }

  footer { padding: 26px 0 34px; }
  .footer-inner { padding: 0 16px; font-size: 13px; }

  .board-2048 { --cell: clamp(62px, 21vw, 92px); --gap: 10px; }
}
