:root{
  --bg:#0b1020;
  --panel:rgba(255,255,255,.08);
  --panel2:rgba(255,255,255,.12);
  --text:#eef2ff;
  --muted:rgba(238,242,255,.68);

  --accent:#ffd54f;          /* yellow */
  --accent2:#1e88e5;         /* blue */
  --danger:#ff5252;
  --good:#69f0ae;

  --shadow:0 12px 40px rgba(0,0,0,.38);
  --radius:18px;
}

*{ box-sizing:border-box; }
[hidden]{ display:none !important; }
body.no-scroll{ overflow:hidden; }
html,body{
  margin:0; padding:0;
  background: radial-gradient(1000px 700px at 20% 10%, rgba(30,136,229,.14), transparent 55%),
              radial-gradient(900px 700px at 90% 20%, rgba(255,213,79,.12), transparent 60%),
              var(--bg);
  color:var(--text);
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,"Apple Color Emoji","Segoe UI Emoji";
}

.container{
  width:min(980px, 96vw);
  margin: 0 auto;
  padding: 14px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

.topbar{
  position: sticky;
  top: 0;
  z-index: 5;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(25,118,210,.28), rgba(255,255,255,.06));
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  /* Default compact from start */
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
}

.toprow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}

.brand{
  display:flex; align-items:center; gap:10px;
  min-width: 0;
}
.logo{
  width:34px; height:34px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 18px rgba(0,0,0,.28);
  flex: 0 0 auto;
}

.logoImg{
  width:34px; height:34px; border-radius: 12px;
  box-shadow: 0 10px 18px rgba(0,0,0,.28);
  flex: 0 0 auto;
  object-fit: cover;
  display:block;
}
.brand h1{
  margin:0;
  font-size: 16px;
  line-height: 1.1;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

/* Level badge (compact) */
.lvlBadge{
  display:inline-flex;
  align-items:baseline;
  gap:4px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.10);
  font-weight: 950;
  letter-spacing: .02em;
  font-size: 12px;
  flex: 0 0 auto;
}
.lvlBadge span{ font-size: 13px; }

.actionsTop{
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:flex-end;
  flex: 0 0 auto;
}

.iconbtn{
  width: 42px;
  height: 42px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius: 14px;
  background: rgba(255,255,255,.08);
  border:1px solid rgba(255,255,255,.12);
  box-shadow: 0 10px 22px rgba(0,0,0,.22);
  color: var(--text);
  font-weight: 900;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}
.iconbtn:active{ transform: translateY(1px); }

.btn{
  appearance:none;
  border:none;
  cursor:pointer;
  padding:10px 14px;
  border-radius: 14px;
  background: rgba(255,255,255,.10);
  color: var(--text);
  border:1px solid rgba(255,255,255,.12);
  box-shadow: 0 10px 22px rgba(0,0,0,.22);
  font-weight: 800;
  letter-spacing: .2px;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active{ transform: translateY(1px); }
.btn.primary{
  background: linear-gradient(135deg, rgba(30,136,229,.95), rgba(30,136,229,.70));
  border: 1px solid rgba(30,136,229,.65);
  color:#061120;
}
.btn.ghost{
  background: rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.10);
}

.statsWrap{ margin-top: 8px; display:flex; flex-direction:column; gap:8px; }

.metaGrid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
}
.metaGrid .pill{ min-width: 0; }
.metaGrid .pill.player{ grid-column: 1 / -1; }

.statsRow{
  display:flex;
  gap:10px;
  overflow-x:auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
}
.statsRow::-webkit-scrollbar{ height: 6px; }
.statsRow::-webkit-scrollbar-thumb{ background: rgba(255,255,255,.12); border-radius: 999px; }

.pill{
  flex: 0 0 auto;
  min-width: 92px;
  background: rgba(0,0,0,.18);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 16px;
  padding: 8px 10px;
}
.pill .label{
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}
.pill .value{
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .2px;
  margin-top: 2px;
}

/* Store head + coins chip */
.store-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}
.coins-chip{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.10);
  font-weight: 950;
}
.coin-dot{ font-size: 12px; color: var(--accent); }


/* Store footer (coins pinned near shop) */
.store-footer{
  position: sticky;
  bottom: calc(10px + env(safe-area-inset-bottom));
  display:flex;
  justify-content:flex-end;
  margin-top: 10px;
  padding-top: 10px;
  padding-bottom: 2px;
  background: linear-gradient(180deg, rgba(11,16,32,0), rgba(11,16,32,.55));
}
.store-footer .coins-chip{
  padding: 10px 12px;
  font-size: 15px;
  background: rgba(0,0,0,.32);
  border-color: rgba(255,255,255,.16);
}
.store-footer .coin-dot{ font-size: 13px; }
/* Menu wallet row */
.menu-wallet{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.10);
  margin-bottom: 2px;
}
.menu-wallet .wl{
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
  font-weight: 900;
}
.menu-wallet .wv{
  font-weight: 950;
}

/* Overlay modal head + compact close */
.modal-head{
  position: relative;
  z-index: 5;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.iconbtn.sm{ width: 36px; height: 36px; border-radius: 12px; }

.modal h2{ margin:0; font-size: 18px; }

.grid{
  display:grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
  margin-top: 14px;
}

.card{
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.05));
  border: 1px solid rgba(255,255,255,.10);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
}

.canvas-wrap{ padding: 12px; }
#game{
  width:100%;
  height:auto;
  display:block;
  border-radius: 16px;
  background: radial-gradient(700px 450px at 30% 20%, rgba(255,255,255,.10), transparent 55%), rgba(0,0,0,.22);
  border:1px solid rgba(255,255,255,.10);
  touch-action: none;
}

.side{
  padding: 12px;
  display:flex;
  flex-direction:column;
  gap: 12px;
}

.section-title{
  font-weight: 900;
  letter-spacing: .2px;
  margin: 0 0 8px;
}
.row{ display:flex; gap:10px; flex-wrap:wrap; }

.small{ margin:0; font-size: 13px; color: var(--muted); }

.shop{
  display:flex;
  flex-direction:column;
  gap: 10px;
}
.shop-item{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding: 10px 12px;
  border-radius: 16px;
  background: rgba(0,0,0,.18);
  border:1px solid rgba(255,255,255,.10);
}
.shop-item .meta{
  display:flex;
  flex-direction:column;
  gap:2px;
  min-width: 0;
}
.shop-item .name{
  font-weight: 900;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}
.shop-item .desc{
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

.overlay{
  position:fixed;
  inset:0;
  background: rgba(0,0,0,.65);
  display:none;
  align-items:center;
  justify-content:center;
  padding: 18px;
  z-index: 20;
}
.overlay.show{ display:flex; }
.modal{
  width:min(520px, 96vw);
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.06));
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 20px;
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
  padding: 16px;
}
.modal.levels-mode{
  max-height: calc(100vh - 40px - env(safe-area-inset-top));
  display:flex;
  flex-direction:column;
  min-height: 0;
}

/* Levels overlay: stretch so internal list can scroll on mobile */
.overlay.levels-open{
  align-items: stretch;
}
.overlay.levels-open .modal.levels-mode{
  margin: auto;
}

/* Make modal height explicit so Pi Browser shows inner scroll */
.modal.levels-mode{
  height: min(720px, calc(100vh - 40px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  overflow: hidden;
}
.levels-shell{ height: 100%; }
.levels-wrap{ max-height: 100%; }

.modal.levels-mode #overlayText{ display:none; }
.modal.levels-mode .modal-actions{
  display:flex;
  flex-direction:column;
  align-items:stretch;
  justify-content:flex-start;
  gap: 10px;
}

.levels-wrap{
  width:100%;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  padding-right: 6px;
  touch-action: pan-y;
}

.levels-shell{
  width:100%;
  flex: 1 1 auto;
  min-height: 0;
  display:flex;
  gap: 10px;
}

.levels-bar{
  flex: 0 0 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(0,0,0,.25);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
  position: relative;
  pointer-events:none;
  margin: 2px 0;
}
.levels-thumb{
  position:absolute;
  left: 1px;
  right: 1px;
  top: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.28);
}
.levels-footer{
  width:100%;
  flex: 0 0 auto;
  display:flex;
  justify-content:flex-end;
}
.modal p{ margin:0 0 12px; color: var(--muted); line-height: 1.35; }
.modal p{ margin:0 0 12px; color: var(--muted); line-height: 1.35; }
.modal-actions{ display:flex; gap:10px; justify-content:flex-end; flex-wrap:wrap; }

/* Levels: make actions area fill modal so the list can actually scroll */
.modal.levels-mode .modal-actions{
  flex: 1 1 auto;
  min-height: 0;
}

/* Compact info tooltip (no full-screen overlay) */
.mini-tip{
  position: fixed;
  z-index: 40;
  width: min(340px, 92vw);
  background: #0f1730;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
  border-radius: 16px;
  padding: 10px 12px;
  display:none;
}
.mini-tip.show{ display:block; }
.mini-tip-title{
  font-weight: 950;
  margin: 0 0 4px;
  font-size: 13px;
}
.mini-tip-text{
  margin: 0;
  font-size: 12.5px;
  color: rgba(238,242,255,.78);
  line-height: 1.25;
}

.level-grid{
  display:grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}
.level-btn{
  padding: 12px 0;
  border-radius: 16px;
  font-weight: 900;
}
.level-btn.locked{
  opacity: .45;
}

/* CandyCrush-like level map */
.level-map{
  position: relative;
  padding: 8px 0 18px;
  min-height: 0;
}
.level-map:before{
  content:"";
  position:absolute;
  left:50%;
  top:0;
  bottom:0;
  width: 6px;
  transform: translateX(-50%);
  background: rgba(255,255,255,.10);
  border-radius: 999px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
}
.level-map-item{
  position: relative;
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 14px 0;
}
.level-map-item.left{ justify-content:flex-start; }
.level-map-item.right{ justify-content:flex-end; }

.level-map-item.left:after,
.level-map-item.right:after{
  content:"";
  position:absolute;
  top:50%;
  height: 6px;
  width: 38%;
  background: rgba(255,255,255,.10);
  border-radius: 999px;
  transform: translateY(-50%);
}
.level-map-item.left:after{ right:50%; }
.level-map-item.right:after{ left:50%; }
.level-map-item.locked:after{ opacity: .35; }

.level-node{
  appearance:none;
  cursor:pointer;
  touch-action: pan-y;
  width: 64px;
  height: 64px;
  border-radius: 22px;
  font-weight: 950;
  letter-spacing: .2px;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 14px 30px rgba(0,0,0,.28);
  background: linear-gradient(180deg, rgba(255,213,79,.95), rgba(30,136,229,.85));
  color: #061120;
}
.level-node{ touch-action: pan-y; }
.level-node:active{ transform: translateY(1px); }
.level-node.done{
  background: linear-gradient(180deg, rgba(105,240,174,.90), rgba(30,136,229,.70));
}
.level-node.current{
  outline: 3px solid rgba(255,255,255,.55);
  outline-offset: 2px;
}
.level-node.locked{
  background: rgba(255,255,255,.06);
  color: rgba(238,242,255,.75);
  opacity: .55;
}

.level-chip{
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,.18);
  border: 1px solid rgba(255,255,255,.10);
  color: var(--text);
  font-weight: 900;
  font-size: 12px;
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.level-map-item.locked .level-chip{ opacity:.45; }


/* ===== Booster buttons (SVG icons) ===== */
.btn.booster{
  display:flex;
  align-items:center;
  justify-content:flex-start;
  gap: 10px;
}
.btn.booster .bico{
  width: 22px;
  height: 22px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  flex: 0 0 auto;
}
.btn.booster .ico{
  width: 22px;
  height: 22px;
  display:block;
}
.btn.booster .btxt{ flex: 1 1 auto; }
.btn.booster .bprice{
  flex: 0 0 auto;
  opacity: .9;
  font-weight: 900;
}

/* ===== Info pills (tap for meaning) ===== */
.pill.info-pill{
  cursor:pointer;
  position: relative;
}
.pill.info-pill:after{
  content:"i";
  position:absolute;
  right: 8px;
  top: 8px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 11px;
  font-weight: 950;
  color: rgba(255,255,255,.88);
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.12);
}
.pill.info-pill:active{ transform: translateY(1px); }

/* ===== Overlay modal variants ===== */
.modal.solid{
  background: #0f1730;
  border: 1px solid rgba(255,255,255,.12);
}
.modal-brand{
  display:flex;
  align-items:center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 16px;
  margin: 8px 0 10px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.10);
}
.modal-brand .jj-mark{
  width: 38px;
  height: 38px;
  border-radius: 14px;
  display:flex;
  align-items:center;
  justify-content:center;
  background: linear-gradient(135deg, rgba(255,213,79,.95), rgba(30,136,229,.85));
  color: #061120;
  box-shadow: 0 12px 26px rgba(0,0,0,.35);
}
.modal-brand .jj-mark svg{ width: 24px; height: 24px; }
.modal-brand .jj-name{
  font-weight: 950;
  letter-spacing: .2px;
}
.modal-brand .jj-sub{
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ===== CandyCrush-like compact header on play ===== */
.topbar{
  transition: padding .18s ease;
}
.topbar .metaGrid{
  overflow:hidden;
  max-height: 90px;
  opacity: 1;
  transform: translateY(0);
  margin-top: 0;
  transition: max-height .22s ease, opacity .18s ease, transform .22s ease, margin-top .22s ease;
  will-change: max-height, opacity, transform;
}
.topbar.compact{
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
}
.topbar.compact .metaGrid{
  max-height: 0;
  opacity: 0;
  transform: translateY(-6px);
  margin-top: -6px;
  pointer-events:none;
}

/* ===== Levels: visible scrollbar + swipe hint ===== */
.levels-wrap{
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.35) transparent;
}
.levels-wrap::-webkit-scrollbar{ width: 8px; }
.levels-wrap::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,.22);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.levels-hint{
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 10px;
  margin: 0 0 10px;
  border-radius: 16px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.10);
  font-size: 12px;
  color: rgba(255,255,255,.86);
}

.levels-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
  padding: 6px 2px 10px;
}
.levels-top-title{
  font-weight: 950;
  letter-spacing: .2px;
  opacity: .95;
}
.levels-x{
  width: 38px;
  height: 38px;
  border-radius: 14px;
}


.toast{
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(0,0,0,.72);
  border: 1px solid rgba(255,255,255,.12);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 999px;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
  display:none;
  z-index: 30;
  max-width: min(92vw, 520px);
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

/* Hamburger sheet */
.sheet{
  position: fixed;
  inset: 0;
  /* Solid backdrop (no see-through) */
  background: #0b1020;
  display:flex;
  align-items:flex-start;
  justify-content:flex-end;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top));
  z-index: 25;
}
.sheet-card{
  width: min(340px, 92vw);
  border-radius: 20px;
  /* Solid menu (no glass transparency) */
  background: #0f1730;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
  overflow:hidden;
}
.sheet-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 12px;
  border-bottom: 1px solid rgba(255,255,255,.10);
}
.sheet-title{ font-weight: 950; letter-spacing:.2px; }
.sheet-body{
  display:flex;
  flex-direction:column;
  gap:10px;
  padding: 12px;
}
.menu-btn{ width: 100%; text-align:left; }

@media (max-width: 920px){
  .container{ padding: 12px; }
  .grid{ grid-template-columns: 1fr; }
  .topbar{ padding-left: 10px; padding-right: 10px; }
  .btn{ padding: 12px 16px; border-radius: 16px; font-size: 14px; }
  .iconbtn{ width: 44px; height: 44px; }
  .metaGrid{ grid-template-columns: 1fr 1fr; }
  .metaGrid .pill{ padding: 10px 10px; }
  .statsRow::-webkit-scrollbar{ height: 0; }
  .level-grid{ grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 420px){
  .brand h1{ display:none; }
  .pill{ min-width: 96px; }
  .level-grid{ grid-template-columns: repeat(3, 1fr); }
}
