/* ==========================================================
   COLOR SORT WATER — stylesheet
   Main game UI styling. Glassmorphism + soft purple theme.
========================================================== */

:root {
  /* Palette */
  --bg-0: #0e0a2a;
  --bg-1: #1a1147;
  --bg-2: #2a1a6d;
  --bg-glow-a: #5b3df0;
  --bg-glow-b: #ff5ea8;
  --bg-glow-c: #42d3ff;

  --ink-0: #ffffff;
  --ink-1: #e9e7ff;
  --ink-2: #b9b6e0;
  --ink-3: #807da6;

  --glass-bg: rgba(255, 255, 255, 0.07);
  --glass-bg-strong: rgba(255, 255, 255, 0.13);
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-border-strong: rgba(255, 255, 255, 0.28);

  --accent: #9d6cff;
  --accent-2: #ff6fb8;
  --success: #4be8a9;
  --danger: #ff5470;

  --shadow-card: 0 10px 40px rgba(0, 0, 0, 0.35);
  --shadow-btn: 0 6px 24px rgba(157, 108, 255, 0.45);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.18);

  --radius-card: 22px;
  --radius-pill: 999px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

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

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  background: var(--bg-0);
  color: var(--ink-0);
  font-family: var(--font);
  font-size: 16px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  text-rendering: optimizeLegibility;
}

body {
  background:
    radial-gradient(120% 70% at 10% 0%, rgba(91, 61, 240, 0.45) 0%, transparent 55%),
    radial-gradient(120% 70% at 90% 100%, rgba(255, 94, 168, 0.35) 0%, transparent 55%),
    radial-gradient(120% 90% at 50% 50%, rgba(66, 211, 255, 0.15) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  background-attachment: fixed;
}

button { font-family: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }
input { font-family: inherit; }

/* ==========================================================
   SCREEN SYSTEM
========================================================== */
.screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: none;
  flex-direction: column;
  z-index: 1;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen.active { display: flex; }
.screen.modal { background: rgba(8, 5, 30, 0.55); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); z-index: 50; align-items: center; justify-content: center; padding: 24px; }

/* ==========================================================
   LOADING SCREEN
========================================================== */
#loading-screen {
  align-items: center; justify-content: center;
  gap: 18px;
  z-index: 80;
}
.loading-orb {
  width: 88px; height: 88px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: var(--shadow-btn);
  position: relative;
  animation: orbFloat 2.6s ease-in-out infinite;
}
.loading-orb::after {
  content: ""; position: absolute; inset: 14px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,.6) 0%, transparent 60%);
  opacity: .7;
}
@keyframes orbFloat { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-12px) rotate(3deg); } }
.loading-title {
  font-size: 26px; font-weight: 800; letter-spacing: 0.5px;
  background: linear-gradient(135deg, #fff 0%, #c9b9ff 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.loading-bar {
  width: min(280px, 60vw); height: 6px;
  background: var(--glass-bg); border-radius: var(--radius-pill);
  overflow: hidden;
}
.loading-bar-fill {
  width: 0%; height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-2) 100%);
  border-radius: var(--radius-pill);
  transition: width 0.2s linear;
  box-shadow: 0 0 16px rgba(157, 108, 255, 0.6);
}
.loading-percent { font-size: 12px; color: var(--ink-2); }

/* ==========================================================
   BUBBLES (ambient)
========================================================== */
.bubbles {
  position: absolute; inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.bubbles .bubble {
  position: absolute; bottom: -40px;
  width: var(--s, 18px); height: var(--s, 18px);
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,.6) 0%, rgba(255,255,255,.1) 50%, transparent 75%);
  animation: bubbleRise var(--d, 14s) linear infinite;
  animation-delay: var(--dl, 0s);
  opacity: var(--o, 0.4);
}
@keyframes bubbleRise {
  0% { transform: translate(0, 0) scale(1); opacity: 0; }
  10% { opacity: var(--o, 0.4); }
  100% { transform: translate(var(--dx, 30px), -120vh) scale(0.7); opacity: 0; }
}

/* ==========================================================
   MENU
========================================================== */
.menu-bg-orb {
  position: absolute; border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
}
.menu-bg-orb--a { top: -200px; left: -100px; width: 480px; height: 480px; background: var(--bg-glow-a); opacity: 0.5; animation: float1 12s ease-in-out infinite; }
.menu-bg-orb--b { bottom: -200px; right: -150px; width: 520px; height: 520px; background: var(--bg-glow-b); opacity: 0.4; animation: float2 14s ease-in-out infinite; }
@keyframes float1 { 0%, 100% { transform: translate(0,0); } 50% { transform: translate(50px, 60px); } }
@keyframes float2 { 0%, 100% { transform: translate(0,0); } 50% { transform: translate(-60px, -50px); } }

.menu-content {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%;
  padding: 36px 24px;
  gap: 28px;
  text-align: center;
}

.menu-title-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.menu-title {
  font-size: clamp(36px, 9vw, 56px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -1.5px;
  margin: 0;
  background: linear-gradient(180deg, #ffffff 0%, #c9b9ff 80%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  text-shadow: 0 4px 24px rgba(157, 108, 255, 0.35);
}
.menu-title span {
  background: linear-gradient(135deg, var(--bg-glow-c) 0%, var(--accent-2) 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.menu-subtitle { color: var(--ink-2); font-size: 14px; letter-spacing: 2px; text-transform: uppercase; margin: 0; }

.menu-main-bottles {
  display: flex; gap: 12px; margin: 12px 0;
  align-items: flex-end;
}
.menu-bottle {
  width: 36px; height: 80px;
  border: 2px solid rgba(255,255,255,.4);
  border-top: 6px solid rgba(220,220,220,.85);
  border-radius: 8px 8px 14px 14px;
  position: relative;
  background: rgba(255,255,255,.05);
  animation: bottleBob 3s ease-in-out infinite;
}
.menu-bottle-fill {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 100%;
  background: linear-gradient(180deg, var(--c) 0%, color-mix(in srgb, var(--c) 70%, #000) 100%);
  border-radius: 0 0 12px 12px;
}
.menu-bottle:nth-child(1) { animation-delay: 0s; }
.menu-bottle:nth-child(2) { animation-delay: 0.2s; height: 95px; }
.menu-bottle:nth-child(3) { animation-delay: 0.4s; }
.menu-bottle:nth-child(4) { animation-delay: 0.6s; height: 90px; }
@keyframes bottleBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

.menu-buttons {
  display: flex; flex-direction: column; gap: 12px;
  width: min(320px, 86vw);
}
.menu-footer {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
  right: 24px;
  display: flex; gap: 10px;
}

/* ==========================================================
   BUTTONS
========================================================== */
.btn {
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  padding: 14px 18px;
  font-size: 16px; font-weight: 700;
  border-radius: var(--radius-card);
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
  position: relative;
  overflow: hidden;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: white;
  box-shadow: var(--shadow-btn);
}
.btn-primary::before {
  content: ""; position: absolute; inset: 1px; border-radius: calc(var(--radius-card) - 1px);
  background: linear-gradient(180deg, rgba(255,255,255,.2) 0%, transparent 50%);
  pointer-events: none;
}
.btn-secondary {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border-strong);
  color: white;
  backdrop-filter: blur(12px);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--ink-1);
}
.btn-ghost:hover { background: var(--glass-bg); }
.btn-danger { color: #ffb5c2; border-color: rgba(255, 84, 112, 0.45); }

.btn-label { font-size: 17px; }
.btn-hint { font-size: 12px; opacity: 0.85; margin-top: 2px; font-weight: 500; letter-spacing: 0.5px; color: rgba(255,255,255,.85); }

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px);
  transition: background .15s ease, transform .15s ease;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 20px; height: 20px; fill: white; }
.icon-btn .ico-sound { display: block; }
.icon-btn .ico-mute { display: none; }
.icon-btn[data-muted="true"] .ico-sound { display: none; }
.icon-btn[data-muted="true"] .ico-mute { display: block; }
.icon-btn[data-muted="false"] .ico-sound { display: block; }
.icon-btn[data-muted="false"] .ico-mute { display: none; }

/* ==========================================================
   TOPBAR
========================================================== */
.topbar {
  display: flex; align-items: center;
  gap: 8px; padding: 14px 16px;
  position: relative;
  z-index: 5;
}
.topbar-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  backdrop-filter: blur(8px);
}
.topbar-btn:active { transform: scale(0.94); }
.topbar-btn svg { width: 22px; height: 22px; fill: white; }
.topbar-title {
  flex: 1; text-align: center;
  font-weight: 700; font-size: 16px;
  display: flex; justify-content: center; align-items: center; gap: 8px;
}
.topbar-progress { color: var(--ink-2); font-size: 13px; font-weight: 600; min-width: 60px; text-align: right; }
.level-badge {
  display: inline-block; padding: 3px 10px;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 600;
  color: var(--ink-1);
  text-transform: uppercase; letter-spacing: 1px;
}

/* ==========================================================
   LEVEL SELECT
========================================================== */
.levels-tabs {
  display: flex; gap: 6px;
  padding: 0 16px 14px;
  overflow-x: auto;
}
.tab {
  padding: 10px 16px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  color: var(--ink-1);
  font-size: 14px; font-weight: 600;
  white-space: nowrap;
  transition: all .2s ease;
}
.tab.active {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(157, 108, 255, 0.5);
}
.levels-grid {
  flex: 1;
  overflow-y: auto;
  padding: 6px 16px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}
.level-card {
  aspect-ratio: 1 / 1;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  position: relative;
  transition: transform .15s ease, background .15s ease;
  font-weight: 700;
}
.level-card:active { transform: scale(0.96); }
.level-card.locked { opacity: 0.5; }
.level-card.completed { background: var(--glass-bg-strong); border-color: rgba(75, 232, 169, 0.4); }
.level-card.current { box-shadow: 0 0 0 2px rgba(157, 108, 255, 0.7), 0 0 24px rgba(157, 108, 255, 0.5); }
.level-card-num { font-size: 20px; color: white; }
.level-card-mini {
  display: flex; gap: 2px; margin-top: 4px;
}
.level-card-mini span { width: 4px; height: 8px; border-radius: 2px; background: var(--mini, white); }
.level-card-stars { font-size: 9px; margin-top: 2px; color: #ffd166; letter-spacing: 1px; }
.level-card-lock { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; color: rgba(255,255,255,.6); }

/* ==========================================================
   GAME SCREEN
========================================================== */
.game-hud {
  display: flex; justify-content: space-around;
  padding: 6px 16px 10px;
  gap: 10px;
}
.hud-stat {
  flex: 1;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 8px 12px;
  text-align: center;
  backdrop-filter: blur(8px);
}
.hud-label { font-size: 10px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: 1.5px; }
.hud-value { font-size: 22px; font-weight: 800; color: white; margin-top: 1px; line-height: 1; }

#game-canvas {
  flex: 1; width: 100%;
  min-width: 0; min-height: 0;   /* prevents intrinsic canvas size from overriding flex layout */
  display: block;
  background: transparent;
  touch-action: none;
}

.game-actions {
  display: flex; gap: 10px;
  padding: 10px 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
  background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.25) 50%);
}
.game-action-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  padding: 12px 8px;
  color: white;
  font-size: 13px; font-weight: 600;
  backdrop-filter: blur(8px);
  transition: transform .12s ease, background .12s ease;
}
.game-action-btn:active { transform: scale(0.96); background: rgba(255,255,255,0.18); }
.game-action-btn.disabled { opacity: 0.45; pointer-events: none; }
.game-action-btn svg { width: 18px; height: 18px; fill: white; }

/* ==========================================================
   MODALS
========================================================== */
.modal-card {
  position: relative;
  background: rgba(20, 16, 60, 0.85);
  border: 1px solid var(--glass-border-strong);
  border-radius: 26px;
  padding: 28px 22px 22px;
  width: min(380px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  text-align: center;
  animation: modalIn 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal-card--wide { width: min(440px, 94vw); text-align: left; }
@keyframes modalIn { from { transform: translateY(20px) scale(0.95); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
.modal-title { margin: 0 0 14px; font-size: 22px; font-weight: 800; }
.modal-subtitle { margin: 18px 0 8px; font-size: 14px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 1.5px; font-weight: 700; }
.modal-buttons { display: flex; gap: 10px; margin-top: 20px; justify-content: center; }

.howto-list { padding-left: 22px; margin: 0 0 8px; line-height: 1.55; font-size: 14.5px; color: var(--ink-1); }
.howto-list li { margin-bottom: 8px; }
.howto-list b { color: white; }

/* Win */
.win-emoji { font-size: 48px; margin-bottom: 4px; }
.win-title { margin: 6px 0 14px; font-size: 26px; font-weight: 900;
  background: linear-gradient(135deg, #ffd166 0%, #ff6fb8 50%, #9d6cff 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.win-stars { font-size: 36px; letter-spacing: 6px; margin-bottom: 14px; }
.win-stars .star { display: inline-block; color: rgba(255,255,255,.2); transition: all .3s ease; }
.win-stars.has-1 .star:nth-child(-n+1) { color: #ffd166; text-shadow: 0 0 18px rgba(255,209,102,.7); transform: scale(1.05); }
.win-stars.has-2 .star:nth-child(-n+2) { color: #ffd166; text-shadow: 0 0 18px rgba(255,209,102,.7); transform: scale(1.1); }
.win-stars.has-3 .star { color: #ffd166; text-shadow: 0 0 22px rgba(255,209,102,.8); transform: scale(1.15); }
.win-stars.has-3 .star:nth-child(1) { animation: starPop 0.5s 0.2s both; }
.win-stars.has-3 .star:nth-child(2) { animation: starPop 0.5s 0.5s both; }
.win-stars.has-3 .star:nth-child(3) { animation: starPop 0.5s 0.8s both; }
@keyframes starPop { from { transform: scale(0); opacity: 0; } to { transform: scale(1.15); opacity: 1; } }
.win-stats { display: flex; justify-content: center; gap: 28px; margin: 16px 0 4px; }
.win-stat { text-align: center; }
.win-stat-label { font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 1.5px; font-weight: 600; }
.win-stat-value { font-size: 32px; font-weight: 800; }

/* Timer */
.timer-stat .hud-value { transition: color .3s ease; }
.timer-stat .hud-value.timer-warn { color: #ffd166; }
.timer-stat .hud-value.timer-critical { color: #ff6b6b; }

/* Lose */
.lose-emoji { font-size: 48px; margin-bottom: 4px; }
.lose-title { margin: 6px 0 8px; font-size: 26px; font-weight: 900; color: #ff6b6b; }
.lose-sub { margin: 0; font-size: 14px; color: var(--ink-2); line-height: 1.4; }


.win-buttons { display: flex; gap: 10px; }
.win-buttons .btn { flex: 1; }

/* Confetti */
.confetti {
  position: absolute; inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: inherit;
}
.confetti span {
  position: absolute;
  width: 8px; height: 12px;
  background: var(--conf, #ff6fb8);
  top: -20px;
  opacity: 0;
  animation: confettiFall var(--d, 3s) ease-in var(--dl, 0s) forwards;
  transform: rotate(var(--r, 0deg));
}
@keyframes confettiFall {
  0% { transform: translate(0, -20px) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--tx, 40px), 380px) rotate(var(--rr, 540deg)); opacity: 0; }
}

/* ==========================================================
   SETTINGS
========================================================== */
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 4px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.setting-label { font-size: 15px; font-weight: 600; }
.setting-row--reset { justify-content: center; border: 0; padding-top: 18px; }

.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer;
  inset: 0;
  background: rgba(255,255,255,.15);
  border-radius: var(--radius-pill);
  transition: .25s;
}
.switch-slider::before {
  position: absolute; content: "";
  height: 22px; width: 22px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: .25s cubic-bezier(0.4, 1.4, 0.6, 1);
}
.switch input:checked + .switch-slider { background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%); }
.switch input:checked + .switch-slider::before { transform: translateX(22px); }

/* ==========================================================
   FULLSCREEN TOGGLE
========================================================== */
.fs-toggle {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  right: 12px;
  z-index: 100;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.fs-toggle:active { transform: scale(0.9); background: rgba(255,255,255,0.2); }
.fs-toggle svg { width: 18px; height: 18px; fill: white; opacity: 0.7; }
.fs-toggle .ico-fs-enter { display: block; }
.fs-toggle .ico-fs-exit { display: none; }
.fs-toggle.is-fullscreen .ico-fs-enter { display: none; }
.fs-toggle.is-fullscreen .ico-fs-exit { display: block; }

@media (orientation: landscape) and (max-height: 500px) {
  .fs-toggle { top: 4px; right: 8px; width: 30px; height: 30px; }
  .fs-toggle svg { width: 15px; height: 15px; }
}

/* ==========================================================
   BANNER AD PLACEHOLDER
========================================================== */
.banner-ad {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 0px);
  z-index: 6;
  pointer-events: none;
}
.banner-ad-inner {
  background: rgba(255,255,255,.06);
  border-top: 1px solid rgba(255,255,255,.12);
  border-radius: 12px 12px 0 0;
  padding: 8px 16px;
  font-size: 12px; color: var(--ink-3);
  display: flex; gap: 8px; align-items: center;
}
.banner-ad-tag {
  background: rgba(255,255,255,.18); padding: 2px 6px; border-radius: 4px;
  font-weight: 700; font-size: 10px; letter-spacing: 1px;
}

/* ==========================================================
   PERSISTENT UTILS
========================================================== */
.no-scroll { overflow: hidden; }

.dim-screen { animation: dimScreen 0.5s ease forwards; }
@keyframes dimScreen { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================================
   TUTORIAL OVERLAY (levels 1-3 inactivity hint)
========================================================== */
.tutorial-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.tutorial-overlay.visible { opacity: 1; }
.tutorial-overlay[hidden] { display: none; }

.tutorial-ghost {
  position: absolute;
  border-radius: 18px;
  border: 4px solid rgba(255, 230, 140, 0.85);
  background: rgba(255, 230, 140, 0.12);
  box-shadow: 0 0 36px rgba(255, 209, 102, 0.65), inset 0 0 18px rgba(255, 230, 140, 0.35);
  pointer-events: none;
  display: none;
  transform-origin: center;
  animation: tutorialGhostPulse 1.8s ease-in-out infinite;
}
.tutorial-overlay.visible .tutorial-ghost { display: block; }
.tutorial-overlay.visible .tutorial-ghost.step-a { animation-delay: 0s; }
.tutorial-overlay.visible .tutorial-ghost.step-b { animation-delay: 0.9s; }
@keyframes tutorialGhostPulse {
  0%, 100% { transform: scale(1.00); box-shadow: 0 0 36px rgba(255, 209, 102, 0.65), inset 0 0 18px rgba(255, 230, 140, 0.35); }
  50%      { transform: scale(1.06); box-shadow: 0 0 56px rgba(255, 209, 102, 0.85), inset 0 0 24px rgba(255, 230, 140, 0.45); }
}

.tutorial-arrow {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  display: none;
  overflow: visible;
}
.tutorial-overlay.visible .tutorial-arrow { display: block; }
.tutorial-arrow path { animation: tutorialArrowMarch 0.9s linear infinite; }
@keyframes tutorialArrowMarch {
  to { stroke-dashoffset: -24; }
}
.tutorial-card {
  background: rgba(20, 16, 60, 0.78);
  border: 1px solid rgba(255, 230, 140, 0.55);
  border-radius: 18px;
  padding: 14px 36px 14px 18px;
  color: white;
  text-align: left;
  max-width: min(320px, 84vw);
  box-shadow: 0 6px 28px rgba(255, 209, 102, 0.35);
  animation: tutorialCardPulse 2.4s ease-in-out infinite;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: relative;
}
.tutorial-card::before {
  content: ""; position: absolute;
  left: 14px; top: -10px; width: 18px; height: 18px;
  background: linear-gradient(135deg, #ffe680 0%, #ff9a3c 100%);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(255, 209, 102, 0.5);
  animation: tutorialPointer 1.6s ease-in-out infinite;
}
@keyframes tutorialCardPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
@keyframes tutorialPointer {
  0%, 100% { transform: rotate(-45deg) translate(0, 0); }
  50% { transform: rotate(-45deg) translate(-4px, -2px); }
}
.tutorial-step { font-size: 15px; font-weight: 700; letter-spacing: 0.2px; }
.tutorial-sub { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.tutorial-dismiss {
  position: absolute;
  top: 4px; right: 6px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  font-size: 18px; line-height: 1;
  pointer-events: auto;
  transition: background .15s ease, color .15s ease;
}
.tutorial-dismiss:active { transform: scale(0.92); background: rgba(255,255,255,0.18); color: white; }

/* ==========================================================
   RESPONSIVE
========================================================== */
@media (max-width: 360px) {
  .hud-value { font-size: 19px; }
  .game-action-btn span { font-size: 12px; }
  .game-action-btn svg { width: 16px; height: 16px; }
}
@media (min-width: 720px) {
  .levels-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 14px; }
}
@media (min-height: 900px) {
  .menu-title { font-size: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* ==========================================================
   LANDSCAPE ORIENTATION — compact layout for wide screens
   ========================================================== */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { padding: 6px 12px; }
  .topbar-title { font-size: 13px; }
  .topbar-btn { width: 32px; height: 32px; }
  .topbar-btn svg { width: 18px; height: 18px; }
  .level-badge { font-size: 9px; padding: 2px 8px; }

  .game-hud {
    position: absolute;
    top: 48px; left: 8px;
    z-index: 10;
    gap: 4px;
    padding: 0;
    flex-direction: column;
    width: auto;
  }
  .hud-stat {
    padding: 4px 8px;
    border-radius: 10px;
    backdrop-filter: blur(12px);
    background: rgba(20, 16, 60, 0.7);
  }
  .hud-label { font-size: 8px; }
  .hud-value { font-size: 14px; }
  #game-canvas { flex: 1; }

  .game-actions {
    position: absolute;
    bottom: 8px; left: 50%;
    transform: translateX(-50%);
    gap: 6px;
    padding: 6px 10px;
    background: rgba(20, 16, 60, 0.7);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    z-index: 10;
    width: auto;
  }
  .game-action-btn {
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 11px;
    flex: none;
  }
  .game-action-btn svg { width: 14px; height: 14px; }
  .game-action-btn span { display: none; }
}

@media (orientation: landscape) and (min-height: 501px) and (max-height: 700px) {
  .game-hud { padding: 4px 12px 6px; gap: 6px; }
  .hud-stat { padding: 4px 10px; }
  .hud-value { font-size: 18px; }
  .game-actions { padding: 6px 12px; gap: 6px; }
  .game-action-btn { padding: 8px 10px; font-size: 12px; }
  .game-action-btn svg { width: 16px; height: 16px; }
}
