/* games.liran.ai - design system
   Dark playful cosmos, glass cards, vivid per-game accents. RTL, Rubik. */

/* ---------- reset & tokens ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b1024;
  --bg2: #141b3d;
  --card: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --text: #f4f6ff;
  --text-dim: #a7b0d8;
  --accent: #4cc9f0;
  --accent2: #b388ff;
  --good: #06d6a0;
  --bad: #ff5c8a;
  --gold: #ffd166;
  --radius: 22px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

html { -webkit-text-size-adjust: 100%; }

:where(a, button, input, .game-card, .btn, .quiz-opt, .mem-card):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 12px;
}
body {
  font-family: "Rubik", -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

/* per-game accents */
body[data-game="flags"]    { --accent: #4cc9f0; --accent2: #4361ee; }
body[data-game="capitals"] { --accent: #ffd166; --accent2: #ff9f1c; }
body[data-game="math"]     { --accent: #06d6a0; --accent2: #16a085; }
body[data-game="memory"]   { --accent: #b388ff; --accent2: #7c4dff; }
body[data-game="simon"]    { --accent: #ff5c8a; --accent2: #d81b60; }
body[data-game="stroop"]   { --accent: #ff9f1c; --accent2: #ff5c8a; }
body[data-game="typing"]   { --accent: #4cc9f0; --accent2: #06d6a0; }
body[data-game="snake"]    { --accent: #9ef01a; --accent2: #38b000; }
body[data-game="aiquiz"]   { --accent: #b388ff; --accent2: #4cc9f0; }

/* ---------- animated background ---------- */
.bg {
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(1000px 600px at 85% -10%, #2b1d5e 0%, transparent 60%),
    radial-gradient(900px 700px at -10% 110%, #0e3057 0%, transparent 55%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg2) 100%);
}
.blob {
  position: fixed; z-index: -1; border-radius: 50%;
  filter: blur(70px); opacity: 0.32; pointer-events: none;
  animation: drift 22s ease-in-out infinite alternate;
}
.blob-1 { width: 44vmax; height: 44vmax; top: -18vmax; inset-inline-start: -10vmax; background: var(--accent); }
.blob-2 { width: 36vmax; height: 36vmax; bottom: -14vmax; inset-inline-end: -8vmax; background: var(--accent2); animation-delay: -8s; animation-duration: 28s; }
.blob-3 { width: 22vmax; height: 22vmax; top: 45%; inset-inline-start: 55%; background: #ff5c8a; opacity: 0.14; animation-delay: -14s; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(6vmax, 4vmax) scale(1.15); }
}

/* subtle starfield */
.stars { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.stars span {
  position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: #fff; opacity: 0.5; animation: twinkle 3.5s ease-in-out infinite;
}
@keyframes twinkle { 0%, 100% { opacity: 0.15; transform: scale(0.8); } 50% { opacity: 0.7; transform: scale(1.2); } }

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px clamp(14px, 4vw, 32px);
  position: sticky; top: 0; z-index: 50;
  background: rgba(11, 16, 36, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.topbar .brand {
  font-weight: 800; font-size: 1.05rem; text-decoration: none;
  display: flex; align-items: center; gap: 8px;
}
.topbar .brand .logo-dot {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  width: 30px; height: 30px; border-radius: 10px;
  display: grid; place-items: center; font-size: 1rem;
  box-shadow: 0 4px 14px rgba(76, 201, 240, 0.35);
}
.topbar .spacer { flex: 1; }
.icon-btn {
  background: var(--card); border: 1px solid var(--card-border); color: var(--text);
  width: 42px; height: 42px; border-radius: 14px; font-size: 1.15rem;
  transition: transform 0.15s, background 0.2s;
}
.icon-btn:hover { transform: translateY(-2px) scale(1.06); background: rgba(255, 255, 255, 0.12); }
.back-link {
  text-decoration: none; font-weight: 600; font-size: 0.95rem; color: var(--text-dim);
  padding: 11px 14px; border-radius: 12px; border: 1px solid var(--card-border);
  background: var(--card); transition: color 0.2s, transform 0.15s;
  white-space: nowrap;
}
.back-link:hover { color: var(--text); transform: translateY(-2px); }
.game-title-chip { font-weight: 800; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }

/* ---------- layout ---------- */
main { flex: 1; width: 100%; max-width: 1080px; margin-inline: auto; padding: clamp(16px, 4vw, 40px); }
#stage { display: flex; flex-direction: column; min-height: 60vh; }

/* ---------- hub (index) ---------- */
.hero { text-align: center; padding: clamp(20px, 5vw, 56px) 0 clamp(10px, 3vw, 28px); }
.hero .mega {
  font-size: clamp(2.1rem, 6.5vw, 4rem); font-weight: 900; line-height: 1.15;
  background: linear-gradient(120deg, #fff 20%, var(--accent) 55%, var(--accent2) 85%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: pop-in 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.hero .sub {
  color: var(--text-dim); font-size: clamp(1.05rem, 2.5vw, 1.3rem); margin-top: 12px;
  animation: pop-in 0.7s 0.12s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.hero .sub b { color: var(--text); }

.games-grid {
  display: grid; gap: clamp(12px, 2.4vw, 22px);
  grid-template-columns: repeat(auto-fill, minmax(min(270px, 100%), 1fr));
  padding-bottom: 30px;
}
.game-card {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 26px 22px 22px; text-decoration: none; display: flex; flex-direction: column;
  transition: transform 0.22s cubic-bezier(0.2, 1.2, 0.4, 1), box-shadow 0.22s, border-color 0.22s;
  animation: card-in 0.6s cubic-bezier(0.2, 1.2, 0.4, 1) both;
  animation-delay: calc(var(--i) * 70ms);
}
@keyframes card-in { from { opacity: 0; transform: translateY(26px) scale(0.96); } to { opacity: 1; transform: none; } }
.game-card::before {
  content: ""; position: absolute; inset: 0; opacity: 0;
  background: radial-gradient(420px 200px at 50% 0%, var(--glow, rgba(76, 201, 240, 0.22)), transparent 70%);
  transition: opacity 0.25s;
}
.game-card:hover { transform: translateY(-7px) scale(1.02); box-shadow: var(--shadow); border-color: rgba(255, 255, 255, 0.25); }
.game-card:hover::before { opacity: 1; }
.game-card:active { transform: translateY(-2px) scale(0.99); }
.game-card .emoji {
  font-size: 2.9rem; display: inline-block; margin-bottom: 12px;
  transition: transform 0.25s;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
}
.game-card:hover .emoji { transform: scale(1.18) rotate(-8deg); }
.game-card h3 { font-size: 1.3rem; font-weight: 800; margin-bottom: 6px; position: relative; }
.game-card p { color: var(--text-dim); font-size: 0.95rem; line-height: 1.5; position: relative; }
.game-card .tag {
  position: absolute; top: 16px; inset-inline-end: 16px;
  font-size: 0.76rem; font-weight: 700; letter-spacing: 0.03em;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.09); border: 1px solid var(--card-border);
  color: color-mix(in srgb, var(--text) 70%, transparent);
}
.game-card .play-hint {
  margin-top: auto; padding-top: 14px; font-weight: 700; font-size: 0.9rem;
  color: var(--acc, var(--accent)); display: flex; align-items: center; gap: 6px; position: relative;
}

/* ---------- screens ---------- */
.screen { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; padding: clamp(10px, 3vw, 30px) 0; }
.intro-emoji { font-size: clamp(4rem, 12vw, 6.2rem); filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.4)); }
.float { animation: floaty 3.2s ease-in-out infinite; }
@keyframes floaty { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-14px) rotate(3deg); } }
.screen h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); font-weight: 900; }
.screen h2 { font-size: clamp(1.6rem, 4.5vw, 2.3rem); font-weight: 900; }
.screen .desc { color: var(--text-dim); font-size: 1.1rem; max-width: 520px; line-height: 1.6; }
.rules { list-style: none; display: flex; flex-direction: column; gap: 8px; margin: 6px 0; }
.rules li {
  background: var(--card); border: 1px solid var(--card-border);
  padding: 10px 18px; border-radius: 14px; font-size: 1rem; color: var(--text);
}
.pb-chip { color: var(--gold); font-size: 1rem; font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--card-border); background: var(--card); color: var(--text);
  padding: 13px 26px; border-radius: 16px; font-size: 1.05rem; font-weight: 700;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s, filter 0.2s;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: scale(0.96); }
.btn-primary {
  /* gradient floor keeps dark label text legible on both stops (WCAG for kids) */
  background: linear-gradient(135deg,
    var(--accent),
    color-mix(in srgb, var(--accent2) 60%, var(--accent)));
  border: none; color: #0b1024;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 45%, transparent);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-big { font-size: 1.25rem; padding: 17px 44px; border-radius: 20px; }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: 0.6; cursor: default; transform: none; }

/* ---------- quiz ---------- */
.quiz-screen { gap: 18px; }
.quiz-top { width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 8px; }
.quiz-progress { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.09); overflow: hidden; }
.quiz-progress-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.4s ease; }
.quiz-meta { display: flex; justify-content: space-between; color: var(--text-dim); font-weight: 600; font-size: 0.95rem; }
.quiz-score { color: var(--gold); }
.quiz-timer { width: 100%; max-width: 640px; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.quiz-timer-fill { height: 100%; width: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--good), var(--gold), var(--bad)); }
.quiz-prompt { font-size: clamp(1.3rem, 4vw, 1.9rem); font-weight: 800; min-height: 60px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.quiz-prompt .flag-img {
  width: min(340px, 78vw); border-radius: 14px; display: block;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5); border: 1px solid rgba(255, 255, 255, 0.18);
}
.quiz-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; width: 100%; max-width: 640px; }
.quiz-opt { font-size: 1.1rem; padding: 16px 12px; }
.opt-correct { background: color-mix(in srgb, var(--good) 30%, var(--card)) !important; border-color: var(--good) !important; animation: pulse-good 0.5s; }
.opt-wrong { background: color-mix(in srgb, var(--bad) 30%, var(--card)) !important; border-color: var(--bad) !important; animation: shake 0.4s; }
@keyframes pulse-good { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 50% { transform: translateX(7px); } 75% { transform: translateX(-4px); } }
.shake { animation: shake 0.4s; }
.pop-in { animation: pop-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
@keyframes pop-in { from { opacity: 0; transform: scale(0.88) translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- end screen ---------- */
.final-score {
  font-size: clamp(3.2rem, 11vw, 5.4rem); font-weight: 900; line-height: 1;
  background: linear-gradient(120deg, var(--gold), var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.score-label { color: var(--text-dim); margin-top: -8px; font-weight: 600; }
.detail { color: var(--text-dim); font-size: 1.05rem; }
.detail b { color: var(--text); }
.rank-line { font-size: 1.1rem; min-height: 1.4em; font-weight: 600; }
.rank-line b { color: var(--gold); }
.pb-badge {
  background: linear-gradient(135deg, var(--gold), #ff9f1c); color: #4a2b00;
  font-weight: 800; padding: 8px 20px; border-radius: 999px; animation: pop-in 0.5s 0.3s both;
}
.end-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.end-lb { width: 100%; max-width: 460px; }
.end-lb h4 { margin: 14px 0 8px; font-size: 1.1rem; }

/* ---------- leaderboard list ---------- */
.lb-list { list-style: none; display: flex; flex-direction: column; gap: 7px; width: 100%; }
.lb-list li {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--card-border);
  padding: 10px 16px; border-radius: 14px; font-size: 1rem;
  animation: pop-in 0.4s both;
}
.lb-list li:nth-child(1) { border-color: rgba(255, 209, 102, 0.55); background: rgba(255, 209, 102, 0.09); }
.lb-list li:nth-child(2) { border-color: rgba(200, 210, 230, 0.4); }
.lb-list li:nth-child(3) { border-color: rgba(205, 127, 50, 0.45); }
.lb-list li.me { outline: 2px solid var(--accent); }
.lb-rank { width: 2em; text-align: center; font-weight: 800; }
.lb-nick { flex: 1; text-align: start; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.lb-empty { color: var(--text-dim); padding: 18px 0; }

/* ---------- modal ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 18px;
  background: rgba(5, 8, 20, 0.7); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; transition: opacity 0.2s;
}
.modal-wrap.open { opacity: 1; }
.modal-card {
  background: linear-gradient(170deg, #1a2148, #10152e);
  border: 1px solid var(--card-border); border-radius: 26px;
  padding: 30px 26px; width: min(430px, 94vw); max-height: 86vh; overflow-y: auto;
  text-align: center; box-shadow: var(--shadow);
  transform: translateY(16px) scale(0.97); transition: transform 0.22s cubic-bezier(0.2, 1.3, 0.4, 1);
}
.modal-wrap.open .modal-card { transform: none; }
.modal-emoji { font-size: 3rem; margin-bottom: 6px; }
.modal-card h3 { font-size: 1.35rem; margin-bottom: 6px; }
.modal-card .hint { color: var(--text-dim); font-size: 0.92rem; margin-bottom: 16px; }
.modal-card input {
  width: 100%; padding: 14px 16px; border-radius: 14px; font-size: 1.1rem; font-family: inherit;
  background: rgba(255, 255, 255, 0.07); border: 1px solid var(--card-border); color: var(--text);
  text-align: center; margin-bottom: 14px; outline: none; transition: border-color 0.2s;
}
.modal-card input:focus { border-color: var(--accent); }
.modal-card .btn { width: 100%; margin-bottom: 8px; }
.lb-body { min-height: 120px; display: flex; flex-direction: column; justify-content: center; margin: 10px 0 14px; }
.spinner {
  width: 38px; height: 38px; margin: 20px auto; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- game HUD (shared) ---------- */
.hud {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  width: 100%; max-width: 640px; margin-bottom: 6px;
}
.hud .stat {
  background: var(--card); border: 1px solid var(--card-border); border-radius: 14px;
  padding: 8px 18px; font-weight: 700; font-size: 1rem; display: flex; gap: 7px; align-items: center;
}
.hud .stat b { color: var(--gold); font-variant-numeric: tabular-nums; }

/* ---------- footer ---------- */
.footer {
  text-align: center; padding: 26px 18px 34px; color: var(--text-dim); font-size: 0.95rem;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.footer .promo {
  background: var(--card); border: 1px solid var(--card-border); border-radius: 18px;
  padding: 14px 22px; max-width: 560px; line-height: 1.6;
}
.footer .promo a { color: var(--accent); font-weight: 700; text-decoration: none; }
.footer .promo a:hover { text-decoration: underline; }
.footer .tiny { font-size: 0.8rem; opacity: 0.75; }

/* ---------- responsive ---------- */
@media (max-width: 560px) {
  .quiz-options { grid-template-columns: 1fr; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar .back-link .bl-txt { display: none; }      /* back-link collapses to a 🎮 icon */
  .topbar .back-link { padding: 9px 12px; font-size: 1.1rem; }
  .game-title-chip { font-size: 0.9rem; white-space: nowrap; overflow: hidden;
    text-overflow: ellipsis; min-width: 0; }
  .btn-big { width: 100%; }
  .end-actions { width: 100%; flex-direction: column; }
}

/* gradient-text fallback for browsers without background-clip: text */
@supports not (background-clip: text) {
  .hero .mega, .final-score { color: var(--accent); background: none; }
}

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