:root {
  --ink: #f4f7ff;
  --panel: rgba(9, 13, 34, 0.88);
  --line: rgba(170, 195, 255, 0.18);
  --cyan: #5ef0ff;
  --violet: #8f7bff;
  --gold: #ffd65a;
  --st: max(10px, env(safe-area-inset-top));
  --sr: max(12px, env(safe-area-inset-right));
  --sb: max(14px, env(safe-area-inset-bottom));
  --sl: max(12px, env(safe-area-inset-left));
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #070a1c;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* ---------- menus ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--st) var(--sr) var(--sb) var(--sl);
  background: radial-gradient(ellipse at center, rgba(4, 6, 18, 0.15), rgba(4, 6, 18, 0.65));
}
.screen.dim { background: rgba(4, 6, 18, 0.58); }
.panel {
  width: min(92vw, 420px);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 22px 20px;
  border-radius: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  animation: rise 0.28s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.title-panel { gap: 14px; }
.logo {
  margin: 4px 0 0;
  font-size: clamp(40px, 14vw, 64px);
  font-weight: 900;
  letter-spacing: 0.12em;
  padding-left: 0.12em;
  line-height: 1;
  background: linear-gradient(180deg, #ffffff 0%, #b8e8ff 45%, #b59bff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(120, 200, 255, 0.45));
}
.tag { margin: 0 0 6px; font-size: 16px; line-height: 1.4; opacity: 0.88; text-wrap: balance; }
h2 { margin: 2px 0 4px; font-size: 26px; font-weight: 900; }
.btn {
  min-height: 54px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.09);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
.btn small { font-size: 12px; font-weight: 700; letter-spacing: 0.02em; opacity: 0.75; margin-left: 6px; }
.btn:active { transform: scale(0.97); }
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn.primary {
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  color: #071022;
  border: 0;
  box-shadow: 0 8px 26px rgba(94, 240, 255, 0.32);
}
.btn.small { min-height: 44px; font-size: 15px; font-weight: 700; letter-spacing: 0.02em; }
.btn.icon { width: 44px; min-height: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 30px; line-height: 40px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.row-head { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.row-head h2 { margin: 0; }

.level-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.level-list li { display: flex; }
.level-list .level-card { flex: 1; }
.nw { white-space: nowrap; }
.level-card {
  width: 100%;
  min-height: 74px;
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 9px 14px 9px 10px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  text-align: left;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
.level-card:hover { background: rgba(255, 255, 255, 0.1); }
.level-card:active { transform: scale(0.98); }
.level-card:disabled { opacity: 0.42; cursor: default; }
.level-card.endless { grid-template-columns: 56px 1fr; }
.lvl-icon { width: 56px; height: 56px; }
.lvl-text b { display: block; font-size: 17px; font-weight: 800; }
.lvl-text small { display: block; font-size: 13px; opacity: 0.78; margin-top: 2px; }
.lvl-text .lvl-sub { opacity: 0.6; font-size: 12px; }
.stars { white-space: nowrap; font-size: 19px; }
.stars span, .big-stars span { color: rgba(255, 255, 255, 0.2); }
.stars .on { color: var(--gold); }
.big-stars { font-size: 46px; letter-spacing: 0.06em; min-height: 0; }
.big-stars:empty { display: none; }
.big-stars .on { color: var(--gold); text-shadow: 0 0 18px rgba(255, 214, 90, 0.6); display: inline-block; animation: pop 0.45s backwards; }
.big-stars .on:nth-child(2) { animation-delay: 0.15s; }
.big-stars .on:nth-child(3) { animation-delay: 0.3s; }
@keyframes pop { from { transform: scale(0.2); opacity: 0; } 70% { transform: scale(1.25); } to { transform: none; opacity: 1; } }
#resText { margin: 0; font-size: 15px; line-height: 1.45; opacity: 0.88; }
.extra { margin: 0; font-size: 15px; font-weight: 700; color: #9fe0ff; }
.extra:empty { display: none; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.hud-top {
  position: absolute;
  top: var(--st);
  left: var(--sl);
  right: var(--sr);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.hud-btn {
  pointer-events: auto;
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(9, 13, 34, 0.62);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.bars { width: 14px; height: 16px; border-left: 5px solid #fff; border-right: 5px solid #fff; }
.goal {
  flex: 1;
  min-width: 0;
  max-width: 540px;
  margin-right: auto;
  padding: 7px 12px 8px;
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(9, 13, 34, 0.55);
}
.goal-row { display: flex; gap: 8px; align-items: center; font-size: 12px; font-weight: 800; letter-spacing: 0.03em; opacity: 0.85; }
#levelName { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#timer { font-variant-numeric: tabular-nums; }
.bar { height: 10px; margin: 5px 0 4px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
#barFill {
  height: 100%;
  transform-origin: left center;
  transform: scaleX(0.01);
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  transition: transform 0.25s ease-out;
}
#goalText { font-size: 14px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud.gold #barFill { background: linear-gradient(90deg, var(--gold), #ff9f43); }
#hud.gold #goalText { color: var(--gold); animation: glow 0.9s ease-in-out infinite alternate; }
@keyframes glow { from { opacity: 0.75; } to { opacity: 1; text-shadow: 0 0 12px rgba(255, 214, 90, 0.8); } }

#toast {
  position: absolute;
  top: calc(var(--st) + 86px);
  left: 50%;
  max-width: 92vw;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(9, 13, 34, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-weight: 800;
  font-size: 15px;
  width: max-content;
  text-align: center;
  text-wrap: balance;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.gold { color: var(--gold); }
#toast.blue { color: #a8e6ff; }
#toast.purple { color: #dcb3ff; }
#toast.green { color: #9dffbe; }

#hint {
  position: absolute;
  left: var(--sl);
  right: calc(var(--sr) + 96px);
  bottom: calc(var(--sb) + 10px);
  margin: 0 auto;
  width: fit-content;
  max-width: 460px;
  padding: 11px 16px;
  border-radius: 16px;
  background: rgba(9, 13, 34, 0.78);
  border: 1px solid rgba(120, 220, 255, 0.28);
  font-size: 15px;
  font-weight: 750;
  line-height: 1.3;
  text-align: center;
  text-wrap: balance;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
}
#hint.show { opacity: 1; transform: none; }

#pullBtn {
  pointer-events: auto;
  position: absolute;
  right: calc(var(--sr) + 4px);
  bottom: calc(var(--sb) + 4px);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  --cd: 1;
  background: conic-gradient(var(--cyan) calc(var(--cd) * 360deg), rgba(255, 255, 255, 0.13) 0);
  display: grid;
  place-content: center;
  isolation: isolate;
  touch-action: none;
}
#pullBtn::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #1d2a5c, #0a0f27);
  z-index: -1;
}
.pull-label { font-weight: 900; font-size: 16px; letter-spacing: 0.06em; }
.pull-key { display: none; font-size: 10px; font-weight: 800; opacity: 0.6; letter-spacing: 0.08em; }
#pullBtn.desk .pull-key { display: block; }
#pullBtn.ready { box-shadow: 0 0 24px rgba(94, 240, 255, 0.5); }
#pullBtn:not(.ready) .pull-label { opacity: 0.55; }
#pullBtn.nudge.ready { animation: nudge 0.9s ease-in-out infinite; }
@keyframes nudge { 50% { transform: scale(1.12); box-shadow: 0 0 36px rgba(94, 240, 255, 0.9); } }

#intro { position: absolute; top: 28%; left: 0; right: 0; text-align: center; opacity: 0; pointer-events: none; }
#intro.go { animation: intro 3s ease-out forwards; }
@keyframes intro { 0% { opacity: 0; transform: scale(0.94); } 12% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; } }
.intro-k { font-size: 13px; font-weight: 800; letter-spacing: 0.32em; opacity: 0.75; }
.intro-t { font-size: clamp(32px, 10vw, 56px); font-weight: 900; margin: 4px 0; text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6); }

.noscript { position: fixed; inset: 40% 0 auto; text-align: center; font-size: 18px; }

/* short screens: phones held sideways */
@media (max-height: 500px) {
  .panel { padding: 14px 18px; gap: 9px; max-height: calc(100dvh - 16px); }
  .logo { font-size: 44px; }
  .tag { font-size: 14px; margin: 0; }
  .btn { min-height: 46px; font-size: 16px; }
  .btn.small { min-height: 44px; }
  #toast { top: calc(var(--st) + 70px); font-size: 14px; }
  #pullBtn { width: 68px; height: 68px; }
  #hint { right: calc(var(--sr) + 84px); font-size: 14px; padding: 9px 14px; }
  #intro { top: 24%; }
  .intro-t { font-size: 34px; }
  .goal { max-width: 420px; }
  .levels-panel { width: min(96vw, 640px); }
  .level-list { display: grid; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 360px) {
  .tag { font-size: 14px; }
  /* narrow phones: stars go under the name so the text gets the width */
  .level-card { grid-template-columns: 48px 1fr; row-gap: 2px; }
  .level-card .lvl-icon { width: 48px; height: 48px; grid-row: span 2; }
  .level-card .stars { grid-column: 2; font-size: 14px; }
  #goalText { font-size: 13px; }
  .lvl-text b { font-size: 15px; }
}
.btn.link { display: grid; place-items: center; text-decoration: none; }
