@font-face {
  font-family: Fredoka;
  src: url("../fonts/Fredoka-latin-ext.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: Fredoka;
  src: url("../fonts/Fredoka.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #24324a;
  --ink-soft: #4a5b76;
  --foam: #f7fbff;
  --mint: #5ee0c8;
  --mint-d: #2bb39c;
  --gold: #ffd56a;
  --peach: #ffb38a;
  --blush: #ff8fab;
  --sky: #8fd3ee;
  --shadow: 0 10px 28px rgba(36, 50, 74, 0.22);
  --radius: 22px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background: radial-gradient(1200px 800px at 50% 0%, #c4eefc 0%, #8ec8ea 45%, #6aa6d6 100%);
  color: var(--ink);
  font-family: Fredoka, "Trebuchet MS", "Segoe UI", sans-serif;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  display: grid;
  place-items: center;
}

#stage {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  background: #6aa6d6;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(20, 40, 70, 0.35);
}

canvas#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 24px 110px;
  pointer-events: none;
  z-index: 4;
}
#screenTitle {
  justify-content: flex-start;
  padding-top: 7%;
  padding-bottom: 0;
}
.overlay.active { pointer-events: auto; }
.overlay.hidden { display: none; }

.panel {
  width: min(920px, 92%);
  background: linear-gradient(180deg, rgba(247,251,255,0.94), rgba(230,244,255,0.9));
  border: 3px solid rgba(255,255,255,0.85);
  border-radius: 28px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.9);
  padding: 28px 28px 24px;
  text-align: center;
  backdrop-filter: blur(8px);
}

.logo {
  font-weight: 700;
  font-size: clamp(42px, 8vw, 84px);
  line-height: 0.9;
  letter-spacing: -0.03em;
  color: #fff;
  text-shadow:
    0 4px 0 #2bb39c,
    0 10px 24px rgba(36,50,74,0.28);
  margin-bottom: 4px;
}
.logo span {
  display: block;
  font-size: 0.42em;
  letter-spacing: 0.28em;
  margin-top: 8px;
  color: #fff7c2;
  text-shadow: 0 3px 0 #e09a3a, 0 8px 16px rgba(36,50,74,0.25);
}

.tagline {
  color: var(--ink-soft);
  font-size: 18px;
  margin: 10px 0 22px;
}

.btn-row, .nav-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

button, .btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 18px;
  border: 0;
  border-radius: 16px;
  padding: 12px 22px;
  cursor: pointer;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 4px 0 #c9d6e6, 0 8px 16px rgba(36,50,74,0.12);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.08s ease;
  pointer-events: auto;
}
button:hover, .btn:hover { filter: brightness(1.04); }
button:active, .btn:active, button.down {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #c9d6e6, 0 4px 10px rgba(36,50,74,0.12);
}
button.primary {
  background: linear-gradient(180deg, #7af0dc, #46d3b8);
  color: #163a34;
  box-shadow: 0 4px 0 #1f9a86, 0 8px 16px rgba(36,50,74,0.14);
}
button.gold {
  background: linear-gradient(180deg, #ffe58a, #ffc84a);
  box-shadow: 0 4px 0 #d39a22, 0 8px 16px rgba(36,50,74,0.14);
}
button.ghost {
  background: rgba(255,255,255,0.55);
  box-shadow: 0 3px 0 rgba(36,50,74,0.12);
}
button:disabled {
  filter: grayscale(0.4) brightness(0.9);
  cursor: default;
  transform: none;
}

h2, h3 { font-weight: 700; }
h2 { font-size: 32px; margin-bottom: 8px; }
h3 { font-size: 20px; margin-bottom: 6px; }
p { color: var(--ink-soft); line-height: 1.45; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin: 16px 0 8px;
}
@media (max-width: 720px) {
  .level-grid { grid-template-columns: repeat(2, 1fr); }
  .overlay { padding-bottom: 128px; }
}

.level-card {
  position: relative;
  border: 0;
  border-radius: 18px;
  padding: 14px 10px 12px;
  background: linear-gradient(180deg, #fff, #e7f5ff);
  box-shadow: 0 4px 0 #c3d6e8, 0 8px 14px rgba(36,50,74,0.1);
  min-height: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.level-card .num {
  font-weight: 700;
  font-size: 26px;
  line-height: 1;
}
.level-card .name {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
}
.level-card .stars { letter-spacing: 1px; font-size: 14px; color: #e0a020; }
.level-card .best { font-size: 11px; color: #5a7; font-weight: 600; }
.level-card.locked {
  background: linear-gradient(180deg, #d7e2ec, #c5d3e0);
  color: #7a8aa0;
  box-shadow: 0 4px 0 #a9b8c8;
}
.level-card.locked .stars, .level-card.locked .best { display: none; }
.level-card.cleared { outline: 3px solid #5ee0c8; }

.howto {
  text-align: left;
  display: grid;
  gap: 8px;
  margin: 12px auto 18px;
  max-width: 520px;
}
.howto div {
  background: rgba(255,255,255,0.7);
  border-radius: 12px;
  padding: 8px 12px;
  color: var(--ink);
  font-weight: 600;
}
.howto kbd {
  display: inline-block;
  background: #24324a;
  color: #fff;
  border-radius: 6px;
  padding: 0 6px;
  font-family: inherit;
  font-size: 13px;
  margin: 0 2px;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: none;
  padding: 14px 16px;
  pointer-events: none;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 8px rgba(20,40,70,0.45);
}
#hud.show { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
#hud .cluster { display: flex; flex-direction: column; gap: 2px; }
#hud .cluster.meta { align-items: flex-end; }
#hud .pill {
  background: rgba(24, 36, 54, 0.42);
  backdrop-filter: blur(8px);
  border-radius: 14px;
  padding: 6px 12px 7px;
  box-shadow: 0 4px 14px rgba(20,40,70,0.18);
}
#hud .score { font-size: 26px; letter-spacing: 0.02em; }
#hud .combo { color: #ffe58a; font-size: 16px; min-height: 0; }
#hud .hearts { font-size: 20px; letter-spacing: 4px; color: #ff6b8a; text-shadow: 0 1px 0 #fff, 0 2px 6px rgba(20,40,70,0.35); }
#hud .hearts .empty { color: rgba(255,255,255,0.45); }
#hud .meta { text-align: right; font-size: 15px; }
#hud button {
  pointer-events: auto;
  padding: 6px 12px;
  font-size: 14px;
  margin-top: 10px;
}

#introCard, #pauseMenu, #resultCard { width: min(520px, 92%); }
#introCard .world { color: var(--mint-d); font-weight: 700; letter-spacing: 0.12em; font-size: 13px; }
#resultCard .stars-big { font-size: 36px; color: #e0a020; margin: 6px 0 10px; }
.breakdown {
  text-align: left;
  margin: 10px auto 16px;
  max-width: 340px;
  background: rgba(255,255,255,0.65);
  border-radius: 14px;
  padding: 10px 14px;
}
.breakdown .row { display: flex; justify-content: space-between; padding: 3px 0; font-weight: 600; }
.breakdown .row.total { border-top: 2px dashed rgba(36,50,74,0.15); margin-top: 6px; padding-top: 8px; font-size: 18px; }

#toast {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translate(-50%, -20px);
  opacity: 0;
  color: #fff;
  font-weight: 700;
  font-size: 42px;
  text-shadow: 0 4px 0 rgba(36,50,74,0.25), 0 10px 24px rgba(20,40,70,0.35);
  z-index: 6;
  pointer-events: none;
  transition: none;
}
#toast.pop {
  animation: toastPop 0.9s ease-out forwards;
}
@keyframes toastPop {
  0% { opacity: 0; transform: translate(-50%, 16px) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.12); }
  60% { opacity: 1; transform: translate(-50%, -8px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -28px) scale(1); }
}

#touch {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  display: none;
}
#touch.show { display: block; }
#touch button {
  position: absolute;
  pointer-events: auto;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  font-size: 28px;
  background: rgba(255,255,255,0.55);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(36,50,74,0.18);
  backdrop-filter: blur(4px);
  bottom: 22px;
}
#touch .left { left: 18px; }
#touch .right { left: 112px; }
#touch .jump { right: 18px; width: 100px; height: 100px; background: rgba(126,240,220,0.75); }
#touch .grip { right: 130px; font-size: 16px; width: 76px; height: 76px; bottom: 30px; }
#touch .pause-btn { top: 12px; right: 12px; bottom: auto; width: 48px; height: 48px; font-size: 18px; }

#scores {
  max-width: 420px;
  margin: 10px auto 16px;
  text-align: left;
}
#scores ol { padding-left: 22px; }
#scores li {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-weight: 600;
  color: var(--ink);
}

.fine { font-size: 12px; color: var(--ink-soft); margin-top: 8px; }
