/* ============================================================
   Arrow Puzzle — style.css
   Main stylesheet: variables, resets, screens, modals, components
   ============================================================ */

/* ── 1. CSS Custom Properties / Themes ─────────────────────── */

:root {
  /* Colour palette */
  --clr-primary:       #6c63ff;
  --clr-primary-dark:  #4a42d4;
  --clr-primary-glow:  rgba(108, 99, 255, 0.45);
  --clr-accent:        #f7c948;
  --clr-accent-dark:   #d4a017;
  --clr-danger:        #ff4d4f;
  --clr-success:       #52c41a;
  --clr-warning:       #faad14;

  /* Surfaces */
  --bg:                #0f0f1a;
  --bg-card:           #1a1a2e;
  --bg-card-2:         #16213e;
  --bg-input:          #12122a;
  --bg-overlay:        rgba(0, 0, 0, 0.72);

  /* Text */
  --txt:               #e8e8f0;
  --txt-muted:         #8888aa;
  --txt-dim:           #555577;

  /* Border */
  --border:            rgba(108, 99, 255, 0.22);
  --border-strong:     rgba(108, 99, 255, 0.5);

  /* Shadows */
  --shadow-card:       0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-btn:        0 4px 16px rgba(108, 99, 255, 0.35);
  --shadow-glow:       0 0 20px rgba(108, 99, 255, 0.5);

  /* Radii */
  --radius-sm:         8px;
  --radius-md:         14px;
  --radius-lg:         20px;
  --radius-xl:         28px;
  --radius-pill:       999px;

  /* Typography */
  --font:              'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:         'Consolas', 'Courier New', monospace;

  /* Transitions */
  --tr-fast:           0.15s ease;
  --tr-med:            0.25s ease;
  --tr-slow:           0.4s ease;

  /* Game cell */
  --cell-size:         clamp(44px, 10vw, 72px);
  --cell-gap:          clamp(3px, 0.8vw, 6px);

  /* Difficulty colours */
  --diff-easy:         #2e7d32;
  --diff-medium:       #f9a825;
  --diff-hard:         #e65100;
  --diff-extreme:      #b71c1c;
  --diff-god:          #4a148c;
}

/* Light theme */
[data-bg="light"] {
  --bg:                #f0f2f8;
  --bg-card:           #ffffff;
  --bg-card-2:         #eef0f8;
  --bg-input:          #f8f9fc;
  --bg-overlay:        rgba(0, 0, 0, 0.50);
  --txt:               #1a1a2e;
  --txt-muted:         #555577;
  --txt-dim:           #aaaacc;
  --border:            rgba(108, 99, 255, 0.18);
  --border-strong:     rgba(108, 99, 255, 0.4);
  --shadow-card:       0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-btn:        0 4px 16px rgba(108, 99, 255, 0.25);
}

/* Neon theme */
[data-bg="neon"] {
  --clr-primary:       #c700ff;
  --clr-primary-dark:  #9200bb;
  --clr-primary-glow:  rgba(199, 0, 255, 0.5);
  --bg:                #080010;
  --bg-card:           #120020;
  --bg-card-2:         #0e0018;
  --bg-input:          #0a0015;
  --border:            rgba(199, 0, 255, 0.28);
  --border-strong:     rgba(199, 0, 255, 0.6);
  --shadow-glow:       0 0 24px rgba(199, 0, 255, 0.6);
  --shadow-btn:        0 4px 20px rgba(199, 0, 255, 0.5);
}

/* ── 2. Reset & Base ────────────────────────────────────────── */

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

html {
  -webkit-text-size-adjust: 100%;   /* prevent iOS auto font-scaling */
  text-size-adjust: 100%;
  /* JS sets --app-height = visualViewport.height for accurate mobile fit */
  --app-height: 100svh;
}

html, body {
  width: 100%;
  height: 100%;
  height: -webkit-fill-available; /* iOS Safari fallback */
  height: var(--app-height, 100svh);
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--txt);
  font-size: 16px;
  line-height: 1.5;
  touch-action: manipulation;       /* eliminate 300ms tap delay */
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
}

input {
  font-family: inherit;
  outline: none;
}

/* ── 3. Screen System ───────────────────────────────────────── */

.screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: var(--app-height, 100svh);  /* uses JS-measured visible height */
  display: flex;
  flex-direction: column;
  background: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--tr-med);
  z-index: 1;
  overflow: hidden;
  /* Safe area: push content below notch / status bar */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  z-index: 2;
}

/* ── 4. Loading Screen ──────────────────────────────────────── */

#screen-loading {
  align-items: center;
  justify-content: center;
  gap: 32px;
  background: var(--bg);
}

.loading-logo {
  font-size: clamp(2.4rem, 8vw, 4rem);
  font-weight: 900;
  text-align: center;
  line-height: 1.1;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px var(--clr-primary-glow));
  animation: pulse-btn 2s ease infinite;
}

.loading-bar {
  width: min(320px, 80vw);
  height: 6px;
  background: var(--bg-card);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: 1px solid var(--border);
}

.loading-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--clr-primary), var(--clr-accent));
  border-radius: var(--radius-pill);
  animation: loading-fill 1.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* ── 5. Auth Screen ─────────────────────────────────────────── */

#screen-auth {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  width: min(400px, 100%);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.game-title-sm {
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 900;
  text-align: center;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.auth-tabs {
  display: flex;
  background: var(--bg-card-2);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--txt-muted);
  transition: all var(--tr-fast);
}

.auth-tab.active {
  background: var(--clr-primary);
  color: #fff;
  box-shadow: 0 2px 12px var(--clr-primary-glow);
}

.auth-tab:hover:not(.active) {
  color: var(--txt);
  background: var(--border);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form.hidden { display: none; }

/* ── 6. Input & Button Components ──────────────────────────── */

.input {
  width: 100%;
  padding: 13px 16px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--txt);
  font-size: 16px;               /* must stay ≥16px — iOS zooms on smaller inputs */
  transition: border-color var(--tr-fast), box-shadow var(--tr-fast);
}

.input::placeholder {
  color: var(--txt-dim);
}

.input:focus {
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px var(--clr-primary-glow);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: all var(--tr-fast);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background var(--tr-fast);
  border-radius: inherit;
}

.btn:hover::after  { background: rgba(255,255,255,0.08); }
.btn:active::after { background: rgba(0,0,0,0.12); }

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-primary-dark));
  color: #fff;
  box-shadow: var(--shadow-btn);
}

.btn-primary:hover {
  box-shadow: 0 6px 24px var(--clr-primary-glow);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card-2);
  color: var(--txt);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--clr-primary);
  color: var(--clr-primary);
}

.btn-large {
  padding: 16px 28px;
  font-size: 1.1rem;
  border-radius: var(--radius-lg);
  width: 100%;
}

.btn-challenge {
  background: linear-gradient(135deg, #ff6b35, #f7c948);
  color: #1a0a00;
  font-weight: 900;
  box-shadow: 0 4px 20px rgba(255, 107, 53, 0.45);
}

.btn-challenge:hover {
  box-shadow: 0 6px 28px rgba(255, 107, 53, 0.65);
  transform: translateY(-1px);
}

.btn-daily {
  background: linear-gradient(135deg, #1565c0, #42a5f5);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(66, 165, 245, 0.4);
}

.btn-daily:hover {
  box-shadow: 0 6px 24px rgba(66, 165, 245, 0.6);
  transform: translateY(-1px);
}

.btn-control {
  background: var(--bg-card);
  color: var(--txt);
  border: 1.5px solid var(--border);
  padding: 10px 14px;
  font-size: 0.875rem;
  border-radius: var(--radius-md);
  flex: 1;
  min-width: 0;
}

.btn-control:hover {
  border-color: var(--clr-primary);
  color: var(--clr-primary);
}

.btn-bomb {
  border-color: var(--clr-danger);
  color: var(--clr-danger);
  position: relative;
}

.btn-bomb:hover {
  background: rgba(255, 77, 79, 0.12);
  border-color: var(--clr-danger);
  color: var(--clr-danger);
}

.btn-icon-sm {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--tr-fast);
  color: var(--txt);
}

.btn-icon-sm:hover {
  border-color: var(--clr-primary);
  box-shadow: 0 0 12px var(--clr-primary-glow);
}

.btn-icon-md {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  font-size: 1.3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--tr-fast);
  color: #ffffff;              /* white icons on dark background */
}

[data-bg="light"] .btn-icon-md {
  color: var(--txt);           /* dark icons on light background */
}

.btn-icon-md:hover {
  border-color: var(--clr-primary);
  box-shadow: 0 0 14px var(--clr-primary-glow);
}

/* ── 7. Main Menu Screen ────────────────────────────────────── */

#screen-menu {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.menu-bg-overlay {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(108, 99, 255, 0.18) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(247, 201, 72, 0.10) 0%, transparent 60%);
  pointer-events: none;
}

.menu-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 20px 20px max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
  gap: 24px;
}

.menu-hud {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hud-coins {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--clr-accent);
  flex: 1;
}

.hud-coins span:first-child { font-size: 1rem; }

.hud-lives {
  display: flex;
  align-items: center;
  gap: 3px;
}

.heart {
  font-size: 1.2rem;
  line-height: 1;
  display: inline-block;
  color: #ff3c50;
}

.heart.empty {
  color: var(--txt-muted);
  opacity: 0.4;
}

.menu-title-block {
  text-align: center;
  padding: 20px 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.game-title {
  font-size: clamp(2.8rem, 10vw, 5rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -2px;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 24px var(--clr-primary-glow));
}

.game-subtitle {
  font-size: 1rem;
  color: var(--txt-muted);
  margin-top: 6px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
}

.menu-row {
  display: flex;
  gap: 12px;
}

.menu-row .btn {
  flex: 1;
}

/* ── 8. Screen Header (shared) ──────────────────────────────── */

.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.screen-header h2 {
  flex: 1;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--txt);
}

.btn-back {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 1.2rem;
  color: var(--txt);
  flex-shrink: 0;
  transition: all var(--tr-fast);
}

.btn-back:hover {
  border-color: var(--clr-primary);
  color: var(--clr-primary);
}

.hud-coins-sm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--clr-accent);
  flex-shrink: 0;
}

/* ── 9. Level Select Screen ─────────────────────────────────── */

#screen-levels {
  overflow: hidden;
}

/* ── Level Select ──────────────────────────────── */
.ls-header {
  display: flex;
  align-items: center;
  padding: 16px 20px 12px;
  gap: 12px;
}
.ls-title { flex: 1; font-size: 1.25rem; font-weight: 800; color: var(--txt); }
.ls-coins { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--clr-accent); font-size: 1rem; }

.ls-progress-bar-wrap { padding: 0 20px 16px; }
.ls-progress-label { font-size: 0.78rem; color: var(--txt-muted); margin-bottom: 6px; }
.ls-progress-track { height: 6px; background: var(--bg-card-2); border-radius: 10px; overflow: hidden; }
.ls-progress-fill { height: 100%; background: linear-gradient(90deg, var(--clr-primary), #a29bfe); border-radius: 10px; transition: width 0.6s cubic-bezier(0.34,1.56,0.64,1); }

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: min-content;
  align-items: start;
  gap: 12px;
  padding: 0 16px max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
  flex: 1;
}

.level-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 14px 12px 12px;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, border-color 0.2s, box-shadow 0.2s;
  overflow: hidden;
  height: auto;
  align-self: start;
}
.level-card:not(.level-locked):hover {
  transform: translateY(-3px);
  border-color: var(--clr-primary);
  box-shadow: 0 8px 24px rgba(108,92,231,0.3);
}
.level-card:not(.level-locked):active { transform: scale(0.97); }

.level-card.level-locked {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.5);
}
.level-card.level-completed {
  border-color: #2ED57360;
}
.level-card.level-completed::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #2ED57308, transparent);
  pointer-events: none;
}

.lc-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.lc-number { font-size: 1.5rem; font-weight: 900; color: var(--txt-muted); line-height: 1; }
.lc-stars { display: flex; gap: 2px; }
.lc-stars .star { font-size: 0.75rem; }
.lc-stars .star-filled { color: #FFC107; }
.lc-stars .star-empty { color: #333355; }

.lc-name { font-size: 0.95rem; font-weight: 700; color: var(--txt); margin-bottom: 10px; line-height: 1.2; }

.lc-meta { display: flex; align-items: center; justify-content: space-between; }
.lc-diff {
  font-size: 0.62rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.08em; padding: 3px 8px; border-radius: 6px; color: #fff;
}
.lc-diff.diff-easy    { background: #2ED573; }
.lc-diff.diff-medium  { background: #FFC107; color: #111; }
.lc-diff.diff-hard    { background: #FF4757; }
.lc-diff.diff-extreme { background: #9B59B6; }
.lc-diff.diff-god     { background: linear-gradient(135deg,#f7971e,#ffd200); color:#111; }

.lc-reward { font-size: 0.75rem; font-weight: 700; color: var(--clr-accent); }

.lc-check {
  width: 18px;
  height: 18px;
  background: #2ED573;
  border-radius: 50%;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: 4px;
}

/* Difficulty pills */
.diff-easy    { background: var(--diff-easy);    color: #fff; }
.diff-medium  { background: var(--diff-medium);  color: #000; }
.diff-hard    { background: var(--diff-hard);    color: #fff; }
.diff-extreme { background: var(--diff-extreme); color: #fff; }
.diff-god     { background: var(--diff-god);     color: #fff; }

.diff-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── 10. Game Screen ────────────────────────────────────────── */

#screen-game {
  overflow: hidden;
}

.game-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.game-header-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.game-level-name {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--txt-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.game-timer {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--txt);
  font-family: var(--font-mono);
  letter-spacing: 1px;
}

.game-timer.danger {
  color: var(--clr-danger);
  animation: pulse-btn 0.6s ease infinite;
}

.game-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.hud-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--clr-accent);
}

.hud-lives-sm {
  display: flex;
  gap: 2px;
}

.hud-lives-sm .heart {
  font-size: 1rem;
}

/* Grid */
#grid-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: hidden;
}

#grid {
  display: grid;
  gap: var(--cell-gap);
  /* columns set dynamically by JS */
}

.cell {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: border-color var(--tr-fast), background var(--tr-fast);
  overflow: hidden;
}

.cell:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-2);
}

.cell.empty {
  background: var(--bg-input);
  border-color: transparent;
  cursor: default;
}

.cell.exit {
  border-color: var(--clr-success);
  background: rgba(82, 196, 26, 0.08);
}

.cell.exit::after {
  content: '→';
  font-size: 1.2rem;
  color: var(--clr-success);
  opacity: 0.6;
}

.cell.highlighted {
  border-color: var(--clr-primary);
  background: rgba(108, 99, 255, 0.1);
}

/* Path flash */
.cell.path-flash {
  animation: path-flash 0.5s ease forwards;
}

/* Arrow token */
.arrow-token {
  width: 80%;
  height: 80%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: transform var(--tr-fast), filter var(--tr-fast);
  position: relative;
}

.arrow-token svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Arrow colors by direction (can be overridden by skin) */
.arrow-token[data-dir="N"],
.arrow-token[data-dir="up"]    { color: #7ec8e3; }
.arrow-token[data-dir="S"],
.arrow-token[data-dir="down"]  { color: #f78c6c; }
.arrow-token[data-dir="E"],
.arrow-token[data-dir="right"] { color: #a8e6cf; }
.arrow-token[data-dir="W"],
.arrow-token[data-dir="left"]  { color: #dda0dd; }

/* Arrow state animations — defined in animations.css */

/* ── Skin Overrides ─────────────────────────────────────────── */
/* Each skin sets --token-glow so animations use the right colour */

[data-skin="neon"] .arrow-token {
  color: #00e5ff !important;
  --token-glow: rgba(0, 229, 255, 0.9);
}
[data-skin="neon"] .arrow-token svg {
  stroke-width: 4;
}

[data-skin="fire"] .arrow-token {
  color: #ff6b35 !important;
  --token-glow: rgba(255, 107, 53, 0.9);
}

[data-skin="ice"] .arrow-token {
  color: #80d8ff !important;
  --token-glow: rgba(128, 216, 255, 0.9);
}
[data-skin="ice"] .arrow-token svg {
  stroke-dasharray: 6 3;
}

[data-skin="gold"] .arrow-token {
  color: #ffd700 !important;
  --token-glow: rgba(255, 215, 0, 0.9);
}

[data-skin="classic"] .arrow-token {
  --token-glow: currentColor;
}

/* ── 11. Game Footer ────────────────────────────────────────── */

.game-footer {
  flex-shrink: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 8px 12px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* ── Stats bar ── */
.game-footer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  color: var(--txt-muted);
  font-weight: 600;
}

.stat-pill b {
  color: var(--txt);
  font-weight: 800;
}

.lives-stat {
  display: flex;
  align-items: center;
  gap: 3px;
}

.lives-stat .heart {
  line-height: 1;
  transition: transform 0.15s ease;
  color: #ff3c50;
}

.lives-stat .heart.empty {
  color: var(--txt-muted);
  opacity: 0.4;
}

.lives-stat .heart.full {
  filter: drop-shadow(0 0 4px rgba(255,60,80,0.7));
}

/* ── Controls grid: 3 utility top / 2 power-up bottom ── */
.game-controls {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: auto auto;
  gap: 6px;
}

/* Row 1 — utility buttons */
#btn-undo    { grid-column: span 2; }
#btn-restart { grid-column: span 2; }
#btn-hint    { grid-column: span 2; }

/* Row 2 — power-up buttons (taller, more prominent) */
#btn-bomb    { grid-column: span 3; }
#btn-rotate  { grid-column: span 3; }

.btn-control {
  padding: 9px 6px;
  font-size: 0.76rem;
  font-weight: 700;
  border-radius: 12px;
  background: var(--bg-card-2);
  border: 1.5px solid var(--border);
  color: var(--txt-muted);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  min-height: 38px;
}

/* Power-up buttons: taller & bolder */
#btn-bomb,
#btn-rotate {
  min-height: 44px;
  font-size: 0.82rem;
  font-weight: 800;
  border-width: 1.5px;
}

.btn-control:not(:disabled):hover {
  border-color: var(--clr-primary);
  color: var(--txt);
  background: rgba(108,92,231,0.1);
}
.btn-control:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-bomb {
  border-color: #FF475730;
  color: #FF4757;
}
.btn-bomb:hover {
  background: rgba(255,71,87,0.12) !important;
  border-color: #FF4757 !important;
  color: #FF4757 !important;
}
.btn-bomb.armed {
  background: rgba(255,71,87,0.2);
  border-color: #FF4757;
  animation: bomb-pulse 0.8s ease infinite;
}
@keyframes bomb-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,71,87,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(255,71,87,0); }
}
.btn-rotate {
  border-color: rgba(0,229,180,0.3);
  color: #00e5b4;
}
.btn-rotate:hover {
  background: rgba(0,229,180,0.12) !important;
  border-color: #00e5b4 !important;
  color: #00e5b4 !important;
}
.btn-rotate.armed {
  background: rgba(0,229,180,0.2);
  border-color: #00e5b4;
  animation: rotate-pulse 0.8s ease infinite;
}
@keyframes rotate-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(0,229,180,0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(0,229,180,0); }
}
.rotate-badge {
  background: rgba(0,229,180,0.2);
  color: #00e5b4;
}
.cost-badge {
  background: rgba(255,193,7,0.2);
  color: #FFC107;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 6px;
}
.count-badge {
  background: rgba(255,71,87,0.2);
  color: #FF4757;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 6px;
  min-width: 16px;
  text-align: center;
}

/* ── 12. Challenge Screen ───────────────────────────────────── */

#screen-challenge {
  overflow: hidden;
}

.challenge-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.challenge-card {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: all var(--tr-fast);
}

.challenge-card:hover {
  border-color: var(--clr-primary);
  box-shadow: 0 4px 18px var(--clr-primary-glow);
  transform: translateY(-2px);
}

.challenge-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.challenge-info {
  flex: 1;
  min-width: 0;
}

.challenge-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--txt);
}

.challenge-desc {
  font-size: 0.82rem;
  color: var(--txt-muted);
  margin-top: 2px;
}

.challenge-reward {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--clr-accent);
  flex-shrink: 0;
}

.challenge-progress {
  height: 4px;
  background: var(--bg-card-2);
  border-radius: var(--radius-pill);
  margin-top: 8px;
  overflow: hidden;
}

.challenge-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--clr-primary), var(--clr-accent));
  border-radius: var(--radius-pill);
  transition: width 0.5s ease;
}

/* ── 13. Modal System ───────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--tr-med);
  padding: 16px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 28px 24px;
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-card), 0 0 40px var(--clr-primary-glow);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modal-in var(--tr-slow) ease both;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background: var(--bg-card-2);
  border: 1.5px solid var(--border);
  font-size: 0.85rem;
  color: var(--txt-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--tr-fast);
}

.modal-close:hover {
  background: var(--clr-danger);
  border-color: var(--clr-danger);
  color: #fff;
}

.modal-card h2 {
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  color: var(--txt);
}

.modal-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.modal-buttons .btn {
  flex: 1;
  min-width: 100px;
}

/* ── 14. Pre-game Modal ─────────────────────────────────────── */

.pregame-card .pregame-difficulty {
  display: flex;
  justify-content: center;
}

.pregame-stats {
  display: flex;
  gap: 16px;
}

.pregame-stat {
  flex: 1;
  text-align: center;
  background: var(--bg-card-2);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  border: 1px solid var(--border);
}

.pregame-stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--clr-accent);
}

.pregame-stat-label {
  font-size: 0.75rem;
  color: var(--txt-muted);
  margin-top: 4px;
}

.pregame-tip {
  font-size: 0.88rem;
  color: var(--txt-muted);
  text-align: center;
  font-style: italic;
  padding: 10px 14px;
  background: var(--bg-card-2);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--clr-primary);
}

/* ── 15. Win Modal ──────────────────────────────────────────── */

.win-card {
  text-align: center;
}

.win-emoji,
.lose-emoji {
  font-size: 3.5rem;
  animation: bounce-in 0.6s ease;
}

.stars-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: 2rem;
}

.star {
  display: inline-block;
  animation: star-pop 0.4s ease both;
  color: #FFC107;
}

.star.star-empty,
.star.empty {
  color: var(--txt-muted);
  opacity: 0.35;
  filter: none;
}

.lc-stars .star-filled { color: #FFC107; }
.lc-stars .star-empty  { color: var(--txt-muted); opacity: 0.35; }

.star:nth-child(1) { animation-delay: 0.1s; }
.star:nth-child(2) { animation-delay: 0.25s; }
.star:nth-child(3) { animation-delay: 0.4s; }

.win-stats {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.win-stat {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.win-stat-label {
  font-size: 0.75rem;
  color: var(--txt-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.win-stat-val {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--txt);
}

.win-stat-coins .win-stat-val {
  color: var(--clr-accent);
}

/* ── 16. Lose Modal ─────────────────────────────────────────── */

.lose-card {
  text-align: center;
}

.lose-card p {
  color: var(--txt-muted);
  font-size: 0.95rem;
}

/* ── 17. Profile Modal ──────────────────────────────────────── */

.profile-card {
  align-items: center;
}

.profile-avatar {
  font-size: 4rem;
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card-2);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-pill);
}

.profile-card h2 {
  color: var(--txt);
}

.profile-stats {
  display: flex;
  gap: 12px;
  width: 100%;
}

.profile-stat {
  flex: 1;
  text-align: center;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 10px;
}

.profile-stat-val {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--clr-primary);
}

.profile-stat-lbl {
  font-size: 0.72rem;
  color: var(--txt-muted);
  margin-top: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.profile-actions {
  width: 100%;
}

.profile-guest-section {
  width: 100%;
  background: var(--bg-card-2);
  border: 1px solid var(--clr-primary);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-guest-hint {
  font-size: 0.82rem;
  color: var(--clr-primary);
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
}

.profile-upgrade-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── 18. Sign-in Reward Modal ───────────────────────────────── */

.signin-reward-card {
  align-items: center;
  text-align: center;
}

.signin-icon {
  font-size: 4rem;
  animation: bounce-in 0.6s ease;
}

.signin-coins {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 2.4rem;
  font-weight: 900;
  color: var(--clr-accent);
  background: var(--bg-card-2);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 12px 28px;
  animation: coin-shine 2s ease infinite;
}

/* ── 19. Confirm Modal ──────────────────────────────────────── */

.confirm-card p {
  font-size: 1rem;
  color: var(--txt);
  text-align: center;
  padding: 4px 0;
}

/* ── 20. Badge Modal ────────────────────────────────────────── */

.badges-card {
  max-height: 80vh;
}

.badge-progress-msg {
  font-size: 0.88rem;
  color: var(--txt-muted);
  text-align: center;
}

.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 12px;
  padding: 4px 0;
}

.badge-card {
  background: var(--bg-card-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  transition: all var(--tr-fast);
}

.badge-card.earned {
  border-color: var(--clr-accent);
  background: rgba(247, 201, 72, 0.08);
  animation: badge-glow 2s ease-in-out infinite;
}

.badge-card.locked {
  opacity: 0.4;
}

.badge-icon {
  font-size: 1.8rem;
}

.badge-name {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--txt);
  line-height: 1.2;
}

.badge-desc {
  font-size: 0.65rem;
  color: var(--txt-muted);
  line-height: 1.3;
}

/* Badge unlock overlay */
.badge-unlock-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-in 0.4s ease;
}

.badge-unlock-card {
  background: var(--bg-card);
  border: 2px solid var(--clr-accent);
  border-radius: var(--radius-xl);
  padding: 36px 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 0 40px rgba(247, 201, 72, 0.5);
  animation: badge-glow 1.5s ease-in-out infinite;
}

.badge-unlock-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--clr-accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.badge-unlock-icon {
  font-size: 4rem;
}

.badge-unlock-name {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--txt);
}

/* ── 21. Toast ──────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 10px 22px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--txt);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  text-overflow: ellipsis;
  overflow: hidden;
  transition: none;
  box-shadow: var(--shadow-card);
}

.toast.show {
  animation: toast-in 0.3s ease forwards;
}

.toast.success { border-color: var(--clr-success); color: var(--clr-success); }
.toast.error   { border-color: var(--clr-danger);  color: var(--clr-danger);  }
.toast.warning { border-color: var(--clr-warning); color: var(--clr-warning); }
.toast.info    { border-color: var(--clr-primary); color: var(--clr-primary); }
.toast.coin    { border-color: var(--clr-accent);  color: var(--clr-accent);  }

/* ── 22. Screen-shake wrapper ───────────────────────────────── */

.screen-shake {
  animation: screen-shake-anim 0.4s ease;
}

/* ── 24. Responsive ─────────────────────────────────────────── */

/* ── Small phones (≤ 400px) ─────────────────────────────────── */
@media (max-width: 400px) {
  /* Game controls: 3 on top row, 2 on bottom row via 6-cell grid */
  .game-controls {
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
  }
  #btn-undo    { grid-column: span 2; }
  #btn-restart { grid-column: span 2; }
  #btn-hint    { grid-column: span 2; }
  #btn-bomb    { grid-column: span 3; }
  #btn-rotate  { grid-column: span 3; }
  .btn-control { padding: 9px 6px; font-size: 0.75rem; }

  /* Modals */
  .modal-card { padding: 20px 16px; }
  .win-stats  { flex-wrap: wrap; }
  .pregame-stats { gap: 10px; }
  .profile-stats { gap: 8px; }

  /* Auth */
  .auth-card { padding: 24px 16px; }

  /* Level select */
  .level-grid { gap: 8px; padding: 0 12px 20px; }
  .level-card { padding: 12px 10px 10px; }
  .lc-name    { font-size: 0.85rem; }

  /* Menu row buttons */
  .menu-row { gap: 7px; }
  .btn-icon-md { width: 44px; height: 44px; font-size: 1.15rem; }
}

/* ── Tiny phones (≤ 360px) ───────────────────────────────────── */
@media (max-width: 360px) {
  .game-controls { gap: 4px; }
  .btn-control   { padding: 8px 4px; font-size: 0.7rem; }
  .cost-badge, .count-badge { font-size: 0.55rem; padding: 1px 3px; }

  .game-level-name { max-width: 80px; }

  .shop-card-preview { height: 80px; }
  .shop-card-name    { font-size: 0.78rem; padding: 8px 10px 2px; }

  .ls-header   { padding: 12px 14px 10px; }
  .ls-title    { font-size: 1.1rem; }

  .btn-large   { padding: 13px 20px; font-size: 1rem; }
}

/* ── Short portrait phones (height ≤ 680px) ─────────────────── */
@media (max-height: 680px) and (orientation: portrait) {
  .menu-content     { gap: 12px; padding: 14px 16px 16px; }
  .game-title       { font-size: clamp(2rem, 8vw, 3.2rem); letter-spacing: -1px; }
  .game-subtitle    { font-size: 0.85rem; margin-top: 3px; }
  .menu-title-block { padding: 8px 0; }
  .menu-buttons     { gap: 10px; padding-bottom: 4px; }
  .btn-large        { padding: 13px 20px; font-size: 1rem; }
  .menu-row         { gap: 8px; }
}

/* ── Very short portrait phones (height ≤ 580px) ────────────── */
@media (max-height: 580px) and (orientation: portrait) {
  .game-subtitle    { display: none; }
  .menu-title-block { padding: 4px 0; }
  .game-title       { font-size: clamp(1.8rem, 7vw, 2.8rem); }
  .btn-large        { padding: 11px 18px; }
  .menu-buttons     { gap: 7px; }
  .menu-content     { gap: 8px; }
}

/* ── Landscape phones (height ≤ 500px) ──────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  /* Game screen: hide secondary stats so grid gets more space */
  .game-footer-top { display: none; }
  .game-footer     { padding: 6px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); gap: 5px; }
  .game-controls   { gap: 4px; }
  .btn-control     { padding: 7px 6px; font-size: 0.72rem; }
  #grid-container  { padding: 6px; }
  .game-header     { padding: 7px 12px; }

  /* Menu in landscape: hide large title, use compact layout */
  .menu-title-block { display: none; }
  .menu-content     { gap: 8px; padding: 10px 16px; justify-content: center; }
  .menu-buttons     { gap: 6px; }
  .btn-large        { padding: 11px 18px; font-size: 0.95rem; }
  .menu-row         { gap: 7px; }

  /* Level select in landscape */
  .level-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── Tablets and large phones (≥ 600px) ─────────────────────── */
@media (min-width: 600px) {
  #screen-auth {
    background:
      radial-gradient(ellipse at 20% 30%, rgba(108, 99, 255, 0.15) 0%, transparent 60%);
  }
  .menu-content {
    max-width: 480px;
    margin: 0 auto;
  }
  .level-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── True tablets (≥ 768px) ─────────────────────────────────── */
@media (min-width: 768px) {
  .menu-content { max-width: 520px; }

  /* Center game header/footer content on wide screens */
  .game-header,
  .game-footer {
    max-width: 600px;
    margin-inline: auto;
    width: 100%;
    /* Re-apply padding since margin: auto is on the element itself */
  }

  .game-header { border-radius: 0 0 var(--radius-md) var(--radius-md); }

  /* Level select: 3 columns on tablet */
  .level-grid { grid-template-columns: repeat(3, 1fr); max-width: 600px; margin-inline: auto; }

  /* Modal wider on tablet */
  .modal-card { width: min(460px, 90vw); }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--clr-primary);
}

/* ── 25. Utility ────────────────────────────────────────────── */

.hidden { display: none !important; }

.text-center { text-align: center; }
.text-muted  { color: var(--txt-muted); }
.text-accent { color: var(--clr-accent); }

.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* Click-outside backdrop inside modal overlays */
.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: -1;
  cursor: default;
}

/* Small button variant used in overlays / popups */
.btn-sm {
  padding: 8px 18px;
  font-size: 0.82rem;
  border-radius: var(--radius-md);
}
