/* Arrows – Puzzle Escape · stylesheet
   Minimalist UI. Light + dark via CSS custom properties.
   Everything outside the canvas: shell, drawer, modals, controls. */

 :root {
  color-scheme: dark;
  --bg:          #071426;
  --bg-soft:     #10233b;
  --panel:       #122944;
  --ink:         #eaf6ff;
  --ink-soft:    #a9c4dc;
  --ink-faint:   #7694b0;
  --line:        #203d5d;
  --line-strong: #315779;
  --accent:      #13a8ff;
  --danger:      #ff657a;
  --heart:       #ff7189;
  --hint:        #ffd166;
  --good:        #28ddb9;
  --shadow:      0 18px 48px rgba(0,0,0,.38), 0 4px 14px rgba(0,0,0,.24);
  --radius:      18px;
  --radius-sm:   10px;
  --t-fast:      120ms;
  --t-med:       240ms;
  --t-slow:      420ms;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root.dark {
  color-scheme: dark;
  --bg:          #050f1e;
  --bg-soft:     #0d1e33;
  --panel:       #10243c;
  --ink:         #f0f8ff;
  --ink-soft:    #b2c9df;
  --ink-faint:   #7896b4;
  --line:        #1d3855;
  --line-strong: #315779;
  --accent:      #25b5ff;
  --danger:      #ff7183;
  --heart:       #ff7183;
  --hint:        #ffd166;
  --good:        #35e4c2;
  --shadow:      0 18px 48px rgba(0,0,0,.48), 0 4px 14px rgba(0,0,0,.30);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 32%, #153456 0%, #0a1b30 48%, #050f1e 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
input {
  font: inherit;
  color: inherit;
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto 50px;
  height: 100dvh;
  width: 100vw;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Top bar ---------- */
.topbar {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  padding: 10px 14px 6px;
  gap: 8px;
}
.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: var(--ink);
  transition: background var(--t-fast);
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn:active { background: var(--line); }

.level-title {
  text-align: center;
  user-select: none;
}
#level-label {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: .01em;
}
.tier {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.tier.easy      { color: #2a8a4f; }
.tier.medium    { color: #3a6fd6; }
.tier.hard      { color: #b8761f; }
.tier.veryhard  { color: #b83a3a; }
.tier.nightmare { color: #7b3aa6; }
.tier.daily     { color: var(--ink); background: var(--ink); color: var(--bg); border-color: var(--ink); }

.hearts {
  display: inline-flex;
  gap: 4px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  min-width: 88px;
  justify-content: center;
}
.heart {
  width: 18px;
  height: 18px;
  display: inline-block;
  color: var(--heart);
  transition: transform var(--t-fast), opacity var(--t-fast);
}
.heart.lost { color: var(--line-strong); opacity: .55; }
.heart.shake { animation: heartShake 360ms ease both; }
@keyframes heartShake {
  0%   { transform: translateX(0) rotate(0); }
  20%  { transform: translateX(-3px) rotate(-8deg); }
  40%  { transform: translateX(3px) rotate(8deg); }
  60%  { transform: translateX(-2px) rotate(-5deg); }
  80%  { transform: translateX(2px) rotate(5deg); }
  100% { transform: translateX(0) rotate(0); }
}

/* ---------- Progress bar ---------- */
.progress {
  height: 5px;
  background: rgba(115,160,198,.20);
  margin: 0 14px;
  border: 1px solid rgba(135,185,222,.12);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #13a8ff, #00d6bd);
  box-shadow: 0 0 12px rgba(19,168,255,.5);
  transition: width var(--t-med) ease;
}

/* ---------- Board ---------- */
.board-wrapper {
  position: relative;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: pan-y pinch-zoom;
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast {
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  transition: opacity var(--t-med), transform var(--t-med);
  max-width: 80%;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.hidden { display: none; }

.level-complete {
  pointer-events: auto;
  background: linear-gradient(155deg, rgba(24,55,86,.98), rgba(10,29,51,.99));
  border: 1px solid rgba(112,183,232,.28);
  border-radius: var(--radius);
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 22px 60px rgba(0,0,0,.48), inset 0 1px 0 rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: pop var(--t-slow) cubic-bezier(.2,.9,.3,1.2);
}
.level-complete.hidden { display: none; }
.lc-check { color: var(--good); filter: drop-shadow(0 0 14px rgba(40,221,185,.32)); }
.lc-title { font-size: 24px; font-weight: 750; color: #f2f9ff; letter-spacing: .01em; }
.lc-sub   { color: #b9d2e8; font-size: 14px; }
.lc-next  { margin-top: 12px; min-width: 140px; }

@keyframes pop {
  0%   { transform: scale(.6); opacity: 0; }
  60%  { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Action bar ---------- */
.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 14px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.action {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  border-radius: 12px;
  color: var(--ink-soft);
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.action span {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .02em;
}
.action:hover  { color: var(--ink); background: var(--bg-soft); }
.action:active { transform: scale(.96); }
.action.action-hint { color: var(--hint); }
.action[disabled] { opacity: .35; cursor: not-allowed; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  visibility: hidden;
}
.drawer.open { pointer-events: auto; visibility: visible; }

.drawer-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.35);
  opacity: 0;
  transition: opacity var(--t-med);
}
.drawer.open .drawer-scrim { opacity: 1; }

.drawer-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(360px, 86vw);
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 24px 22px;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform var(--t-med) cubic-bezier(.2,.8,.3,1);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.drawer.open .drawer-panel { transform: translateX(0); }

.drawer-close {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 24px;
  line-height: 1;
}
#drawer-title { margin: 12px 0 0; font-size: 28px; letter-spacing: -.01em; }
.drawer-sub  { margin: -4px 0 0; color: var(--ink-soft); font-size: 13px; letter-spacing: .04em; }

.drawer-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 4px;
}
.drawer-stats > div {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drawer-stats strong { font-size: 18px; font-weight: 600; }
.drawer-stats span   { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .08em; }

.drawer-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.drawer-btn {
  text-align: left;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 500;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.drawer-btn:hover { background: var(--line); }

.drawer-section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-faint);
  margin: 8px 0 8px;
}
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  font-size: 14px;
  cursor: pointer;
}
.toggle input { accent-color: var(--ink); width: 18px; height: 18px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  visibility: hidden;
  pointer-events: none;
}
.modal.open { visibility: visible; pointer-events: auto; }

.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
  opacity: 0;
  transition: opacity var(--t-med);
}
.modal.open .modal-scrim { opacity: 1; }

.modal-content {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + 12px));
  width: min(420px, 92vw);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 22px 22px 18px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity var(--t-med), transform var(--t-med) cubic-bezier(.2,.8,.3,1);
}
.modal.open .modal-content {
  transform: translate(-50%, -50%);
  opacity: 1;
}
.modal-wide { width: min(680px, 96vw); }
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 22px;
  line-height: 1;
}
.modal h2 { margin: 4px 0 14px; font-size: 22px; font-weight: 600; }
.modal-body { color: var(--ink-soft); line-height: 1.55; font-size: 15px; }
.modal-body ul { padding-left: 20px; margin: 10px 0; }
.modal-body li { margin: 4px 0; }
.note { font-size: 13px; color: var(--ink-faint); }
.heart-inline { color: var(--heart); font-weight: 700; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
  gap: 8px;
}

.btn-primary {
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  transition: filter var(--t-fast), transform var(--t-fast);
}
.btn-primary:hover  { filter: brightness(1.1); }
.btn-primary:active { transform: scale(.97); }

.btn-secondary {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 500;
  transition: background var(--t-fast);
}
.btn-secondary:hover { background: var(--line); }

/* ---------- Levels modal ---------- */
.levels-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.levels-controls input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.difficulty-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
  overflow-x: auto;
}
.tab {
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover  { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }

.levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 6px;
  max-height: 50dvh;
  overflow-y: auto;
  padding: 4px;
}
.lvl-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.lvl-cell:hover { background: var(--line); color: var(--ink); }
.lvl-cell.solved {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.lvl-cell.current {
  outline: 2px solid var(--hint);
  outline-offset: 2px;
}
.lvl-cell.solved::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--good);
}

.levels-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------- Achievements ---------- */
.ach-counter {
  font-size: 13px;
  color: var(--ink-faint);
  font-weight: 500;
}
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  max-height: 60dvh;
  overflow-y: auto;
  padding: 2px;
}
.ach {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.ach.locked   { opacity: .5; }
.ach.unlocked { border-color: var(--good); }
.ach-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.ach.unlocked .ach-icon { background: var(--good); color: white; border-color: var(--good); }
.ach-title { font-weight: 600; font-size: 14px; }
.ach-desc  { font-size: 12px; color: var(--ink-faint); margin-top: 2px; }

/* ---------- Misc ---------- */
.hidden { display: none !important; }

@media (max-width: 380px) {
  .actions { padding: 6px 8px 10px; }
  .action span { font-size: 10px; }
  #level-label { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .level-complete { animation: none; }
  .heart.shake { animation: none; }
  .drawer-panel, .modal-content, .drawer-scrim, .modal-scrim, .toast,
  .icon-btn, .action, .drawer-btn, .lvl-cell {
    transition: none !important;
  }
}


/* ---------- GetPlayEarn visual refresh (presentation only) ----------
   Gameplay, level generation, persistence and input logic are untouched. */
body {
  background:
    radial-gradient(ellipse at 50% 8%, rgba(115, 190, 193, .13), transparent 42%),
    linear-gradient(180deg, var(--bg) 0%, #eef5f7 100%);
}
:root.dark body {
  background:
    radial-gradient(ellipse at 50% 8%, rgba(72, 151, 155, .13), transparent 42%),
    linear-gradient(180deg, #14232b 0%, #101c22 100%);
}
.app { max-width: 1120px; margin: 0 auto; }
.topbar {
  padding: 12px 18px 9px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 76%, transparent);
}
.icon-btn {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--line-strong) 72%, transparent), 0 4px 10px rgba(34, 71, 86, .07);
}
.icon-btn:hover { background: var(--bg-soft); transform: translateY(-1px); }
#level-label { color: var(--ink); font-weight: 750; letter-spacing: .015em; }
.tier {
  padding: 4px 11px;
  border-color: color-mix(in srgb, var(--accent) 22%, var(--line));
  background: color-mix(in srgb, var(--accent) 9%, var(--bg));
  letter-spacing: .09em;
}
.hearts {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7), 0 3px 9px rgba(34,71,86,.06);
}
.progress {
  height: 5px;
  margin: 0 18px;
  background: color-mix(in srgb, var(--line) 80%, var(--bg));
  border-radius: 999px;
}
.progress-fill {
  border-radius: inherit;
  background: linear-gradient(90deg, #58b6b1, #3b8d9a 72%, #6b9fbd);
  box-shadow: 0 0 10px rgba(71, 165, 169, .22);
}
.board-wrapper {
  margin: 10px 14px 8px;
  border: 1px solid color-mix(in srgb, var(--line) 84%, transparent);
  border-radius: 22px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--bg) 96%, white), color-mix(in srgb, var(--bg-soft) 76%, var(--bg)));
  background-size: auto;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.68), 0 8px 24px rgba(42, 79, 94, .055);
}
#game-canvas { border-radius: inherit; }
.actions {
  margin: 0 14px 10px;
  padding: 9px 10px calc(10px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  box-shadow: 0 7px 22px rgba(39,75,91,.09), inset 0 1px 0 rgba(255,255,255,.8);
}
.action {
  min-height: 58px;
  border: 1px solid transparent;
  border-radius: 13px;
  color: var(--ink-soft);
}
.action svg { filter: drop-shadow(0 1px 0 rgba(255,255,255,.45)); }
.action:hover {
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  border-color: var(--line);
  box-shadow: 0 2px 0 var(--line-strong), 0 4px 10px rgba(39,75,91,.07);
}
.action.action-hint { color: #bd8533; }
:root.dark .action.action-hint { color: #f0c477; }
.level-complete {
  position: relative;
  overflow: visible;
  min-width: min(300px, 82vw);
  padding: 30px 34px 26px;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line));
  border-radius: 24px;
  background: linear-gradient(155deg, var(--bg) 0%, color-mix(in srgb, var(--bg-soft) 72%, var(--bg)) 100%);
  box-shadow: 0 20px 54px rgba(35, 78, 93, .18), inset 0 1px 0 rgba(255,255,255,.85);
}
.level-complete::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -44px -38px;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 12% 22%, #f2c66a 0 3px, transparent 4px),
    radial-gradient(ellipse at 82% 18%, #6fc5bf 0 3px, transparent 4px),
    radial-gradient(ellipse at 92% 58%, #8bb9dc 0 3px, transparent 4px),
    radial-gradient(ellipse at 8% 72%, #e88d9b 0 3px, transparent 4px),
    radial-gradient(ellipse at 30% 92%, #82c6a8 0 3px, transparent 4px),
    radial-gradient(ellipse at 72% 88%, #e9b76b 0 3px, transparent 4px);
  animation: celebration-sparkle 1.8s ease-in-out infinite alternate;
}
@keyframes celebration-sparkle {
  from { transform: translateY(0) scale(.96); opacity: .55; }
  to { transform: translateY(-7px) scale(1.04); opacity: 1; }
}
.lc-check {
  width: 76px; height: 76px;
  display: grid; place-items: center;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(145deg, #65c9b2, #319b91);
  box-shadow: 0 5px 0 #277f79, 0 10px 22px rgba(49,155,145,.22), inset 0 1px 0 rgba(255,255,255,.55);
}
.lc-title { margin-top: 5px; font-size: 25px; font-weight: 800; letter-spacing: -.02em; }
.lc-sub { color: var(--ink-soft); }
.btn-primary {
  border: 1px solid color-mix(in srgb, var(--accent) 65%, #246d76);
  border-radius: 13px;
  background: linear-gradient(180deg, #438f9a 0%, #2f707f 100%);
  box-shadow: 0 3px 0 #245967, 0 7px 14px rgba(39,111,124,.20), inset 0 1px 0 rgba(255,255,255,.28);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #245967, 0 3px 8px rgba(39,111,124,.16); }
.btn-secondary, .drawer-btn, .tab, .lvl-cell {
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.btn-secondary {
  border-color: var(--line);
  border-radius: 11px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  box-shadow: 0 2px 0 var(--line-strong);
}
.drawer-panel, .modal-content {
  background: linear-gradient(155deg, var(--bg) 0%, var(--bg-soft) 100%);
  border-color: var(--line);
  box-shadow: 0 20px 60px rgba(20,50,63,.22);
}
.drawer-btn {
  border-radius: 12px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-soft) 100%);
  box-shadow: 0 2px 0 var(--line-strong);
}
.drawer-btn:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.lvl-cell { border-radius: 12px; }
.lvl-cell.current { outline-color: var(--accent); }
.ach.unlocked { border-color: var(--good); background: color-mix(in srgb, var(--good) 8%, var(--bg)); }

@media (max-width: 600px) {
  .topbar { padding: 8px 10px 7px; grid-template-columns: 42px 1fr auto; gap: 5px; }
  .board-wrapper { margin: 8px 8px 6px; border-radius: 16px; }
  .actions { margin: 0 8px 7px; padding: 6px 5px calc(7px + env(safe-area-inset-bottom)); border-radius: 15px; gap: 3px; }
  .action { min-height: 54px; padding: 8px 3px; }
}
@media (prefers-reduced-motion: reduce) {
  .level-complete::before { animation: none; }
}


/* ---------- GetPlayEarn premium visual pass v2 (visual-only) ---------- */
:root {
  --bg: #f2f6ff;
  --bg-soft: #e8efff;
  --ink: #263f70;
  --ink-soft: #61749a;
  --ink-faint: #8b9bbb;
  --line: #d5e0f5;
  --line-strong: #b8c9e9;
  --accent: #527fe5;
  --good: #22ad91;
  --hint: #e5a63c;
}
:root.dark {
  --bg: #101a32;
  --bg-soft: #192747;
  --ink: #e9f0ff;
  --ink-soft: #b8c8e8;
  --ink-faint: #8195bc;
  --line: #293b61;
  --line-strong: #3b5280;
  --accent: #7ea5ff;
  --good: #52d7b7;
  --hint: #ffd078;
}
body {
  background:
    radial-gradient(ellipse at 14% 12%, rgba(112,154,255,.20), transparent 34%),
    radial-gradient(ellipse at 88% 78%, rgba(116,210,207,.17), transparent 36%),
    linear-gradient(145deg, #f7f9ff 0%, #eaf1ff 52%, #f1f8ff 100%);
}
:root.dark body {
  background:
    radial-gradient(ellipse at 14% 12%, rgba(74,111,205,.22), transparent 36%),
    radial-gradient(ellipse at 88% 78%, rgba(49,156,166,.13), transparent 38%),
    linear-gradient(145deg, #101a32 0%, #14213d 55%, #102a38 100%);
}
.topbar {
  background: linear-gradient(180deg, rgba(255,255,255,.82), rgba(242,247,255,.68));
  backdrop-filter: blur(14px);
}
:root.dark .topbar {
  background: linear-gradient(180deg, rgba(18,31,57,.88), rgba(18,31,57,.68));
}
#level-label {
  font-size: 19px;
  font-weight: 850;
  letter-spacing: -.025em;
  text-shadow: 0 1px 0 rgba(255,255,255,.75);
}
:root.dark #level-label { text-shadow: 0 1px 0 rgba(0,0,0,.25); }
.tier {
  padding: 5px 13px;
  border: 1px solid rgba(91,132,220,.24);
  background: linear-gradient(180deg, #fafdff, #e4edff);
  box-shadow: 0 2px 0 rgba(81,117,190,.12), inset 0 1px 0 #fff;
}
:root.dark .tier {
  background: linear-gradient(180deg, #263d68, #1b2d50);
  border-color: #3b568a;
}
.hearts {
  border-color: rgba(126,151,205,.28);
  background: linear-gradient(180deg, rgba(255,255,255,.94), rgba(230,239,255,.92));
  box-shadow: 0 5px 14px rgba(54,83,143,.10), inset 0 1px 0 #fff;
}
:root.dark .hearts {
  background: linear-gradient(180deg, #21375f, #182a49);
  box-shadow: 0 5px 14px rgba(0,0,0,.18), inset 0 1px 0 rgba(255,255,255,.08);
}
.progress {
  height: 6px;
  background: rgba(105,137,199,.18);
  box-shadow: inset 0 1px 2px rgba(38,63,112,.10);
}
.progress-fill {
  background: linear-gradient(90deg, #43c5c7 0%, #5689f4 54%, #9568e9 100%);
  box-shadow: 0 0 13px rgba(84,137,244,.45);
}
.board-wrapper {
  border: 1px solid rgba(116,147,210,.30);
  background: radial-gradient(ellipse at 50% 0%, rgba(255,255,255,.96), rgba(239,245,255,.94) 60%, rgba(231,241,255,.96));
  background-size: auto;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.95),
    inset 0 -18px 42px rgba(105,143,218,.07),
    0 14px 34px rgba(48,78,140,.11);
}
:root.dark .board-wrapper {
  background: radial-gradient(ellipse at 50% 0%, #1d3157, #172847 65%, #14243f);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07), 0 14px 34px rgba(0,0,0,.22);
}
.icon-btn {
  border-radius: 13px;
  border-color: rgba(103,139,210,.28);
  background: linear-gradient(180deg, #fff, #eaf1ff);
  box-shadow: 0 3px 0 rgba(95,125,190,.18), 0 6px 14px rgba(55,83,145,.10);
}
:root.dark .icon-btn {
  background: linear-gradient(180deg, #2b416b, #1c2e50);
  border-color: #3b5686;
  box-shadow: 0 3px 0 rgba(0,0,0,.18), 0 6px 14px rgba(0,0,0,.15);
}
.actions {
  border: 1px solid rgba(111,145,210,.28);
  background: linear-gradient(180deg, rgba(255,255,255,.94), rgba(235,242,255,.96));
  box-shadow: 0 10px 26px rgba(49,78,139,.12), inset 0 1px 0 #fff;
}
:root.dark .actions {
  background: linear-gradient(180deg, rgba(31,50,84,.98), rgba(21,37,65,.98));
  border-color: #314a76;
  box-shadow: 0 10px 26px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.06);
}
.action { color: #536f9e; }
:root.dark .action { color: #b7c9ed; }
.action svg { filter: drop-shadow(0 2px 2px rgba(65,94,158,.16)); }
.action.action-hint { color: #c18423; }
:root.dark .action.action-hint { color: #ffd078; }
.level-complete {
  min-width: min(320px, 84vw);
  padding: 32px 34px 28px;
  border: 1px solid rgba(101,145,232,.36);
  border-radius: 28px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(115,166,255,.14), transparent 58%),
    linear-gradient(155deg, #ffffff, #edf3ff 90%);
  box-shadow: 0 24px 70px rgba(35,65,130,.24), inset 0 1px 0 #fff;
}
:root.dark .level-complete {
  background: radial-gradient(ellipse at 50% 0%, rgba(100,147,255,.18), transparent 60%), linear-gradient(155deg, #263d68, #192b4b);
  border-color: #4969a4;
  box-shadow: 0 24px 70px rgba(0,0,0,.38), inset 0 1px 0 rgba(255,255,255,.08);
}
.lc-check {
  width: 84px; height: 84px;
  border-radius: 26px;
  background: linear-gradient(145deg, #52d8c0, #268fba 72%, #3973d8);
  box-shadow: 0 6px 0 #267e9f, 0 13px 24px rgba(48,145,190,.28), inset 0 2px 0 rgba(255,255,255,.55);
}
.lc-title { font-size: 27px; font-weight: 900; color: #294d91; }
:root.dark .lc-title { color: #f1f5ff; }
.lc-sub { font-size: 15px; }
.lc-next { min-width: 176px; padding: 13px 22px; font-size: 15px; }
.btn-primary {
  border: 1px solid #477fe2;
  border-radius: 15px;
  background: linear-gradient(180deg, #69a0ff, #3975df 65%, #3266c4);
  box-shadow: 0 4px 0 #2855a7, 0 9px 18px rgba(49,103,204,.25), inset 0 1px 0 rgba(255,255,255,.42);
}
.btn-secondary {
  border-color: rgba(105,139,208,.30);
  background: linear-gradient(180deg, #fff, #eaf1ff);
  box-shadow: 0 3px 0 rgba(95,125,190,.18);
}
:root.dark .btn-secondary {
  background: linear-gradient(180deg, #2b416b, #1c2e50);
  border-color: #3b5686;
  color: #eaf1ff;
}
.drawer-panel, .modal-content {
  border-radius: 22px;
  background: linear-gradient(155deg, #fff, #edf3ff);
}
:root.dark .drawer-panel, :root.dark .modal-content {
  background: linear-gradient(155deg, #243a63, #172947);
}
.drawer-btn {
  background: linear-gradient(180deg, #fff, #edf3ff);
  border-color: rgba(105,139,208,.25);
}
:root.dark .drawer-btn {
  background: linear-gradient(180deg, #2a416c, #1b2d4f);
  border-color: #3b5686;
}
@media (max-width: 600px) {
  .board-wrapper { border-radius: 20px; }
  .level-complete { padding: 26px 24px 24px; }
}


/* ---------- GetPlayEarn fail / retry screen v4 ---------- */
.fail-content {
  width: min(430px, 92vw);
  padding: 28px 24px 22px;
  overflow: hidden;
  text-align: center;
  border: 1px solid rgba(82, 151, 226, .34);
  border-radius: 26px;
  background:
    radial-gradient(ellipse at 50% -8%, rgba(66, 139, 232, .18), transparent 54%),
    linear-gradient(155deg, #f8fbff 0%, #eaf2ff 100%);
  box-shadow: 0 26px 76px rgba(8, 27, 58, .30), inset 0 1px 0 rgba(255,255,255,.92);
}
:root.dark .fail-content {
  background:
    radial-gradient(ellipse at 50% -8%, rgba(64, 133, 235, .22), transparent 56%),
    linear-gradient(155deg, #20385f 0%, #142541 100%);
  border-color: rgba(106, 160, 244, .38);
  box-shadow: 0 26px 76px rgba(0,0,0,.46), inset 0 1px 0 rgba(255,255,255,.08);
}
.fail-emblem {
  width: 76px; height: 76px; margin: 2px auto 10px;
  display: grid; place-items: center; border-radius: 24px;
  color: #fff;
  background: linear-gradient(145deg, #ff8295, #e84e72 72%, #c83c69);
  box-shadow: 0 6px 0 #b9365d, 0 13px 25px rgba(225, 72, 111, .25), inset 0 1px 0 rgba(255,255,255,.42);
}
.fail-emblem svg { width: 48px; height: 48px; overflow: visible; }
.fail-emblem svg path:first-child { fill: rgba(255,255,255,.16); stroke: #fff; stroke-width: 2.6; stroke-linejoin: round; }
.fail-emblem .fail-mark { fill: none; stroke: #fff; stroke-width: 3.6; stroke-linecap: round; }
.fail-eyebrow { margin: 0 0 4px; color: #df5a78; font-size: 10px; font-weight: 900; letter-spacing: .20em; }
:root.dark .fail-eyebrow { color: #ff9aad; }
.fail-content h2 { margin: 0 0 7px; color: #213d68; font-size: 25px; font-weight: 850; letter-spacing: -.035em; }
:root.dark .fail-content h2 { color: #f1f6ff; }
.fail-copy { max-width: 290px; margin: 0 auto; color: #64799b; font-size: 13px; line-height: 1.5; }
:root.dark .fail-copy { color: #c0d0ed; }
.fail-copy p { margin: 0; }
.fail-lives { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 15px 0 17px; }
.fail-life { color: #ed6c87; font-size: 17px; line-height: 1; text-shadow: 0 2px 5px rgba(221,74,111,.20); }
.fail-lives-label { margin-left: 4px; color: #7184a4; font-size: 11px; font-weight: 700; }
:root.dark .fail-lives-label { color: #b4c5e3; }
.reward-ad-slot {
  display: flex; align-items: center; gap: 11px; padding: 13px;
  text-align: left; border: 1px dashed rgba(76, 132, 205, .48);
  border-radius: 16px; background: rgba(255,255,255,.66);
}
:root.dark .reward-ad-slot { background: rgba(7,18,36,.28); border-color: rgba(112,164,238,.45); }
.reward-ad-icon { flex: 0 0 36px; width: 36px; height: 36px; display: grid; place-items: center;
  padding-left: 2px; border-radius: 12px; color: #fff; font-size: 14px;
  background: linear-gradient(145deg, #35b7c4, #347fe1); box-shadow: 0 3px 0 #2864b2; }
.reward-ad-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.reward-ad-copy strong { color: #29466f; font-size: 12px; font-weight: 800; }
.reward-ad-copy span { color: #61799d; font-size: 10px; line-height: 1.35; }
.reward-ad-copy small { color: #8a9ab4; font-size: 9px; line-height: 1.3; }
:root.dark .reward-ad-copy strong { color: #e7f0ff; }
:root.dark .reward-ad-copy span { color: #c0d0ed; }
:root.dark .reward-ad-copy small { color: #93a9cc; }
.reward-ad-button { flex: 0 0 auto; padding: 7px 8px; border: 1px solid rgba(107,132,169,.25); border-radius: 9px;
  color: #8392a9; background: #e8edf5; font-size: 9px; font-weight: 800; cursor: not-allowed; }
:root.dark .reward-ad-button { color: #9eafc9; background: #263b5c; border-color: #40577d; }
.fail-footer { justify-content: stretch; margin-top: 15px; }
.fail-retry { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px 18px; border: 1px solid #2868c9; border-radius: 13px;
  background: linear-gradient(180deg, #438df0, #2868cf);
  box-shadow: 0 4px 0 #1e50a5, 0 8px 18px rgba(44,105,205,.22), inset 0 1px 0 rgba(255,255,255,.32);
  color: #fff; font-size: 14px; font-weight: 850; }
.fail-retry span { font-size: 18px; line-height: 12px; }
.fail-retry:hover { filter: brightness(1.07); transform: translateY(-1px); }
.fail-retry:active { transform: translateY(2px); }
@media (max-width: 420px) {
  .fail-content { padding: 24px 16px 18px; }
  .reward-ad-slot { gap: 8px; padding: 10px; }
  .reward-ad-button { padding: 7px 6px; }
}


/* ---------- GetPlayEarn Visual Audit v6: final, single-source overrides ---------- */
:root {
  --grid-dot: rgba(143, 203, 255, .52);
  --grid-border: rgba(82, 164, 235, .64);
}

/* The playable board is intentionally dark in BOTH app themes. Canvas alone draws the dots. */
.board-wrapper {
  background-color: #071629 !important;
  /* Dots are drawn exactly once by canvas.js. Keep CSS free of a second dot layer. */
  background-image:
    radial-gradient(ellipse at 50% 38%, rgba(24, 69, 111, .72) 0%, rgba(10, 34, 58, .34) 55%, transparent 82%),
    linear-gradient(145deg, #071629 0%, #0a2038 52%, #061426 100%) !important;
  background-size: auto, auto !important;
  background-position: center, center !important;
  border: 1px solid rgba(86, 157, 213, .40) !important;
  box-shadow: inset 0 1px 0 rgba(185, 224, 255, .07), 0 12px 34px rgba(0, 0, 0, .24) !important;
}
#game-canvas { background: transparent !important; }

/* Fail state: one compact centered card, never a scrollable white page. */
.modal-content.fail-content {
  width: min(340px, calc(100vw - 28px)) !important;
  max-width: 340px !important;
  max-height: min(360px, calc(100dvh - 24px)) !important;
  height: auto !important;
  overflow: hidden !important;
  overflow-y: hidden !important;
  padding: 14px 15px 13px !important;
  border-radius: 22px !important;
  text-align: center !important;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(35, 133, 218, .22), transparent 58%),
    linear-gradient(155deg, #142e4a 0%, #091a2e 100%) !important;
  border: 1px solid rgba(87, 169, 226, .46) !important;
  box-shadow: 0 22px 58px rgba(0, 0, 0, .52), inset 0 1px 0 rgba(255, 255, 255, .08) !important;
}
.fail-content .modal-close { color: #d7eaff !important; }
.fail-emblem {
  width: 46px !important; height: 46px !important;
  margin: 0 auto 5px !important; border-radius: 16px !important;
  box-shadow: 0 4px 0 #a92f50, 0 8px 18px rgba(225, 72, 111, .22), inset 0 1px 0 rgba(255,255,255,.35) !important;
}
.fail-emblem svg { width: 30px !important; height: 30px !important; }
.fail-eyebrow { margin: 0 0 3px !important; font-size: 9px !important; }
.fail-content h2 { margin: 0 0 4px !important; color: #f3f8ff !important; font-size: 20px !important; }
.fail-copy { max-width: 290px !important; color: #c0d4e8 !important; font-size: 12px !important; line-height: 1.35 !important; }
.fail-lives { gap: 6px !important; margin: 6px 0 7px !important; }
.fail-life { font-size: 15px !important; }
.fail-lives-label { color: #b8cde0 !important; font-size: 10px !important; }
.reward-ad-slot {
  gap: 8px !important; padding: 8px 9px !important; border-radius: 12px !important;
  background: rgba(4, 15, 28, .56) !important;
  border: 1px dashed rgba(90, 170, 225, .48) !important;
}
.reward-ad-icon { flex-basis: 29px !important; width: 29px !important; height: 29px !important; }
.reward-ad-copy { gap: 2px !important; }
.reward-ad-copy strong { color: #edf7ff !important; font-size: 11px !important; }
.reward-ad-copy span { color: #c1d8ea !important; font-size: 9px !important; line-height: 1.25 !important; }
.reward-ad-copy small { color: #91aec8 !important; font-size: 8px !important; line-height: 1.2 !important; }
.reward-ad-button { padding: 6px 7px !important; font-size: 8px !important; }
.fail-footer { margin-top: 7px !important; }
.fail-retry { padding: 9px 15px !important; border-radius: 11px !important; font-size: 13px !important; }
@media (max-height: 560px) {
  .modal-content.fail-content { max-height: calc(100dvh - 16px) !important; padding: 10px 13px !important; }
  .fail-emblem { width: 42px !important; height: 42px !important; margin-bottom: 3px !important; }
  .fail-emblem svg { width: 28px !important; height: 28px !important; }
  .fail-lives { margin: 5px 0 6px !important; }
  .fail-footer { margin-top: 6px !important; }
}


/* ---------- GetPlayEarn Menu Refresh v9: menu-only presentation ---------- */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid !important;
  place-items: center !important;
  padding: 16px;
  box-sizing: border-box;
  overflow: hidden;
}
.drawer-scrim {
  background: rgba(2, 9, 20, .76);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
.drawer-panel {
  position: relative !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  left: auto !important;
  justify-self: center;
  align-self: center;
  margin: 0 auto;
  width: min(540px, calc(100vw - 32px));
  height: auto;
  max-height: min(760px, calc(100dvh - 32px));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 26px 22px;
  gap: 16px;
  border: 1px solid rgba(113, 178, 232, .38);
  border-radius: 24px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(54, 133, 209, .20), transparent 58%),
    linear-gradient(155deg, #142d49 0%, #091a2e 100%);
  box-shadow: 0 26px 80px rgba(0,0,0,.58), inset 0 1px 0 rgba(255,255,255,.08);
  transform: translateY(14px) scale(.97);
  transition: transform var(--t-med) cubic-bezier(.2,.8,.3,1), opacity var(--t-med);
  opacity: 0;
  color: #edf6ff;
}
.drawer.open .drawer-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}
.drawer-close {
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(151, 194, 235, .24);
  background: rgba(255,255,255,.07);
  color: #eaf5ff;
}
#drawer-title {
  margin: 4px 48px 0 0;
  color: #f4f9ff;
  font-size: 26px;
  font-weight: 800;
}
.drawer-sub { color: #a9c4df; font-size: 13px; }
.drawer-stats { gap: 10px; margin-top: 2px; }
.drawer-stats > div {
  min-width: 0;
  padding: 12px 8px;
  background: rgba(83, 145, 205, .12);
  border: 1px solid rgba(116, 174, 225, .25);
  border-radius: 14px;
}
.drawer-stats strong { color: #fff; font-size: 21px; }
.drawer-stats span {
  color: #b6cde3;
  font-size: 9px;
  letter-spacing: .06em;
}
.drawer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}
.drawer-btn {
  min-height: 52px;
  padding: 12px 14px;
  border-radius: 13px;
  border: 1px solid rgba(116, 174, 225, .28);
  background: linear-gradient(180deg, rgba(49, 91, 137, .72), rgba(26, 55, 88, .88));
  color: #f1f7ff;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.07);
}
.drawer-btn:hover { background: linear-gradient(180deg, #376da4, #234c78); border-color: rgba(143, 198, 245, .52); }
.drawer-section {
  padding: 13px 15px 10px;
  border: 1px solid rgba(116, 174, 225, .24);
  border-radius: 15px;
  background: rgba(5, 17, 31, .30);
}
.drawer-section h3 {
  margin: 0 0 7px;
  color: #9fc4e5;
  font-size: 11px;
  letter-spacing: .12em;
}
.drawer-section .toggle {
  padding: 9px 3px;
  color: #e6f2ff;
  font-size: 13px;
}
.drawer-section .toggle input { accent-color: #ffd43b; }
/* Achievements remain available as milestone badges; match the game's dark visual language. */
#modal-achievements .modal-content {
  background: linear-gradient(155deg, #142d49 0%, #091a2e 100%);
  border-color: rgba(113, 178, 232, .38);
  color: #edf6ff;
}
#modal-achievements .modal-close { color: #edf6ff; }
#modal-achievements .achievements-grid { gap: 9px; }
#modal-achievements .ach {
  background: rgba(83, 145, 205, .12);
  border-color: rgba(116, 174, 225, .24);
  border-radius: 14px;
}
#modal-achievements .ach.locked { opacity: .68; }
#modal-achievements .ach.unlocked {
  border-color: rgba(255, 212, 59, .78);
  background: rgba(255, 212, 59, .08);
}
#modal-achievements .ach-icon {
  background: rgba(4, 17, 31, .52);
  border-color: rgba(116, 174, 225, .24);
  color: #dceeff;
}
#modal-achievements .ach.unlocked .ach-icon {
  background: linear-gradient(145deg, #ffd43b, #f4a900);
  border-color: #ffd43b;
  color: #17253a;
}
#modal-achievements .ach-title { color: #f3f8ff; }
#modal-achievements .ach-desc { color: #b3cce3; }
#modal-achievements .ach-counter { color: #ffd43b; font-size: 14px; }
@media (max-width: 520px) {
  .drawer { padding: 12px; }
  .drawer-panel {
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    padding: 22px 17px 17px;
    gap: 13px;
  }
  .drawer-actions { gap: 7px; }
  .drawer-btn { min-height: 48px; padding: 10px 8px; font-size: 13px; }
  .drawer-stats > div { padding: 10px 5px; }
  .drawer-stats span { font-size: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .drawer-panel { transition: none !important; }
}


/* Sequential progression: locked levels remain visible but cannot be selected. */
.lvl-cell.locked, .lvl-cell.locked:disabled {
  opacity: .52;
  color: var(--ink-faint);
  background: color-mix(in srgb, var(--bg-soft) 72%, var(--line));
  border-style: dashed;
  cursor: not-allowed;
  box-shadow: none;
}
.lvl-cell.locked:hover {
  transform: none;
  color: var(--ink-faint);
  background: color-mix(in srgb, var(--bg-soft) 72%, var(--line));
}
.lvl-cell.locked::before {
  content: "🔒";
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 9px;
  line-height: 1;
}
.tab.tier-locked { opacity: .68; }
.tab.tier-locked:not(.active) { border-bottom-color: transparent; }

/* v12: compact reward UI and cohesive compact menu/subpages. */
.topbar { grid-template-columns: 42px minmax(0,1fr) auto; }
.topbar-right { display:flex; align-items:center; gap:9px; }
.coin-balance { display:flex; align-items:center; gap:5px; padding:6px 9px; border-radius:999px; border:1px solid rgba(255,212,59,.42); background:linear-gradient(145deg,rgba(255,212,59,.18),rgba(255,153,40,.08)); color:#ffe28a; white-space:nowrap; }
.coin-balance .coin-glyph { color:#ffd43b; font-size:15px; text-shadow:0 0 9px rgba(255,212,59,.6); }
.coin-balance strong { font-size:13px; font-variant-numeric:tabular-nums; }
.coin-balance small { font-size:8px; letter-spacing:.08em; color:#e7c96f; }
.level-complete { width:min(310px, calc(100vw - 36px)); padding:19px 20px 17px; gap:8px; border-radius:20px; }
.level-complete::before { inset:-16px -14px; opacity:.55; }
.lc-check { width:54px; height:54px; border-radius:17px; }
.lc-check svg { width:38px; height:38px; }
.lc-title { margin-top:1px; font-size:21px; }
.lc-sub { font-size:12px; }
.lc-reward { display:flex; align-items:center; justify-content:center; gap:10px; min-width:150px; margin:5px auto 2px; padding:9px 17px; border-radius:14px; border:1px solid rgba(255,212,59,.4); background:linear-gradient(145deg,rgba(255,212,59,.17),rgba(255,157,40,.07)); color:#ffe28a; box-shadow:inset 0 1px 0 rgba(255,255,255,.07); }
.lc-coin { display:grid; place-items:center; width:27px; height:27px; border-radius:50%; color:#6d4b00; font-size:19px; background:linear-gradient(145deg,#fff09b,#ffbd24); box-shadow:0 2px 0 #bd8110,0 0 13px rgba(255,212,59,.3); }
.lc-reward strong { display:block; font-size:19px; line-height:1.05; color:#ffdf70; }
.lc-reward small { display:block; margin-top:2px; font-size:8px; letter-spacing:.13em; color:#d9c17c; }
.lc-next { min-width:145px; padding:10px 18px; margin-top:2px; }
.drawer-panel { width:min(410px,calc(100vw - 30px)); max-height:min(620px,calc(100dvh - 28px)); padding:20px 19px 17px; gap:11px; border-radius:20px; }
#drawer-title { font-size:22px; }
.drawer-sub { font-size:11px; }
.drawer-stats > div { padding:9px 6px; }
.drawer-stats strong { font-size:17px; }
.drawer-actions { gap:7px; }
.drawer-btn { min-height:43px; padding:9px 10px; font-size:12px; border-radius:11px; }
.drawer-section { padding:10px 12px 8px; border-radius:13px; }
.drawer-section .toggle { padding:7px 2px; font-size:12px; }
.modal-content { width:min(390px,calc(100vw - 30px)); max-height:82dvh; padding:18px 17px 15px; border-radius:19px; }
.modal-wide { width:min(620px,calc(100vw - 24px)); }
.modal h2 { font-size:19px; margin:3px 0 11px; }
#modal-levels .levels-controls { gap:6px; }
#modal-levels .difficulty-tabs { gap:4px; }
#modal-levels .tab { padding:7px 8px; font-size:11px; }
#modal-levels .lvl-cell { min-height:34px; border-radius:9px; font-size:11px; }
#modal-achievements .achievements-grid { gap:7px; }
#modal-achievements .ach { padding:9px; border-radius:11px; }
@media(max-width:520px) {
 .topbar { grid-template-columns:36px minmax(0,1fr) auto; padding:7px 8px 5px; gap:4px; }
 .topbar-right { gap:5px; }
 .coin-balance { padding:5px 7px; gap:4px; }
 .coin-balance small { display:none; }
 .coin-balance strong { font-size:12px; }
 .drawer-panel { width:calc(100vw - 26px); padding:17px 14px 14px; gap:9px; }
 .modal-content { padding:16px 13px 13px; }
 .level-complete { width:min(290px,calc(100vw - 34px)); padding:16px 16px 14px; }
}


/* v13: align level controls, improve reward contrast, compact dark subpages. */
.topbar {
  grid-template-columns: 42px minmax(0,1fr);
  grid-template-rows: auto auto;
  column-gap: 8px;
  row-gap: 3px;
  padding: 7px 12px 6px;
}
.topbar > #btn-menu { grid-column: 1; grid-row: 1 / span 2; align-self: center; }
.topbar > .level-title { grid-column: 2; grid-row: 1; align-self: end; text-align: center; }
.topbar > .topbar-right {
  grid-column: 2; grid-row: 2; justify-self: center;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.coin-balance {
  padding: 4px 9px; gap: 5px;
  color: #563900; background: linear-gradient(180deg,#fff3c4,#f5d77a);
  border: 1px solid #c99a32; box-shadow: 0 2px 0 rgba(113,77,14,.16);
}
.coin-balance .coin-glyph { color:#8a5a00; text-shadow:none; }
.coin-balance strong { color:#493000; font-size:13px; font-weight:900; }
.coin-balance small { color:#65470d; font-size:8px; font-weight:800; }
.hearts { padding:4px 9px; gap:6px; }
.level-complete {
  width:min(286px,calc(100vw - 38px)); min-width:0;
  padding:16px 18px 14px; gap:6px; border-radius:18px;
}
.lc-check { width:48px; height:48px; border-radius:15px; }
.lc-check svg { width:34px; height:34px; }
.lc-title { font-size:20px; }
.lc-sub { color:#344f78; font-size:12px; font-weight:650; }
:root.dark .lc-sub { color:#d7e6fa; }
.lc-reward {
  min-width:138px; padding:7px 13px; margin:3px auto;
  background:linear-gradient(145deg,#eaf4ff,#d6e8ff);
  border:1px solid #7ca8d9; color:#183b68; box-shadow:0 2px 0 rgba(27,69,116,.12);
}
.lc-reward strong { color:#173e70; font-size:20px; font-weight:900; }
.lc-reward small { color:#31577e; font-size:8px; font-weight:850; }
.lc-coin { background:linear-gradient(145deg,#ffe99a,#e5ad28); color:#513400; box-shadow:0 2px 0 #a97917; }
.lc-next { min-width:138px; padding:9px 16px; }
/* Level and achievement pages use the same navy family as the main menu. */
.modal-content {
  background:linear-gradient(155deg,#243d68 0%,#172b4c 100%) !important;
  color:#edf5ff; border:1px solid #456797 !important;
  box-shadow:0 22px 58px rgba(4,13,31,.48), inset 0 1px 0 rgba(255,255,255,.08);
}
.modal h2, .modal-content h2 { color:#f3f7ff; }
.modal-body { color:#c6d7ee; }
#modal-levels .levels-controls input {
  color:#f3f7ff; background:#152746; border:1px solid #45658f;
}
#modal-levels .levels-controls input::placeholder { color:#9eb5d4; }
#modal-levels .btn-secondary, #modal-levels .tab {
  color:#d9e8fb; background:linear-gradient(180deg,#304d78,#20395f);
  border-color:#496b99;
}
#modal-levels .tab.active { color:#ffe08a; border-bottom-color:#ffd45c; }
#modal-levels .tab.tier-locked { color:#a8bad3; opacity:1; }
#modal-levels .levels-grid { grid-template-columns:repeat(auto-fill,minmax(42px,1fr)); gap:5px; max-height:46dvh; }
#modal-levels .lvl-cell {
  min-height:38px; aspect-ratio:1.15/1; border-radius:8px;
  color:#eaf3ff; background:#29466f; border:1px solid #5578a7;
  font-size:11px; font-weight:750;
}
#modal-levels .lvl-cell.solved { color:#092d35; background:linear-gradient(145deg,#83e2cb,#42bda8); border-color:#8ce9d4; }
#modal-levels .lvl-cell.current { outline:2px solid #ffd45c; outline-offset:1px; }
#modal-levels .lvl-cell.locked, #modal-levels .lvl-cell.locked:disabled {
  color:#c4d0e1; background:#172a48; border:1px solid #344f74;
  opacity:1; box-shadow:none;
}
#modal-levels .lvl-cell.locked::before { content:"🔒"; font-size:9px; opacity:.95; }
#modal-levels .levels-pager { color:#d7e6f8; }
#modal-achievements .ach { background:#20395f; border-color:#45658e; color:#eaf3ff; }
#modal-achievements .ach p, #modal-achievements .ach span { color:#bfd1e9; }
.modal-close { color:#eaf3ff !important; }
@media(max-width:520px) {
  .topbar { grid-template-columns:36px minmax(0,1fr); padding:6px 8px 5px; }
  .topbar-right { gap:5px; }
  .coin-balance { padding:4px 7px; }
  .coin-balance small { display:inline; font-size:7px; }
  .hearts { padding:4px 7px; }
  #modal-levels .levels-grid { grid-template-columns:repeat(auto-fill,minmax(35px,1fr)); gap:4px; }
  #modal-levels .lvl-cell { min-height:33px; font-size:10px; }
}


/* v14: centered game HUD, clear controls and compact level navigation */
.topbar {
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  grid-template-rows: auto auto;
  align-items: center;
  row-gap: 3px;
  padding: 9px 12px 7px;
}
#btn-menu { grid-column: 1; grid-row: 1 / span 2; }
.level-title { grid-column: 2; grid-row: 1; justify-self: center; }
.topbar-right {
  grid-column: 2;
  grid-row: 2;
  justify-self: center;
  gap: 9px;
  margin-top: 2px;
}
.coin-balance {
  color: #263653;
  background: linear-gradient(145deg, #ffe28a, #f5b942);
  border: 1px solid #c58b25;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.8), 0 2px 0 rgba(93,65,20,.24), 0 3px 8px rgba(0,0,0,.12);
  padding: 7px 12px;
}
.coin-balance .coin-glyph { color: #795018; text-shadow: none; }
.coin-balance small { color: #4b3a20; font-weight: 800; }
.hearts {
  box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 2px 0 rgba(25,45,80,.12);
}
.levels-close {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #294d91, #142b61);
  border: 1px solid #6688c8;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.22), 0 3px 8px rgba(4,14,42,.25);
}
.levels-close span { font-size: 27px; line-height: 1; font-weight: 500; }
.levels-close:hover { color: #fff; filter: brightness(1.15); }
.lvl-cell { user-select: none; -webkit-user-select: none; }
.lvl-cell:focus { outline: none; }
.lvl-cell:focus-visible { outline: 2px solid var(--hint); outline-offset: 2px; }
#btn-daily { display: none !important; }
@media (max-width: 520px) {
  .topbar { grid-template-columns: 38px minmax(0,1fr) 38px; padding-inline: 8px; }
  .coin-balance { padding: 6px 9px; }
  .coin-balance strong { font-size: 13px; }
  .hearts { padding: 6px 8px; }
}

/* v16: compact menu and level panel, carried forward without touching gameplay styles. */
.drawer { padding: 12px; }
.drawer-panel {
  width: min(350px, calc(100vw - 28px));
  max-height: min(520px, calc(100dvh - 24px));
  padding: 16px 15px 13px;
  gap: 9px;
  border-radius: 18px;
}
#drawer-title { font-size: 20px; margin-top: 2px; }
.drawer-close { width: 32px; height: 32px; top: 10px; right: 10px; }
.drawer-stats { gap: 7px; }
.drawer-stats > div { padding: 7px 5px; border-radius: 11px; }
.drawer-stats strong { font-size: 16px; }
.drawer-actions { gap: 6px; }
.drawer-btn { min-height: 37px; padding: 7px 8px; font-size: 11px; border-radius: 10px; }
.drawer-section { padding: 8px 10px 6px; border-radius: 11px; }
.drawer-section .toggle { padding: 5px 2px; font-size: 11px; }
#modal-levels .modal-content {
  width: min(500px, calc(100vw - 32px));
  max-height: min(650px, calc(100dvh - 36px));
  padding: 15px 15px 12px;
  border-radius: 18px;
}
#modal-levels h2 { font-size: 17px; margin: 2px 42px 8px 0; }
#modal-levels .levels-controls { gap: 5px; }
#modal-levels .levels-controls input { min-width: 0; height: 34px; padding: 6px 9px; font-size: 11px; }
#modal-levels .levels-controls button { min-height: 34px; padding: 6px 9px; font-size: 10px; border-radius: 9px; }
#modal-levels .difficulty-tabs { gap: 3px; margin: 8px 0 6px; }
#modal-levels .tab { padding: 5px 6px; font-size: 10px; }
#modal-levels .levels-grid {
  grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
  gap: 4px; max-height: min(39dvh, 330px); padding: 2px;
}
#modal-levels .lvl-cell { min-height: 29px; aspect-ratio: 1.15 / 1; font-size: 9px; border-radius: 7px; }
#modal-levels .lvl-cell.locked::before { font-size: 7px; }
#modal-levels .levels-pager { padding-top: 7px; font-size: 11px; }
#modal-levels .levels-pager button { min-height: 32px; padding: 6px 10px; font-size: 10px; }
#modal-levels .levels-close { width: 32px; height: 32px; border-radius: 9px; }
#modal-levels .levels-close span { font-size: 23px; }
@media (max-width: 520px) {
  .drawer-panel { width: min(340px, calc(100vw - 24px)); padding: 14px 12px 11px; gap: 8px; }
  #modal-levels .modal-content { width: calc(100vw - 22px); padding: 13px 11px 10px; max-height: calc(100dvh - 24px); }
  #modal-levels .levels-grid { grid-template-columns: repeat(auto-fill, minmax(27px, 1fr)); gap: 3px; max-height: 38dvh; }
  #modal-levels .lvl-cell { min-height: 27px; font-size: 8px; }
  #modal-levels .tab { padding: 5px 4px; font-size: 9px; }
}


/* V18: correctly center the HUD using the actual three-child header structure.
   Visual-only change: gameplay, progression, coins logic and menu logic untouched. */
.topbar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: stretch;
  column-gap: 8px;
  row-gap: 5px;
  padding: 9px 12px 9px;
}
#btn-menu {
  grid-column: 1;
  grid-row: 1 / span 2;
  justify-self: start;
  align-self: center;
}
.level-title {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
}
#level-label {
  color: #173b70;
  font-weight: 850;
  text-align: center;
}
#level-tier {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 14px;
  border: 1px solid #7898ca;
  border-radius: 999px;
  color: #173d78;
  background: linear-gradient(180deg, #ffffff 0%, #e4eeff 48%, #c7d9f7 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.98), inset 0 -2px 0 rgba(71,102,158,.16), 0 3px 0 #8da9d4, 0 5px 8px rgba(29,59,111,.16);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .09em;
  text-shadow: 0 1px 0 #fff;
}
.topbar-right {
  grid-column: 2;
  grid-row: 2;
  justify-self: center;
  align-self: center;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 9px;
  width: max-content;
  max-width: 100%;
  min-width: 0;
  margin: 1px 0 0;
}
.coin-balance {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  color: #382300;
  background: linear-gradient(180deg, #fff4c9 0%, #f5d477 48%, #dfa43b 100%);
  border: 1px solid #ad741c;
  border-radius: 999px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.96), inset 0 -2px 0 rgba(125,76,10,.18), 0 3px 0 #9b671d, 0 5px 9px rgba(48,35,12,.18);
  text-shadow: 0 1px 0 rgba(255,255,255,.55);
}
.coin-balance .coin-glyph { color: #70420a; }
.coin-balance strong { color: #352000; font-size: 14px; font-weight: 950; }
.coin-balance small { color: #4a2d08; font-size: 8px; font-weight: 950; }
.hearts {
  min-width: 94px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid #d99ab0;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff 0%, #ffe9f0 55%, #f5c7d5 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.98), inset 0 -2px 0 rgba(176,91,120,.12), 0 3px 0 #d59aad, 0 5px 9px rgba(91,37,59,.13);
}
.heart {
  filter: drop-shadow(0 1px 0 rgba(255,255,255,.9)) drop-shadow(0 2px 1px rgba(137,35,70,.2));
}
@media (max-width: 520px) {
  .topbar {
    grid-template-columns: 38px minmax(0, 1fr) 38px;
    column-gap: 5px;
    row-gap: 5px;
    padding: 7px 8px 8px;
  }
  #level-tier { min-height: 30px; padding: 4px 12px; font-size: 10px; }
  .topbar-right { gap: 7px; }
  .coin-balance { min-height: 33px; padding: 5px 9px; gap: 5px; }
  .coin-balance strong { font-size: 13px; }
  .coin-balance small { font-size: 7px; }
  .hearts { min-width: 82px; min-height: 33px; padding: 5px 8px; gap: 5px; }
  .heart { width: 16px; height: 16px; }
}
@media (max-width: 370px) {
  .topbar { grid-template-columns: 32px minmax(0,1fr) 32px; column-gap: 3px; padding-inline: 5px; }
  .topbar-right { gap: 5px; }
  .coin-balance { padding-inline: 7px; }
  .coin-balance small { display: inline; font-size: 6px; }
  .hearts { min-width: 74px; gap: 4px; padding-inline: 6px; }
  .heart { width: 14px; height: 14px; }
}


/* V21: mobile-only responsive sizing.
   Preserve V20 desktop layout, 3D HUD appearance, game logic and progression.
   The board occupies the available viewport space and the canvas follows its
   container on narrow portrait/landscape screens. */
@media (max-width: 768px) {
  html, body {
    width: 100%;
    min-width: 0;
    min-height: 100%;
    overflow: hidden;
  }
  .app {
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    overflow: hidden;
  }
  .topbar,
  .progress,
  .board-wrapper,
  .actions {
    min-width: 0;
  }
  .board-wrapper {
    width: auto;
    min-width: 0;
    min-height: 0;
    margin: 7px 7px 5px;
    border-radius: 15px;
  }
  #game-canvas {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    touch-action: pan-y pinch-zoom;
  }
  .actions {
    margin: 0 7px calc(5px + env(safe-area-inset-bottom));
    padding: 5px 4px calc(6px + env(safe-area-inset-bottom));
    gap: 3px;
  }
  .action {
    min-width: 0;
    min-height: 48px;
    padding: 6px 2px;
  }
}
@media (max-width: 420px) {
  .topbar {
    padding: 6px 5px 7px;
    column-gap: 3px;
    row-gap: 4px;
  }
  #btn-menu {
    width: 34px;
    height: 34px;
  }
  #level-label { font-size: clamp(15px, 4.5vw, 18px); }
  #level-tier {
    min-height: 27px;
    padding: 3px 10px;
    font-size: 9px;
  }
  .topbar-right { gap: 5px; }
  .coin-balance {
    min-height: 30px;
    padding: 4px 7px;
    gap: 4px;
  }
  .coin-balance strong { font-size: 12px; }
  .coin-balance small { font-size: 6px; }
  .hearts {
    min-width: 70px;
    min-height: 30px;
    padding: 4px 6px;
    gap: 4px;
  }
  .heart { width: 13px; height: 13px; }
  .board-wrapper { margin: 5px 5px 4px; border-radius: 12px; }
  .action span { font-size: 10px; }
}
@media (max-height: 560px) and (max-width: 768px) {
  .topbar { padding-top: 3px; padding-bottom: 4px; row-gap: 2px; }
  #btn-menu { width: 32px; height: 32px; }
  #level-tier { min-height: 24px; padding-block: 2px; }
  .coin-balance, .hearts { min-height: 27px; padding-block: 3px; }
  .action { min-height: 40px; padding-block: 3px; }
}

/* GetPlayEarn below-game banner slot; it occupies its own grid row. */
.gpe-ad-below-game{width:100%;height:50px;min-height:50px;max-height:50px;display:flex;flex:0 0 50px;justify-content:center;align-items:center;overflow:hidden;background:rgba(5,15,30,.45)}
.gpe-ad-below-game iframe,.gpe-ad-below-game img{display:block;width:min(320px,100%);height:50px;max-width:100%;max-height:50px;border:0;object-fit:contain}


/* GetPlayEarn mobile banner reservation: keep the 320x50 ad visible below controls.
   Desktop layout remains unchanged. */
/* Fixed 320x50 banner reservation is shared by mobile and desktop. */
@media (max-width: 768px) {
  .app { grid-template-rows: auto auto minmax(0, 1fr) auto 50px; }
}
