/* ============================================================
   Gummy Welt — UI skin
   Soft candy glass, rounded everything, chunky pressable buttons.
   ============================================================ */

:root {
  --grape-900: #1b0f2b;
  --grape-800: #2a1740;
  --grape-700: #3a2159;
  --grape-600: #4d2d72;

  --pink: #ff6fae;
  --pink-deep: #e0407f;
  --tangerine: #ffab3d;
  --tangerine-deep: #f0801c;
  --lime: #7ee081;
  --lime-deep: #45bd6b;
  --berry: #8c6cff;
  --sky: #58cdf5;
  --cream: #fff6e9;

  --panel: rgba(60, 32, 92, 0.72);
  --panel-line: rgba(255, 255, 255, 0.16);
  --text: #fff6e9;
  --text-dim: #d6bfe8;

  --r-lg: 28px;
  --r-md: 18px;
  --r-sm: 12px;

  --shadow-panel: 0 24px 60px rgba(12, 4, 24, 0.55), 0 2px 0 rgba(255, 255, 255, 0.12) inset;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

/* `hidden` has to win over the display rules below it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--grape-900);
  color: var(--text);
  font-family: "Nunito", "Baloo 2", ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display",
               "Trebuchet MS", system-ui, -apple-system, sans-serif;
  font-weight: 800;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  user-select: none;
}

#app { position: fixed; inset: 0; }

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ─────────────────────────── Screens ─────────────────────────── */

.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: calc(18px + var(--safe-t)) calc(18px + var(--safe-r)) calc(18px + var(--safe-b)) calc(18px + var(--safe-l));
  animation: screen-in 0.34s cubic-bezier(0.22, 1.2, 0.36, 1) both;
}
.screen[hidden] { display: none; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.screen-title,
.screen-modal { align-items: center; justify-content: center; }

.screen-title {
  gap: clamp(18px, 4vh, 42px);
  text-align: center;
  background: radial-gradient(58% 62% at 50% 46%, rgba(24, 10, 42, 0.55), rgba(24, 10, 42, 0.14) 62%, transparent 78%);
}

.screen-levels,
.screen-skins,
.screen-how {
  background: radial-gradient(120% 90% at 50% 0%, rgba(140, 108, 255, 0.28), transparent 60%),
              linear-gradient(180deg, rgba(27, 15, 43, 0.9), rgba(27, 15, 43, 0.97));
  backdrop-filter: blur(10px);
  gap: 14px;
}

.screen-modal {
  background: radial-gradient(90% 70% at 50% 40%, rgba(60, 32, 92, 0.55), rgba(14, 6, 26, 0.86));
  backdrop-filter: blur(7px);
}

/* ─────────────────────────── Title ─────────────────────────── */

.title-art { display: grid; gap: 6px; }

.logo {
  margin: 0;
  font-size: clamp(46px, 13vw, 118px);
  line-height: 0.88;
  letter-spacing: 0.02em;
  display: grid;
  gap: 0.02em;
}
.logo-line { display: block; }
.logo-line-2 { color: #fff; }

.ltr {
  display: inline-block;
  background: linear-gradient(180deg, #fff 4%, var(--pink) 46%, var(--pink-deep) 96%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 0 rgba(120, 24, 70, 0.55)) drop-shadow(0 16px 24px rgba(0, 0, 0, 0.45));
  animation: letter-bob 2.6s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.08s);
}
.logo-line-2 .ltr {
  background: linear-gradient(180deg, #fff 4%, var(--tangerine) 46%, var(--tangerine-deep) 96%);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 6px 0 rgba(150, 70, 8, 0.5)) drop-shadow(0 16px 24px rgba(0, 0, 0, 0.45));
}

@keyframes letter-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-9px) rotate(-1.6deg); }
}

.tagline {
  margin: 0;
  font-size: clamp(13px, 2.6vw, 19px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 2px 10px rgba(24, 8, 40, 0.9), 0 0 22px rgba(24, 8, 40, 0.7);
}

.title-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}
.star-total {
  font-size: 15px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.28);
  border-radius: 999px;
  padding: 7px 14px;
}
.star-total b { color: var(--tangerine); }

/* ─────────────────────────── Buttons ─────────────────────────── */

.menu { display: grid; gap: 13px; width: min(320px, 82vw); }
.menu-compact { width: min(260px, 74vw); }
.menu-row { grid-auto-flow: column; width: auto; gap: 10px; }

.gummy-btn {
  position: relative;
  border: 0;
  padding: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #a687d6, #6f4aa8);
  box-shadow: 0 7px 0 #4b2c78, 0 12px 22px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  font: inherit;
  color: var(--text);
  transition: transform 0.09s ease, box-shadow 0.09s ease, filter 0.15s ease;
}
.gummy-btn > span {
  display: block;
  padding: 15px 26px;
  border-radius: 999px;
  font-size: clamp(16px, 2.4vw, 20px);
  letter-spacing: 0.03em;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 58%);
  text-shadow: 0 2px 3px rgba(40, 10, 60, 0.5);
}
.gummy-btn:hover { filter: brightness(1.08); }
.gummy-btn:active,
.gummy-btn.pressed {
  transform: translateY(6px);
  box-shadow: 0 1px 0 #4b2c78, 0 5px 12px rgba(0, 0, 0, 0.4);
}
.gummy-btn:focus-visible { outline: 3px solid var(--sky); outline-offset: 4px; }

.gummy-btn-primary {
  background: linear-gradient(180deg, #ff9ac6, var(--pink-deep));
  box-shadow: 0 7px 0 #a92457, 0 12px 26px rgba(224, 64, 127, 0.42);
}
.gummy-btn-primary:active,
.gummy-btn-primary.pressed { box-shadow: 0 1px 0 #a92457, 0 5px 14px rgba(224, 64, 127, 0.4); }

.gummy-btn[disabled] { filter: grayscale(0.7) brightness(0.7); pointer-events: none; }

.icon-btn {
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 17px;
  line-height: 1;
  color: var(--text);
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid var(--panel-line);
  display: grid;
  place-items: center;
  transition: transform 0.1s ease, background 0.15s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.24); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.off { opacity: 0.4; }

/* ─────────────────────────── Screen headers ─────────────────────────── */

.screen-head {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 12px;
  width: min(920px, 100%);
  margin: 0 auto;
}
.screen-head h2 {
  margin: 0;
  text-align: center;
  font-size: clamp(20px, 4vw, 30px);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3);
}
.screen-sub {
  margin: 0 auto;
  width: min(920px, 100%);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
}

/* ─────────────────────────── Level select ─────────────────────────── */

.worlds {
  width: min(920px, 100%);
  margin: 0 auto;
  overflow-y: auto;
  padding: 4px 4px 40px;
  display: grid;
  gap: 22px;
  scrollbar-width: thin;
}
.world-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}
.world-head h3 { margin: 0; font-size: 19px; }
.world-head span { font-size: 13px; color: var(--text-dim); font-weight: 700; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
}

.level-card {
  position: relative;
  border: 1px solid var(--panel-line);
  border-radius: var(--r-md);
  padding: 12px 12px 10px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.04));
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.12s cubic-bezier(0.3, 1.4, 0.5, 1), box-shadow 0.15s ease;
}
.level-card::after {
  content: '';
  position: absolute;
  inset: -40% -10% auto;
  height: 70%;
  background: radial-gradient(60% 100% at 50% 0%, rgba(255, 255, 255, 0.28), transparent 70%);
  pointer-events: none;
}
.level-card:hover { transform: translateY(-4px) scale(1.02); box-shadow: 0 14px 26px rgba(0, 0, 0, 0.35); }
.level-card:active { transform: translateY(0) scale(0.98); }
.level-card .num { font-size: 12px; color: var(--text-dim); letter-spacing: 0.1em; }
.level-card .name { display: block; font-size: 15px; margin: 2px 0 8px; line-height: 1.15; }
.level-card .mini-stars { font-size: 15px; letter-spacing: 2px; color: rgba(255, 255, 255, 0.22); }
.level-card .mini-stars b { color: var(--tangerine); font-weight: inherit; text-shadow: 0 0 10px rgba(255, 171, 61, 0.7); }
.level-card .best { position: absolute; right: 10px; bottom: 9px; font-size: 11px; color: var(--text-dim); }

.level-card.locked { cursor: not-allowed; filter: grayscale(0.6); opacity: 0.55; }
.level-card.locked:hover { transform: none; box-shadow: none; }
.level-card.locked::before {
  content: '🔒';
  position: absolute;
  top: 9px;
  right: 10px;
  font-size: 14px;
  opacity: 0.9;
}
.level-card[data-world="1"] { background: linear-gradient(165deg, rgba(126, 224, 129, 0.26), rgba(255, 255, 255, 0.04)); }
.level-card[data-world="2"] { background: linear-gradient(165deg, rgba(140, 108, 255, 0.28), rgba(255, 255, 255, 0.04)); }
.level-card[data-world="3"] { background: linear-gradient(165deg, rgba(255, 143, 168, 0.26), rgba(255, 255, 255, 0.04)); }
.level-card.boss { background: linear-gradient(165deg, rgba(255, 111, 174, 0.35), rgba(140, 108, 255, 0.18)); }
.level-card.cleared { border-color: rgba(255, 171, 61, 0.4); }

/* ─────────────────────────── Bear shop ─────────────────────────── */

.skin-grid {
  width: min(920px, 100%);
  margin: 0 auto;
  overflow-y: auto;
  padding: 6px 4px 40px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
.skin-card {
  border: 1px solid var(--panel-line);
  border-radius: var(--r-md);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.03));
  padding: 12px;
  display: grid;
  justify-items: center;
  gap: 7px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  transition: transform 0.12s ease, border-color 0.2s ease;
}
.skin-card:hover { transform: translateY(-3px); }
.skin-card canvas { width: 84px; height: 84px; }
.skin-card .skin-name { font-size: 14px; }
.skin-card .skin-req { font-size: 11.5px; color: var(--text-dim); font-weight: 700; }
.skin-card.selected { border-color: var(--tangerine); box-shadow: 0 0 0 2px rgba(255, 171, 61, 0.35), 0 12px 24px rgba(0, 0, 0, 0.35); }
.skin-card.locked { filter: grayscale(0.85) brightness(0.75); cursor: not-allowed; }

/* ─────────────────────────── How to play ─────────────────────────── */

.how-grid {
  width: min(920px, 100%);
  margin: 0 auto;
  overflow-y: auto;
  padding: 6px 4px 40px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.how-card {
  border: 1px solid var(--panel-line);
  border-radius: var(--r-md);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.03));
  padding: 16px;
}
.how-icon { font-size: 26px; }
.how-card h3 { margin: 6px 0 6px; font-size: 17px; }
.how-card p { margin: 0; font-size: 13.5px; line-height: 1.5; font-weight: 700; color: var(--text-dim); }
.how-card b { color: var(--cream); }

/* ─────────────────────────── Panels / results ─────────────────────────── */

.panel {
  position: relative;
  width: min(430px, 90vw);
  border-radius: var(--r-lg);
  padding: 30px 26px 24px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(16px);
  display: grid;
  justify-items: center;
  gap: 16px;
  text-align: center;
  animation: pop-in 0.4s cubic-bezier(0.2, 1.5, 0.4, 1) both;
}
@keyframes pop-in {
  from { transform: scale(0.86) translateY(18px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.panel h2 { margin: 0; font-size: clamp(21px, 4.4vw, 28px); }

.ribbon {
  position: absolute;
  top: -16px;
  padding: 8px 22px;
  border-radius: 999px;
  font-size: 14px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #ffd479, var(--tangerine-deep));
  color: #4a2000;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.stars { display: flex; gap: 10px; font-size: 46px; line-height: 1; }
.stars .star {
  color: rgba(255, 255, 255, 0.16);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  transform: scale(0.7);
  transition: none;
}
.stars .star.on {
  color: var(--tangerine);
  text-shadow: 0 0 22px rgba(255, 171, 61, 0.85), 0 3px 0 rgba(140, 70, 0, 0.5);
  animation: star-pop 0.5s cubic-bezier(0.2, 1.8, 0.4, 1) both;
}
@keyframes star-pop {
  0%   { transform: scale(0.2) rotate(-40deg); opacity: 0; }
  70%  { transform: scale(1.35) rotate(8deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.tally {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
}
.tally li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text-dim);
  animation: slide-in 0.3s ease both;
}
.tally li.good { color: var(--lime); background: rgba(126, 224, 129, 0.14); }
.tally li b { color: var(--cream); }
@keyframes slide-in { from { opacity: 0; transform: translateX(-10px); } }

.score-big { font-size: 40px; line-height: 1; display: flex; align-items: baseline; gap: 8px; }
.score-big small { font-size: 13px; color: var(--text-dim); letter-spacing: 0.1em; text-transform: uppercase; }
.best-line { font-size: 13px; color: var(--tangerine); min-height: 16px; font-weight: 700; }
.toggle-row { display: flex; gap: 10px; }

/* ─────────────────────────── HUD ─────────────────────────── */

.hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
}
.hud[hidden] { display: none; }
.hud-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.hud-bottom { flex-direction: column; align-items: center; gap: 8px; }
.hud-cluster { display: flex; gap: 8px; align-items: center; }
.hud .icon-btn { pointer-events: auto; }

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(20, 8, 36, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.13);
  font-size: 15px;
  line-height: 1;
  backdrop-filter: blur(8px);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}
.chip-icon { font-size: 14px; }
.chip-score { color: var(--tangerine); }
.chip-combo {
  color: #fff;
  background: linear-gradient(180deg, var(--pink), var(--pink-deep));
  border-color: rgba(255, 255, 255, 0.35);
  animation: combo-pulse 0.55s ease-in-out infinite alternate;
}
@keyframes combo-pulse { from { transform: scale(1); } to { transform: scale(1.09); } }
.chip.warn { color: #ff9aa8; }

.charge-rail { display: flex; gap: 7px; }
.charge-pip {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  border: 2px solid rgba(255, 255, 255, 0.3);
  transition: transform 0.18s cubic-bezier(0.2, 1.7, 0.4, 1), background 0.18s ease;
}
.charge-pip.on {
  background: radial-gradient(circle at 35% 30%, #fff, var(--sky));
  border-color: #fff;
  box-shadow: 0 0 12px rgba(88, 205, 245, 0.85);
  transform: scale(1.14);
}

.focus-meter {
  width: min(190px, 46vw);
  height: 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.focus-meter i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--sky), #b6f0ff);
  transform-origin: left;
  transition: transform 0.08s linear;
}
.focus-meter.empty i { background: linear-gradient(90deg, #7a5f92, #a189b8); }

/* ─────────────────────────── Toasts ─────────────────────────── */

.toast-layer {
  position: absolute;
  left: 0;
  right: 0;
  top: 22%;
  display: grid;
  justify-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  padding: 9px 20px;
  border-radius: 999px;
  font-size: clamp(15px, 3.2vw, 21px);
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 226, 245, 0.9));
  color: #6a1442;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
  animation: toast-life 1.5s cubic-bezier(0.2, 1.3, 0.4, 1) forwards;
}
@keyframes toast-life {
  0%   { opacity: 0; transform: translateY(16px) scale(0.7); }
  16%  { opacity: 1; transform: translateY(0) scale(1.06); }
  26%  { transform: scale(1); }
  76%  { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-22px) scale(0.94); }
}

/* ─────────────────────────── Fade ─────────────────────────── */

.fade {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: var(--grape-900);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s ease;
}
.fade.on { opacity: 1; pointer-events: all; }

/* ─────────────────────────── Small screens ─────────────────────────── */

/* Portrait phones: the bottom of the screen is where thumbs drag, so the
   charge pips and focus meter ride up under the top row instead. */
@media (orientation: portrait) and (max-width: 620px) {
  .hud {
    justify-content: flex-start;
    gap: 10px;
  }
  .hud-bottom { align-items: center; }
  .charge-rail { gap: 9px; }
  .charge-pip { width: 17px; height: 17px; }
  .focus-meter { width: min(150px, 40vw); }
  .toast-layer { top: 30%; }
}

@media (max-height: 560px) {
  .screen-title { gap: 12px; }
  .logo { font-size: clamp(38px, 9vw, 62px); }
  .gummy-btn > span { padding: 11px 22px; }
  .menu { gap: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
