:root {
  --ink: #150E3A;
  --gold: #FFC94D;
  --gold-deep: #B4791A;
  --pink: #FF5FA0;
  --pink-deep: #C43380;
  --mint: #3ECF8E;
  --panel-bg: rgba(21, 13, 46, .80);
  --panel-border: rgba(255, 201, 77, .32);
  --text: #FFF6E8;
  --text-dim: rgba(255, 246, 232, .65);
  --font-display: 'Baloo 2', 'Arial Rounded MT Bold', 'Segoe UI', sans-serif;
  --font-body: 'Nunito', 'Segoe UI', Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--ink); font-family: var(--font-body);
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none; touch-action: none;
}
button { font-family: inherit; -webkit-tap-highlight-color: transparent; }

#game { position: fixed; inset: 0; display: block; touch-action: none; cursor: crosshair; z-index: 1; }

/* ---------------------------------------------------------------------------
   Screens
--------------------------------------------------------------------------- */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .22s ease; z-index: 20;
}
.screen.visible { opacity: 1; pointer-events: auto; }

/* ---------------------------------------------------------------------------
   Buttons
--------------------------------------------------------------------------- */
.btn-3d {
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
  border: none; border-radius: 16px; cursor: pointer; color: #fff;
  padding: 14px 22px; display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 6px 0 var(--shadow-c), 0 9px 16px rgba(0,0,0,.35);
  transform: translateY(0); transition: transform .08s, box-shadow .08s;
}
.btn-3d:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--shadow-c), 0 2px 6px rgba(0,0,0,.3); }
.btn-primary { background: linear-gradient(180deg,#FFE07A,#FFC94D); color: #5C3A00; --shadow-c: #B4791A; }
.btn-secondary { background: linear-gradient(180deg,#FF9AD0,#FF5FA0); color: #5C0030; --shadow-c: #C43380; }
.btn-ghost { background: linear-gradient(180deg, rgba(255,255,255,.18), rgba(255,255,255,.08)); color: #fff; --shadow-c: rgba(0,0,0,.4); backdrop-filter: blur(6px); }
.btn-danger { background: linear-gradient(180deg,#FF9A8A,#E5503C); color: #4A0900; --shadow-c: #A82F1E; }
.btn-lg { width: 100%; font-size: 19px; padding: 16px; }
.btn-sm { padding: 10px 14px; font-size: 14px; gap: 5px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
  background: linear-gradient(180deg,#8F63DD,#6C3FB8);
  box-shadow: 0 4px 0 #4A2A85, 0 7px 12px rgba(0,0,0,.3);
  transition: transform .08s, box-shadow .08s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #4A2A85, 0 2px 6px rgba(0,0,0,.25); }
.icon-btn.glass { background: rgba(255,255,255,.15); backdrop-filter: blur(10px); box-shadow: 0 4px 0 rgba(0,0,0,.28), inset 0 1px 0 rgba(255,255,255,.25); }

/* ---------------------------------------------------------------------------
   Loading
--------------------------------------------------------------------------- */
.loading-screen {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  background: linear-gradient(180deg,#241457,#5B2C8C,#B24B95); transition: opacity .5s;
}
.loading-screen.done { opacity: 0; }
.loading-mark { animation: floatBob 1.6s ease-in-out infinite; }
@keyframes floatBob { 0%,100%{ transform: translateY(0);} 50%{ transform: translateY(-10px);} }
.loading-title { font-family: var(--font-display); color: #fff; font-size: 22px; text-align: center; letter-spacing: .5px; }
.loading-title span { display: block; font-size: 12px; letter-spacing: 5px; color: var(--gold); margin-top: 5px; }
.loading-bar { width: 160px; height: 8px; border-radius: 6px; background: rgba(255,255,255,.2); overflow: hidden; }
.loading-fill { width: 0%; height: 100%; border-radius: 6px; background: linear-gradient(90deg,#FFD23F,#FF7A33); animation: loadFill 1s ease-in-out forwards; }
@keyframes loadFill { to { width: 100%; } }

/* ---------------------------------------------------------------------------
   Menu
--------------------------------------------------------------------------- */
.menu-card {
  width: min(92vw, 380px); background: var(--panel-bg); border: 2px solid var(--panel-border);
  border-radius: 28px; padding: 30px 26px 32px; backdrop-filter: blur(16px);
  box-shadow: 0 24px 70px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.08);
  display: flex; flex-direction: column; align-items: center; gap: 13px; position: relative;
}
.game-logo { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 6px; }
.game-logo canvas { width: 90px; height: 90px; }
.game-logo h1 { font-family: var(--font-display); font-size: 29px; color: #fff; margin: 0; text-align: center; line-height: 1; text-shadow: 0 3px 0 rgba(0,0,0,.28); }
.game-logo h1 span { display: block; font-size: 13px; letter-spacing: 6px; color: var(--gold); margin-top: 6px; }
.menu-stats { display: flex; gap: 14px; margin-bottom: 6px; }
.stat { display: flex; align-items: center; gap: 5px; font-weight: 800; color: #fff; font-size: 13px; background: rgba(255,255,255,.08); padding: 7px 12px; border-radius: 12px; }
.menu-row { display: flex; gap: 12px; width: 100%; }
.menu-row .btn-3d { flex: 1; font-size: 14px; padding: 12px 8px; }
.corner-btn { position: absolute; top: 16px; right: 16px; width: 38px; height: 38px; }
#play-btn, #levels-btn { width: 100%; }

/* ---------------------------------------------------------------------------
   Panels (levels / shop / settings)
--------------------------------------------------------------------------- */
.panel-screen { align-items: center; justify-content: center; padding: 18px; }
.panel {
  width: min(100%, 560px); max-height: min(86vh, 680px); margin: 0 auto;
  background: linear-gradient(160deg, rgba(42,25,77,.94), rgba(18,12,43,.96));
  border: 2px solid var(--panel-border); border-radius: 28px; backdrop-filter: blur(16px);
  display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.05) inset;
}
.panel-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid rgba(255,255,255,.12); flex-shrink: 0; }
.panel-head h2 { font-family: var(--font-display); color: #fff; font-size: 24px; margin: 0; flex: 1; text-align: center; letter-spacing: .3px; text-shadow: 0 2px 8px rgba(0,0,0,.3); }
.panel-head .spacer { width: 40px; flex-shrink: 0; }
.coin-tag { display: flex; align-items: center; gap: 5px; background: rgba(255,255,255,.1); padding: 7px 13px; border-radius: 12px; color: #fff; font-weight: 800; font-size: 13px; flex-shrink: 0; }

.level-grid {
  overflow: hidden; min-height: 0; padding: 12px 18px 8px;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 9px; align-content: start;
}
.page-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(255,255,255,.12); background: rgba(8,5,24,.18); }
.page-nav .btn-3d { flex-shrink: 0; }
.page-lab { color: var(--text-dim); font-weight: 800; font-size: 14px; letter-spacing: .5px; text-align: center; flex: 1; }
.world-tag {
  grid-column: 1 / -1; color: var(--gold); font-family: var(--font-display);
  font-size: 15px; letter-spacing: 2.2px; text-transform: uppercase;
  text-align: center; margin: 2px 2px 4px; opacity: .98;
  text-shadow: 0 2px 10px rgba(255,201,77,.22);
}
.lvl {
  aspect-ratio: 1; border-radius: 16px; border: 1px solid rgba(255,255,255,.16); cursor: pointer;
  background: linear-gradient(145deg,#A5F1D1,#36B985); color: #0B3D26;
  font-family: var(--font-display); font-weight: 700; font-size: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  box-shadow: 0 5px 0 #1D8F5C, 0 8px 16px rgba(0,0,0,.2), inset 0 1px 0 rgba(255,255,255,.3); transition: transform .12s, filter .12s;
}
.lvl:active { transform: translateY(3px); box-shadow: 0 1px 0 #1D8F5C; }
.lvl.current { background: linear-gradient(145deg,#FFE99A,#F6B62F); color: #5C3A00; border-color: rgba(255,255,255,.45); box-shadow: 0 5px 0 #B4791A, 0 8px 18px rgba(255,201,77,.28), inset 0 1px 0 rgba(255,255,255,.5); animation: pulseCurrent 1.6s ease-in-out infinite; }
.lvl.locked { background: linear-gradient(145deg,#62677D,#373C50); color: rgba(255,255,255,.5); border-color: rgba(255,255,255,.08); box-shadow: 0 5px 0 #262a36, inset 0 1px 0 rgba(255,255,255,.08); cursor: default; }
.lvl-stars { display: flex; gap: 1px; height: 11px; }
.lvl .star-on { color: #B4791A; }
.lvl .star-off { color: rgba(0,0,0,.18); }
@keyframes pulseCurrent { 0%,100%{ transform: scale(1);} 50%{ transform: scale(1.06);} }

.shop-list { padding: 16px 18px 24px; display: flex; flex-direction: column; gap: 12px; overflow: hidden; }
.shop-item { display: flex; align-items: center; gap: 12px; background: rgba(255,255,255,.06); border-radius: 16px; padding: 12px; }
.shop-icon { width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: rgba(255,255,255,.08); overflow: hidden; }
.shop-info { flex: 1; display: flex; flex-direction: column; color: #fff; min-width: 0; }
.shop-info b { font-family: var(--font-display); font-size: 15px; }
.shop-info span { font-size: 12px; color: var(--text-dim); }
.btn-sm svg { flex-shrink: 0; }

.fx-fire { background: linear-gradient(160deg,#FFD23F,#FF7A33); color: #5C1A00; }
.fx-lightning { background: linear-gradient(160deg,#FFF6C8,#4FD8F5); color: #0A3550; }
.fx-bomb { background: linear-gradient(160deg,#8B92A6,#4A4E5C); color: #fff; }

.settings-list { padding: 16px 18px 4px; display: flex; flex-direction: column; }
.setting-row { display: flex; align-items: center; gap: 12px; padding: 14px 6px; color: #fff; font-weight: 700; font-size: 15px; border-bottom: 1px solid rgba(255,255,255,.07); }
.setting-row span { flex: 1; }
.toggle { width: 48px; height: 28px; border-radius: 16px; border: none; background: rgba(255,255,255,.18); position: relative; cursor: pointer; flex-shrink: 0; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .18s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toggle.on { background: linear-gradient(90deg,#3ECF8E,#2FB57A); }
.toggle.on::after { left: 23px; }
#reset-btn { margin: 16px 18px 24px; }

/* ---------------------------------------------------------------------------
   Modals (pause / end)
--------------------------------------------------------------------------- */
.modal-screen { padding: 20px; }
.modal {
  width: min(90vw, 340px); background: var(--panel-bg); border: 2px solid var(--panel-border);
  border-radius: 26px; padding: 32px 26px; backdrop-filter: blur(16px);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  box-shadow: 0 24px 70px rgba(0,0,0,.5);
}
.modal h2 { font-family: var(--font-display); color: #fff; font-size: 25px; margin: 0 0 2px; text-align: center; }
.modal .btn-3d { width: 100%; }
.stars-row { display: flex; gap: 10px; margin-bottom: 4px; }
.stars-row .star-on { color: #FFC94D; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.stars-row .star-off { color: rgba(255,255,255,.18); }
.end-detail { color: #fff; text-align: center; font-size: 16px; line-height: 1.75; margin: 0 0 6px; }
.end-detail b { color: var(--gold); font-family: var(--font-display); font-size: 19px; }
.coin-line { color: #FFC94D; font-weight: 800; }

/* ---------------------------------------------------------------------------
   HUD
--------------------------------------------------------------------------- */
.hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; display: none; }
.hud.visible { display: block; }
.hud-top { position: relative; display: flex; align-items: center; padding: max(10px, env(safe-area-inset-top)) 10px 0; min-height: 50px; }
.hud-top .icon-btn { pointer-events: auto; position: relative; z-index: 2; width: 40px; height: 40px; }
.hud-pills { position: absolute; left: 0; right: 0; top: max(10px, env(safe-area-inset-top)); display: flex; gap: 4px; flex-wrap: nowrap; justify-content: center; align-items: center; pointer-events: none; padding: 0 46px; }
.hud-spacer { width: 40px; flex-shrink: 0; }
.pill { pointer-events: auto; display: flex; align-items: center; gap: 5px; background: rgba(20,12,42,.62); backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.16); color: #fff; font-weight: 800; font-family: var(--font-display); font-size: 17px; padding: 7px 10px; border-radius: 12px; white-space: nowrap; flex-shrink: 0; }
.pill-lab { font-family: var(--font-body); font-weight: 700; font-size: 10px; text-transform: uppercase; letter-spacing: .3px; color: var(--text-dim); margin-right: 1px; }
.coin-pill { color: var(--gold); }

.drop-warn { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); background: rgba(220,40,40,.88); color: #fff; font-weight: 800; font-size: 14px; padding: 7px 16px; border-radius: 20px; display: flex; align-items: center; gap: 6px; opacity: 0; transition: opacity .2s; }
.drop-warn.show { opacity: 1; animation: warnPulse 1s infinite; }
@keyframes warnPulse { 0%,100%{ transform: translateX(-50%) scale(1);} 50%{ transform: translateX(-50%) scale(1.05);} }

.booster-bar { position: absolute; left: 14px; bottom: max(18px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.booster-btn { pointer-events: auto; position: relative; width: 52px; height: 52px; border-radius: 16px; border: none; cursor: pointer; background: rgba(255,255,255,.12); backdrop-filter: blur(8px); box-shadow: 0 4px 0 rgba(0,0,0,.32), 0 7px 12px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.2); transition: transform .08s, opacity .15s; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.booster-btn:active { transform: translateY(3px); }
.booster-btn.armed { outline: 3px solid #fff; animation: armedPulse .7s infinite; }
.booster-btn.empty { opacity: .38; filter: grayscale(.6); }
.mini-canvas { width: 100%; height: 100%; pointer-events: none; }
@keyframes armedPulse { 0%,100%{ box-shadow: 0 4px 0 rgba(0,0,0,.32), 0 0 0 0 rgba(255,255,255,.55);} 50%{ box-shadow: 0 4px 0 rgba(0,0,0,.32), 0 0 0 8px rgba(255,255,255,0);} }
.badge { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 10px; background: #fff; color: #222; font-size: 11px; font-weight: 900; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 4px rgba(0,0,0,.3); z-index: 2; }

/* ---------------------------------------------------------------------------
   Toast + combo popup
--------------------------------------------------------------------------- */
.toast { position: fixed; bottom: 104px; left: 50%; transform: translateX(-50%) translateY(16px); background: rgba(20,12,42,.92); color: #fff; padding: 11px 22px; border-radius: 20px; font-weight: 700; font-size: 15px; opacity: 0; transition: all .25s; pointer-events: none; z-index: 50; border: 1px solid rgba(255,255,255,.15); text-align: center; max-width: 80vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.combo-pop { position: fixed; top: 36%; left: 50%; transform: translate(-50%,-50%) scale(.6); color: #fff; font-family: var(--font-display); font-size: 30px; font-weight: 800; text-shadow: 0 3px 10px rgba(0,0,0,.5), 0 0 20px rgba(255,201,77,.5); opacity: 0; pointer-events: none; z-index: 15; white-space: nowrap; }
.combo-pop.show { animation: comboPop .9s ease-out forwards; }
@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.5); }
  15% { opacity: 1; transform: translate(-50%,-50%) scale(1.08); }
  30% { transform: translate(-50%,-50%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-64%) scale(1.05); }
}

/* ---------------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------------- */
@media (max-width: 380px) {
  .level-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; padding: 6px 12px 3px; }
  .lvl { font-size: 13px; border-radius: 11px; }
  .lvl-stars { transform: scale(.82); }
  .game-logo h1 { font-size: 25px; }
  .menu-card { padding: 24px 20px 26px; }
}
@media (max-height: 640px) {
  .menu-card { gap: 9px; padding: 18px 22px 22px; }
  .game-logo { margin-bottom: 2px; }
}
@media (max-width: 719px) {
  .panel-screen { padding: 14px; }
  .panel { max-height: 88vh; }
}
@media (min-width: 720px) {
  .panel { border-radius: 28px; border-bottom: 2px solid var(--panel-border); max-height: 74vh; }
}
