/* ============================================================
   FIND THE DIFFERENCE — core styles
   ============================================================ */

:root {
  --bg-0: #070b1c;
  --bg-1: #0b1026;
  --bg-2: #141a38;
  --panel: rgba(16, 22, 51, 0.92);
  --panel-line: rgba(0, 229, 255, 0.35);
  --cyan: #00e5ff;
  --magenta: #ff4fd8;
  --gold: #ffd400;
  --green: #37ff8b;
  --red: #ff4d5e;
  --ink: #eaf2ff;
  --ink-dim: #9fb0d0;
  --radius: 16px;
  --font: "Segoe UI", "SF Pro Display", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 120% at 20% 0%, var(--bg-2) 0%, var(--bg-1) 45%, var(--bg-0) 100%);
  color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

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

#app { position: fixed; inset: 0; }

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.screen.active { display: flex; }

/* ---------- Loading ---------- */
#screen-loading { background: radial-gradient(120% 120% at 50% 30%, var(--bg-2), var(--bg-0)); z-index: 60; }
.loading-inner { text-align: center; width: min(78vw, 420px); }
.loading-bar {
  height: 14px;
  margin: 26px auto 14px;
  border: 2px solid rgba(0, 229, 255, 0.4);
  border-radius: 999px;
  padding: 2px;
  background: rgba(0, 0, 0, 0.35);
}
.loading-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.8);
  transition: width 0.25s ease;
}
.loading-text { color: var(--ink-dim); letter-spacing: 2px; font-size: 13px; }

/* ---------- Title ---------- */
.game-title {
  font-size: clamp(30px, 7vw, 64px);
  letter-spacing: 3px;
  text-transform: uppercase;
  font-weight: 800;
  line-height: 1.02;
  background: linear-gradient(180deg, #ffffff, #bfe6ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 18px rgba(0, 229, 255, 0.35));
}
.game-title .accent {
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.game-title.big { font-size: clamp(38px, 8vw, 72px); }

/* ---------- Menu ---------- */
.menu-inner {
  text-align: center;
  padding: 20px;
  max-width: 460px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.menu-tagline { color: var(--ink-dim); font-size: clamp(13px, 2.4vw, 16px); letter-spacing: 1px; }

.menu-chip {
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid var(--panel-line);
  color: var(--cyan);
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 1px;
  font-size: 14px;
}

.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: min(100%, 340px); }
.menu-foot { color: var(--ink-dim); font-size: 11px; opacity: 0.8; letter-spacing: 1px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(38, 50, 96, 0.95), rgba(20, 27, 56, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(0, 229, 255, 0.08);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease, filter 0.2s ease;
  position: relative;
  min-height: 44px;
}
.btn:hover { filter: brightness(1.15); transform: translateY(-1px); box-shadow: 0 8px 0 rgba(0,0,0,0.35), 0 0 18px rgba(0, 229, 255, 0.25); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.35); }
.btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(180deg, #00c4e0, #0086a8);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
  box-shadow: 0 6px 0 rgba(0, 90, 110, 0.8), 0 0 22px rgba(0, 229, 255, 0.45);
}
.btn-primary:hover { box-shadow: 0 8px 0 rgba(0, 90, 110, 0.8), 0 0 30px rgba(0, 229, 255, 0.65); }

.btn-danger {
  background: linear-gradient(180deg, #ff5b6e, #c0273c);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 6px 0 rgba(120, 10, 25, 0.7);
}

.btn-ghost { background: transparent; border: 1px solid rgba(255,255,255,0.2); box-shadow: none; }
.btn-ghost:hover { box-shadow: none; background: rgba(255,255,255,0.06); }

.btn-icon { padding: 10px; border-radius: 50%; min-height: 40px; width: 44px; }

.btn-big { font-size: 18px; padding: 16px 26px; }
.btn-ico { font-size: 15px; }

.btn-hud { min-height: 42px; padding: 8px 12px; border-radius: 10px; position: relative; }
.hud-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--magenta);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 10px rgba(255, 79, 216, 0.7);
}

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 18px 50px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.08);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 18px;
  width: min(92vw, 720px);
  max-height: 92vh;
  overflow-y: auto;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head h2 {
  font-size: clamp(20px, 4vw, 28px);
  letter-spacing: 3px;
  font-weight: 900;
  color: var(--ink);
  text-shadow: 0 0 18px rgba(0, 229, 255, 0.4);
}
.panel-head-spacer { width: 44px; height: 40px; }

/* Level grid */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 12px;
}
.level-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 6px;
  background: linear-gradient(180deg, rgba(38, 50, 96, 0.9), rgba(18, 24, 52, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 1px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.15s ease;
  position: relative;
  min-height: 70px;
  touch-action: manipulation;
}
.level-cell:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 0 18px rgba(0, 229, 255, 0.35); filter: brightness(1.15); }
.level-cell:active:not(:disabled) { transform: translateY(1px); }
.level-cell:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.level-cell:disabled { opacity: 0.45; cursor: not-allowed; }
.level-cell .lc-num { font-size: 16px; }
.level-cell .lc-star { font-size: 12px; line-height: 1; }
.level-cell .lc-time { font-size: 10px; font-weight: 600; color: var(--ink-dim); letter-spacing: 0.5px; }
.level-cell.locked { background: linear-gradient(180deg, rgba(30, 34, 54, 0.9), rgba(16, 18, 32, 0.9)); }
.lock-ico { position: absolute; top: 6px; right: 8px; opacity: 0.85; }

/* ---------- How to play ---------- */
.howto-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.howto-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px;
}
.howto-card h3 { color: var(--cyan); font-size: 15px; letter-spacing: 2px; margin-bottom: 6px; text-transform: uppercase; }
.howto-card p { color: var(--ink-dim); font-size: 13px; line-height: 1.5; }
.howto-card b { color: var(--ink); }

/* ---------- Settings ---------- */
.settings-body { display: flex; flex-direction: column; gap: 10px; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  min-height: 52px;
  font-weight: 700;
  letter-spacing: 1px;
}
.setting-row:hover { background: rgba(255, 255, 255, 0.09); }
.setting-row:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
.setting-row.danger .setting-label { color: var(--red); }
.setting-value { color: var(--ink-dim); font-size: 13px; font-weight: 600; }
.toggle {
  width: 54px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: background 0.2s ease;
  flex: none;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  transition: left 0.2s ease;
}
.toggle.on { background: linear-gradient(90deg, var(--cyan), #00a2c0); }
.toggle.on::after { left: 28px; }
.settings-note { color: var(--ink-dim); font-size: 12px; text-align: center; padding-top: 6px; }

/* ---------- Game screen ---------- */
.game-root { padding: 0; }
.game-hud {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 22px;
  padding: 10px clamp(10px, 2vw, 26px);
  width: 100%;
  background: linear-gradient(180deg, rgba(10, 15, 34, 0.85), rgba(10, 15, 34, 0.4));
  border-bottom: 1px solid rgba(0, 229, 255, 0.18);
  z-index: 5;
}
.hud-cell { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 64px; }
.hud-label { font-size: 9px; letter-spacing: 2px; color: var(--ink-dim); font-weight: 700; }
.hud-value { font-size: clamp(18px, 3vw, 26px); font-weight: 900; letter-spacing: 1px; line-height: 1.1; color: var(--ink); }
.hud-value.timer-value { color: var(--cyan); text-shadow: 0 0 14px rgba(0, 229, 255, 0.6); }
.hud-value.danger { color: var(--red); animation: none; }
.hud-buttons { display: flex; gap: 8px; margin-left: auto; }

.stars { display: inline-flex; gap: 2px; color: var(--gold); filter: drop-shadow(0 0 6px rgba(255, 212, 0, 0.55)); }
.stars .st-empty { color: rgba(255, 255, 255, 0.22); filter: none; }
.stars.mini svg { width: 15px; height: 15px; }
.stars.big { justify-content: center; margin: 4px 0 10px; }
.stars.big svg { width: 34px; height: 34px; }

#scenes {
  flex: 1;
  display: flex;
  gap: 12px;
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: 6px clamp(4px, 2vw, 18px);
  min-height: 0;
}
.scene {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  margin: auto;
  flex: 1 1 0;
  min-width: 0;
  aspect-ratio: 16 / 10;
  max-width: min(50vw, 860px);
  max-height: calc(100vh - 170px);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.22), 0 12px 40px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255,255,255,0.06);
  background: #0d1330;
  cursor: crosshair;
  touch-action: none;
}
.scene canvas { display: block; }
.scene-overlay { position: absolute; inset: 0; pointer-events: none; }
.scene-tag {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 10px;
  letter-spacing: 2px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.55);
  background: rgba(0, 0, 0, 0.3);
  padding: 3px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.mobile-controls {
  display: none;
  gap: 12px;
  padding: 10px;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}
.btn-mobile { flex: 1; min-height: 52px; font-size: 16px; }

.game-footer { padding: 6px 14px 12px; text-align: center; }
.hint-text { color: var(--ink-dim); font-size: 12px; letter-spacing: 1px; }

/* ---------- Modals ---------- */
.modal {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(4, 7, 18, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 40;
  padding: 18px;
}
.modal.open { display: flex; }
.modal-card {
  background: linear-gradient(180deg, #1a2148, #10152f);
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  padding: clamp(20px, 4vw, 32px);
  width: min(92vw, 420px);
  text-align: center;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 24px 70px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.08);
}
.modal-card h2 {
  font-size: clamp(22px, 5vw, 30px);
  letter-spacing: 2.5px;
  font-weight: 900;
  margin-bottom: 10px;
  background: linear-gradient(180deg, #fff, #9cd7ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.modal-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.modal-buttons .btn { width: 100%; }

.complete-stats { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--ink-dim); }
.complete-stats b { color: var(--ink); }
.complete-score {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 14px;
  padding: 10px 16px;
  background: rgba(0, 229, 255, 0.1);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  font-weight: 800;
  letter-spacing: 1.5px;
  font-size: 14px;
}
.score-gain { color: var(--green); font-size: 24px; text-shadow: 0 0 14px rgba(55, 255, 139, 0.6); }
.gameover-line { color: var(--ink-dim); font-size: 15px; }
.gameover-line b { color: var(--ink); }

/* Level intro */
.level-intro { z-index: 35; pointer-events: none; }
.intro-card { text-align: center; padding: 22px 40px; }
.intro-name { color: var(--cyan); font-size: 18px; letter-spacing: 2px; margin-top: 4px; }
.intro-count { color: var(--gold); font-weight: 800; letter-spacing: 2px; margin-top: 8px; }

/* Toast */
.toast {
  position: absolute;
  z-index: 80;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%);
  background: rgba(10, 15, 34, 0.95);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  padding: 10px 22px;
  font-weight: 700;
  letter-spacing: 1px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 86vw;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.toast.show { opacity: 1; }

/* Keyboard focus visibility */
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }