/* Aly Baba Arcade: shared look for every game page. Deep aubergine night, candy-bright accents, round friendly type. */
:root {
  --bg: #1b0a3a;
  --bg-2: #2a1157;
  --card: #34196a;
  --card-line: #4a2a8c;
  --ink: #fff6e6;
  --ink-dim: #cdbcf2;
  --saffron: #ffc72c;
  --coral: #ff5d8f;
  --turq: #1fd6c4;
  --violet: #9a6dff;
  --lime: #b4f04e;
  --sky: #4cc9f0;
  --tang: #ff8a3d;
  --danger: #ff6b6b;
  --good: #7fe3a8;
  --a: var(--saffron);
  --font-display: "Lilita One", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-ar-display: "Lalezar", "Cairo", sans-serif;
  --font-ar-body: "Cairo", "Segoe UI", Tahoma, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  background:
    radial-gradient(700px 420px at 85% 0%, rgba(255, 93, 143, .25), transparent 70%),
    radial-gradient(800px 500px at 0% 30%, rgba(154, 109, 255, .28), transparent 70%),
    radial-gradient(1px 1px at 20px 30px, #fff8, transparent 60%) 0 0 / 130px 130px,
    radial-gradient(1.5px 1.5px at 80px 90px, #ffd9fb99, transparent 60%) 0 0 / 170px 170px,
    var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}
body[data-lang="ar"] { font-family: var(--font-ar-body); font-size: 18px; }
.wrap { max-width: 620px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
button, a { font: inherit; color: inherit; }
button { touch-action: manipulation; }
:is(a, button, [tabindex]):focus-visible { outline: 3px solid var(--saffron); outline-offset: 3px; border-radius: 12px; }

/* header */
.gtop { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: calc(14px + env(safe-area-inset-top, 0px)); flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 800; padding: 6px 14px 6px 10px; min-height: 40px; background: var(--card); border: 2px solid var(--card-line); border-radius: 999px; }
.back svg { width: 18px; height: 18px; }
html[dir="rtl"] .back svg { transform: scaleX(-1); }
.back:hover { border-color: var(--a); }
.gtop-right { display: flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 14px; background: var(--card); border: 2px solid var(--card-line); border-radius: 999px; font-weight: 800; cursor: pointer; }
.pill svg { width: 22px; height: 22px; }
button.pill:hover { border-color: var(--a); }
.pill.pop { animation: pillpop .5s ease-out; }
@keyframes pillpop { 40% { transform: scale(1.18); border-color: var(--saffron); } }
.gtitle { margin: 6px 0 0; font-family: var(--font-display); font-weight: 400; font-size: clamp(34px, 9vw, 48px); line-height: 1.05; letter-spacing: .01em; color: var(--a); text-wrap: balance; }
body[data-lang="ar"] .gtitle { font-family: var(--font-ar-display); letter-spacing: 0; line-height: 1.25; }
.gsub { margin: 0; color: var(--ink-dim); text-wrap: pretty; }

/* panels and hud */
.panel { background: var(--card); border: 2px solid var(--card-line); border-radius: 22px; padding: 12px; }
.hud { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; justify-content: space-between; }
.stat { display: flex; flex-direction: column; min-width: 0; }
.stat small { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); font-weight: 800; }
body[data-lang="ar"] .stat small { letter-spacing: 0; font-size: 13px; text-transform: none; }
.stat b { font-family: var(--font-display); font-weight: 400; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.hud-left { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer; min-height: 48px; padding: 8px 22px; border-radius: 999px; background: var(--a); color: #2a1157; font-family: var(--font-display); font-size: 20px; letter-spacing: .02em; box-shadow: 0 5px 0 rgba(0, 0, 0, .28); transition: transform .1s, box-shadow .1s; text-decoration: none; }
body[data-lang="ar"] .btn { font-family: var(--font-ar-display); font-size: 22px; letter-spacing: 0; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .28); }
.btn.ghost { background: var(--card); color: var(--ink); border: 2px solid var(--card-line); box-shadow: none; }
.btn.small { min-height: 38px; padding: 4px 16px; font-size: 16px; }
.chip { font: inherit; font-weight: 700; color: var(--ink); background: var(--bg-2); border: 2px solid var(--card-line); border-radius: 999px; padding: 4px 14px; min-height: 36px; cursor: pointer; }
.chip:hover { border-color: var(--a); }
.chip[aria-pressed="true"] { background: var(--a); color: #2a1157; border-color: var(--a); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }

/* game area + overlay */
.stage { position: relative; }
.overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; text-align: center; padding: 18px; background: rgba(20, 8, 46, .78); backdrop-filter: blur(3px); border-radius: inherit; }
.overlay[hidden] { display: none; }
.overlay .box { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 30ch; }
.overlay h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 34px; line-height: 1.1; color: var(--a); }
body[data-lang="ar"] .overlay h2 { font-family: var(--font-ar-display); line-height: 1.3; }
.overlay p { margin: 0; color: var(--ink); text-wrap: pretty; }
.overlay .big { font-family: var(--font-display); font-size: 44px; line-height: 1; color: var(--ink); }
.newbest { color: var(--saffron); font-weight: 800; }
canvas.game { display: block; width: 100%; height: auto; border-radius: 16px; touch-action: none; -webkit-user-select: none; user-select: none; background: #120628; }

.msg { margin: 0; min-height: 3.1em; padding: 10px 14px; border-radius: 14px; background: var(--bg-2); border: 2px solid var(--card-line); text-wrap: pretty; }
.msg.good { border-color: var(--good); }
.msg.bad { border-color: var(--danger); }

.howto { color: var(--ink-dim); font-size: 15px; display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
body[data-lang="ar"] .howto { font-size: 16.5px; }
.howto li { padding-inline-start: 16px; position: relative; text-wrap: pretty; }
.howto li::before { content: ""; position: absolute; inset-inline-start: 0; top: .62em; width: 6px; height: 6px; background: var(--a); transform: rotate(45deg); border-radius: 1px; }
.howto-title { margin: 6px 0 -4px; font-family: var(--font-display); font-weight: 400; font-size: 22px; }
body[data-lang="ar"] .howto-title { font-family: var(--font-ar-display); }

.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 140%); z-index: 50; background: var(--saffron); color: #2a1157; font-weight: 800; padding: 10px 18px; border-radius: 999px; max-width: calc(100vw - 32px); transition: transform .3s, opacity .3s; text-align: center; opacity: 0; visibility: hidden; }
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }

/* in-game control pad */
.pad { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.pad button { min-width: 64px; min-height: 64px; border-radius: 18px; border: 2px solid var(--card-line); background: var(--bg-2); color: var(--ink); font-weight: 800; font-size: 22px; cursor: pointer; display: grid; place-items: center; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.pad button:active, .pad button.on { background: var(--a); color: #2a1157; border-color: var(--a); }
.pad svg { width: 28px; height: 28px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* Phones: keep controls above the browser's floating address bar */
.wrap { padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }
@media (max-width: 640px) {
  .wrap { gap: 10px; }
  .gsub { display: none; }
  .gtitle { font-size: clamp(28px, 8vw, 36px); margin-top: 0; }
}

/* Phones: on-screen controls stay pinned above the browser's bottom bar, even if the page isn't scrolled */
@media (max-width: 700px) {
  .dpad, .ctrls, .flapbtn, .jumpbtn { position: sticky; bottom: calc(env(safe-area-inset-bottom, 0px) + 74px); z-index: 5; }
}

/* level switch under the header: Easy / Normal / Hard, remembered per game */
.levelbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0 2px; }
.levelbar .lvlabel { color: var(--ink-dim, #cbb8f0); font-weight: 800; font-size: 14px; margin-inline-end: 2px; }
.levelbar .chip { min-height: 34px; padding: 3px 14px; font-size: 15px; }
