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

:root {
  --bg1: #2b2140;
  --bg2: #1a1330;
  --card: rgba(255, 255, 255, 0.08);
  --card2: rgba(255, 255, 255, 0.12);
  --text: #f4efff;
  --muted: #a99cc7;
  --accent: #ffb703;
  --gem: #7ae7ff;
  --green: #6ede8a;
  --red: #ff6b81;
  --radius: 18px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Roboto', system-ui, sans-serif;
  background: radial-gradient(ellipse at top, var(--bg1), var(--bg2) 70%);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#game {
  position: relative;
  max-width: 520px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 6px;
}
.res {
  flex: 1;
  background: var(--card);
  border-radius: 12px;
  padding: 7px 10px;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}
.res.gem { color: var(--gem); }
.res.coin { color: var(--accent); }
.res-sub {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.2;
  min-height: 12px;
}
#btn-settings {
  background: var(--card);
  border: none;
  border-radius: 12px;
  font-size: 17px;
  padding: 7px 11px;
  cursor: pointer;
  color: var(--text);
}

#level-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  font-size: 13px;
  color: var(--muted);
}
#level-center { flex: 1; text-align: center; min-width: 0; }
#level-label { font-weight: 700; color: var(--text); font-size: 15px; }
#cat-progress { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lvl-btn {
  background: var(--card);
  border: none;
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  padding: 8px 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.lvl-btn:not(:disabled):active { background: var(--card2); transform: scale(0.94); }
.lvl-btn:disabled { opacity: 0.25; cursor: default; }

#boss-timer {
  margin: 2px 14px;
  height: 22px;
  background: rgba(0,0,0,0.4);
  border-radius: 11px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 107, 129, 0.5);
}
#boss-timer-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #ff6b81, #ff9f43);
  border-radius: 11px;
  transform-origin: left;
}
#boss-timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  z-index: 1;
}

#arena {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
  padding: 4px 16px;
}
#hp-wrap {
  width: 100%;
  max-width: 340px;
  height: 20px;
  background: rgba(0,0,0,0.4);
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  margin-bottom: 8px;
  flex-shrink: 0;
}
#hp-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #6ede8a, #b8f2b0);
  border-radius: 10px;
  transform-origin: left;
  transition: transform 0.08s linear;
}
#arena.boss #hp-fill { background: linear-gradient(90deg, #ff6b81, #ffb3c1); }
#hp-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #10221a;
  z-index: 1;
}
#arena.boss #hp-text { color: #33101a; }

#item-name {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 6px;
  text-align: center;
  flex-shrink: 0;
}
#arena.boss #item-name { color: var(--red); }
#item-name .armor {
  font-size: 12px;
  font-weight: 700;
  color: #9db8d8;
  background: rgba(157, 184, 216, 0.15);
  border-radius: 8px;
  padding: 2px 7px;
  vertical-align: middle;
}
#item-name .kills {
  font-size: 12px;
  font-weight: 700;
  color: #ffb3c1;
  background: rgba(255, 107, 129, 0.15);
  border-radius: 8px;
  padding: 2px 7px;
  vertical-align: middle;
}

#arena.enrage #item-tap-zone {
  animation: bossPulse 0.35s ease-in-out infinite alternate;
}
#arena.enrage #hp-fill { background: linear-gradient(90deg, #ff2e4d, #ff758f); }

#boss-call {
  margin-bottom: 8px;
  background: linear-gradient(180deg, #ff8fa3, #e5476b);
  color: #fff;
  border: none;
  border-radius: 14px;
  font-weight: 900;
  font-size: 14px;
  padding: 9px 18px;
  cursor: pointer;
  flex-shrink: 0;
  animation: bossCallPulse 1s ease-in-out infinite alternate;
}
#boss-call:active { transform: scale(0.95); }
@keyframes bossCallPulse {
  from { box-shadow: 0 0 6px rgba(255, 80, 110, 0.4); }
  to   { box-shadow: 0 0 20px rgba(255, 80, 110, 0.9); }
}

#item-tap-zone {
  width: min(62vw, 240px);
  height: min(62vw, 240px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  background: radial-gradient(circle at 35% 30%, var(--item-c1, #ffe9a8), var(--item-c2, #ffd45e));
  box-shadow: 0 10px 40px rgba(0,0,0,0.45), inset 0 -8px 24px rgba(0,0,0,0.18), inset 0 8px 24px rgba(255,255,255,0.25);
  transition: transform 0.09s ease-out;
  flex-shrink: 0;
}
#item-tap-zone.squishing { transform: scale(0.9, 0.82); }
#arena.boss #item-tap-zone {
  box-shadow: 0 0 34px rgba(255, 80, 110, 0.75), inset 0 -8px 24px rgba(0,0,0,0.25);
  animation: bossPulse 0.9s ease-in-out infinite alternate;
}
@keyframes bossPulse {
  from { box-shadow: 0 0 22px rgba(255, 80, 110, 0.55), inset 0 -8px 24px rgba(0,0,0,0.25); }
  to   { box-shadow: 0 0 46px rgba(255, 80, 110, 0.95), inset 0 -8px 24px rgba(0,0,0,0.25); }
}
#item-emoji {
  font-size: min(32vw, 120px);
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.3));
}
#item-emoji svg {
  width: min(50vw, 195px);
  height: min(50vw, 195px);
  display: block;
}
#boss-badge {
  position: absolute;
  top: -6px;
  right: 2px;
  font-size: 34px;
  display: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}
#arena.boss #boss-badge { display: block; }

#combo {
  margin-top: 8px;
  font-size: 15px;
  font-weight: 900;
  color: var(--accent);
  height: 20px;
  flex-shrink: 0;
  text-shadow: 0 0 12px rgba(255, 183, 3, 0.5);
}

.dmg-float {
  position: absolute;
  font-weight: 900;
  font-size: 20px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.55);
  pointer-events: none;
  animation: floatUp 0.8s ease-out forwards;
  z-index: 5;
  white-space: nowrap;
}
.dmg-float.crit { color: var(--accent); font-size: 27px; }
.dmg-float.coins {
  color: var(--green);
  font-size: 17px;
  animation: floatUpSoft 0.9s ease-out forwards;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -80px) scale(1.15); }
}
@keyframes floatUpSoft {
  0% { opacity: 0.55; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -55px) scale(1.05); }
}
.particle {
  position: absolute;
  font-size: 18px;
  pointer-events: none;
  animation: partFly 0.7s ease-out forwards;
  z-index: 4;
}
@keyframes partFly {
  0% { opacity: 1; transform: translate(0, 0) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.4) rotate(var(--rot)); }
}

#energy-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px;
  font-size: 14px;
  flex-shrink: 0;
}
#energy-bar {
  flex: 1;
  height: 14px;
  background: rgba(0,0,0,0.4);
  border-radius: 7px;
  overflow: hidden;
}
#energy-fill {
  height: 100%;
  background: linear-gradient(90deg, #48cae4, #7ae7ff);
  border-radius: 7px;
  transform-origin: left;
  transition: transform 0.15s linear;
}
#energy-wrap.empty #energy-fill { background: linear-gradient(90deg, #ff6b81, #ff9f43); }
#energy-wrap.shake { animation: shake 0.3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
#energy-text { font-size: 12px; font-weight: 700; color: var(--muted); min-width: 64px; text-align: right; }
#energy-regen {
  font-size: 11px;
  font-weight: 700;
  color: var(--gem);
  white-space: nowrap;
}

#bonus-bar {
  display: flex;
  gap: 6px;
  padding: 0 10px;
  flex-shrink: 0;
}
#bonus-bar:empty { display: none; }
.bonus-btn {
  flex: 1;
  background: linear-gradient(180deg, #b388ff, #7c4dff);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-weight: 800;
  font-size: 12px;
  padding: 8px 6px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bonus-btn:active { transform: scale(0.96); }
.bonus-btn:disabled { background: #4a4160; color: #8d84a5; cursor: default; }
.bonus-btn.wide { width: 100%; margin-bottom: 10px; flex: none; }

#tabs {
  display: flex;
  gap: 6px;
  padding: 6px 10px calc(10px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}
#tabs button {
  flex: 1;
  background: var(--card);
  border: none;
  border-radius: 14px;
  color: var(--text);
  padding: 8px 2px;
  font-size: 19px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background 0.15s;
}
#tabs button span { font-size: 10px; font-weight: 700; color: var(--muted); }
#tabs button.active { background: var(--card2); box-shadow: inset 0 0 0 1.5px var(--accent); }
#tabs button.attention::after {
  content: '';
  position: absolute;
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  margin-top: -32px;
  margin-left: 26px;
}
#tabs button { position: relative; }

#panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 72%;
  background: linear-gradient(180deg, #322752, #241a42);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  z-index: 20;
  animation: slideUp 0.22s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
#panel.hidden { display: none; }
#panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 8px;
  flex-shrink: 0;
}
#panel-title { font-size: 18px; font-weight: 900; }
#panel-close {
  background: var(--card);
  border: none;
  color: var(--text);
  border-radius: 10px;
  font-size: 15px;
  padding: 6px 12px;
  cursor: pointer;
}
#panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 20px;
  -webkit-overflow-scrolling: touch;
}

.shop-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.shop-row .icon { font-size: 26px; flex-shrink: 0; }
.shop-row .info { flex: 1; min-width: 0; }
.shop-row .name { font-weight: 800; font-size: 14px; }
.shop-row .name .lvl { color: var(--muted); font-weight: 600; font-size: 12px; }
.shop-row .eff { font-size: 12px; color: var(--muted); margin-top: 2px; }
.shop-row .eff .next { color: var(--green); }
.buy-btn {
  background: linear-gradient(180deg, #ffc933, #f5a300);
  color: #3d2a00;
  border: none;
  border-radius: 12px;
  font-weight: 900;
  font-size: 13px;
  padding: 9px 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 78px;
}
.buy-btn.gem-cost { background: linear-gradient(180deg, #8cecff, #38b6d8); color: #062c36; }
.buy-btn:disabled { background: #4a4160; color: #8d84a5; cursor: default; }
.buy-btn:not(:disabled):active { transform: scale(0.95); }

.rebirth-card {
  background: linear-gradient(135deg, rgba(122, 231, 255, 0.15), rgba(155, 93, 229, 0.2));
  border: 1px solid rgba(122, 231, 255, 0.35);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  text-align: center;
}
.rebirth-card h3 { font-size: 16px; margin-bottom: 6px; }
.rebirth-card p { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.rebirth-card .big { font-size: 22px; font-weight: 900; color: var(--gem); }
.rebirth-btn {
  margin-top: 10px;
  width: 100%;
  background: linear-gradient(180deg, #8cecff, #38b6d8);
  color: #062c36;
  border: none;
  border-radius: 14px;
  font-weight: 900;
  font-size: 15px;
  padding: 12px;
  cursor: pointer;
}
.rebirth-btn:disabled { background: #4a4160; color: #8d84a5; }
.rebirth-btn.confirm { background: linear-gradient(180deg, #ff8fa3, #e5476b); color: #fff; }

.catalog-head { text-align: center; font-size: 13px; color: var(--muted); margin: 6px 0 10px; }
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}
.cat-cell {
  aspect-ratio: 1;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  position: relative;
  overflow: hidden;
}
.cat-cell svg { width: 68%; height: 62%; display: block; }
.cat-cell .cat-name {
  font-size: 7.5px;
  font-weight: 700;
  color: rgba(0,0,0,0.65);
  text-align: center;
  padding: 0 2px;
  line-height: 1.1;
  max-height: 18px;
  overflow: hidden;
}
.cat-cell.unknown { background: var(--card); color: var(--muted); font-size: 20px; }
.cat-cell.unknown .cat-name { color: var(--muted); }
.cat-cell.locked { background: rgba(0,0,0,0.3); font-size: 18px; }
.cat-cell.locked .cat-name { color: #6d6488; }

.ach-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  opacity: 0.55;
}
.ach-row.done { opacity: 1; box-shadow: inset 0 0 0 1.5px rgba(255, 183, 3, 0.55); }
.ach-row .icon { font-size: 24px; }
.ach-row .info { flex: 1; }
.ach-row .name { font-weight: 800; font-size: 14px; }
.ach-row .desc { font-size: 12px; color: var(--muted); }
.ach-row .reward { font-size: 13px; font-weight: 800; color: var(--gem); white-space: nowrap; }

.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: 14px;
}
.slider-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.slider-wrap input[type="range"] {
  width: 120px;
  accent-color: var(--accent);
  cursor: pointer;
}
#uivol-label {
  font-size: 12px;
  color: var(--muted);
  min-width: 36px;
  text-align: right;
}
.toggle {
  width: 52px; height: 28px;
  border-radius: 14px;
  background: #4a4160;
  border: none;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s;
}
.toggle.on { background: var(--green); }
.toggle.on::after { left: 27px; }
.danger-btn {
  width: 100%;
  background: rgba(255, 107, 129, 0.15);
  border: 1px solid rgba(255, 107, 129, 0.5);
  color: var(--red);
  border-radius: var(--radius);
  padding: 12px;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}
.about { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; line-height: 1.6; }

.info-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid rgba(169, 156, 199, 0.5);
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
}
.info-btn:active { background: var(--card2); }

#doc-modal {
  position: absolute;
  inset: 0;
  background: rgba(10, 6, 24, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 24px;
}
#doc-modal.hidden { display: none; }
#doc-card {
  background: linear-gradient(180deg, #3a2d5e, #291f4a);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 18px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.18s ease-out;
}
#doc-title { font-size: 18px; font-weight: 900; margin-bottom: 10px; }
#doc-text { font-size: 13px; line-height: 1.55; color: #d9d2ec; }
#doc-text p { margin-bottom: 8px; }
#doc-text .doc-now { color: var(--green); font-weight: 700; }
#doc-text .doc-next { color: var(--muted); }
#doc-close {
  width: 100%;
  margin-top: 8px;
  background: linear-gradient(180deg, #ffc933, #f5a300);
  color: #3d2a00;
  border: none;
  border-radius: 12px;
  font-weight: 900;
  font-size: 14px;
  padding: 10px;
  cursor: pointer;
}

#loader {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at top, var(--bg1), var(--bg2) 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 300;
  transition: opacity 0.3s;
}
#loader.hidden { opacity: 0; pointer-events: none; }
#loader-emoji { font-size: 72px; animation: loaderBounce 0.9s ease-in-out infinite alternate; }
@keyframes loaderBounce {
  from { transform: scale(1, 1); }
  to   { transform: scale(1.12, 0.88); }
}
#loader-title {
  font-size: 15px;
  font-weight: 900;
  margin: 14px 0 18px;
  padding: 0 28px;
  text-align: center;
  line-height: 1.4;
}
#loader-bar {
  width: 180px;
  height: 10px;
  background: rgba(0,0,0,0.4);
  border-radius: 5px;
  overflow: hidden;
}
#loader-fill {
  height: 100%;
  width: 40%;
  border-radius: 5px;
  background: linear-gradient(90deg, #ffc933, #f5a300);
  animation: loaderSlide 1.1s ease-in-out infinite alternate;
}
@keyframes loaderSlide {
  from { margin-left: 0; width: 30%; }
  to   { margin-left: 70%; width: 30%; }
}

#toasts {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  width: 90%;
}
.toast {
  background: rgba(20, 14, 40, 0.92);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  animation: toastIn 0.25s ease-out, toastOut 0.4s ease-in 2.6s forwards;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  max-width: 100%;
}
.toast.gold { border-color: rgba(255, 183, 3, 0.6); color: var(--accent); }
.toast.gem { border-color: rgba(122, 231, 255, 0.6); color: var(--gem); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-12px); } }

@media (max-height: 620px) {
  #item-tap-zone { width: min(48vw, 180px); height: min(48vw, 180px); }
  #item-emoji { font-size: min(26vw, 92px); }
  #item-emoji svg { width: min(38vw, 145px); height: min(38vw, 145px); }
}

@media (orientation: landscape) and (max-height: 480px) {
  #game { overflow-y: auto; }
  #topbar { padding: 6px 10px 4px; }
  .res { font-size: 13px; padding: 5px 8px; }
  .res-sub { font-size: 9px; min-height: 10px; }
  #level-info { padding: 2px 10px; }
  .lvl-btn { padding: 5px 10px; font-size: 14px; }
  #level-label { font-size: 13px; }
  #cat-progress { font-size: 11px; }
  #arena { padding: 2px 10px; min-height: 150px; }
  #hp-wrap { height: 16px; margin-bottom: 4px; }
  #item-tap-zone { width: max(96px, 30vh); height: max(96px, 30vh); }
  #item-emoji svg { width: max(76px, 24vh); height: max(76px, 24vh); }
  #item-name { font-size: 13px; margin-bottom: 3px; }
  #combo { height: 14px; font-size: 12px; margin-top: 3px; }
  #boss-call { font-size: 12px; padding: 6px 12px; margin-bottom: 4px; }
  #energy-wrap { padding: 2px 10px; font-size: 12px; }
  #boss-timer { height: 18px; }
  #tabs { padding: 4px 8px 6px; }
  #tabs button { font-size: 15px; padding: 4px 2px; }
  #tabs button span { font-size: 9px; }
  .bonus-btn { font-size: 10px; padding: 5px 4px; }
  #panel { height: 88%; }
  #toasts { top: 44px; }
}
