:root {
  --ink: #251c3d;
  --ink-soft: #594b7a;
  --pink: #ff568e;
  --pink-dark: #d9356d;
  --mint: #2fd9a4;
  --mint-dark: #17ab7e;
  --gold: #ffcf48;
  --gold-dark: #e09c14;
  --sky: #4cc9f0;
  --glass: rgba(255, 255, 255, 0.86);
  --glass-border: rgba(255, 255, 255, 0.95);
  --shadow-soft: 0 12px 32px rgba(42, 26, 86, 0.16);
  --font-display: 'Fredoka', 'Nunito', 'Avenir Next Rounded', 'SF Pro Rounded', ui-rounded, 'Segoe UI', system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #8fd3ff;
  color: var(--ink);
  font-family: var(--font-display);
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#game-canvas:active {
  cursor: grabbing;
}

.is-hidden {
  display: none !important;
}

/* =========================================================================
   START SCREEN — Compact floating card that celebrates the live 3D course
   ========================================================================= */
.overlay-start {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: clamp(18px, 4vw, 44px);
  pointer-events: none;
  z-index: 20;
}

.start-card {
  pointer-events: auto;
  width: min(410px, calc(100vw - 36px));
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 3px solid var(--glass-border);
  border-radius: 28px;
  padding: 24px 26px 22px;
  box-shadow: 0 18px 44px rgba(36, 22, 82, 0.2), 0 4px 0 rgba(255, 255, 255, 0.7) inset;
  text-align: left;
}

.start-badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, #fff099, #ffd166);
  color: #6b4300;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  margin-bottom: 10px;
  box-shadow: 0 2px 0 rgba(224, 156, 20, 0.35);
}

.game-title {
  margin: 0 0 10px;
  line-height: 0.96;
  font-size: clamp(34px, 5vw, 48px);
  font-weight: 900;
  letter-spacing: -0.02em;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.title-wobble {
  color: var(--pink);
  text-shadow: 0 4px 0 #ffd2e2;
}

.title-rush {
  color: #269fe6;
  text-shadow: 0 4px 0 #cceeff;
}

.start-tagline {
  margin: 0 0 16px;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--ink-soft);
  font-weight: 600;
}

.best-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: #e9fff6;
  border: 2px solid #8ef0cb;
  color: #0d7a57;
  font-size: 13px;
  font-weight: 800;
}

.btn-play {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 15px 28px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(180deg, #ff6fa0 0%, #ff4784 100%);
  color: #ffffff;
  font-family: inherit;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.05em;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--pink-dark), 0 12px 24px rgba(255, 71, 132, 0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease;
}

.btn-play:hover {
  filter: brightness(1.04);
  transform: translateY(-2px);
  box-shadow: 0 8px 0 var(--pink-dark), 0 16px 28px rgba(255, 71, 132, 0.42);
}

.btn-play:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--pink-dark), 0 6px 14px rgba(255, 71, 132, 0.3);
}

.btn-play-icon {
  font-size: 18px;
}

.controls-strip {
  margin-top: 15px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-soft);
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 7px;
  background: #f5f1ff;
  border: 1.5px solid #d7cbf5;
  box-shadow: 0 2px 0 #d7cbf5;
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink);
}

/* Compact iframe preview mode (sulat-peek=1) */
body.is-peek-mode .overlay-start {
  padding: 12px;
}
body.is-peek-mode .start-card {
  width: min(260px, calc(100vw - 24px));
  padding: 14px 16px;
  border-radius: 20px;
}
body.is-peek-mode .start-badge {
  font-size: 9.5px;
  padding: 4px 10px;
  white-space: nowrap;
}
body.is-peek-mode .start-tagline,
body.is-peek-mode .controls-strip {
  display: none;
}
body.is-peek-mode .game-title {
  font-size: 24px;
  margin-bottom: 10px;
}
body.is-peek-mode .btn-play {
  padding: 10px 18px;
  font-size: 16px;
}

/* =========================================================================
   IN-GAME HUD
   ========================================================================= */
.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}

.hud-left,
.hud-center,
.hud-right {
  position: fixed;
  top: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.hud-left {
  left: 14px;
}

.hud-center {
  left: 50%;
  transform: translateX(-50%);
}

.hud-right {
  right: 14px;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2.5px solid var(--glass-border);
  box-shadow: var(--shadow-soft);
}

.hud-label {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.hud-value {
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.split-delta {
  font-size: 12px;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.split-delta.is-ahead {
  background: #d8ffef;
  color: #0c8a5e;
}

.split-delta.is-behind {
  background: #ffe0ea;
  color: #c92a5d;
}

.cp-track {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cp-pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e1dbf2;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 3px rgba(37, 28, 61, 0.16);
  transition: transform 0.2s ease, background 0.2s ease;
}

.cp-pip.is-done {
  background: var(--mint);
  transform: scale(1.15);
}

.cp-pip.is-next {
  background: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 207, 72, 0.38);
}

.cp-crown {
  font-size: 14px;
  line-height: 1;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 2.5px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.1s ease, background 0.15s ease;
}

.icon-btn:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(2px);
}

.icon-btn .icon-sound-off {
  display: none;
}

.icon-btn.is-muted .icon-sound-on {
  display: none;
}

.icon-btn.is-muted .icon-sound-off {
  display: block;
  color: var(--pink);
}

/* Bottom-left Dive meter (safe from host bottom-right bar) */
.dive-pill {
  position: fixed;
  left: 16px;
  bottom: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 6px 18px rgba(37, 28, 61, 0.12);
}

.dive-pill-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dive-bar {
  width: 54px;
  height: 8px;
  border-radius: 999px;
  background: #e4ddf5;
  overflow: hidden;
  display: block;
}

.dive-bar-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff70a6, #ffd166);
  transform-origin: left center;
}

.onboarding-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(37, 28, 61, 0.8);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 24px rgba(24, 14, 52, 0.25);
}

/* =========================================================================
   FLOATING CALLOUTS (CHECKPOINT / WHOOPS / BONK / RING COMBO / FINISH)
   ========================================================================= */
.callout {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translate(-50%, -14px) scale(0.8);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  z-index: 25;
  transition: opacity 0.18s ease, transform 0.24s cubic-bezier(0.22, 1.4, 0.36, 1);
}

.callout.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.callout-title {
  display: inline-block;
  padding: 8px 22px;
  border-radius: 999px;
  font-size: clamp(22px, 3.6vw, 32px);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #ffffff;
  border: 3px solid #ffffff;
  box-shadow: 0 10px 24px rgba(32, 18, 72, 0.24);
}

.callout-sub {
  margin-top: 6px;
  font-size: 12.5px;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: #ffffff;
  text-shadow: 0 2px 6px rgba(28, 16, 62, 0.45);
}

.callout--checkpoint .callout-title {
  background: linear-gradient(135deg, #27d99b, #14b885);
}

.callout--whoops .callout-title {
  background: linear-gradient(135deg, #ff7096, #ff477e);
}

.callout--bonk .callout-title {
  background: linear-gradient(135deg, #ff9f1c, #ff595e);
}

.callout--boost .callout-title {
  background: linear-gradient(135deg, #4cc9f0, #4895ef);
}

.callout--streak .callout-title {
  background: linear-gradient(135deg, #ffb703, #fb8500);
}

.callout--finish .callout-title {
  background: linear-gradient(135deg, #ffd166, #ff5c8a);
}

/* =========================================================================
   MODALS (PAUSE & FINISH)
   ========================================================================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(32, 22, 68, 0.34);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 30;
}

.modal-card {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, 0.94);
  border: 3.5px solid #ffffff;
  border-radius: 30px;
  padding: 26px 26px 24px;
  box-shadow: 0 24px 60px rgba(32, 18, 76, 0.28);
  text-align: center;
}

.modal-title {
  margin: 0 0 18px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.btn-primary,
.btn-secondary {
  width: 100%;
  padding: 13px 20px;
  border: none;
  border-radius: 16px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.btn-primary {
  background: linear-gradient(180deg, #3ee0ab, #1ec28e);
  color: #ffffff;
  box-shadow: 0 5px 0 var(--mint-dark);
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--mint-dark);
}

.btn-secondary {
  background: #f2edff;
  color: var(--ink);
  box-shadow: 0 4px 0 #d8cef2;
}

.btn-secondary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #d8cef2;
}

.modal-controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  padding-top: 14px;
  border-top: 2px dashed #e5ddf7;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-soft);
  text-align: left;
}

/* Finish card */
.finish-badges {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.medal-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.medal-badge--gold {
  background: linear-gradient(135deg, #ffe680, #ffbf2e);
  color: #6b4100;
}

.medal-badge--silver {
  background: linear-gradient(135deg, #eef3ff, #c9d8f5);
  color: #36476b;
}

.medal-badge--bronze {
  background: linear-gradient(135deg, #ffd6b8, #f09d65);
  color: #6b300c;
}

.new-best-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--pink);
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.finish-title {
  margin-bottom: 16px;
  color: var(--pink);
}

.finish-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat-box {
  background: #f7f4ff;
  border: 2px solid #e9e2fa;
  border-radius: 18px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-box--hero {
  grid-column: span 2;
  background: linear-gradient(135deg, #fff8db, #ffe9f2);
  border-color: #ffd6e6;
}

.stat-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.stat-value {
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.stat-box--hero .stat-value {
  font-size: 32px;
  color: var(--pink);
}

.finish-extras {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

.btn-run-again {
  font-size: 20px;
}

/* =========================================================================
   MOBILE / TOUCH CONTROLS (raised clear of bottom-right host share bar)
   ========================================================================= */
.touch-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 18;
}

.touch-stick-zone {
  position: fixed;
  left: 18px;
  bottom: 24px;
  width: 136px;
  height: 136px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
}

.touch-stick-base {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.34);
  border: 3px solid rgba(255, 255, 255, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 22px rgba(32, 18, 72, 0.16);
}

.touch-stick-knob {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ff74a4, #ff4784);
  border: 3px solid #ffffff;
  box-shadow: 0 4px 12px rgba(217, 53, 109, 0.35);
}

.touch-action-cluster {
  position: fixed;
  right: 18px;
  bottom: 84px; /* Stays cleanly above the bottom-right host share bar */
  display: flex;
  align-items: flex-end;
  gap: 12px;
  pointer-events: auto;
}

.touch-btn {
  border: 3px solid #ffffff;
  border-radius: 50%;
  color: #ffffff;
  font-family: inherit;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 6px 18px rgba(32, 18, 72, 0.24);
  transition: transform 0.08s ease;
}

.touch-btn--jump {
  width: 82px;
  height: 82px;
  font-size: 16px;
  background: linear-gradient(180deg, #3ee0ab, #1ec28e);
}

.touch-btn--dive {
  width: 62px;
  height: 62px;
  font-size: 12px;
  background: linear-gradient(180deg, #ffd166, #ff9f1c);
}

.touch-btn.is-pressed {
  transform: scale(0.92);
}

/* =========================================================================
   RESPONSIVE ADJUSTMENTS
   ========================================================================= */
@media (max-width: 780px) {
  .hud-center {
    top: 62px;
  }

  .hud-pill {
    padding: 6px 11px;
    gap: 6px;
  }

  .hud-value {
    font-size: 15px;
  }

  .dive-pill,
  .onboarding-toast {
    display: none;
  }
}

@media (max-width: 520px) {
  .overlay-start {
    padding: 14px;
    align-items: flex-start;
    justify-content: center;
  }

  .start-card {
    padding: 18px 18px 16px;
    border-radius: 22px;
  }

  .hud-left,
  .hud-right {
    top: 10px;
    gap: 5px;
  }

  .hud-left {
    left: 10px;
  }

  .hud-right {
    right: 10px;
  }

  .hud-center {
    top: 56px;
  }

  .hud-pill {
    padding: 5px 10px;
    gap: 5px;
  }

  .hud-value {
    font-size: 14px;
  }

  .hud-timer-pill .hud-label,
  .hud-fails-pill .hud-label {
    display: none;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 11px;
  }

  #btn-camera-reset {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn-play,
  .callout,
  .cp-pip,
  .icon-btn {
    transition: none;
  }
}
