/* Type Racing — full-screen 3D canvas with a 2D HTML overlay UI.
   Bright racetrack pinks, sky blue, and sunny yellow. Self-contained: system
   fonts, no network dependencies, so it runs offline in the desktop/mobile
   shells like the other games in this portfolio. */

:root {
  --pink: #ff5aa0;
  --pink-deep: #d63a82;
  --yellow: #ffd23f;
  --green: #6fcf97;
  --sky: #9fd8ff;
  --ink: #35233a;
  --ui-font: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--ui-font);
  color: var(--ink);
  background: var(--sky);
  user-select: none;
}

#game-shell { position: fixed; inset: 0; }
#game-canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }

/* ===================== HUD ===================== */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px 14px;
  pointer-events: none;
}
.pips {
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: clamp(1.3rem, 6vw, 2rem);
}
.pip {
  filter: grayscale(0.5) brightness(1.05);
  opacity: 0.7;
  transition: transform 0.2s, filter 0.2s, opacity 0.2s;
}
.pip.on {
  filter: none;
  opacity: 1;
  transform: scale(1.18);
  animation: pipPop 0.35s ease;
}
@keyframes pipPop {
  0% { transform: scale(0.5) rotate(-20deg); }
  60% { transform: scale(1.4) rotate(8deg); }
  100% { transform: scale(1.18) rotate(0); }
}

#timer-bar {
  height: 16px;
  width: min(680px, 92vw);
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}
#timer-fill {
  height: 100%;
  width: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.12s linear, background 0.25s;
}

/* ===================== PAUSE BUTTON ===================== */
.pause-btn {
  position: absolute;
  top: 10px;
  right: 12px;
  display: none;            /* shown during a race */
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  font-size: 1.5rem;
  cursor: pointer;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.14);
  z-index: 20;
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}
.pause-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.14); }

/* ===================== PAUSE / DECORATE PANEL ===================== */
.pause-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: none;            /* flex when paused */
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 14px calc(16px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(255, 246, 251, 0.98), rgba(255, 246, 251, 0.92));
  border-top: 5px solid var(--pink);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -12px 40px rgba(214, 58, 130, 0.25);
  z-index: 20;
}
.pp-title {
  font-weight: 800;
  font-size: clamp(1rem, 4.4vw, 1.4rem);
  color: var(--pink-deep);
  text-align: center;
}
.decor-palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: min(600px, 96vw);
}
.decor-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  border: 3px solid var(--pink);
  background: #fff;
  border-radius: 18px;
  padding: 8px 6px 6px;
  width: clamp(80px, 28vw, 96px);
  font-family: inherit;
  box-shadow: 0 4px 0 rgba(214, 58, 130, 0.35);
  transition: transform 0.07s ease, box-shadow 0.07s ease, background 0.1s;
}
.decor-btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 rgba(214, 58, 130, 0.35);
  background: #fff0f7;
}
.db-emoji { font-size: clamp(1.7rem, 8vw, 2.4rem); line-height: 1; }
.db-label { font-weight: 800; font-size: clamp(0.75rem, 3vw, 0.95rem); color: var(--ink); }
.decor-count {
  font-weight: 700;
  font-size: 0.95rem;
  color: #8a7d92;
}
.pp-actions { display: flex; gap: 12px; margin-top: 2px; }
.pp-btn {
  font-family: inherit;
  cursor: pointer;
  border: none;
  font-weight: 800;
  padding: 0.55em 1.5em;
  font-size: clamp(1rem, 4vw, 1.25rem);
  color: #fff;
  background: var(--pink);
  border-radius: 999px;
  box-shadow: 0 6px 0 var(--pink-deep);
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}
.pp-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--pink-deep); }
.pp-btn--soft {
  color: var(--pink-deep);
  background: #ffe3f1;
  box-shadow: 0 6px 0 #f3b6d3;
}
.pp-btn--soft:active { box-shadow: 0 1px 0 #f3b6d3; }

/* ===================== THE WORD YOU TYPE ===================== */
.word {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
  gap: clamp(4px, 1.4vw, 10px);
  pointer-events: none;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 96vw;
}
.tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(42px, 12vw, 84px);
  height: clamp(52px, 15vw, 100px);
  font-size: clamp(1.8rem, 8vw, 4rem);
  font-weight: 800;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  border-radius: 16px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.16);
  transition: transform 0.1s, background 0.12s, color 0.12s, box-shadow 0.12s;
}
.tile.current {
  background: #fff6c4;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.16), 0 0 0 4px var(--yellow);
  animation: tilePulse 0.7s ease-in-out infinite alternate;
}
.tile.ok {
  background: var(--green);
  color: #fff;
  box-shadow: 0 6px 0 #3ea86a;
  transform: translateY(2px);
}
.tile.bad {
  background: #ff5a5a;
  color: #fff;
  box-shadow: 0 6px 0 #c33;
  animation: tileBad 0.3s ease;
}
@keyframes tilePulse {
  from { box-shadow: 0 6px 0 rgba(0,0,0,0.16), 0 0 0 4px var(--yellow); }
  to   { box-shadow: 0 6px 0 rgba(0,0,0,0.16), 0 0 0 9px rgba(255, 210, 63, 0); }
}
@keyframes tileBad {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.word-pop { animation: wordPop 0.3s cubic-bezier(0.2, 1.5, 0.4, 1); }
@keyframes wordPop {
  from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.word-shake { animation: wordShake 0.4s ease; }
@keyframes wordShake {
  0%, 100% { transform: translate(-50%, -50%); }
  20% { transform: translate(-53%, -50%); }
  40% { transform: translate(-47%, -50%); }
  60% { transform: translate(-52%, -50%); }
  80% { transform: translate(-48%, -50%); }
}

/* ===================== CROSSED-OFF WORDS ===================== */
.done {
  position: absolute;
  top: 54%;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: min(700px, 94vw);
  pointer-events: none;
}
.done-word {
  font-weight: 800;
  font-size: clamp(0.85rem, 3.2vw, 1.15rem);
  text-transform: uppercase;
  text-decoration: line-through;
  text-decoration-thickness: 3px;
  text-decoration-color: var(--pink-deep);
  color: rgba(53, 35, 58, 0.55);
  background: rgba(255, 255, 255, 0.85);
  padding: 2px 10px;
  border-radius: 999px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1);
  animation: doneIn 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes doneIn {
  from { transform: scale(0.3) rotate(-8deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}

/* ===================== HIDDEN TYPING INPUT ===================== */
#typebox {
  position: fixed;
  bottom: 8px;
  left: 50%;
  width: 2px;
  height: 2px;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px;      /* 16px stops iOS from zooming when it focuses */
  background: transparent;
  color: transparent;
  caret-color: transparent;
}

/* ===================== TOAST ===================== */
.toast {
  position: absolute;
  top: 24%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  opacity: 0;
  pointer-events: none;
  font-size: clamp(1.4rem, 6vw, 2.4rem);
  font-weight: 800;
  padding: 0.3em 0.85em;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transition: transform 0.22s cubic-bezier(0.2, 1.6, 0.4, 1), opacity 0.22s;
}
.toast-show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast-good { color: var(--green); }
.toast-bad { color: var(--pink-deep); }

/* ===================== OVERLAY SCREENS ===================== */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: radial-gradient(circle at 50% 30%, rgba(200, 235, 255, 0.72), rgba(255, 90, 160, 0.5));
  backdrop-filter: blur(2px);
}
.card {
  background: #fffdf9;
  border: 5px solid var(--pink);
  border-radius: 28px;
  padding: clamp(20px, 5vw, 36px);
  max-width: 560px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(214, 58, 130, 0.3);
}
.card-emoji { font-size: clamp(2.6rem, 12vw, 4rem); }
.card h1 {
  margin: 0.2em 0 0.3em;
  font-size: clamp(1.6rem, 6.6vw, 2.5rem);
  color: var(--pink-deep);
  line-height: 1.05;
}
.card p {
  margin: 0.5em 0;
  font-size: clamp(1rem, 3.6vw, 1.18rem);
  line-height: 1.5;
}
.card .sub { color: #8a7d92; font-size: 1rem; }

.big-btn {
  font-family: inherit;
  cursor: pointer;
  border: none;
  font-weight: 800;
  margin-top: 14px;
  padding: 0.7em 2em;
  font-size: clamp(1.15rem, 4.4vw, 1.5rem);
  color: #fff;
  background: var(--pink);
  border-radius: 999px;
  box-shadow: 0 7px 0 var(--pink-deep);
  transition: transform 0.07s ease, box-shadow 0.07s ease;
}
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--pink-deep); }

/* ===================== LOADING ===================== */
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--pink-deep);
  background: var(--sky);
}
