: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);
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
}

.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:38px; height:38px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 18px rgba(0,0,0,.28);
  flex: 0 0 auto;
}
.brand h1{
  margin:0;
  font-size: 16px;
  line-height: 1.1;
  letter-spacing: .2px;
  white-space: nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}

.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: 10px; display:flex; flex-direction:column; gap:10px; }

.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: 104px;
  background: rgba(0,0,0,.18);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 16px;
  padding: 10px 12px;
}
.pill .label{
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}
.pill .value{
  font-size: 15px;
  font-weight: 900;
  letter-spacing: .2px;
  margin-top: 2px;
}

.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;
}
.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:auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 6px;
}
.levels-footer{
  width:100%;
  flex: 0 0 auto;
  display:flex;
  justify-content:flex-end;
}
.modal h2{ margin:0 0 8px; font-size: 18px; }
.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; }

.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;
}

.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;
  background: rgba(0,0,0,.55);
  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;
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.06));
  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{ font-size: 15px; }
  .pill{ min-width: 96px; }
  .level-grid{ grid-template-columns: repeat(3, 1fr); }
}
