@font-face {
  font-family: "Lilita One";
  src: url("../assets/fonts/LilitaOne-Regular.ttf") format("truetype");
  font-display: block;
}

:root {
  --ink: #2A1650;
  --ink-deep: #170A33;
  --sky-top: #46BFFF;
  --sky-bottom: #8C6BFF;
  --yellow: #FFC21F;
  --orange: #FF7B12;
  --coral: #FF4F6D;
  --teal: #22C7D6;
  --white: #FFFFFF;
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
  font-family: "Lilita One", system-ui, sans-serif;
  color: var(--white);
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}

#app { position: fixed; inset: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 12px 0;
  pointer-events: none;
}
.hud-right { display: flex; gap: 8px; align-items: center; }
.pill {
  pointer-events: auto;
  display: flex; align-items: center; gap: 6px;
  background: var(--ink); border-radius: 999px;
  padding: 6px 14px; font-size: 20px; letter-spacing: 0.5px;
  box-shadow: 0 4px 0 var(--ink-deep);
}
#levelPill.hard { background: #D7263D; box-shadow: 0 4px 0 #7A0F22; }
.coin {
  display: inline-block; width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFF2A8, #FFC21F 55%, #F08A00);
  border: 2px solid var(--ink);
}
button { font-family: inherit; cursor: pointer; border: none; color: inherit; }
.round {
  pointer-events: auto; width: 42px; height: 42px; border-radius: 50%;
  background: var(--ink); box-shadow: 0 4px 0 var(--ink-deep);
  display: grid; place-items: center; padding: 0;
}
.round svg { width: 24px; height: 24px; color: var(--white); }

/* ---------- bottom bar ---------- */
#bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; align-items: center; gap: 18px;
  padding: 0 12px max(14px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.tool {
  pointer-events: auto; position: relative;
  width: 58px; height: 58px; border-radius: 18px;
  background: var(--white); color: var(--ink);
  border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink);
  display: grid; place-items: center; padding: 0;
}
.tool svg { width: 30px; height: 30px; }
.tool:active, .btn:active, .go:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.ad {
  position: absolute; top: -8px; right: -8px;
  background: var(--yellow); color: var(--ink); border: 2px solid var(--ink);
  border-radius: 8px; font-size: 11px; padding: 1px 4px;
}
.go {
  pointer-events: auto;
  height: 62px; min-width: 150px; border-radius: 20px;
  font-size: 30px; letter-spacing: 1px;
  background: linear-gradient(180deg, #7CF29A, #2DBE5F);
  border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink);
  color: var(--white); text-shadow: 0 2px 0 var(--ink);
  visibility: hidden; transform: scale(0.6); opacity: 0;
  transition: transform 0.18s cubic-bezier(.3,1.6,.6,1), opacity 0.15s;
}
.go.show { visibility: visible; transform: scale(1); opacity: 1; animation: goPulse 1.1s ease-in-out infinite 0.3s; }
@keyframes goPulse { 50% { transform: scale(1.07); } }

/* ---------- banner and tip ---------- */
#banner {
  position: absolute; left: 50%; top: 38%;
  transform: translate(-50%, -50%) scale(0.4) rotate(-4deg);
  font-size: 46px; padding: 10px 28px; border-radius: 18px;
  background: #D7263D; border: 4px solid var(--ink); box-shadow: 0 6px 0 var(--ink);
  text-shadow: 0 3px 0 var(--ink); white-space: nowrap;
  opacity: 0; pointer-events: none;
}
#banner.show { animation: bannerIn 1.6s ease forwards; }
#banner.new { background: #22C7D6; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-4deg); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(-4deg); }
  25% { transform: translate(-50%, -50%) scale(1) rotate(-4deg); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-4deg); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9) rotate(-4deg); }
}
#tip {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: calc(max(10px, env(safe-area-inset-top)) + 56px);
  max-width: 92%; text-align: center;
  font-size: 19px; line-height: 1.2; padding: 8px 16px; border-radius: 14px;
  background: rgba(42, 22, 80, 0.88);
  opacity: 0; transition: opacity 0.25s; pointer-events: none;
}
#tip.show { opacity: 1; }

/* ---------- panels ---------- */
.panel {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(23, 10, 51, 0.55);
  opacity: 0; visibility: hidden; transition: opacity 0.2s;
}
.panel.show { opacity: 1; visibility: visible; }
.card {
  width: min(86vw, 340px);
  background: var(--white); color: var(--ink);
  border: 4px solid var(--ink); border-radius: 28px; box-shadow: 0 8px 0 var(--ink);
  padding: 22px 22px 18px; text-align: center;
  transform: scale(0.7); transition: transform 0.25s cubic-bezier(.3,1.6,.6,1);
}
.panel.show .card { transform: scale(1); }
.card h1 {
  margin: 0 0 8px; font-weight: normal; font-size: 42px; letter-spacing: 1px;
  color: var(--yellow); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink);
}
.card h1.red { color: var(--coral); }
.card p { margin: 0 0 16px; font-size: 18px; color: #5A4A86; font-family: system-ui, sans-serif; font-weight: 700; }
.stars { display: flex; justify-content: center; gap: 8px; margin: 4px 0 10px; }
.stars i {
  width: 52px; height: 52px; display: block;
  clip-path: polygon(50% 0, 63% 33%, 98% 36%, 71% 58%, 80% 94%, 50% 75%, 20% 94%, 29% 58%, 2% 36%, 37% 33%);
  background: #D9D3F7; transform: scale(0.6);
}
.stars i:nth-child(2) { transform: translateY(-8px) scale(0.6); }
.stars i.on { background: linear-gradient(180deg, #FFF06A, #FFB21E); animation: starPop 0.35s cubic-bezier(.3,1.8,.6,1) forwards; }
.stars i:nth-child(2).on { animation-name: starPop2; }
@keyframes starPop { to { transform: scale(1); } }
@keyframes starPop2 { to { transform: translateY(-8px) scale(1); } }
.reward { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 30px; margin-bottom: 10px; }
.reward .coin { width: 28px; height: 28px; }
.gift { margin: 4px 6px 14px; }
.gift-label { font-size: 15px; margin-bottom: 4px; color: #5A4A86; }
.gift-bar { height: 14px; border-radius: 99px; background: #E9E4FF; border: 2px solid var(--ink); overflow: hidden; }
#giftFill { height: 100%; width: 20%; background: linear-gradient(90deg, #FF8AC8, #FF4F6D); transition: width 0.6s ease 0.3s; }
.btn {
  position: relative; display: block; width: 100%;
  margin-top: 10px; padding: 12px; border-radius: 18px;
  font-size: 26px; letter-spacing: 1px;
  border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink);
}
.btn.primary { background: linear-gradient(180deg, #7CF29A, #2DBE5F); color: var(--white); text-shadow: 0 2px 0 var(--ink); }
.btn.secondary { background: linear-gradient(180deg, #FFE36A, #FFB21E); color: var(--ink); font-size: 22px; }
.btn .ad { top: -10px; right: -6px; }

/* ---------- ad placeholder ---------- */
#adStub {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0, 0, 0, 0.85); font-size: 24px;
  opacity: 0; visibility: hidden; transition: opacity 0.15s;
}
#adStub.show { opacity: 1; visibility: visible; }

/* ---------- level menu ---------- */
#levelPill { cursor: pointer; color: var(--white); font-family: inherit; }
.grid-ico { width: 16px; height: 16px; fill: currentColor; opacity: 0.85; }
.levels-card { width: min(92vw, 440px); max-height: 86vh; display: flex; flex-direction: column; padding: 16px 14px 14px; }
.levels-head { display: flex; align-items: center; justify-content: center; padding: 0 4px 6px; }
.levels-head h1 { margin: 0; font-size: 34px; }
#levelsClose { flex: none; font-size: 22px; padding: 9px; }
#levelList { overflow-y: auto; padding: 4px 2px 6px; overscroll-behavior: contain; }
.stage-title {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 4px 8px; font-size: 18px; color: var(--ink);
}
.stage-title .count { font-size: 13px; color: #8A7FB0; margin-left: auto; }
.stage-title.locked { color: #B7B0D6; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lv {
  position: relative; aspect-ratio: 1 / 1; border-radius: 14px; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 20px; color: var(--white); text-shadow: 0 2px 0 var(--ink);
  background: linear-gradient(180deg, #8C6BFF, #6A4BE0);
  border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink);
}
.lv.hard { background: linear-gradient(180deg, #FF6B7F, #D7263D); }
.lv.current { background: linear-gradient(180deg, #7CF29A, #2DBE5F); }
.lv.locked { background: #E4E0F5; color: #B7B0D6; text-shadow: none; box-shadow: 0 4px 0 #B7B0D6; border-color: #B7B0D6; cursor: default; }
.lv .st { display: flex; gap: 1px; margin-top: 1px; }
.lv .st i { width: 10px; height: 10px; display: block; background: rgba(255,255,255,0.3);
  clip-path: polygon(50% 0, 63% 33%, 98% 36%, 71% 58%, 80% 94%, 50% 75%, 20% 94%, 29% 58%, 2% 36%, 37% 33%); }
.lv .st i.on { background: #FFD43B; }
.lv .lock { width: 16px; height: 16px; fill: #B7B0D6; }

/* ---------- loading screen ---------- */
#loading {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6vh;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
  transition: opacity 0.25s;
}
#loading.hide { opacity: 0; pointer-events: none; }
.load-logo { width: min(78vw, 60vh, 460px); height: auto; }
.load-bar {
  width: min(60vw, 260px); height: 18px; border-radius: 99px;
  background: rgba(42, 22, 80, 0.35); border: 3px solid var(--ink); overflow: hidden;
}
#loadFill {
  display: block; height: 100%; width: 15%; border-radius: 99px;
  background: repeating-linear-gradient(-45deg, #FFE14A 0 10px, #FFC21F 10px 20px);
  background-size: 28px 28px; animation: loadStripes 0.6s linear infinite;
  transition: width 0.3s ease;
}
@keyframes loadStripes { to { background-position: 28px 0; } }

/* ---------- wide, low screens: buttons beside the city ---------- */
body.wide #bar { top: 0; padding: 0; }
body.wide #clearBtn { position: absolute; left: 12px; bottom: max(14px, env(safe-area-inset-bottom)); }
body.wide #hintBtn { position: absolute; right: 12px; bottom: max(14px, env(safe-area-inset-bottom)); }
body.wide .go { position: absolute; right: 12px; top: 50%; margin-top: -31px; }
body.wide #tip { top: max(10px, env(safe-area-inset-top)); max-width: calc(100% - 340px); }

/* ---------- paused by YouTube: stop every animation ---------- */
body.paused *, body.paused *::before, body.paused *::after { animation-play-state: paused !important; }
