:root {
  --bg: #0f1226;
  --bg-2: #1a1f3d;
  --card: #232a52;
  --accent: #ffcb3d;
  --accent-2: #4ea1ff;
  --good: #35d07f;
  --text: #eef1ff;
  --muted: #9aa3d0;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-2), var(--bg));
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.hidden { display: none !important; }

/* ===== Menu ===== */
.menu-header {
  text-align: center;
  padding: 32px 16px 16px;
}
.menu-header h1 {
  font-size: clamp(28px, 5vw, 44px);
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.menu-header p { color: var(--muted); margin-top: 8px; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
  padding: 20px;
  max-width: 1100px;
  margin: 0 auto;
}
.loading { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px; }

.level-tile {
  position: relative;
  aspect-ratio: 16 / 10;
  border: none;
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  background: var(--card);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  color: var(--text);
}
.level-tile:hover:not(:disabled) { transform: translateY(-3px) scale(1.02); }
.level-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.level-tile.locked { filter: grayscale(0.8) brightness(0.55); cursor: not-allowed; }
.level-tile.cleared { outline: 3px solid var(--good); }

.level-num {
  position: absolute; top: 6px; left: 8px;
  font-weight: 800; font-size: 18px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.8);
}
.star { position: absolute; top: 6px; right: 8px; color: var(--accent); font-size: 20px; text-shadow: 0 1px 4px #000; }
.lock { position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; }

/* ===== Game HUD ===== */
.hud {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 5;
  flex-wrap: wrap;
}
.hud-title { font-weight: 800; font-size: 18px; }
.hud-stat { color: var(--muted); font-size: 15px; }
.hud-stat b { color: var(--text); }
.hud-btn {
  border: none; border-radius: 10px; padding: 8px 14px;
  background: var(--card); color: var(--text); font-weight: 600;
  cursor: pointer; transition: background 0.12s;
}
.hud-btn:hover:not(:disabled) { background: #2e3667; }
.hud-btn:disabled { opacity: 0.4; cursor: default; }
#hint-btn { margin-left: auto; background: var(--accent); color: #241a00; }
#hint-btn:hover:not(:disabled) { background: #ffd766; }

/* ===== Stage / panes ===== */
/* Mobile-first: panes stacked vertically. */
.stage {
  max-width: 720px;
  margin: 14px auto;
  padding: 0 12px 40px;
  display: flex; flex-direction: column; gap: 8px;
}
.pane {
  position: relative;
  width: 100%;
  aspect-ratio: 1024 / 640;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: crosshair;
  background: #000;
}
.pane canvas { width: 100%; height: 100%; display: block; }

.divider {
  text-align: center; color: var(--muted); font-size: 13px;
  position: relative;
}
.divider span { background: var(--bg); padding: 0 10px; position: relative; z-index: 1; }
.divider::before {
  content: ""; position: absolute; top: 50%; left: 0; right: 0;
  height: 1px; background: rgba(255,255,255,0.12);
}

/* ===== Markers ===== */
.found-circle {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: pop 0.35s ease;
  aspect-ratio: 1;
}
.wrong-mark {
  position: absolute;
  width: 8%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  animation: pop 0.2s ease;
}
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(0.2); opacity: 0; }
  60% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); }
}
.hint-pulse {
  position: absolute;
  transform: translate(-50%, -50%);
  aspect-ratio: 1;
  border: 3px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  animation: hintpulse 1.6s ease-out;
}
@keyframes hintpulse {
  0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(0.9); }
  60% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
}
.shake { animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ===== Overlay ===== */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(5, 7, 20, 0.7);
  backdrop-filter: blur(4px);
}
.overlay-card {
  background: var(--card);
  padding: 32px 36px;
  border-radius: 18px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop 0.3s ease;
  max-width: 90vw;
}
.overlay-card h2 { font-size: 26px; margin-bottom: 10px; color: var(--accent); }
.overlay-card .stat { color: var(--muted); margin-bottom: 22px; }
.overlay-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.overlay-actions button {
  border: none; border-radius: 10px; padding: 12px 20px;
  font-weight: 700; cursor: pointer; background: var(--bg-2); color: var(--text);
  transition: transform 0.1s;
}
.overlay-actions button:hover { transform: translateY(-2px); }
.overlay-actions .primary { background: var(--good); color: #04120a; }

/* Desktop: two images side-by-side (horizontal). */
@media (min-width: 900px) {
  .stage {
    max-width: 1200px;
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }
  .pane { flex: 1 1 0; min-width: 0; }
  .divider { flex: 0 0 auto; }
  /* Rotate the "find the differences" label to sit between the columns. */
  .divider span { writing-mode: vertical-rl; padding: 10px 0; }
  .divider::before {
    top: 0; bottom: 0; left: 50%; right: auto;
    width: 1px; height: auto;
  }
}