:root {
  /* ---- GamesJi brand palette (matches the main site) ---- */
  --blue: #8b5cf6;            /* was solid blue -> now violet accent */
  --blue-dark: #7c3aed;
  --blue-light: rgba(139,92,246,.18);
  --cyan: #22d3ee;
  --rose: #fb5384;
  --black: #eef1fb;           /* "black" = primary text -> light on dark bg */
  --gray: #8b93ad;            /* secondary/dim text */
  --gray-light: rgba(255,255,255,.08); /* subtle glass surface */
  --white: #0c1120;           /* "white" = main surface -> dark navy card */
  --bg-0: #080b14;
  --bg-1: #0f1424;
  --glass: rgba(255,255,255,.055);
  --glass-hi: rgba(255,255,255,.14);
  --border: rgba(255,255,255,.18);
  --red: #ef4444;
  --green: #16e37b;
  --green-light: #7dffbc;
  --gold: #f5b942;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 650px at 12% -10%, #1c1140 0%, transparent 60%),
    radial-gradient(900px 550px at 112% 110%, #062330 0%, transparent 55%),
    var(--bg-0);
  color: var(--black);
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  animation: fadeIn .25s ease;
}
.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- HOME ---------- */
#screen-home { justify-content: flex-start; align-items: center; overflow-y: auto; }

.seo-content {
  max-width: 380px;
  margin-top: 8px;
  padding: 16px 4px 4px;
  text-align: left;
  border-top: 1px solid var(--border);
}
.seo-content h2 {
  font-size: .95rem;
  font-weight: 800;
  color: var(--black);
  margin-bottom: 8px;
}
.seo-content p {
  font-size: .78rem;
  line-height: 1.5;
  color: var(--gray);
  margin-bottom: 10px;
}
.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  width: 100%;
}
.logo {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--black);
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(90deg, #fff, var(--cyan) 75%);
  -webkit-background-clip: text;
  background-clip: text;
}
.logo-arrow {
  color: var(--cyan);
  display: inline-block;
  animation: bounceArrow 1.4s ease-in-out infinite;
  -webkit-text-fill-color: var(--cyan);
}
@keyframes bounceArrow {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(6px); }
}
.accent { color: var(--cyan); -webkit-text-fill-color: var(--cyan); }
.tagline { color: var(--gray); font-size: .95rem; margin-bottom: 8px; }

.home-stats { display: flex; gap: 10px; margin-bottom: 8px; }
.stat-pill {
  background: var(--glass);
  border: 1.5px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--black);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .95rem;
}
.stat-pill.small { padding: 6px 12px; font-size: .85rem; }
.top-bar .stat-pill {
  background: var(--glass);
  color: var(--black);
}

/* ---------- GAME SCREEN LAYOUT (fixed proportions) ----------
   Header ~5%, board area ~80%, bottom bar ~15% of the screen height,
   as requested. Using flex-basis with grow/shrink disabled on the
   header/footer so they stay compact and the board fills the rest. */
#screen-game.active {
  display: flex;
  flex-direction: column;
}
.top-bar.game-top-bar-compact {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 5px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.back-btn-sm {
  width: 28px;
  height: 28px;
  font-size: .9rem;
}
.level-title-compact {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  color: var(--black);
  font-size: .85rem;
}
.lives-display-sm { font-size: .75rem; gap: 2px; }

#screen-game .maze-wrap {
  flex: 1 1 auto;
  min-height: 0;
}
#screen-game .bottom-bar {
  flex: 0 0 auto;
}

.btn {
  border: none;
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
  font-size: 1rem;
}
.btn:active { transform: scale(.96); }
.btn-primary {
  background: linear-gradient(155deg, var(--blue), var(--cyan) 130%);
  color: #08101f;
  padding: 14px 32px;
  box-shadow: 0 4px 22px rgba(139,92,246,.4);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary {
  background: var(--glass);
  color: var(--black);
  border: 2px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 12px 28px;
}
.btn-ghost {
  background: transparent;
  color: var(--gray);
  padding: 10px 20px;
}
.btn-large { width: 220px; font-size: 1.15rem; padding: 16px 32px; }

.home-footer {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  align-items: center;
}
.icon-btn {
  background: var(--glass);
  border: 1.5px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--black);
}
.install-btn {
  width: auto;
  border-radius: 999px;
  padding: 0 16px;
  gap: 6px;
  font-weight: 700;
  color: var(--cyan);
  font-size: .85rem;
}

/* ---------- TOP BAR ---------- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  gap: 10px;
  background: var(--glass);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}
.top-bar h2 { font-size: 1.1rem; font-weight: 800; color: var(--black); }
.back-btn {
  background: var(--glass);
  border: 1.5px solid var(--border);
  width: 40px;
  height: 40px;
  border-radius: 14px;
  font-size: 1.2rem;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--black);
}
.back-btn:active { border-color: var(--cyan); }

.level-title {
  font-weight: 800;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--black);
}
.diff-tag {
  font-size: .7rem;
  background: var(--glass);
  border: 1px solid var(--border);
  color: var(--cyan);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.lives-display { display: flex; gap: 3px; font-size: 1.05rem; }
.heart { transition: transform .25s ease; }
.heart.lost {
  animation: heartLoss .45s ease forwards;
}
@keyframes heartLoss {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4) rotate(-15deg); }
  100% { transform: scale(0); opacity: 0; }
}

/* ---------- LEVEL GRID ---------- */
.level-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 16px;
  align-content: start;
}
.level-cell {
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--glass);
  border: 1.5px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--black);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  position: relative;
  transition: transform .12s ease, border-color .15s ease;
}
.level-cell:active { transform: scale(.92); }
.level-cell.locked {
  background: rgba(255,255,255,.03);
  border-color: rgba(255,255,255,.08);
  color: var(--gray);
  cursor: not-allowed;
}
.level-cell.completed {
  background: linear-gradient(155deg, var(--blue), var(--cyan) 140%);
  border-color: transparent;
  color: #08101f;
}
.level-cell.completed::after {
  content: "✓";
  position: absolute;
  top: 2px;
  right: 6px;
  font-size: .65rem;
}
.level-cell.current {
  outline: 3px solid var(--rose);
  outline-offset: 2px;
}
.level-cell .lock-icon { font-size: .9rem; }

/* ---------- MAZE BOARD (thin-line maze style) ---------- */
.maze-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  min-height: 0;
  position: relative;
}
.maze-board {
  background: linear-gradient(160deg, var(--bg-1), #0a0e1a);
  border-radius: 22px;
  position: relative;
  touch-action: none;
  border: 3px solid transparent;
  background-clip: padding-box;
  box-shadow:
    0 2px 24px rgba(0,0,0,.45),
    0 0 0 3px rgba(139,92,246,.35),
    0 0 24px rgba(34,211,238,.12);
  transition: background .25s ease, border-color .25s ease;
}

/* Floating dark/light toggle over the maze board */
.theme-toggle-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.theme-toggle-btn:active { transform: scale(.92); }

/* ---------- GAME SCREEN — ALT (DEEP) THEME ----------
   The default look above already matches the GamesJi site palette.
   Toggling "dark mode" in-game just swaps to an even deeper variant
   of the same violet/cyan scheme, so it always stays on-brand. */
#app.dark-theme #screen-game {
  background: #05070d;
}
#app.dark-theme #screen-game .top-bar {
  background: rgba(255,255,255,.03);
}
#app.dark-theme .maze-board {
  background: linear-gradient(160deg, #0a0d1a, #060810);
  box-shadow:
    0 2px 28px rgba(0,0,0,.6),
    0 0 0 3px rgba(34,211,238,.32),
    0 0 26px rgba(139,92,246,.16);
}
#app.dark-theme #screen-game .bottom-bar {
  background: rgba(255,255,255,.02);
  border-top-color: var(--border);
}
#app.dark-theme #screen-game .btn-icon-label {
  background: rgba(255,255,255,.06);
  color: var(--black);
}
#app.dark-theme #screen-game .btn-icon-label#btn-next:not(:disabled) {
  background: linear-gradient(155deg, var(--blue), var(--cyan) 130%);
  color: #08101f;
}
#app.dark-theme .popup-card {
  background: #0c1120;
  color: var(--black);
  border: 1.5px solid var(--border);
}
#app.dark-theme .popup-card p {
  color: var(--gray);
}

/* Piece line / arrow — default idle color set via JS.
   Neon glow: a layered drop-shadow filter gives every line a soft,
   gentle luminous halo, regardless of which color (idle/target/
   selected) is currently applied via JS. Color is set at the
   piece-group level so it drives currentColor for both the line
   (stroke) and the arrowhead (fill, set separately via JS). Kept
   intentionally soft/low-intensity, not a harsh bright glow. */
.piece-group { color: #FF073A; }
.piece-target { color: var(--green); }

.piece-line, .piece-arrow {
  transition: stroke .2s ease, fill .2s ease;
  filter: drop-shadow(0 0 1px currentColor) drop-shadow(0 0 2.5px currentColor);
}
.piece-shadow, .piece-core, .piece-arrow-shadow, .piece-arrow-core {
  pointer-events: none;
}

/* Target (green) piece: same soft static glow as every other piece,
   just green instead of blue. No pulsing/blinking on its own -- a
   highlight only ever appears when the player taps Hint (see
   .hint-pulse below). */

/* NOTE: free/extractable pieces intentionally get NO automatic glow
   or blink here -- that highlight only appears when the player
   taps the Hint button (see .hint-pulse below). The piece-free class
   is still tracked in JS for game logic, it just isn't styled. */

/* Hint flash on a normal piece */
.hint-pulse {
  animation: hintFlash 1s ease-in-out infinite;
}
@keyframes hintFlash {
  0%,100% { opacity: 1; }
  50%      { opacity: .4; }
}

.piece-blocked-shake {
  animation: blockedShake .45s ease;
}
@keyframes blockedShake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-5px); }
  40%     { transform: translateX(5px); }
  60%     { transform: translateX(-4px); }
  80%     { transform: translateX(4px); }
}

.green-word { color: var(--green-light); font-weight: 800; }

.bottom-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  gap: 8px;
}
.btn-icon-label {
  background: var(--glass);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 14px;
  font-size: .72rem;
  font-weight: 700;
  color: var(--black);
  cursor: pointer;
  position: relative;
  flex: 1;
  transition: transform .1s ease, background .15s ease, border-color .15s ease;
}
.btn-icon-label:active { transform: scale(.94); }
.btn-icon-label:hover { border-color: var(--cyan); }
.btn-icon-label .icon { font-size: 1.3rem; }
.btn-icon-label:disabled { opacity: .4; cursor: not-allowed; }
.btn-icon-label#btn-next:not(:disabled) {
  background: linear-gradient(155deg, var(--blue), var(--cyan) 130%);
  color: #08101f;
  border-color: transparent;
}
.cost-tag {
  position: absolute;
  top: 2px;
  right: 6px;
  background: var(--gold);
  color: #241a04;
  font-size: .6rem;
  padding: 1px 6px;
  border-radius: 999px;
}

/* ---------- EMBEDDED MODE (loaded inside GamesJi's iframe) ----------
   Strip every text element so the iframe shows nothing but the game
   itself: no home screen copy, no ad banners, no level numbers/labels,
   just the board and icon-only controls. The standalone page (visited
   directly, not embedded) keeps all of this for SEO + normal UX. */
#app.embedded #ad-top-banner,
#app.embedded #ad-bottom-banner,
#app.embedded .seo-content,
#app.embedded .home-content,
#app.embedded #screen-home,
#app.embedded #screen-levels {
  display: none !important;
}
#app.embedded .top-bar.game-top-bar-compact .back-btn-sm,
#app.embedded .top-bar.game-top-bar-compact .level-title-compact {
  display: none !important;
}
#app.embedded .top-bar.game-top-bar-compact {
  justify-content: flex-end;
  background: transparent;
  border-bottom: none;
  min-height: 28px;
  padding: 8px 10px 0;
}
#app.embedded .bottom-bar .btn-icon-label span:not(.icon):not(.cost-tag) {
  display: none !important;
}
#app.embedded .bottom-bar .btn-icon-label {
  padding: 10px;
}
#app.embedded .bottom-bar {
  border-top: none;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}


.ad-slot {
  width: 100%;
  background: var(--glass);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray);
  font-size: .75rem;
  flex-shrink: 0;
}
.ad-top { height: 50px; }
.ad-bottom { height: 50px; }

/* ---------- POPUPS ---------- */
/* Ensure the [hidden] attribute always wins over component display rules
   (e.g. .popup-overlay { display:flex } would otherwise override it) */
[hidden] {
  display: none !important;
}

.popup-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4,6,14,.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn .2s ease;
}
.popup { width: 100%; display: flex; justify-content: center; padding: 24px; }
.popup-card {
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 28px 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.04) inset;
  animation: popIn .3s cubic-bezier(.34,1.56,.64,1);
}
.popup-card.small { padding: 16px 20px; max-width: 240px; }
@keyframes popIn {
  from { transform: scale(.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.popup-title { font-size: 1.4rem; margin-bottom: 12px; color: var(--black); }
.popup-title.success {
  background: linear-gradient(90deg, var(--cyan), var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.popup-title.fail { color: var(--rose); }
.popup-card p { color: var(--gray); margin-bottom: 16px; }

.coin-anim {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--gold);
  margin: 16px 0;
  animation: coinPop .5s ease;
}
@keyframes coinPop {
  0% { transform: scale(0) rotate(-30deg); }
  60% { transform: scale(1.2) rotate(10deg); }
  100% { transform: scale(1) rotate(0); }
}
.icon.big { font-size: 2rem; }

.popup-actions { display: flex; gap: 10px; margin-top: 8px; }
.popup-actions.vertical { flex-direction: column; }
.popup-actions .btn { flex: 1; }

.popup-toast {
  position: absolute;
  top: 20%;
  left: 0; right: 0;
  padding: 0 24px;
}
.wrong-text { color: var(--rose); font-weight: 800; font-size: 1.1rem; margin: 0; }

/* ---------- RESPONSIVE ---------- */
@media (min-width: 600px) {
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
@media (max-height: 640px) {
  .home-content { gap: 10px; }
  .logo { font-size: 1.9rem; }
}
