/* ---------------------------------------------------------------------------
   Terminal Dash — UI styles.
   Palette matches the mockups: warm cream world, dark-teal HUD pills,
   coral action buttons, golden yellow accents.
--------------------------------------------------------------------------- */

:root {
  --teal-dark: #143d3b;
  --teal-mid: #2e6e6a;
  --teal-light: #3f8f86;
  --coral: #f46f52;
  --coral-dark: #d4553a;
  --yellow: #f2b135;
  --yellow-dark: #c8862a;
  --blue: #35c4f0;
  --cream: #f7e3c8;
  --white: #fffdf8;
  --font: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  touch-action: none; /* we handle all gestures ourselves */
}

#game canvas { display: block; }

.hidden { display: none !important; }

/* ------------------------------------------------------------------ */
/* Loading                                                             */
/* ------------------------------------------------------------------ */

#loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cream);
  color: var(--teal-mid);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  z-index: 50;
}

/* ------------------------------------------------------------------ */
/* HUD                                                                 */
/* ------------------------------------------------------------------ */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none; /* only the buttons re-enable events */
  z-index: 10;
}

#hud button { pointer-events: auto; }

#score-wrap {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: calc(14px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

#score-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--teal-dark);
  border-radius: 999px;
  padding: 7px 22px 7px 8px;
  box-shadow: 0 4px 10px rgba(40, 25, 10, 0.25);
}

/* small pill hanging off the score: gold + blue tickets collected vs total */
#ticket-counts {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--teal-dark);
  border-radius: 999px;
  padding: 5px 14px;
  margin-left: 12px;
  box-shadow: 0 3px 8px rgba(40, 25, 10, 0.22);
  font-size: 13px;
  color: #cfe3dc;
}
#ticket-counts .count { display: flex; align-items: center; gap: 5px; font-weight: 700; }
#ticket-counts b { color: var(--yellow); font-weight: 800; font-size: 15px; }
#ticket-counts i { font-style: normal; opacity: 0.75; }
#ticket-counts .count.blue b { color: var(--blue); }
.icon-ticket.mini { width: 19px; transform: rotate(-12deg); }
.icon-ticket.mini path { fill: var(--yellow); }
.icon-ticket.mini.blue path { fill: var(--blue); }

/* speed-tier chips */
#tier-badge {
  background: var(--coral);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 4px 12px;
  margin-left: 12px;
  box-shadow: 0 3px 8px rgba(40, 25, 10, 0.22);
}

#title-tier {
  margin-top: 14px;
  background: var(--coral);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 8px 22px;
  box-shadow: 0 4px 0 var(--coral-dark);
}

.lb-row .tiermark {
  color: var(--coral);
  font-size: 12px;
  margin-left: 6px;
}

#finish-stats small { font-size: 12px; color: var(--coral); }

/* score pill flashes red when points are lost */
@keyframes penalty-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
#score-pill.penalty {
  animation: penalty-shake 0.4s ease;
  background: #7c2f22;
}
#score-pill.penalty #score-value { color: #ffb4a6; }

.ticket-badge {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--teal-mid);
  border: 3px solid var(--teal-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.icon-ticket { width: 28px; transform: rotate(-12deg); }
.icon-ticket path { fill: var(--yellow); }
.icon-ticket .ticket-dash { stroke: var(--yellow-dark); stroke-width: 2; stroke-dasharray: 3 3; fill: none; }
.icon-ticket .ticket-stamp { fill: var(--yellow-dark); }
.icon-ticket.blue path { fill: var(--blue); }
.icon-ticket.blue .ticket-dash { stroke: #e8fbff; }
.icon-ticket.blue .ticket-stamp { fill: #e8fbff; }

.score-text { display: flex; flex-direction: column; line-height: 1.05; }
.score-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #9dbbb4;
}
#score-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--white);
  min-width: 2ch;
}

.square-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(40, 25, 10, 0.25);
  transition: transform 0.08s ease;
}
.square-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(40, 25, 10, 0.25); }
.square-btn svg { width: 24px; height: 24px; }
.square-btn.yellow { background: var(--yellow); }
.square-btn.yellow svg path { fill: #8a5b12; }
.square-btn.coral { background: var(--coral); }
.square-btn.coral svg rect { fill: #fff; }

#settings-btn {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
}

/* --- bottom progress bar ------------------------------------------ */

#progress-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(92vw, 560px);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--teal-dark);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: 0 4px 10px rgba(40, 25, 10, 0.25);
}

.icon-suitcase { width: 26px; height: 26px; flex: 0 0 auto; }
.icon-suitcase rect { fill: var(--yellow); }
.icon-suitcase .suitcase-handle { stroke: var(--yellow); fill: none; }
.icon-suitcase .suitcase-strap { stroke: var(--yellow-dark); stroke-width: 1.6; }

.icon-flag { width: 24px; height: 24px; flex: 0 0 auto; }
.icon-flag path { fill: #e8e4da; }
.icon-flag .flag-pole { stroke: #e8e4da; }

#progress-track {
  position: relative;
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: #0c2a29;
}

#progress-fill {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd34d, var(--yellow));
  transform-origin: left center;
  transform: scaleX(0);
}

#progress-handle {
  position: absolute;
  top: 50%;
  left: 0;
  width: 8px;
  height: 22px;
  border-radius: 4px;
  background: #35514e;
  border: 2px solid #557a75;
  transform: translate(-50%, -50%);
}

.progress-marker {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: #0c2a29;
  border: 2px solid #3d6360;
}
.progress-marker.done {
  background: var(--blue);
  border-color: #bdefff;
}

#pause-btn { width: 42px; height: 42px; border-radius: 12px; flex: 0 0 auto; }

/* ------------------------------------------------------------------ */
/* Floating +10 texts                                                  */
/* ------------------------------------------------------------------ */

#float-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 9;
}

.float-text {
  position: absolute;
  font-weight: 800;
  font-size: 22px;
  color: var(--yellow);
  text-shadow: 0 2px 0 rgba(90, 50, 0, 0.35);
  animation: float-up 0.8s ease-out forwards;
  transform: translate(-50%, -50%);
}
.float-text.blue { color: var(--blue); font-size: 28px; }
.float-text.red { color: #ff6b5e; font-size: 26px; }

@keyframes float-up {
  0%   { opacity: 1; translate: 0 0; scale: 0.6; }
  20%  { scale: 1.15; }
  100% { opacity: 0; translate: 0 -70px; scale: 1; }
}

/* score pop when collecting */
@keyframes score-pop {
  0% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
#score-value.pop { animation: score-pop 0.18s ease-out; }

/* ------------------------------------------------------------------ */
/* Title screen                                                        */
/* ------------------------------------------------------------------ */

#title-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12vh 20px 12vh;
  background: linear-gradient(180deg, rgba(255, 240, 210, 0.35), rgba(255, 240, 210, 0) 40%);
  cursor: pointer;
}

.logo-img {
  width: min(84vw, 480px);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 12px 26px rgba(60, 35, 10, 0.28));
  animation: logo-in 0.7s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes logo-in {
  from { transform: scale(0.85) translateY(-14px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.tap-to-start {
  display: flex;
  align-items: center;
  gap: 14px;
  animation: pulse 1.4s ease-in-out infinite;
}
.tap-label {
  font-size: clamp(24px, 6vw, 34px);
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--white);
  text-shadow:
    2px 0 0 var(--teal-dark), -2px 0 0 var(--teal-dark), 0 2px 0 var(--teal-dark), 0 -2px 0 var(--teal-dark),
    1.5px 1.5px 0 var(--teal-dark), -1.5px 1.5px 0 var(--teal-dark), 1.5px -1.5px 0 var(--teal-dark), -1.5px -1.5px 0 var(--teal-dark),
    0 4px 0 var(--teal-mid);
}
.wing { display: flex; flex-direction: column; gap: 4px; }
.wing i { display: block; height: 5px; border-radius: 3px; background: var(--yellow); box-shadow: 0 2px 0 var(--yellow-dark); }
.wing i:nth-child(1) { width: 26px; }
.wing i:nth-child(2) { width: 18px; }
.wing i:nth-child(3) { width: 22px; }
.wing.left { align-items: flex-end; }
.wing.right { align-items: flex-start; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

.start-hint {
  position: absolute;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--teal-mid);
  opacity: 0.85;
}

/* ------------------------------------------------------------------ */
/* Modals                                                              */
/* ------------------------------------------------------------------ */

.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(70, 45, 20, 0.35);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.modal-card {
  width: min(86vw, 380px);
  background: var(--teal-dark);
  border-radius: 24px;
  padding: 26px 26px 24px;
  text-align: center;
  color: var(--white);
  box-shadow: 0 18px 50px rgba(40, 20, 0, 0.45);
  animation: card-in 0.28s cubic-bezier(0.24, 1.3, 0.5, 1);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

@keyframes card-in {
  from { transform: scale(0.7) translateY(24px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.modal-title.blue { color: var(--blue); }
.modal-title.yellow { color: var(--yellow); }

.modal-text {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.45;
  color: #e6efe9;
}

.modal-ticket {
  position: relative;
  width: 84px;
  filter: drop-shadow(0 0 14px rgba(53, 196, 240, 0.8));
  animation: ticket-bob 1.6s ease-in-out infinite;
}
.modal-ticket .icon-ticket { width: 84px; }

/* round badge holding the per-fact emoji icon */
.fact-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: #0e3438;
  border: 3px solid rgba(53, 196, 240, 0.55);
  font-size: 44px;
  line-height: 1;
}

@keyframes ticket-bob {
  0%, 100% { transform: rotate(-10deg) translateY(0); }
  50% { transform: rotate(-6deg) translateY(-6px); }
}

.spark { position: absolute; color: #d8f7ff; animation: spark 1.2s ease-in-out infinite; }
.spark.s1 { top: -10px; left: -6px; font-size: 14px; }
.spark.s2 { bottom: -6px; right: -10px; font-size: 18px; animation-delay: 0.4s; }
.spark.s3 { top: 6px; right: -16px; font-size: 11px; animation-delay: 0.8s; }
@keyframes spark { 0%, 100% { opacity: 0.2; transform: scale(0.7); } 50% { opacity: 1; transform: scale(1.2); } }

.pill-btn {
  border: none;
  border-radius: 999px;
  font-family: var(--font);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 13px 30px;
  cursor: pointer;
  color: #fff;
  min-width: 220px;
  transition: transform 0.08s ease;
}
.pill-btn:active { transform: scale(0.96); }
.pill-btn.coral { background: var(--coral); box-shadow: 0 4px 0 var(--coral-dark); }
.pill-btn.teal { background: var(--teal-mid); box-shadow: 0 4px 0 #1d4a47; }
.pill-btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

/* two-line replay buttons: action on top, multiplier detail underneath */
.pill-btn .l1 { display: block; line-height: 1.15; }
.pill-btn .l2 {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.5px;
  opacity: 0.85;
  margin-top: 2px;
}

/* --- how-to-play modal ---------------------------------------------- */

.help-rows {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  margin: 4px 0 6px;
}

.help-row {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: #e6efe9;
}
.help-row b { color: var(--yellow); }
.help-row b.red { color: #ff8a7a; }

.cone-wrap { position: relative; display: flex; }
.cone-icon { width: 30px; }
.cone-warn { position: absolute; top: -8px; right: -11px; font-size: 13px; }

.help-icon {
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  line-height: 1;
}
.help-icon .icon-ticket { width: 42px; }

.keys-icon { width: 58px; }
.keys-icon rect { fill: var(--teal-mid); stroke: var(--teal-light); stroke-width: 1.5; }
.keys-icon .key-arrow { fill: #fff; }

.help-icon.bob { animation: help-bob 1.4s ease-in-out infinite; }
@keyframes help-bob {
  0%, 100% { transform: translateY(-3px); }
  50% { transform: translateY(3px); }
}

.help-icon.glint { animation: help-glint 2.2s ease-in-out infinite; }
@keyframes help-glint {
  0%, 100% { filter: brightness(1); transform: scale(1) rotate(0deg); }
  50% { filter: brightness(1.45) drop-shadow(0 0 6px rgba(255, 220, 120, 0.7)); transform: scale(1.12) rotate(-4deg); }
}

/* --- finish modal -------------------------------------------------- */

#finish-stats { font-size: 17px; font-weight: 700; color: var(--cream); line-height: 1.5; }
#finish-stats .big { font-size: 40px; font-weight: 800; color: var(--yellow); display: block; line-height: 1.1; }

#finish-entry { display: flex; gap: 10px; align-items: center; justify-content: center; }

#initials-input {
  width: 92px;
  border: 3px solid var(--teal-mid);
  border-radius: 14px;
  background: #0c2a29;
  color: var(--yellow);
  font-family: var(--font);
  font-size: 26px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  padding: 8px 4px;
  outline: none;
}
#initials-input:focus { border-color: var(--yellow); }

#finish-entry .pill-btn { min-width: 0; padding: 13px 20px; font-size: 14px; }

#leaderboard { width: 100%; display: flex; flex-direction: column; gap: 4px; max-height: 32vh; overflow-y: auto; }

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0e302e;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 15px;
  font-weight: 700;
}
.lb-row .rank { color: #7fa39d; width: 26px; text-align: right; }
.lb-row .name { flex: 1; text-align: left; letter-spacing: 2px; }
.lb-row .pts { color: var(--yellow); }
.lb-row.me { outline: 2px solid var(--yellow); background: #1a4a45; }
.lb-empty { color: #7fa39d; font-size: 14px; font-weight: 600; padding: 6px; }

/* ------------------------------------------------------------------ */
/* Finish banner                                                       */
/* ------------------------------------------------------------------ */

#finish-banner {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-4deg);
  z-index: 25;
  font-size: clamp(48px, 14vw, 92px);
  font-weight: 800;
  font-style: italic;
  letter-spacing: 4px;
  color: var(--yellow);
  text-shadow:
    3px 0 0 var(--teal-dark), -3px 0 0 var(--teal-dark), 0 3px 0 var(--teal-dark), 0 -3px 0 var(--teal-dark),
    2px 2px 0 var(--teal-dark), -2px 2px 0 var(--teal-dark), 2px -2px 0 var(--teal-dark), -2px -2px 0 var(--teal-dark),
    0 8px 0 var(--yellow-dark), 0 14px 26px rgba(60, 35, 10, 0.4);
  animation: banner-in 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
  pointer-events: none;
}

@keyframes banner-in {
  from { transform: translate(-50%, -50%) rotate(-4deg) scale(0.2); opacity: 0; }
  to   { transform: translate(-50%, -50%) rotate(-4deg) scale(1); opacity: 1; }
}
