:root {
  --ink: #0a4a6e;
  --cyan: #19b6e9;
  --foam: #eafcff;
  --sun: #ffd24d;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none; /* no iOS rubber-band / pull-to-refresh under the game */
  background: #0b3550;
  font-family: 'Arial Rounded MT Bold', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }
#app canvas { display: block; }

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
}

/* ---------- pause overlay ---------- */

#pause {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 25, 40, 0.55);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
#pause.on { display: flex; }

.pause-box {
  background: linear-gradient(180deg, #ffffff, #dff4fd);
  border: 5px solid var(--cyan);
  border-radius: 30px;
  padding: 34px 64px;
  text-align: center;
  transform: rotate(-2deg);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), inset 0 3px 0 #fff;
}
.pause-box h2 {
  margin: 0 0 10px;
  font-size: 58px;
  color: var(--ink);
  letter-spacing: 8px;
  text-shadow: 0 2px 0 #fff;
}
.pause-box p {
  margin: 14px 0 0;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 1px;
  color: #3a7a99;
}
.pause-btns {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 18px 0 4px;
  min-width: 280px;
}
.pause-btn {
  font: inherit;
  font-weight: 900;
  font-size: 19px;
  letter-spacing: 1.5px;
  color: #fff;
  cursor: pointer;
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 13px 28px;
  background: linear-gradient(180deg, #2ec8f5, #0f9bd0);
  box-shadow: 0 6px 0 rgba(7, 58, 87, 0.35), 0 10px 22px rgba(0, 0, 0, 0.22);
  text-shadow: 0 2px 0 rgba(7, 58, 87, 0.4);
  transition: transform 0.14s cubic-bezier(0.3, 1.6, 0.5, 1), box-shadow 0.14s ease;
}
.pause-btn:hover { transform: translateY(-3px) scale(1.03); }
.pause-btn:active { transform: translateY(1px) scale(0.98);
  box-shadow: 0 3px 0 rgba(7, 58, 87, 0.35); }
.pause-btn.pause-go { background: linear-gradient(180deg, #54e08a, #1faf55); }
.pause-btn.pause-out { background: linear-gradient(180deg, #ff9a8a, #e8503a); }

/* ---------- menu / title screen ---------- */

#menu {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: hidden;
  background:
    radial-gradient(circle at 14% 108%, rgba(255, 255, 255, 0.40) 0 70px, rgba(255, 255, 255, 0.12) 71px 86px, transparent 87px),
    radial-gradient(circle at 88% 102%, rgba(255, 255, 255, 0.32) 0 110px, rgba(255, 255, 255, 0.10) 111px 130px, transparent 131px),
    radial-gradient(circle at 70% -6%, rgba(255, 255, 255, 0.28) 0 90px, transparent 91px),
    linear-gradient(180deg, #1693d2 0%, #3fc3ee 36%, #9fe7ff 70%, #e6fbff 100%);
}
#menu.hidden { display: none; }

#menu-bubbles {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.mb {
  position: absolute;
  bottom: -130px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.95) 0 9%, rgba(255, 255, 255, 0.25) 32%, rgba(255, 255, 255, 0.05) 58%, rgba(255, 255, 255, 0.38) 100%);
  border: 2px solid rgba(255, 255, 255, 0.55);
  animation: mb-rise linear infinite;
  opacity: 0.85;
}

@keyframes mb-rise {
  0%   { transform: translate(0, 0); opacity: 0; }
  8%   { opacity: 0.85; }
  50%  { transform: translate(46px, -55vh); }
  92%  { opacity: 0.7; }
  100% { transform: translate(-14px, -112vh); opacity: 0; }
}

.menu-inner {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
}

.title {
  margin: 0;
  font-size: clamp(52px, 9vw, 118px);
  line-height: 0.95;
  text-align: center;
  color: #fff;
  letter-spacing: 3px;
  transform: rotate(-2.5deg);
  text-shadow:
    0 5px 0 var(--ink),
    0 10px 0 rgba(10, 74, 110, 0.35),
    0 18px 34px rgba(0, 0, 0, 0.35);
  animation: title-bob 3.2s ease-in-out infinite;
}
.title span {
  color: var(--sun);
  text-shadow:
    0 5px 0 #8a5a00,
    0 10px 0 rgba(138, 90, 0, 0.35),
    0 18px 34px rgba(0, 0, 0, 0.35);
}

@keyframes title-bob {
  0%, 100% { transform: rotate(-2.5deg) translateY(0); }
  50%      { transform: rotate(-1.6deg) translateY(-7px); }
}

.subtitle {
  margin: 0 0 8px;
  font-size: 21px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 2px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #dff4fd);
  border: 3px solid var(--cyan);
  border-radius: 999px;
  padding: 7px 26px;
  transform: rotate(1.5deg);
  box-shadow: 0 5px 0 rgba(7, 58, 87, 0.25), inset 0 2px 0 #fff;
  text-shadow: 0 1px 0 #fff;
}

.cards {
  display: flex;
  gap: 26px;
  margin: 10px 0 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.track-card {
  position: relative;
  width: min(258px, 80vw);
  background: linear-gradient(180deg, #ffffff, #eefaff);
  border: 4px solid rgba(255, 255, 255, 0.85);
  border-radius: 24px;
  padding: 10px 10px 14px;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.18s cubic-bezier(0.3, 1.6, 0.5, 1), box-shadow 0.18s ease, border-color 0.18s ease;
  box-shadow: 0 10px 26px rgba(4, 40, 64, 0.30);
}
.track-card:nth-child(1) { transform: rotate(-2.2deg); }
.track-card:nth-child(2) { transform: rotate(1.2deg); }
.track-card:nth-child(3) { transform: rotate(-1.2deg); }

.track-card.sel {
  border-color: var(--acc);
  transform: translateY(-12px) scale(1.06) rotate(0deg);
  box-shadow:
    0 16px 0 -6px var(--acc2),
    0 26px 46px rgba(4, 40, 64, 0.40),
    0 0 0 6px rgba(255, 255, 255, 0.35);
}

.card-top {
  position: relative;
  height: 110px;
  border-radius: 16px 16px 8px 8px;
  display: flex;
  align-items: flex-end;
  padding: 12px 14px;
  overflow: hidden;
  background:
    radial-gradient(circle at 84% 22%, rgba(255, 255, 255, 0.38) 0 15px, transparent 16px),
    radial-gradient(circle at 68% 66%, rgba(255, 255, 255, 0.26) 0 9px, transparent 10px),
    radial-gradient(circle at 93% 68%, rgba(255, 255, 255, 0.22) 0 6px, transparent 7px),
    radial-gradient(circle at 10% 18%, rgba(255, 255, 255, 0.20) 0 11px, transparent 12px),
    linear-gradient(135deg, var(--acc), var(--acc2));
}

.card-num {
  position: absolute;
  top: 2px;
  right: 10px;
  font-size: 64px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.30);
  text-shadow: none;
  line-height: 1;
}

.card-name {
  position: relative;
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 1px;
  line-height: 1.05;
  text-shadow: 0 2px 0 rgba(10, 40, 60, 0.45), 0 4px 10px rgba(0, 0, 0, 0.3);
}

.card-sub {
  margin: 10px 4px 6px;
  min-height: 38px;
  font-size: 14px;
  font-weight: 800;
  color: #15506e;
  line-height: 1.3;
}

.card-go {
  display: inline-block;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #fff;
  background: linear-gradient(180deg, var(--acc), var(--acc2));
  border-radius: 999px;
  padding: 5px 16px;
  margin-left: 4px;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.15s ease, transform 0.18s cubic-bezier(0.3, 1.6, 0.5, 1);
  text-shadow: 0 1px 0 rgba(10, 40, 60, 0.4);
}
.track-card.sel .card-go { opacity: 1; transform: scale(1); }

.hint {
  margin: 12px 0 0;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(10, 74, 110, 0.55);
}

.legend {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 1px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #dff4fd);
  border: 3px solid var(--cyan);
  border-radius: 999px;
  padding: 8px 24px;
  transform: rotate(-1deg);
  box-shadow: 0 5px 0 rgba(7, 58, 87, 0.25), inset 0 2px 0 #fff;
  text-shadow: 0 1px 0 #fff;
}

.audio-line {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 2px;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 0 rgba(10, 74, 110, 0.5);
}
.audio-line span { color: var(--sun); }

/* ---------- multiplayer HUD extras ---------- */

#mp-ping {
  position: absolute;
  top: 234px;
  right: 16px;
  z-index: 31;
  display: none;
  pointer-events: none;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, #ffffff, #dff4fd);
  border: 3px solid #2ecc71;
  border-radius: 999px;
  padding: 4px 13px;
  box-shadow: 0 4px 0 rgba(7, 58, 87, 0.25);
  transform: rotate(2deg);
  text-shadow: 0 1px 0 #fff;
}
#mp-ping.mid { border-color: #f0a32e; }
#mp-ping.bad { border-color: #e8503a; }

#mp-wait {
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translate(-50%, -50%) rotate(-1.5deg);
  display: none;
  z-index: 31;
  pointer-events: none;
  white-space: nowrap;
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 2px;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #dff4fd);
  border: 3px solid var(--cyan);
  border-radius: 999px;
  padding: 12px 32px;
  box-shadow: 0 6px 0 rgba(7, 58, 87, 0.25), inset 0 2px 0 #fff;
  text-shadow: 0 1px 0 #fff;
}
#mp-wait.on { display: block; animation: mp-bob 1.6s ease-in-out infinite; }

@keyframes mp-bob {
  0%, 100% { transform: translate(-50%, -50%) rotate(-1.5deg); }
  50%      { transform: translate(-50%, -56%) rotate(-0.7deg); }
}

/* ---- Landscape-only on mobile: portrait blocker overlay ----
   Shown ONLY on touch (coarse-pointer) devices held in portrait; covers
   everything (z above settings/pause) so the game is landscape-only. */
#wk-rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  color: var(--ink);
  background: linear-gradient(180deg, #5ab0e8, #bfe6ff);
  font-family: 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
}
#wk-rotate .wk-rot-ico {
  font-size: 64px;
  filter: drop-shadow(0 6px 10px rgba(0, 40, 80, .3));
  animation: wk-rotate-tilt 1.8s ease-in-out infinite;
}
#wk-rotate .wk-rot-txt { font-size: 21px; font-weight: 900; letter-spacing: 2px; text-shadow: 0 2px 0 rgba(255,255,255,.5); }
#wk-rotate .wk-rot-sub { font-size: 13px; font-weight: 700; letter-spacing: 1px; opacity: .8; }
@keyframes wk-rotate-tilt {
  0%, 100% { transform: rotate(-12deg); }
  50%      { transform: rotate(78deg); }
}
@media (orientation: portrait) and (pointer: coarse) {
  #wk-rotate { display: flex; }
}

/* Single-race difficulty mirror (sits on the blue menu background; its own white
   pill since the settings .wk-seg style is scoped to the settings panel). */
.sp-diff {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(180deg, #ffffff, #dff4fd);
  border: 3px solid var(--cyan); border-radius: 999px;
  padding: 7px 10px 7px 20px; transform: rotate(-0.6deg);
  box-shadow: 0 5px 0 rgba(7,58,87,.25), inset 0 2px 0 #fff;
}
.sp-diff-label { font-size: 14px; font-weight: 900; letter-spacing: 2px; color: var(--ink); text-shadow: 0 1px 0 #fff; }
.sp-diff-seg { display: flex; background: rgba(10,74,110,.1); border-radius: 14px; padding: 4px; box-shadow: inset 0 2px 4px rgba(10,74,110,.16); }
.sp-diff-btn {
  font: inherit; font-weight: 900; font-size: 13px; letter-spacing: .5px; color: var(--ink);
  background: transparent; border: none; border-radius: 11px; padding: 11px 14px; cursor: pointer; min-width: 44px;
  white-space: nowrap; -webkit-tap-highlight-color: transparent;
  transition: background .16s ease, color .16s ease, transform .12s ease, box-shadow .16s ease;
}
.sp-diff-btn:hover:not(.on) { background: rgba(255,255,255,.5); }
.sp-diff-btn.on {
  background: linear-gradient(180deg, #2ec8f5, #0f9bd0); color: #fff;
  box-shadow: 0 3px 0 rgba(7,58,87,.3); text-shadow: 0 1px 0 rgba(7,58,87,.4); transform: scale(1.03);
}
@media (max-width: 760px), (max-height: 540px) {
  .sp-diff { flex-direction: column; gap: 6px; padding: 8px 12px; }
  .sp-diff-btn { padding: 10px 12px; font-size: 12px; }
}

/* Landscape phone (short + touch): shrink the single-race track-select so the
   title + cards fit without scrolling. Desktop (fine pointer) is untouched. */
@media (pointer: coarse) and (max-height: 560px) {
  .menu-inner { gap: 8px; padding: 10px; }
  .title { font-size: clamp(34px, 7vw, 58px); }
  .subtitle { font-size: 15px; padding: 5px 18px; margin: 0 0 4px; }
  .cards { gap: 14px; margin: 4px 0; }
  .hint, .legend, .audio-line { font-size: 11px; margin: 2px 0; }
}
