:root {
  --bg1: #12142b;
  --bg2: #1b1f45;
  --card: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --text: #eef1ff;
  --muted: #9aa2c8;
  --accent: #ffd166;
  --accent2: #7ee0c0;
  --pink: #ff7bac;
  --bad: #ff6b6b;
  --case-hi: #ff8f6b;
  --case-lo: #e0563f;
  --case-lid-hi: #ffb08c;
  --case-lid-lo: #f0714f;
  --radius: 20px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { min-height: 100%; }

body {
  font-family: "Trebuchet MS", "Segoe UI", Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 15% -10%, #2b3070 0%, transparent 60%),
    radial-gradient(900px 700px at 110% 20%, #4b2a6b 0%, transparent 55%),
    linear-gradient(160deg, var(--bg1), var(--bg2) 60%, #101230);
  background-attachment: fixed;
  overflow-x: hidden;
  padding: 18px clamp(10px, 3vw, 34px) 26px;
}

/* ---------- фоновый декор ---------- */
.bg-decor { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.bg-item {
  position: absolute;
  font-size: 44px;
  opacity: 0.13;
  animation: floaty 14s ease-in-out infinite;
  filter: drop-shadow(0 0 12px rgba(255, 255, 255, 0.3));
}
.i1 { top: 12%; left: 4%; animation-delay: 0s; }
.i2 { top: 68%; left: 8%; animation-delay: -2s; }
.i3 { top: 38%; left: 46%; animation-delay: -4s; }
.i4 { top: 80%; left: 72%; animation-delay: -6s; }
.i5 { top: 8%;  left: 78%; animation-delay: -8s; }
.i6 { top: 52%; left: 92%; animation-delay: -3s; }
.i7 { top: 88%; left: 30%; animation-delay: -9s; }
.i8 { top: 25%; left: 25%; animation-delay: -5s; }
@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(-8deg); }
  50% { transform: translateY(-34px) rotate(10deg); }
}

/* ---------- HUD ---------- */
.hud {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(300px, 1.3fr) minmax(260px, 1fr);
  gap: 14px;
  max-width: 1400px;
  margin: 0 auto 18px;
}

.hud-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  font-size: 34px;
  background: linear-gradient(135deg, var(--accent), #ff9f43);
  border-radius: 14px;
  width: 56px; height: 56px;
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(255, 209, 102, 0.35);
  animation: wobble 3.5s ease-in-out infinite;
}
@keyframes wobble { 0%,100% { transform: rotate(-6deg);} 50% { transform: rotate(8deg);} }
.brand h1 { font-size: 20px; letter-spacing: 2px; }
.brand p { font-size: 12px; color: var(--muted); }

.counters { display: flex; gap: 12px; align-items: center; justify-content: space-around; }
.counter { display: flex; align-items: center; gap: 9px; }
.counter-icon { font-size: 26px; }
.counter-value { display: block; font-size: 26px; font-weight: 800; line-height: 1; }
.counter-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.pencils .counter-value { color: var(--accent); }
.perclick .counter-value { color: var(--accent2); }
.clicks .counter-value { color: var(--pink); }
.counter-value.bump { animation: bump 0.28s ease; }
@keyframes bump { 0% { transform: scale(1);} 40% { transform: scale(1.28);} 100% { transform: scale(1);} }

.level-card { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.level-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.level-badge {
  background: linear-gradient(135deg, var(--accent), #ff9f43);
  color: #2b1c05;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 5px 12px;
  border-radius: 999px;
}
.level-badge b { font-size: 15px; }
.level-name { font-size: 13px; color: var(--accent2); font-weight: 700; }
.level-bar { height: 14px; background: rgba(0, 0, 0, 0.35); border-radius: 999px; overflow: hidden; border: 1px solid var(--card-border); }
.level-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent2), var(--accent), var(--pink));
  background-size: 200% 100%;
  animation: slide 3s linear infinite;
  transition: width 0.35s ease;
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.6);
}
@keyframes slide { to { background-position: 200% 0; } }
.level-next { font-size: 12px; color: var(--muted); }

/* ---------- Раскладка ---------- */
.layout {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(340px, 1fr) minmax(250px, 320px);
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}

.panel {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 16px;
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
}
.panel-title { font-size: 17px; display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.panel-title span { font-size: 20px; }
.panel-sub { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.items { display: flex; flex-direction: column; gap: 10px; }

.item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border-radius: 15px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s, background 0.2s;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  width: 100%;
}
.item:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--accent); background: rgba(255, 209, 102, 0.1); }
.item:active:not(:disabled) { transform: scale(0.97); }
.item:disabled { cursor: not-allowed; opacity: 0.55; }
.item.owned { border-color: rgba(126, 224, 192, 0.65); background: rgba(126, 224, 192, 0.12); opacity: 1; }
.item.active-skin { box-shadow: 0 0 0 2px var(--accent2), 0 0 18px rgba(126, 224, 192, 0.45); }

.item-emoji {
  font-size: 24px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255,255,255,0.14), rgba(255,255,255,0.03));
  flex-shrink: 0;
}
.item-info { flex: 1; min-width: 0; }
.item-name { font-size: 14px; font-weight: 700; }
.item-desc { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.item-cost { font-size: 13px; font-weight: 800; color: var(--accent); white-space: nowrap; }
.item.lvl-tag .item-cost { color: var(--accent2); }
.item-owned-tag { font-size: 12px; font-weight: 800; color: var(--accent2); }

/* ---------- Сцена с пеналом ---------- */
.stage {
  position: relative;
  min-height: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 26px 10px;
}
.stage-glow {
  position: absolute;
  width: 460px; height: 460px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 209, 102, 0.28), transparent 65%);
  filter: blur(10px);
  animation: pulseGlow 3s ease-in-out infinite;
  pointer-events: none;
}
@keyframes pulseGlow { 0%,100% { transform: scale(1); opacity: 0.8;} 50% { transform: scale(1.12); opacity: 1;} }

.case-btn {
  position: relative;
  z-index: 2;
  width: min(100%, 480px);
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.45));
}
.case-btn:hover { transform: scale(1.03); }
.case-btn:active, .case-btn.hit, .case-btn.pressed { transform: scale(0.94) rotate(-1.5deg); }
.case-svg { width: 100%; height: auto; display: block; }
.case-hint {
  position: absolute;
  left: 50%; bottom: -6px;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.8);
  animation: hintBlink 1.4s ease-in-out infinite;
}
@keyframes hintBlink { 0%,100% { opacity: 0.55;} 50% { opacity: 1;} }

.case-decor .d { fill: rgba(255, 255, 255, 0.35); }

/* ---------- Скины пенала ---------- */
.case-btn[data-skin="classic"] { --case-hi: #ff8f6b; --case-lo: #e0563f; --case-lid-hi: #ffb08c; --case-lid-lo: #f0714f; }
.case-btn[data-skin="sunset"]  { --case-hi: #ff9e5e; --case-lo: #d64570; --case-lid-hi: #ffc07a; --case-lid-lo: #ef6a8b; }
.case-btn[data-skin="ocean"]   { --case-hi: #5ec8ff; --case-lo: #1560b8; --case-lid-hi: #93ddff; --case-lid-lo: #2b86d9; }
.case-btn[data-skin="diamond"] { --case-hi: #eaf7ff; --case-lo: #7fb6d9; --case-lid-hi: #ffffff; --case-lid-lo: #a9d4ee; }
.case-btn[data-skin="mint"]    { --case-hi: #7ee0c0; --case-lo: #23a586; --case-lid-hi: #a6f0d8; --case-lid-lo: #37c39f; }
.case-btn[data-skin="berry"]   { --case-hi: #ff7bac; --case-lo: #c9307a; --case-lid-hi: #ffa3c4; --case-lid-lo: #e04e93; }
.case-btn[data-skin="gold"]    { --case-hi: #ffe08a; --case-lo: #d99a18; --case-lid-hi: #fff0b8; --case-lid-lo: #f0b93a; }
.case-btn[data-skin="neon"]    { --case-hi: #5ce1ff; --case-lo: #7a3bff; --case-lid-hi: #8ef0ff; --case-lid-lo: #9a5cff; }
.case-btn[data-skin="galaxy"]  { --case-hi: #5468ff; --case-lo: #1b1148; --case-lid-hi: #8b7bff; --case-lid-lo: #3a2a7a; }
.case-btn[data-skin="rainbow"] {
  --case-hi: #ff8f6b; --case-lo: #7a3bff;
  --case-lid-hi: #ffd166; --case-lid-lo: #7ee0c0;
}
.case-btn[data-skin="rainbow"] .case-body { animation: hueSpin 5s linear infinite; }
@keyframes hueSpin { to { filter: hue-rotate(360deg); } }
.case-btn[data-skin="gold"] .case-body { animation: goldShine 2.4s ease-in-out infinite; }
@keyframes goldShine { 0%,100% { filter: brightness(1);} 50% { filter: brightness(1.25);} }
.case-btn[data-skin="neon"] { animation: neonFlicker 3s ease-in-out infinite; }
@keyframes neonFlicker { 0%,100% { filter: drop-shadow(0 0 14px rgba(92,225,255,.5));} 50% { filter: drop-shadow(0 0 26px rgba(122,59,255,.85));} }
.case-btn[data-skin="galaxy"] .d { fill: #fff; animation: twinkle 2s ease-in-out infinite; }
.case-btn[data-skin="galaxy"] .d2 { animation-delay: -0.7s; }
.case-btn[data-skin="galaxy"] .d3 { animation-delay: -1.3s; }
@keyframes twinkle { 0%,100% { opacity: 0.3;} 50% { opacity: 1;} }
.case-btn[data-skin="mint"] .case-decor .d { fill: rgba(255,255,255,.55); }
.case-btn[data-skin="berry"] .case-decor .d { fill: rgba(255,255,255,.5); }

/* ---------- Всплывающие карандаши ---------- */
.float-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.float-num {
  position: absolute;
  font-size: 24px;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7), 0 0 14px rgba(255, 209, 102, 0.7);
  animation: rise 1s ease-out forwards;
  white-space: nowrap;
}
@keyframes rise {
  0% { transform: translateY(0) scale(0.7); opacity: 0; }
  20% { transform: translateY(-14px) scale(1.15); opacity: 1; }
  100% { transform: translateY(-110px) scale(1); opacity: 0; }
}
.particle {
  position: absolute;
  font-size: 22px;
  animation: fly 0.85s ease-out forwards;
  pointer-events: none;
}
@keyframes fly {
  0% { transform: translate(0, 0) rotate(0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(0.4); opacity: 0; }
}
.combo {
  position: absolute;
  bottom: 6px;
  font-size: 15px;
  font-weight: 800;
  color: var(--pink);
  text-shadow: 0 0 12px rgba(255, 123, 172, 0.7);
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 6;
}
.combo.show { opacity: 1; }

/* ---------- Футер, тосты ---------- */
.footer {
  position: relative;
  z-index: 2;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
}
.ghost-btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--card-border);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.16); transform: translateY(-2px); }
.ghost-btn.danger:hover { background: rgba(255, 107, 107, 0.25); border-color: var(--bad); }
.footer-note { font-size: 12px; color: var(--muted); }

.toasts {
  position: fixed;
  left: 0; right: 0; bottom: 26px;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 50;
}
.toast {
  background: linear-gradient(135deg, var(--accent), #ff9f43);
  color: #2b1c05;
  font-weight: 800;
  font-size: 14px;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  transform: translateY(140px);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.2, 1.4, 0.4, 1), opacity 0.3s;
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.out { transform: translateY(140px); opacity: 0; }

/* всплывающие числа и частицы */
.float-num, .particle, .confetti { position: fixed; pointer-events: none; }
.confetti {
  font-size: 26px;
  animation: confettiFall 1.6s ease-in forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(90vh) rotate(720deg); opacity: 0; }
}
.level-card.pop { animation: pop 0.45s cubic-bezier(0.2, 1.5, 0.4, 1); }
.lvl-reward { color: var(--accent); font-weight: 700; }

.levelup-flash {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 12, 30, 0.6);
  z-index: 60;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.levelup-box {
  background: linear-gradient(160deg, #2b3070, #1b1f45);
  border: 2px solid var(--accent);
  border-radius: 26px;
  padding: 34px 46px;
  text-align: center;
  box-shadow: 0 0 60px rgba(255, 209, 102, 0.45);
  animation: pop 0.45s cubic-bezier(0.2, 1.5, 0.4, 1);
}
@keyframes pop { from { transform: scale(0.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.levelup-box .big { font-size: 46px; font-weight: 900; color: var(--accent); }
.levelup-box .name { font-size: 20px; margin-top: 6px; color: var(--accent2); }
.levelup-box .sub { font-size: 14px; color: var(--muted); margin-top: 10px; }

/* ---------- Адаптив ---------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .hud { grid-template-columns: 1fr; }
  .stage { min-height: 420px; order: -1; }
}
@media (max-width: 460px) {
  .counters { flex-wrap: wrap; }
  .counter-value { font-size: 21px; }
  .brand h1 { font-size: 17px; }
}
