:root{
  --bg1:#4b0aa3;
  --bg2:#140a2b;
  --glass:#d8d8ff;
  --glass2:#ffffff;
  --shadow: rgba(0,0,0,.35);
  --btn:#2a1b57;
  --btn2:#3a2a74;
  --text:#ffffff;
  --portraitWidth: min(96vw, calc(96dvh * 9 / 16), 560px);
  --portraitHeight: min(96dvh, calc(96vw * 16 / 9), calc(560px * 16 / 9));
}

/* ============ RESET & BASE ============ */
*{box-sizing:border-box}
html, body{
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* NO SCROLLING */
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 0%, #6b1bd6 0%, var(--bg1) 35%, var(--bg2) 100%);
}

/* Starry background - full screen */
#bg{
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(2px 2px at 15% 70%, rgba(255,255,255,.35) 50%, transparent 55%),
    radial-gradient(2px 2px at 35% 82%, rgba(255,255,255,.25) 50%, transparent 55%),
    radial-gradient(1px 1px at 62% 75%, rgba(255,255,255,.28) 50%, transparent 55%),
    radial-gradient(2px 2px at 80% 65%, rgba(255,255,255,.22) 50%, transparent 55%),
    radial-gradient(1px 1px at 78% 90%, rgba(255,255,255,.25) 50%, transparent 55%),
    radial-gradient(1px 1px at 10% 90%, rgba(255,255,255,.18) 50%, transparent 55%);
  opacity: .7;
  z-index: 0;
}

/* ============ SPLASH SCREEN (Portrait Container) ============ */
.portrait-root{
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: var(--portraitWidth);
  height: var(--portraitHeight);
  margin: auto;
  z-index: 9999;
  pointer-events: auto;
  transition: opacity 0.4s ease;
}
.portrait-root.splash-hidden{
  opacity: 0;
  pointer-events: none;
}

.splash-screen{
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 24px;
  border: 2px solid rgba(255,255,255,0.1);
}
.splash-bg{
  position: absolute;
  inset: 0;
  background: url("assets/splash_background.png") center center / cover no-repeat;
  background-color: #4b0aa3; /* fallback if image fails */
}

/* Loading UI: centered inside portrait root (no fixed) */
.loadingWrap{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 92%;
  max-width: 360px;
  text-align: center;
  z-index: 1;
}
.splash-loading-text{
  color: #fff;
  font-size: clamp(20px, 3.6vw, 28px);
  font-weight: 700;
  margin-bottom: 14px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.splash-progress-wrap{
  width: 100%;
  height: clamp(14px, 2.2vw, 18px);
  border-radius: 999px;
  background: rgba(255,255,255,0.2);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.3), 0 0 16px rgba(55, 168, 255, 0.35);
}
.splash-progress-bar{
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #8e3cff 0%, #e040fb 50%, #37a8ff 100%);
  background-size: 200% 100%;
  transition: width 0.12s linear;
  box-shadow: 0 0 12px rgba(168, 85, 255, 0.6);
}

.splash-error{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  padding: 20px;
  z-index: 2;
}
.splash-error p{
  color: #fff;
  margin: 0 0 14px;
  font-weight: 700;
}
.splash-error[hidden]{
  display: none !important;
}

/* ============ PORTRAIT CANVAS ============ */
.game-viewport{
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: var(--portraitWidth);
  height: var(--portraitHeight);
  background: linear-gradient(180deg, rgba(75, 10, 163, 0.3) 0%, rgba(20, 10, 43, 0.5) 100%);
  border-radius: 24px;
  border: 2px solid rgba(255,255,255,0.1);
  box-shadow: 
    0 0 60px rgba(107, 27, 214, 0.4),
    0 25px 80px rgba(0,0,0,0.5),
    inset 0 0 30px rgba(107, 27, 214, 0.2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 1;
  touch-action: none;
}

/* ============ SCREENS ============ */
.screen{
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.screen.active{
  display: flex;
}

/* ============ MENU PANEL ============ */
.panel{
  width: 100%;
  max-width: 320px;
  padding: 24px 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.06));
  box-shadow: 0 18px 60px var(--shadow);
  border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(6px);
  text-align: center;
}

/* Keep only one main container visual on menu */
.menu-screen{
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6vh 0 4vh;
}
#menuScreen .panel{
  max-width: min(560px, 92%);
  width: min(560px, 92%);
  height: 100%;
  padding: clamp(16px, 3vh, 30px) clamp(18px, 4vw, 36px) clamp(12px, 2.2vh, 20px);
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  position: relative;
}
#menuScreen{
  position: relative;
  z-index: 10;
}
.menuSettingsBtn{
  position: absolute;
  top: 14px;
  right: 14px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.35);
  background: linear-gradient(180deg, #ffe45a 0%, #f2b700 100%);
  box-shadow: 0 10px 22px rgba(0,0,0,.3), 0 0 14px rgba(255, 208, 47, .45);
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 12;
}
.menuSettingsBtn svg{
  width: 24px;
  height: 24px;
  fill: none;
  stroke: #111;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.menuSettingsPopup{
  position: absolute;
  top: 72px;
  right: 14px;
  width: 210px;
  border-radius: 16px;
  background: rgba(14, 22, 50, .92);
  border: 1px solid rgba(255,255,255,.2);
  box-shadow: 0 12px 28px rgba(0,0,0,.35);
  backdrop-filter: blur(8px);
  padding: 10px;
  z-index: 13;
}
.menuSettingsPopup[hidden]{
  display: none !important;
}
.menuSettingsHeader{
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 8px;
}
.menuSettingsClose{
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.menuToggleBtn{
  width: 100%;
  height: 42px;
  margin-top: 8px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.24);
  background: linear-gradient(180deg, rgba(56, 203, 122, .94), rgba(30, 152, 86, .94));
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.menuToggleBtn.off{
  background: linear-gradient(180deg, rgba(244, 94, 94, .95), rgba(182, 46, 46, .95));
}

#menuScreen .logo{
  width: clamp(240px, 58vw, 420px);
  margin: clamp(10px, 2.6vh, 24px) auto clamp(14px, 2.8vh, 22px);
}
.logo-wrap{
  margin: 6vh 0 4vh;
}

.menu-buttons{
  display: flex;
  flex-direction: column;
  gap: 2.2vh;
  width: min(82vw, 340px);
  max-width: 340px;
  margin: 0 auto;
}

#menuScreen .btn{
  margin-top: 0;
  padding: clamp(12px, 2vh, 18px) clamp(14px, 2vw, 20px);
  font-size: clamp(18px, 2.4vw, 30px);
  border-radius: 16px;
}

#menuScreen .devBy{
  margin-top: 0;
  font-size: clamp(12px, 3.2vw, 15px);
}
#menuScreen .footer{
  margin-top: auto;
  margin-bottom: 0;
  padding-top: 2vh;
  opacity: .9;
  text-align: center;
}

/* Always lift menu action block on desktop */
@media (min-width: 521px){
  #menuScreen .menu-screen{ transform: none; }
}

@media (max-width: 520px){
  #menuScreen .menu-screen{ transform: none; }
  #menuScreen .btn{
    margin-top: 0;
  }
  .menu-buttons{ width: 88vw; gap: 16px; }
  .logo-wrap{ margin: 5vh 0 3vh; }
  .menu-screen{ padding-bottom: 3vh; }
}

/* Desktop/laptop height responsiveness for main menu */
@media (min-width: 521px) and (max-height: 920px){
  #menuScreen .menu-screen{ transform: none; }
  #menuScreen .logo{
    width: clamp(220px, 42vw, 360px);
    margin: 8px auto 14px;
  }
  #menuScreen .btn{
    margin-top: 9px;
    padding: 11px 16px;
    font-size: clamp(24px, 2vw, 30px);
  }
  #menuScreen .devBy{
    margin-top: 7px;
    font-size: 14px;
  }
}

@media (min-width: 521px) and (max-height: 780px){
  #menuScreen .menu-screen{ transform: none; }
  #menuScreen .logo{
    width: clamp(200px, 38vw, 320px);
    margin: 6px auto 10px;
  }
  #menuScreen .btn{
    margin-top: 8px;
    padding: 10px 14px;
    font-size: clamp(20px, 1.8vw, 26px);
  }
  #menuScreen .devBy{
    margin-top: 6px;
    font-size: 13px;
  }
}

.menu-logo{
  position: relative;
  min-height: 60px;
}
.menu-logo.logo-failed .logo{
  display: none;
}
.menu-logo.logo-failed .logo-fallback{
  display: block;
}

.logo{
  width: 85%;
  max-width: 420px;
  height: auto;
  display: block;
  margin: 24px auto 16px;
  pointer-events: none;
  user-select: none;
  animation: logo-enter 0.4s ease-out;
}
@keyframes logo-enter{
  0%{ opacity: 0; transform: scale(0.9); }
  100%{ opacity: 1; transform: scale(1); }
}

.logo-fallback{
  display: none;
  margin: 24px auto 16px;
  font-size: clamp(22px, 6vw, 32px);
  font-weight: 800;
  letter-spacing: .5px;
  line-height: 1.2;
  background: linear-gradient(135deg, #ff4bd1 0%, #8e3cff 50%, #37a8ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
}
.devBy{
  margin-top: 14px;
  opacity: .85;
  font-weight: 600;
  font-size: 13px;
}

/* ============ TOP BAR ============ */
.topbar{
  position: relative;
  flex-shrink: 0;
  width: calc(100% - 20px);
  height: 50px;
  margin: 10px auto 0;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.06));
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 10px 40px var(--shadow);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  z-index: 5;
}
.topTitle{
  font-weight: 800;
  font-size: clamp(18px, 5vw, 24px);
  letter-spacing: .3px;
}
.topRight{width: 40px}

.iconBtn{
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.18);
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.04));
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.iconBtn:active{transform: scale(.96)}

/* Game topbar redesign */
.gameTopbar{
  margin-top: 12px;
  height: 72px;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  padding: 0 12px;
  overflow: hidden;
  width: calc(100% - 24px);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  z-index: 50;
}
.topbar-left{
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 1;
}
.topbar-left,
.header-left{
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-btn{
  width: 56px !important;
  height: 56px !important;
  min-width: 56px !important;
  min-height: 56px !important;
  display: flex;
  align-items: center;
  justify-content: center;
}
.uiRoundBtn{
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.24);
  background: linear-gradient(180deg, #4ad4ff 0%, #2d8eff 100%);
  box-shadow:
    0 10px 22px rgba(0,0,0,.35),
    0 0 16px rgba(71, 200, 255, .45),
    inset 0 2px 4px rgba(255,255,255,.28);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .16s ease;
}
.uiRoundBtn svg{
  width: 23px;
  height: 23px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.uiRoundBtn:active{
  transform: scale(.95);
}

/* Gameplay-only yellow/black theme for Back */
#btnBackFromGame.uiRoundBtn{
  background: linear-gradient(180deg, #FFD84D 0%, #FFC107 100%);
  border: 2px solid rgba(0,0,0,0.4);
  color: #000000;
  border-radius: 50%;
  box-shadow:
    0 4px 10px rgba(0,0,0,0.25),
    inset 0 2px 4px rgba(255,255,255,0.4);
}

#btnBackFromGame.uiRoundBtn svg{
  stroke: #000000;
  fill: #000000;
}

/* Gameplay Restart button: icon only (no circle/background) */
#btnRestart.uiRoundBtn{
  width: 56px !important;
  height: 56px !important;
  min-width: 56px !important;
  min-height: 56px !important;
  border-radius: 0;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* No extra overlays/decorations on restart button/icon */
.restart-btn::before,
.restart-btn::after,
.restart-icon::before,
.restart-icon::after{
  content: none !important;
  display: none !important;
}

#btnRestart.uiRoundBtn .restart-icon{
  width: 165%;
  height: 165%;
  display: block;
  object-fit: contain;
  opacity: 1;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  filter: none !important;
}

#btnBackFromGame.uiRoundBtn:hover{
  transform: scale(1.05);
  filter: brightness(1.05);
}

#btnBackFromGame.uiRoundBtn:active{
  transform: scale(0.95);
  box-shadow: inset 0 3px 6px rgba(0,0,0,0.3);
}

#btnRestart.uiRoundBtn:active{
  transform: scale(0.92);
  box-shadow: none !important;
}
.gameLevelTitle{
  position: static;
  transform: none;
  margin: 0;
  font-size: clamp(18px, 5vw, 28px);
  font-weight: 900;
  color: #fff;
  letter-spacing: .8px;
  text-shadow: 0 4px 18px rgba(0,0,0,.45);
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  justify-self: center;
  max-width: 100%;
}
.coinWrap{
  position: relative;
  z-index: 1;
  justify-self: end;
}
.coinPill{
  position: relative;
  min-width: 108px;
  height: 52px;
  border-radius: 18px;
  padding: 0 12px 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(9, 16, 38, .62);
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 10px 24px rgba(0,0,0,.35);
  backdrop-filter: blur(8px);
}
.coinIcon{
  width: clamp(20px, 5vw, 24px);
  height: clamp(20px, 5vw, 24px);
  flex-shrink: 0;
}
.coinPill .coins-display{
  color: #fff;
  font-size: clamp(18px, 5.2vw, 22px);
  font-weight: 800;
  letter-spacing: .2px;
  line-height: 1;
}
/* ============ BUTTONS ============ */
.btn{
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.14);
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.06));
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  margin-top: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.btn.primary{
  background: linear-gradient(180deg, rgba(255,255,255,.18), rgba(255,255,255,.08));
}
.btn:active{transform: scale(.98)}

/* ============ LEVELS SCREEN ============ */
#levelsScreen{
  justify-content: flex-start;
  padding: 0;
}
#levelsScreen .topbar{
  margin-top: 10px;
}
.levelsWrap{
  flex: 1;
  width: 100%;
  padding: 15px 12px;
  overflow-y: auto;
  overflow-x: hidden;
}
.levelsGrid{
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 5px;
}
.levelTile{
  aspect-ratio: 1;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,.14);
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.06));
  box-shadow: 0 6px 16px rgba(0,0,0,.16);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: clamp(22px, 5.2vw, 30px);
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease;
}
.levelTile .colors-label{
  font-size: clamp(10px, 2.2vw, 13px);
  font-weight: 700;
  opacity: 0.92;
  margin-top: 7px;
  letter-spacing: .2px;
}
.levelTile:active:not(.locked){
  transform: scale(0.95);
}
.levelTile.locked{
  opacity: .4;
  cursor: not-allowed;
  font-size: clamp(22px, 5vw, 28px);
}
.levelTile.current{
  outline: 2px solid rgba(56, 255, 122, 0.8);
  background: linear-gradient(180deg, rgba(56, 255, 122, 0.2), rgba(56, 255, 122, 0.08));
}

/* Difficulty colors */
.levelTile[data-colors="3"],
.levelTile[data-colors="4"]{
  border-color: rgba(56, 255, 122, 0.4);
}
.levelTile[data-colors="5"],
.levelTile[data-colors="6"]{
  border-color: rgba(255, 228, 74, 0.4);
}
.levelTile[data-colors="7"],
.levelTile[data-colors="8"]{
  border-color: rgba(255, 138, 43, 0.4);
}
.levelTile[data-colors="9"],
.levelTile[data-colors="10"]{
  border-color: rgba(255, 59, 59, 0.4);
}
.levelTile[data-colors="11"],
.levelTile[data-colors="12"],
.levelTile[data-colors="13"],
.levelTile[data-colors="14"],
.levelTile[data-colors="15"],
.levelTile[data-colors="16"],
.levelTile[data-colors="17"]{
  border-color: rgba(142, 60, 255, 0.4);
}

@media (max-width: 520px){
  .levelsGrid{
    gap: 10px;
  }
  .levelTile{
    font-size: clamp(20px, 6.2vw, 26px);
  }
  .levelTile .colors-label{
    font-size: clamp(10px, 2.7vw, 12px);
    margin-top: 6px;
  }
}

/* ============ STORE SCREEN ============ */
#storeScreen{
  justify-content: flex-start;
  padding: 0;
}
#storeScreen .topbar{
  margin-top: 10px;
}
.storeTopRight{
  width: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.storeCoinsDisplay{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 170px;
  height: 38px;
  padding: 0 14px;
  border-radius: 14px;
  background: rgba(8, 14, 34, .82);
  border: 1.5px solid rgba(255,255,255,.26);
  color: #ffe88d;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: .2px;
  text-shadow: 0 1px 3px rgba(0,0,0,.35);
  box-shadow: 0 6px 14px rgba(0,0,0,.25);
  white-space: nowrap;
}
.storeWrap{
  flex: 1;
  width: 100%;
  padding: 15px 12px;
  overflow-y: auto;
  overflow-x: hidden;
}
.storeGrid{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 5px;
}
.storeItem{
  position: relative;
  aspect-ratio: 0.75;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,.14);
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.06));
  box-shadow: 0 6px 16px rgba(0,0,0,.16);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, border-color 0.2s ease;
}
.storeItem:active{
  transform: scale(0.95);
}
.storeItem.selected{
  border-color: rgba(56, 255, 122, 0.9);
  box-shadow: 0 0 20px rgba(56, 255, 122, 0.4);
}
.storeItem.locked{
  border-color: rgba(255, 215, 0, 0.45);
}
.storeItem.locked .storePreview{
  filter: grayscale(.55) brightness(.78);
}
.storePreview{
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  background-size: cover;
  background-position: center;
}
.storeLock{
  position: absolute;
  top: 8px;
  left: 8px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0,0,0,.72);
  border: 1.5px solid rgba(255,215,0,.75);
  color: #ffd96e;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  box-shadow: 0 4px 10px rgba(0,0,0,.35);
}
.storeLock svg{
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #ffd96e;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.storeLabel{
  height: 22%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.3);
  padding: 4px;
}
.storeBuyBtn{
  width: calc(100% - 10px);
  height: 40px;
  margin: 5px auto 4px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(56, 203, 122, .92), rgba(30, 152, 86, .92));
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: .2px;
  text-shadow: 0 1px 3px rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}
.storeBuyBtn.owned{
  background: linear-gradient(180deg, rgba(68, 112, 255, .9), rgba(48, 78, 196, .9));
}
.storeBuyBtn svg{
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.storePrice{
  height: 22px;
  min-height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #ffe07a;
  background: rgba(9, 15, 35, 0.72);
  border-top: 1px solid rgba(255,255,255,.12);
}
.storePrice.owned{
  color: #73ffaf;
}

@media (max-width: 520px){
  .storeGrid{
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .storeItem{
    aspect-ratio: 0.78;
  }
}
.storeCheck{
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, #38ff7a 0%, #2dd864 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  color: #1b1333;
  box-shadow: 0 2px 6px rgba(56, 255, 122, 0.6);
  z-index: 10;
}

/* ============ GAME SCREEN ============ */
#gameScreen{
  justify-content: flex-start;
  padding: 0;
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}
#gameScreen .topbar{
  margin-top: 10px;
  flex: 0 0 auto;
}
.gameWrap{
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 70px 8px calc(90px + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
  min-height: 0;
}

/* Board wrapper for scaling */
.boardWrap{
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  max-height: 55vh;
  overflow: hidden;
  padding: 2vh 0;
}

/* Board - CSS Grid for tube layout */
.board{
  display: grid;
  grid-template-columns: repeat(var(--tube-cols, 5), auto);
  gap: 8px;
  padding: 8px;
  justify-content: center;
  align-items: start;
  touch-action: none;
  overflow: visible;
  transform: scale(1.15);
  transform-origin: center center;
  max-height: 55vh;
}

/* ============ TUBES ============ */
.tube{
  width: var(--tube-width, 54px);
  height: var(--tube-height, 172px);
  position: relative;
  background: transparent !important;
  cursor: grab;
  user-select: none;
  transition: transform 0.2s ease, filter 0.2s ease;
  touch-action: none;
  pointer-events: auto;
  filter: drop-shadow(3px 8px 12px rgba(0,0,0,.28));
}
.tube::before,
.tube::after{
  display: none !important;
}
.tube.selected-floating{
  transform: translateY(-20px);
  filter: drop-shadow(0 10px 16px rgba(0,0,0,.25));
}
.tube:active{
  cursor: grabbing;
}
/* Drag ghost - clone that follows pointer */
.tube.drag-ghost{
  cursor: grabbing;
  pointer-events: none !important;
  touch-action: none;
}
.tube.dragging{
  cursor: grabbing;
  filter: drop-shadow(0 16px 24px rgba(0,0,0,.34));
  z-index: 100;
}
.tube.valid-target{
  transform: translateY(-6px) scale(1.05);
  filter: drop-shadow(0 0 10px rgba(110, 216, 132, .45))
          drop-shadow(3px 10px 14px rgba(0,0,0,.30));
}
.tube.valid-target .glass{
  border-color: rgba(255,255,255,.98);
}

/* Completed tube */
.tube.completed{
  cursor: default;
}
.tube.completed .glass{
  border-color: rgba(255,255,255,.98);
}
@keyframes completed-pulse{
  0%, 100%{ 
    box-shadow:
      inset 4px 0 0 rgba(255,255,255,.18),
      inset -4px 0 0 rgba(255,255,255,.08),
      0 0 15px rgba(56, 255, 122, 0.5),
      0 0 30px rgba(56, 255, 122, 0.3);
  }
  50%{ 
    box-shadow:
      inset 4px 0 0 rgba(255,255,255,.18),
      inset -4px 0 0 rgba(255,255,255,.08),
      0 0 20px rgba(56, 255, 122, 0.7),
      0 0 40px rgba(56, 255, 122, 0.4);
  }
}
.tube.completed::after{
  content: "✓";
  position: absolute;
  top: -8px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, #38ff7a 0%, #2dd864 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  color: #1b1333;
  box-shadow: 0 2px 6px rgba(56, 255, 122, 0.6);
  z-index: 10;
  animation: checkmark-appear 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes checkmark-appear{
  0%{ transform: scale(0); opacity: 0; }
  100%{ transform: scale(1); opacity: 1; }
}

/* Tube parts - inner elements don't block pointer events */
.glass{
  position: absolute;
  left: 7px;
  right: 7px;
  top: 16px;
  bottom: 0;
  border-radius: 0 0 24px 24px / 0 0 30px 30px;
  border-left: 3.2px solid rgba(255,255,255,.96);
  border-right: 3.2px solid rgba(255,255,255,.96);
  border-bottom: 3.2px solid rgba(255,255,255,.96);
  border-top: 0;
  background: transparent !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
  pointer-events: none;
}
.glass::before{
  content: "";
  position: absolute;
  left: 5px;
  top: 10px;
  bottom: 18px;
  width: 9px;
  border-radius: 999px;
  background: linear-gradient(
    180deg,
    rgba(255,255,255,.86) 0%,
    rgba(255,255,255,.50) 35%,
    rgba(255,255,255,.14) 100%
  );
  filter: blur(0.2px);
  opacity: .95;
}
.glass::after{
  content: "";
  position: absolute;
  right: 7px;
  top: 20px;
  bottom: 24px;
  width: 4px;
  border-radius: 999px;
  background: linear-gradient(
    180deg,
    rgba(255,255,255,.30) 0%,
    rgba(255,255,255,.08) 100%
  );
  opacity: .55;
}
.tube.empty .glass::before{
  opacity: .85;
}
.neck{
  display: none !important;
}
.liquid{
  position: absolute;
  left: 10px;
  right: 10px;
  top: 19px;
  bottom: 0;
  border-radius: 0 0 20px 20px / 0 0 26px 26px;
  clip-path: inset(0 0 0 0 round 0 0 20px 20px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}
.tube.empty .liquid{
  display: none;
}
.seg{
  width: 100%;
  height: calc(25% + 2px);
  margin: -1px 0 0;
  flex: 0 0 auto;
  position: relative;
  transition: none;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background-image: none !important;
  background-clip: padding-box;
  pointer-events: none;
}
.seg:first-child{
  margin-top: 0;
}
.seg:last-child{
  height: calc(25% + 3px);
  margin-bottom: -1px;
}
.seg.filled::before{
  display: none !important;
  content: none !important;
}
.seg.filled::after{
  display: none !important;
  content: none !important;
}

/* ============ POUR STREAM ============ */
.pour-stream{
  position: fixed;
  width: 8px;
  height: 0;
  border-radius: 4px 4px 6px 6px;
  pointer-events: none;
  z-index: 150;
  transform-origin: top center;
  opacity: 0;
  transition: height 0.1s ease-out, opacity 0.1s ease;
}
.pour-stream.flowing{
  opacity: 1;
  box-shadow: 
    0 0 6px var(--stream-color),
    0 0 12px var(--stream-color),
    inset 2px 0 3px rgba(255,255,255,0.4);
}
.pour-stream.stopping{
  opacity: 0;
  transition: opacity 0.15s ease;
}
.pour-stream::after{
  content: "";
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  background: inherit;
  box-shadow: 0 2px 6px var(--stream-color);
  animation: droplet 0.3s ease-in-out infinite;
}
@keyframes droplet{
  0%, 100%{ transform: translateX(-50%) scale(1); }
  50%{ transform: translateX(-50%) scale(1.1) translateY(2px); }
}
.pour-stream::before{
  content: "";
  position: absolute;
  top: 0;
  left: 2px;
  width: 2px;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(180deg, 
    rgba(255,255,255,0.5) 0%, 
    rgba(255,255,255,0.2) 50%,
    rgba(255,255,255,0.4) 100%);
}

/* ============ HINT ============ */
.hint{
  flex-shrink: 0;
  opacity: .9;
  font-weight: 600;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0,0,0,.2);
  border: 1px solid rgba(255,255,255,.10);
  text-align: center;
  margin-top: 8px;
  pointer-events: none;
}

/* ============ ADD TUBE BUTTON ============ */
.ad-btn,
.ad-button{
  margin: 0;
  border-radius: 16px;
  border: 2.5px solid rgba(255,255,255,0.95);
  background: linear-gradient(180deg, #4a2c9f 0%, #2d1f64 100%);
  color: #fff;
  font-size: clamp(14px, 2.6vw, 17px);
  font-weight: 900;
  letter-spacing: .2px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 14px 22px;
  min-height: clamp(76px, 10.2vh, 92px);
  height: auto;
  box-shadow: 0 8px 22px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.18);
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.ad-icon{
  width: 80px;
  height: 80px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(255,215,0,0.8))
          drop-shadow(0 0 12px rgba(255,215,0,0.5));
  transition: transform 0.15s ease, filter 0.15s ease;
}
.ad-button:hover .ad-icon{
  transform: scale(1.1);
  filter: drop-shadow(0 0 10px rgba(255,215,0,1))
          drop-shadow(0 0 20px rgba(255,215,0,0.8));
}
.ad-button:active .ad-icon{
  transform: scale(0.95);
}
.ad-button span{
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}
#skipLevelBtn{
  background: linear-gradient(180deg, #3f5ccf 0%, #2b3d97 100%);
}
.bottom-actions{
  position: absolute;
  left: 50%;
  bottom: calc(1.6vh + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: clamp(8px, 2.4vw, 20px);
  width: min(96%, 560px);
}
.bottom-actions button{
  flex: 1 1 0;
  max-width: 270px;
  min-width: 0;
  min-height: clamp(76px, 10.2vh, 92px);
  height: auto;
  padding: clamp(6px, 1.2vh, 10px) clamp(8px, 2vw, 12px);
}
.ad-btn:active{
  transform: scale(0.97);
}
.ad-btn:disabled,
.ad-btn.used{
  opacity: 0.5;
  cursor: not-allowed;
  border-color: rgba(255,255,255,0.4);
  background: linear-gradient(180deg, #3a2a5a 0%, #2a1a4a 100%);
}

/* ============ TOAST ============ */
.toast{
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(20, 5, 45, 0.95);
  border: 2px solid #38ff7a;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
  z-index: 30;
  pointer-events: none;
}
.toast.show{
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* New tube pop animation */
.tube.tube-just-added{
  animation: tube-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes tube-pop{
  0%{ transform: scale(0.5); opacity: 0.5; }
  60%{ transform: scale(1.12); }
  100%{ transform: scale(1); opacity: 1; }
}

/* ============ WIN OVERLAY ============ */
.overlay{
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.45);
  z-index: 20;
  border-radius: 24px;
}
.overlay.show{display: flex}
.overlayCard{
  width: calc(100% - 40px);
  max-width: 300px;
  padding: 20px;
  border-radius: 20px;
  background: rgba(20, 5, 45, 0.95);
  border: 3px solid #ffffff;
  box-shadow:
    0 0 10px rgba(168, 85, 255, 0.8),
    0 0 25px rgba(168, 85, 255, 0.5),
    0 18px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.win-icon{
  font-size: 48px;
  margin-bottom: 10px;
  animation: trophy-bounce 0.8s ease infinite;
}
@keyframes trophy-bounce{
  0%, 100%{ transform: translateY(0) scale(1); }
  50%{ transform: translateY(-6px) scale(1.08); }
}
.overlayTitle{
  font-size: 24px;
  font-weight: 900;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #38ff7a 0%, #ffe44a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.overlayBtns{
  display: flex;
  gap: 8px;
}
.overlayBtns .btn{
  margin-top: 0;
  font-size: 14px;
  padding: 10px 12px;
}

@media (max-width: 390px){
  .board{
    transform: scale(1);
  }
  .gameTopbar{
    padding: 0 6px;
    width: calc(100% - 12px);
  }
  .topbar-left{
    gap: 6px;
  }
  .uiRoundBtn{
    width: 42px;
    height: 42px;
  }
  .uiRoundBtn svg{
    width: 18px;
    height: 18px;
  }
  .coinPill{
    min-width: 84px;
    height: 44px;
    padding: 0 8px;
    gap: 4px;
  }
  .coinPill .coins-display{
    font-size: 16px;
  }
  .gameLevelTitle{
    font-size: clamp(16px, 5vw, 22px);
  }
  .bottom-actions{
    width: min(97%, 460px);
    gap: 8px;
  }
  .bottom-actions button{
    min-height: 76px;
    height: auto;
    max-width: none;
    min-width: 0;
  }
  .ad-btn{
    font-size: 13px;
    letter-spacing: 0;
    gap: 12px;
  }
  .ad-icon{
    width: 64px;
    height: 64px;
  }
  .ad-button span{
    font-size: 18px;
  }
}

@media (max-width: 768px) and (orientation: portrait){
  :root{
    --portraitWidth: 100vw;
    --portraitHeight: 100dvh;
  }
  .portrait-root{
    top: 0;
    left: 0;
    transform: none;
    width: 100vw;
    height: 100dvh;
    max-height: none;
  }
  .splash-screen{
    border-radius: 0;
    border: 0;
  }
  .game-viewport{
    top: 0;
    left: 0;
    transform: none;
    width: 100vw;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border: 0;
    box-shadow: none;
  }
  .boardWrap{
    flex: 1;
    min-height: 0;
    max-height: 52vh;
    padding: 1.2vh 0;
  }
  .board{
    transform: scale(1.02);
    max-height: 52vh;
  }
  .gameWrap{
    padding-top: 70px;
  }
  .bottom-actions{
    bottom: calc(1.2vh + env(safe-area-inset-bottom, 0px));
    width: min(97%, 520px);
    gap: 10px;
  }
  .bottom-actions button{
    min-height: 76px;
    height: auto;
    max-width: none;
    min-width: 0;
  }
  .ad-btn{
    font-size: clamp(13px, 3.2vw, 15px);
    gap: clamp(12px, 3vw, 16px);
  }
  .ad-icon{
    width: clamp(64px, 14vw, 80px);
    height: clamp(64px, 14vw, 80px);
  }
  .ad-button span{
    font-size: clamp(16px, 4vw, 22px);
  }
}

@media (max-width: 600px){
  .ad-icon{
    width: 64px;
    height: 64px;
  }
}

@media (max-width: 320px){
  .bottom-actions{
    flex-wrap: wrap;
    gap: 8px;
  }
  .bottom-actions button{
    max-width: none;
    width: 100%;
  }
}
