/* ===================== Base / resets ===================== */
:root {
  --bg: #fef6e4;
  --ink: #21203a;
  --primary: #ff6b6b;
  --primary-dark: #e6543f;
  --accent: #3fb0ac;
  --gold: #ffb703;
  --card-bg: #ffffff;
  --tile-event: #ffd166;
  --tile-flavor: #a7e8bd;
  --tile-start: #8ecae6;
  --tile-end: #f6a6c1;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(33, 32, 58, 0.15);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: linear-gradient(180deg, #fef6e4 0%, #ffe8d6 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.hidden { display: none !important; }

.screen {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 24px;
}

/* ===================== Buttons ===================== */
.btn {
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 700;
  font-size: 1rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
  box-shadow: var(--shadow);
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; transform: none; cursor: default; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
}

.btn-big {
  width: 100%;
  min-height: 52px;
  font-size: 1.05rem;
}

/* ===================== Ticker ===================== */
.ticker {
  background: var(--ink);
  color: #baffc9;
  overflow: hidden;
  white-space: nowrap;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 0.75rem;
  padding: 6px 0;
}
.ticker-track {
  display: inline-flex;
  gap: 28px;
  padding-left: 100%;
  animation: ticker-scroll 22s linear infinite;
}
.ticker-track span { display: inline-block; }
@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-100%); }
}

/* ===================== Start screen ===================== */
.start-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 20px;
  gap: 14px;
}
.start-emoji { font-size: 3rem; }
.start-card h1 {
  font-size: 1.7rem;
  line-height: 1.25;
  margin: 0;
}
.subtitle {
  color: #4a4863;
  font-size: 0.95rem;
  line-height: 1.5;
  max-width: 360px;
}
.footer {
  text-align: center;
  font-size: 0.75rem;
  color: #8b89a3;
  padding: 12px 20px 4px;
}

/* ===================== Progress bar ===================== */
.progress-wrap {
  padding: 12px 16px 6px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 5;
}
.progress-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.8rem;
  font-weight: 700;
  color: #4a4863;
  margin-bottom: 6px;
}
#progress-percent {
  font-size: 0.95rem;
  color: var(--primary-dark);
}
.progress-track {
  position: relative;
  height: 18px;
  background: #f0e9d8;
  border-radius: 999px;
  overflow: visible;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.12);
}
.progress-fill {
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--primary));
  transition: width 0.5s cubic-bezier(.2,.8,.3,1);
}
.progress-delta {
  position: absolute;
  top: -6px;
  transform: translate(-50%, -100%);
  font-weight: 800;
  font-size: 0.9rem;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}
.progress-delta.positive { background: #d7f5e0; color: #1f7a4a; }
.progress-delta.negative { background: #fbdada; color: #b73939; }
.progress-delta.pop {
  animation: delta-pop 0.9s ease forwards;
}
@keyframes delta-pop {
  0% { opacity: 0; transform: translate(-50%, -80%) scale(0.8); }
  15% { opacity: 1; transform: translate(-50%, -130%) scale(1.05); }
  75% { opacity: 1; transform: translate(-50%, -130%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* ===================== Board ===================== */
.board-wrap {
  position: relative;
  padding: 16px 10px 8px;
}
.board {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.board-row {
  display: flex;
  gap: 6px;
}
.board-row.reverse { flex-direction: row-reverse; }

.tile {
  flex: 1;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--tile-event);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.08);
  position: relative;
  transition: outline 0.2s ease;
  padding: 4px 2px;
}
.tile-icon { font-size: 1.5rem; line-height: 1; }
.tile-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: #322f52;
  margin-top: 3px;
  text-align: center;
  line-height: 1.15;
  padding: 0 2px;
}
.tile-flavor { background: var(--tile-flavor); }
.tile-start .tile-icon { font-size: 1.9rem; }
.tile-start .tile-label { font-size: 0.8rem; }
.tile-start { background: var(--tile-start); }
.tile-end .tile-icon { font-size: 2.1rem; }
.tile-end .tile-label { font-size: 0.8rem; }
.tile-end { background: var(--tile-end); }
.tile-visited { outline: 3px solid rgba(33,32,58,0.15); outline-offset: -3px; }
.tile-current { outline: 3px solid var(--primary); outline-offset: -3px; }

.car-token {
  position: absolute;
  font-size: 1.6rem;
  transform: translate(-50%, -55%);
  transition: left 0.35s ease, top 0.35s ease;
  z-index: 4;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,0.3));
  pointer-events: none;
}

/* ===================== Controls / toast ===================== */
.controls {
  padding: 14px 16px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.spin-result {
  font-weight: 700;
  color: var(--primary-dark);
  font-size: 0.9rem;
}

.toast {
  margin: 0 16px;
  background: var(--card-bg);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  text-align: center;
  animation: toast-in 0.25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===================== Event modal ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(33, 32, 58, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  padding: 0;
}
@media (min-width: 520px) {
  .modal-overlay { align-items: center; }
}

.modal-card {
  background: var(--card-bg);
  width: 100%;
  max-width: 480px;
  border-radius: 24px 24px 0 0;
  padding: 24px 20px 28px;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.25);
  animation: modal-in 0.28s cubic-bezier(.2,.8,.3,1.2);
  max-height: 88vh;
  overflow-y: auto;
}
@media (min-width: 520px) {
  .modal-card { border-radius: 24px; }
}
@keyframes modal-in {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-icon { font-size: 2.2rem; text-align: center; margin-bottom: 4px; }
#event-title { text-align: center; margin: 0 0 8px; font-size: 1.25rem; }
#event-prompt { text-align: center; color: #4a4863; margin: 0 0 18px; line-height: 1.4; }

.event-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.choice-btn {
  border: 2px solid #eee0c8;
  background: #fffaf0;
  border-radius: 14px;
  padding: 13px 16px;
  text-align: left;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  min-height: 44px;
  transition: background 0.15s ease, transform 0.1s ease;
}
.choice-btn:active { transform: scale(0.98); background: #fdf0d8; }

.event-result { margin-top: 18px; text-align: center; }
.event-result p {
  background: #f0faf3;
  border-radius: 14px;
  padding: 14px;
  font-weight: 600;
  color: #1f5f4a;
  margin: 0 0 14px;
}

/* ===================== Ending screen ===================== */
.end-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 30px 22px 10px;
  gap: 10px;
  justify-content: center;
}
.end-emoji { font-size: 3.5rem; }
.end-card h1 { font-size: 1.5rem; margin: 4px 0; }
#end-text { color: #4a4863; line-height: 1.5; font-size: 0.95rem; }

.end-progress-wrap {
  width: 100%;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin: 14px 0 20px;
}
.end-progress-wrap .progress-track { margin-top: 2px; }
