@font-face { font-family: 'Fredoka'; font-weight: 500; font-display: swap; src: url(vendor/fonts/Fredoka-Medium.ttf) format('truetype'); }
@font-face { font-family: 'Fredoka'; font-weight: 600; font-display: swap; src: url(vendor/fonts/Fredoka-SemiBold.ttf) format('truetype'); }
@font-face { font-family: 'Fredoka'; font-weight: 700; font-display: swap; src: url(vendor/fonts/Fredoka-Bold.ttf) format('truetype'); }

:root {
  --bg: #0b0a24;
  --ink: #ffffff;
  --muted: #bdb6ee;
  --cyan: #5ff0ff;
  --gold: #ffd34d;
  --green: #7dff6a;
  --coral: #ff5a6e;
  --pink: #ff6bd6;
  --panel: rgba(18, 14, 52, 0.86);
  --edge: rgba(140, 125, 255, 0.35);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  font-weight: 500;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

body { position: fixed; inset: 0; }

canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }

[hidden] { display: none !important; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }

/* ---------- HUD (top-left; the top-right corner stays free for the host) ---------- */
.hud {
  position: fixed;
  top: calc(var(--sat) + 10px);
  left: calc(var(--sal) + 16px);
  pointer-events: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), 0 0 18px rgba(95, 240, 255, 0.35);
}
.score { font-weight: 700; font-size: clamp(34px, 6.4vmin, 54px); line-height: 1; letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
.hud-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.hud-best { font-size: 14px; color: var(--muted); }
.combo {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 10px 3px 8px; border-radius: 999px;
  background: rgba(18, 14, 52, 0.6); border: 1px solid var(--edge);
  font-size: 16px; text-shadow: none;
}
.combo b { font-weight: 700; min-width: 22px; }
.combo .meter { width: 58px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
.combo .meter i { display: block; height: 100%; width: 100%; background: currentColor; transform-origin: left center; transform: scaleX(0); }
.combo[data-level="1"] { color: var(--muted); }
.combo[data-level="2"] { color: var(--cyan); }
.combo[data-level="3"] { color: var(--green); }
.combo[data-level="4"] { color: var(--gold); }
.combo[data-level="5"] { color: var(--pink); }
.bump { animation: bump 0.3s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* ---------- floating feedback ---------- */
.pops { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.pop {
  position: absolute; transform: translate(-50%, -50%);
  font-weight: 700; font-size: 20px; color: var(--cyan); white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  animation: rise 0.8s ease-out forwards;
}
.pop.hot { color: #fff07a; font-size: 22px; }
.pop.gold { color: var(--gold); font-size: 22px; }
.pop.alien { color: var(--green); font-size: 22px; }
@keyframes rise {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}

.banner {
  position: fixed; left: 50%; top: calc(var(--sat) + 16vh);
  transform: translateX(-50%);
  padding: 6px 16px; border-radius: 999px;
  background: rgba(18, 14, 52, 0.7); border: 1px solid var(--edge);
  font-weight: 600; font-size: clamp(16px, 3.4vmin, 22px); white-space: nowrap;
  pointer-events: none; opacity: 0; visibility: hidden;
}
.banner.show { visibility: visible; animation: bannerIn 0.25s ease-out forwards; }
.banner.combo { color: var(--gold); }
.banner.distance { color: var(--cyan); }
.banner.tip { color: #fff; white-space: normal; text-align: center; max-width: min(86vw, 420px); }
@keyframes bannerIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.count {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%);
  font-weight: 700; font-size: clamp(72px, 20vmin, 140px); color: #fff;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 0 30px rgba(95, 240, 255, 0.6);
  pointer-events: none; opacity: 0;
}
.count.show { opacity: 1; }
.count.bump { animation: countIn 0.35s ease-out; }
@keyframes countIn { from { transform: translate(-50%, -50%) scale(1.6); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }

.hint {
  position: fixed; left: 50%; bottom: calc(var(--sab) + 9vh); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px 10px 14px; border-radius: 999px;
  background: rgba(18, 14, 52, 0.78); border: 1px solid var(--cyan);
  font-weight: 700; font-size: 22px; pointer-events: none; white-space: nowrap;
}
.tap-ring { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--cyan); animation: tap 0.9s ease-out infinite; }
@keyframes tap { 0% { transform: scale(0.6); opacity: 1; } 100% { transform: scale(1.35); opacity: 0.2; } }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0;
  padding: calc(var(--sat) + 64px) calc(var(--sar) + 18px) calc(var(--sab) + 18px) calc(var(--sal) + 18px);
  display: flex; flex-direction: column; align-items: center;
}
.title { justify-content: space-between; }
.logo { margin: 0; line-height: 0.85; text-align: center; font-weight: 700; }
.logo-ufo { display: block; font-size: clamp(26px, 6vmin, 44px); letter-spacing: 0.4em; margin-right: -0.4em; color: var(--cyan); }
.logo-flip {
  display: block; font-size: clamp(76px, 20vmin, 150px); letter-spacing: 0.03em;
  filter: drop-shadow(0 5px 0 #2b1d78) drop-shadow(0 0 22px rgba(125, 110, 255, 0.55));
}
.logo-flip span, .logo-flip em {
  display: inline-block; font-style: normal;
  background: linear-gradient(180deg, #ffffff 0%, #d6cfff 55%, #9d8bff 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo-flip em { transform: scaleY(-1); color: transparent; background: linear-gradient(180deg, #9d8bff 0%, #d6cfff 45%, #ffffff 100%); -webkit-background-clip: text; background-clip: text; }
.title-top { display: flex; flex-direction: column; align-items: center; }
.tagline { margin: 10px 0 0; color: var(--muted); font-size: clamp(14px, 2.6vmin, 18px); text-align: center; }
.title-bottom { display: flex; flex-direction: column; align-items: center; gap: 12px; width: min(100%, 380px); }
.title-best { font-size: 18px; color: var(--muted); }
.title-best b { color: var(--gold); font-size: 22px; margin-left: 4px; }
.skins { display: flex; align-items: center; gap: 12px; width: 100%; justify-content: center; }
.round {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: rgba(18, 14, 52, 0.75); border: 1px solid var(--edge);
  font-size: 28px; line-height: 40px; font-weight: 700;
}
.skin-name { display: flex; flex-direction: column; align-items: center; min-width: 170px; }
.skin-name b { font-size: 19px; font-weight: 600; }
.skin-name small { color: var(--muted); font-size: 13px; }
.lock { margin-top: 3px; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: rgba(255, 90, 110, 0.2); color: #ffb4bf; }
.big {
  min-width: 210px; padding: 14px 34px; border-radius: 999px;
  background: linear-gradient(180deg, #7af6ff 0%, #2fc6ff 100%); color: #0b0a24;
  font-weight: 700; font-size: 26px; letter-spacing: 0.02em;
  box-shadow: 0 5px 0 #1a6fa8, 0 0 26px rgba(95, 240, 255, 0.45);
}
.big:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #1a6fa8, 0 0 20px rgba(95, 240, 255, 0.4); }
.ghost { padding: 10px 22px; border-radius: 999px; border: 1px solid var(--edge); background: rgba(18, 14, 52, 0.6); font-weight: 600; font-size: 17px; }
.howto { margin: 0; font-size: 14px; color: var(--muted); }

.result { justify-content: center; padding-top: calc(var(--sat) + 18px); }
.card {
  width: min(100%, 360px);
  padding: 18px 22px 20px; border-radius: 26px;
  background: var(--panel); border: 1px solid var(--edge);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  text-align: center; animation: cardIn 0.3s ease-out;
}
@keyframes cardIn { from { transform: translateY(18px) scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
.card h2 { margin: 0; font-size: 22px; font-weight: 600; color: var(--muted); }
.final { font-size: 64px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.new-best { display: inline-block; margin: 2px 0 6px; padding: 2px 12px; border-radius: 999px; background: var(--gold); color: #2a1c00; font-weight: 700; font-size: 14px; }
.breakdown { list-style: none; padding: 0; margin: 10px 0 8px; display: grid; gap: 6px; }
.breakdown li { display: grid; grid-template-columns: 1fr auto 64px; gap: 10px; align-items: baseline; font-size: 17px; }
.breakdown span { text-align: left; color: var(--muted); }
.breakdown b { font-weight: 600; }
.breakdown em { font-style: normal; text-align: right; color: var(--cyan); font-weight: 600; }
.best-line { font-size: 16px; color: var(--muted); }
.best-line b { color: var(--gold); }
.unlock { margin-top: 8px; padding: 6px 10px; border-radius: 12px; background: rgba(125, 255, 106, 0.16); color: var(--green); font-weight: 600; font-size: 15px; }
.next { margin-top: 6px; font-size: 13px; color: var(--muted); }
.actions { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 14px; }

.sound {
  position: fixed; left: calc(var(--sal) + 14px); bottom: calc(var(--sab) + 14px);
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(18, 14, 52, 0.75); border: 1px solid var(--edge);
  display: grid; place-items: center;
}
.sound svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sound .spk { fill: #fff; }
.sound .slash { display: none; stroke: var(--coral); }
.sound.off .wave { display: none; }
.sound.off .slash { display: inline; }

.loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; gap: 12px;
  background: var(--bg); font-size: 20px; color: var(--muted); transition: opacity 0.3s;
}
.loading.gone { opacity: 0; pointer-events: none; visibility: hidden; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.2); border-top-color: var(--cyan); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Short landscape screens: tighter menus. */
@media (max-height: 500px) {
  .screen { padding-top: calc(var(--sat) + 14px); }
  .title { flex-direction: row; justify-content: space-around; align-items: center; }
  .logo-flip { font-size: clamp(64px, 22vh, 120px); }
  .tagline { max-width: 260px; }
  .title-bottom { gap: 8px; width: auto; }
  .big { padding: 10px 28px; font-size: 22px; min-width: 180px; }
  .card { padding: 12px 18px 14px; width: min(100%, 560px); display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; align-items: center; }
  .card h2, .final, .new-best, .best-line { grid-column: 1; }
  .new-best { justify-self: center; }
  .card .breakdown { grid-column: 2; grid-row: 1 / span 3; margin: 0; }
  .final { font-size: 48px; }
  .unlock, .next { grid-column: 1 / span 2; }
  .actions { grid-column: 1 / span 2; flex-direction: row; justify-content: center; margin-top: 10px; }
  .hint { bottom: calc(var(--sab) + 6vh); font-size: 18px; }
  .score { font-size: 30px; }
  .hud-row { margin-top: 4px; }
  .combo { font-size: 14px; padding: 2px 8px 2px 7px; }
  .banner { top: auto; bottom: calc(var(--sab) + 12px); }
}

/* Host pause: freeze every CSS animation too. */
body.is-paused *, body.is-paused *::before, body.is-paused *::after { animation-play-state: paused !important; }

@media (prefers-reduced-motion: reduce) {
  .tap-ring, .bump, .count.bump, .card { animation: none; }
}
