:root {
  --ink: #12304a;
  --ink-soft: #3d6280;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-line: rgba(255, 255, 255, 0.9);
  --accent: #f2622e;
  --accent2: #2f6fd0;
  --shadow: 0 8px 26px rgba(20, 60, 95, 0.22);
  --r: 18px;
}

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

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: #cfe4f4;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
}

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

.hidden { display: none !important; }

/* ------------------------------------------------------------------ HUD */
#hud {
  position: absolute; inset: 0; pointer-events: none;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) calc(env(safe-area-inset-right, 0px) + 14px)
           calc(env(safe-area-inset-bottom, 0px) + 12px) calc(env(safe-area-inset-left, 0px) + 14px);
  display: flex; flex-direction: column; justify-content: space-between;
}

.hud-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }

.panel {
  background: var(--glass); border: 2px solid var(--glass-line);
  border-radius: var(--r); padding: 7px 14px; box-shadow: var(--shadow);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  text-align: left; min-width: 96px;
}
.panel.right { text-align: right; }
.panel .big { font-size: 26px; font-weight: 900; line-height: 1.05; letter-spacing: -0.5px; }
.panel .lbl { font-size: 11px; font-weight: 800; letter-spacing: 1.4px; color: var(--ink-soft); }

.lives { font-size: 19px; letter-spacing: 2px; line-height: 1.2; }
.lives .dead { filter: grayscale(1); opacity: 0.32; }

.combo {
  align-self: flex-start; margin-top: 4px;
  font-size: 24px; font-weight: 900; color: #fff;
  background: linear-gradient(135deg, var(--accent), #ffa53c);
  padding: 5px 15px; border-radius: 999px; box-shadow: var(--shadow);
  transform-origin: center; animation: pop 0.28s ease;
}
@keyframes pop { 0% { transform: scale(1.5); } 100% { transform: scale(1); } }

.banner {
  position: absolute; left: 0; right: 0; top: 24%;
  text-align: center; font-size: clamp(22px, 6vw, 40px); font-weight: 900;
  letter-spacing: 3px; color: #fff; opacity: 0;
  text-shadow: 0 4px 16px rgba(15, 50, 80, 0.55);
}
.banner.show { animation: bannerIn 2.2s ease forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translateY(18px) scale(0.9); }
  15% { opacity: 1; transform: translateY(0) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px); }
}

#popups { position: absolute; left: 0; right: 0; top: 38%; text-align: center; }
.pop {
  font-size: clamp(18px, 5vw, 30px); font-weight: 900; color: #fff;
  text-shadow: 0 3px 12px rgba(15, 50, 80, 0.6); animation: popUp 1.15s ease forwards;
  letter-spacing: 1px;
}
.pop.gold { color: #ffd85e; }
.pop.bad { color: #ff8f7a; }
@keyframes popUp {
  0% { opacity: 0; transform: translateY(14px) scale(0.8); }
  20% { opacity: 1; transform: translateY(0) scale(1.06); }
  100% { opacity: 0; transform: translateY(-46px) scale(1); }
}

.hud-bottom { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }

#tiltbar {
  position: relative; width: min(46vw, 190px); height: 10px; border-radius: 999px;
  background: var(--glass); border: 2px solid var(--glass-line); box-shadow: var(--shadow);
}
#tiltbar::after {
  content: ''; position: absolute; left: 50%; top: -4px; width: 2px; height: 14px;
  background: rgba(30, 80, 120, 0.35); transform: translateX(-50%);
}
#tiltdot {
  position: absolute; top: 50%; left: 50%; width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(160deg, #fff, #bcd8f0);
  border: 2px solid #fff; box-shadow: 0 3px 10px rgba(20, 60, 95, 0.35);
  transform: translate(-50%, -50%);
}

#speedo { text-align: right; }
#speedo .speed { font-size: 30px; font-weight: 900; line-height: 1; color: #fff;
  text-shadow: 0 3px 12px rgba(15, 50, 80, 0.5); }
#speedo .speed small { font-size: 12px; font-weight: 800; margin-left: 4px; letter-spacing: 1px; }
#speedo .bar {
  margin-top: 5px; width: min(40vw, 160px); height: 8px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.55); overflow: hidden; box-shadow: var(--shadow);
}
#speedo .bar i { display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, #6fd2f5, #2f6fd0 60%, var(--accent));
  transition: width 0.12s linear; }

.icon-btn {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + 74px);
  right: calc(env(safe-area-inset-right, 0px) + 14px);
  pointer-events: auto; width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid var(--glass-line); background: var(--glass); color: var(--ink);
  font-size: 15px; font-weight: 900; box-shadow: var(--shadow); cursor: pointer;
}

/* -------------------------------------------------------------- Screens */
.screen {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 18px; z-index: 10;
}
.screen.dim { background: rgba(140, 185, 220, 0.45); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }

.card {
  width: min(92vw, 440px); max-height: 92vh; overflow-y: auto;
  background: linear-gradient(170deg, rgba(255,255,255,0.94), rgba(230,244,253,0.9));
  border: 2px solid #fff; border-radius: 26px; box-shadow: 0 20px 50px rgba(20, 60, 95, 0.3);
  padding: 24px 22px; text-align: center;
}
.card.small { width: min(88vw, 360px); }

h1 { margin: 0 0 2px; font-size: clamp(38px, 12vw, 62px); font-weight: 900; letter-spacing: -1.5px; }
h1 span { color: var(--accent); }
h2 { margin: 0 0 12px; font-size: 26px; font-weight: 900; letter-spacing: 0.5px; }
.sub { margin: 0 0 18px; color: var(--ink-soft); font-size: 15px; font-weight: 600; }

button {
  font-family: inherit; cursor: pointer; display: block; width: 100%;
  border-radius: 16px; font-weight: 900; letter-spacing: 1px;
}
.primary {
  padding: 16px; font-size: 20px; border: none; color: #fff; margin: 6px 0;
  background: linear-gradient(160deg, var(--accent), #ff9445);
  box-shadow: 0 8px 20px rgba(242, 98, 46, 0.4);
}
.primary:active { transform: translateY(2px); }
.ghost {
  padding: 11px; font-size: 14px; margin-top: 8px; color: var(--ink);
  background: rgba(255, 255, 255, 0.7); border: 2px solid rgba(140, 180, 210, 0.5);
}

.best { margin: 12px 0 4px; font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.best b { color: var(--ink); font-size: 17px; }

.howto { margin: 16px 0 6px; text-align: left; display: grid; gap: 9px; }
.howto div { display: flex; align-items: center; gap: 11px; font-size: 13.5px; color: var(--ink-soft); font-weight: 600; }
.howto i { font-style: normal; font-size: 19px; width: 26px; text-align: center; }
.howto b { color: var(--ink); }

.opts { margin-top: 16px; display: grid; gap: 8px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 13px; font-weight: 800; color: var(--ink-soft); }

.seg { display: flex; gap: 4px; background: rgba(255, 255, 255, 0.7);
  border: 2px solid rgba(140, 180, 210, 0.5); border-radius: 14px; padding: 3px; }
.seg-btn {
  width: auto; padding: 7px 12px; font-size: 12.5px; border: none; border-radius: 11px;
  background: transparent; color: var(--ink-soft); white-space: nowrap;
}
.seg-btn.on { background: linear-gradient(160deg, var(--accent), #ff9445); color: #fff;
  box-shadow: 0 3px 10px rgba(242, 98, 46, 0.35); }
input[type=range] { flex: 1; accent-color: var(--accent); }
.note { margin-top: 10px; font-size: 12px; font-weight: 700; color: var(--ink-soft); min-height: 16px; }
.note.warn { color: #c2582f; }

.stats { display: flex; justify-content: space-around; margin: 8px 0 14px; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 26px; font-weight: 900; }
.stats span { font-size: 11px; font-weight: 800; letter-spacing: 1px; color: var(--ink-soft); }

.calib-icon { font-size: 44px; animation: tilt 1.4s ease-in-out infinite; }
@keyframes tilt { 0%,100% { transform: rotate(-14deg); } 50% { transform: rotate(14deg); } }
.count { font-size: 54px; font-weight: 900; color: var(--accent); }

@media (min-width: 820px) {
  .howto div { font-size: 15px; }
}
