/* ===========================================================
   AbelGames Pro — Shared Theme
   Light + Dark, glass UI, fluid type, mobile-friendly
   =========================================================== */

:root {
  color-scheme: light dark;

  /* Brand */
  --brand-1: #7b3ff5;
  --brand-2: #2ad0ff;
  --brand-3: #ff5ba7;
  --brand-grad: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  --brand-grad-warm: linear-gradient(120deg, var(--brand-3), #ffb86b);

  /* Light theme defaults */
  --bg-1: #f7fbff;
  --bg-2: #e7f7f0;
  --bg-3: #fff1f5;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-2: rgba(255, 255, 255, 0.62);
  --surface-strong: #ffffff;
  --ink: #1c1340;
  --ink-2: #4a3b86;
  --ink-mute: #6f6796;
  --line: #e6d4ff;
  --ring: rgba(123, 63, 245, 0.45);
  --shadow: 0 12px 32px rgba(36, 7, 83, 0.18);
  --shadow-lg: 0 24px 60px rgba(36, 7, 83, 0.22);

  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-xl: 28px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --font: "Quicksand", "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --header-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg-1: #1a0f3a;
  --bg-2: #0a1130;
  --bg-3: #2a1758;
  --surface: rgba(28, 19, 64, 0.66);
  --surface-2: rgba(28, 19, 64, 0.4);
  --surface-strong: #1f1547;
  --ink: #f3eaff;
  --ink-2: #cdb8ff;
  --ink-mute: #9c92c8;
  --line: rgba(255, 255, 255, 0.1);
  --ring: rgba(123, 63, 245, 0.7);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-1: #1a0f3a;
    --bg-2: #0a1130;
    --bg-3: #2a1758;
    --surface: rgba(28, 19, 64, 0.66);
    --surface-2: rgba(28, 19, 64, 0.4);
    --surface-strong: #1f1547;
    --ink: #f3eaff;
    --ink-2: #cdb8ff;
    --ink-mute: #9c92c8;
    --line: rgba(255, 255, 255, 0.1);
    --ring: rgba(123, 63, 245, 0.7);
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(255, 91, 167, 0.16) 10%, transparent 60%),
    radial-gradient(700px 400px at 100% 0%, rgba(42, 208, 255, 0.18) 0%, transparent 55%),
    radial-gradient(620px 360px at 70% 100%, rgba(255, 184, 107, 0.2), transparent 58%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Subtle aurora layer */
body::before {
  content: "";
  position: fixed;
  inset: -20vh -10vw;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(40vmax 30vmax at 70% 20%, rgba(42, 208, 255, 0.18), transparent 60%),
    radial-gradient(35vmax 25vmax at 10% 80%, rgba(255, 91, 167, 0.18), transparent 60%),
    radial-gradient(45vmax 30vmax at 90% 90%, rgba(123, 63, 245, 0.18), transparent 60%);
  filter: blur(20px);
  animation: aurora 24s ease-in-out infinite alternate;
}

@keyframes aurora {
  0%   { transform: translate3d(-2%, -2%, 0) scale(1); }
  100% { transform: translate3d(2%, 2%, 0) scale(1.05); }
}

@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

a { color: var(--brand-1); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ====== App shell ====== */
.app-nav {
  position: sticky; top: 0; z-index: 50;
  padding-top: var(--safe-top);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.app-nav-inner {
  max-width: 1240px; margin: 0 auto;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 14px;
}
.brand {
  display: inline-flex; align-items: center; gap: 12px;
  font-weight: 800; letter-spacing: 0.2px;
  color: var(--ink);
}
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: conic-gradient(from 210deg, #ffcc70, #c850c0, #4158d0, #2ad0ff, #ffcc70);
  box-shadow: inset 0 0 12px #ffffff80, 0 6px 16px rgba(123,63,245,.35);
  position: relative;
}
.brand-logo::after {
  content: ""; position: absolute; inset: 6px; border-radius: 8px;
  background: var(--surface-strong);
  display: grid; place-items: center;
}
.brand-logo::before {
  content: "▶"; position: absolute; inset: 6px; border-radius: 8px;
  display: grid; place-items: center;
  font-size: 14px; color: var(--brand-1); font-weight: 900;
  z-index: 1;
}
.brand-name { font-size: 1.05rem; }
.brand-name b { color: var(--brand-1); }

.nav-spacer { flex: 1; }
.nav-actions { display: inline-flex; align-items: center; gap: 8px; }

/* ====== Buttons ====== */
.btn {
  appearance: none; cursor: pointer; user-select: none;
  font-family: inherit; font-weight: 700;
  border: 1px solid var(--line); background: var(--surface-strong); color: var(--ink);
  padding: 9px 14px; border-radius: var(--radius-sm);
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px;
}
.btn:hover { background: color-mix(in srgb, var(--surface-strong) 88%, var(--brand-1)); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn.icon { padding: 9px; min-width: 40px; justify-content: center; }
.btn.primary {
  border: 0; color: #fff;
  background: var(--brand-grad);
  box-shadow: 0 8px 22px rgba(42,208,255,.35);
}
.btn.primary:hover { filter: brightness(1.05); background: var(--brand-grad); }
.btn.ghost { background: transparent; }

/* ====== Layout ====== */
.wrap {
  position: relative; z-index: 1;
  max-width: 1240px; margin: 0 auto;
  padding: 20px 16px calc(40px + var(--safe-bot));
}

.hero {
  display: grid; gap: 14px;
  padding: 24px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(255,255,255,.9), rgba(255,255,255,.64)),
    radial-gradient(circle at 85% 10%, rgba(42,208,255,.24), transparent 32%);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}
.hero h1 {
  margin: 0; font-size: clamp(1.4rem, 2.5vw + 0.6rem, 2.2rem);
  line-height: 1.15;
  background: linear-gradient(120deg, var(--brand-1), var(--brand-3), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { margin: 0; color: var(--ink-mute); }

/* Tools row */
.tools {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-top: 6px;
}
.search {
  flex: 1 1 240px; min-width: 200px;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--surface-strong);
  border: 1px solid var(--line); border-radius: 999px;
  box-shadow: var(--shadow);
}
.search input {
  flex: 1; border: 0; background: transparent; outline: 0;
  font: inherit; color: var(--ink); min-width: 0;
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  cursor: pointer;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  font-weight: 700; font-size: 0.85rem; color: var(--ink-2);
}
.chip.active {
  color: #fff; border-color: transparent;
  background: var(--brand-grad);
  box-shadow: 0 6px 16px rgba(123,63,245,.35);
}

/* Cards grid */
.grid {
  margin-top: 18px;
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.card {
  position: relative;
  display: flex; flex-direction: column; gap: 10px;
  padding: 10px;
  background: rgba(255,255,255,.76);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  overflow: hidden;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--brand-2) 45%, var(--line)); }
.card .thumb {
  height: 150px; border-radius: var(--radius-sm);
  overflow: hidden; position: relative;
  background:
    radial-gradient(circle at 22% 18%, rgba(255,255,255,.8), transparent 20%),
    linear-gradient(135deg, #14182f, #273a66 48%, #0fb7c7);
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; filter: saturate(1.18) contrast(1.04); }
.card .thumb::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(180deg, transparent 42%, rgba(0,0,0,.28)),
    radial-gradient(circle at 80% 16%, rgba(255,255,255,.2), transparent 20%);
  pointer-events: none;
}
.card::before {
  content: attr(data-category);
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 1;
  padding: 5px 9px;
  border-radius: 999px;
  color: #fff;
  background: rgba(8,12,30,.58);
  border: 1px solid rgba(255,255,255,.24);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  backdrop-filter: blur(8px);
}
.card .meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card h3 { margin: 0; font-size: 1.04rem; color: var(--ink); }
.card .sub { font-size: .8rem; color: var(--ink-mute); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card .badge {
  font-size: .7rem; padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--brand-1) 14%, transparent);
  color: var(--brand-1); font-weight: 800;
}
.card .best {
  font-size: .72rem; color: var(--ink-mute); font-weight: 700;
}
.card .play {
  appearance: none; border: 0; cursor: pointer;
  padding: 10px 16px; border-radius: 10px;
  font-family: inherit; font-weight: 800; color: #fff;
  background: var(--brand-grad);
  box-shadow: 0 6px 18px rgba(42,208,255,.32);
}
.card .play:hover { filter: brightness(1.06); }

/* Empty state */
.empty {
  text-align: center; padding: 40px 16px; color: var(--ink-mute);
  border: 1px dashed var(--line); border-radius: var(--radius-lg);
  margin-top: 18px;
}

/* ====== Overlay player ====== */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  display: none; align-items: center; justify-content: center;
  background: #05070d;
}
.overlay.show { display: flex; }
.player {
  position: relative;
  width: 100vw;
  height: 100dvh;
  background: var(--surface-strong);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.player-head {
  display: flex; align-items: center; gap: 10px;
  min-height: 52px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-strong) 90%, #0b1020);
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
}
.crumbs { font-size: .92rem; color: var(--ink-mute); }
.crumbs a { color: var(--brand-1); }
.player-actions { margin-left: auto; display: inline-flex; gap: 8px; }
iframe.frame {
  flex: 1; width: 100%; min-height: 0; border: 0; background: #05070d;
}

/* ====== Footer ====== */
.foot {
  margin-top: 28px; padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--ink-mute); font-size: .85rem;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between;
}

/* ====== Toast ====== */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bot));
  transform: translateX(-50%) translateY(80px);
  background: var(--surface-strong); color: var(--ink);
  border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  padding: 10px 14px; border-radius: 999px;
  z-index: 999; opacity: 0; transition: opacity .25s, transform .25s;
  font-weight: 700;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ====== Responsive ====== */
@media (max-width: 720px) {
  .app-nav-inner { padding: 10px 12px; }
  .wrap { padding: 14px 12px calc(40px + var(--safe-bot)); }
  .hero { padding: 16px; border-radius: var(--radius-lg); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .card { padding: 8px; border-radius: var(--radius-sm); }
  .card .thumb { height: 110px; }
  .card h3 { font-size: 0.96rem; }
  .player { width: 100vw; height: 100dvh; border-radius: 0; }
  .player-head { padding: calc(10px + var(--safe-top)) 10px 10px; }
}

/* ====== Game shell (used inside game pages) ====== */
.game-shell {
  --pad: clamp(8px, 1.4vw, 16px);
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: 0;
  background: linear-gradient(135deg, var(--bg-1), var(--bg-2));
}
.game-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  min-height: 52px;
  padding: 8px var(--pad);
  padding-top: calc(8px + var(--safe-top));
  background: rgba(255,255,255,.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.game-bar .title { font-weight: 800; color: var(--ink); }
.game-bar .scores { display: inline-flex; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.game-bar .pill, .pill {
  background: var(--surface-strong); padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-2); font-weight: 800; font-size: .85rem;
}
.game-bar .pill b, .pill b { color: var(--brand-1); }
.game-bar select, .pill select {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-weight: 800;
}
.game-stage {
  flex: 1; min-height: 0; display: grid; place-items: center; padding: var(--pad);
  position: relative;
  overflow: hidden;
}
.game-stage canvas, .game-stage .stage {
  width: auto;
  height: min(82dvh, calc(100dvh - 78px - var(--safe-top) - var(--safe-bot)));
  max-width: 100%;
  max-height: calc(100dvh - 78px - var(--safe-top) - var(--safe-bot));
  border-radius: var(--radius-sm);
  box-shadow: 0 18px 45px rgba(12, 18, 40, .22);
  touch-action: none;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* On-screen mobile pad */
.touchpad {
  display: none;
  position: fixed; left: 0; right: 0; bottom: calc(8px + var(--safe-bot));
  padding: 0 12px;
  pointer-events: none;
  z-index: 30;
}
.touchpad .pad-inner {
  display: grid; grid-template-columns: auto 1fr auto;
  gap: 10px; align-items: end;
  pointer-events: none;
}
.touchpad .dpad {
  display: grid; grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px); gap: 4px;
  pointer-events: auto;
}
.touchpad .dpad button {
  border: 1px solid var(--line);
  background: var(--surface-strong);
  color: var(--ink);
  border-radius: 14px; font-size: 1.4rem;
  font-weight: 900;
  box-shadow: var(--shadow);
  display: grid; place-items: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.touchpad .dpad button:active { background: color-mix(in srgb, var(--surface-strong) 70%, var(--brand-1)); }
.touchpad .dpad .empty { background: transparent; border: 0; box-shadow: none; }
.touchpad .actions {
  display: flex; gap: 10px; flex-direction: column; align-items: end;
  pointer-events: auto;
}
.touchpad .actions button {
  width: 72px; height: 72px; border-radius: 50%;
  border: 0; color: #fff; font-weight: 900; font-size: 1rem;
  background: var(--brand-grad);
  box-shadow: 0 8px 22px rgba(42,208,255,.35);
}

/* Show on touch devices */
@media (hover: none) and (pointer: coarse) {
  .touchpad.show-on-touch { display: block; }
}

/* Generic helpers */
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.mute { color: var(--ink-mute); }
.center { text-align: center; }
.hidden { display: none !important; }
