:root {
  --sky-top: #7fd1ff;
  --sky-bottom: #ffe9a8;
  --road: #a3aebd;
  --road-dash: #7b8493;
  --road-fill-a: #ffd166;
  --road-fill-b: #ffb703;
  --accent: #ff6f59;
  --accent-shadow: rgba(255, 111, 89, .35);
  --green: #3dd68c;
  --purple: #8c6fe6;
  --purple-shadow: rgba(140, 111, 230, .28);
  --card-bg: #fffdf6;
  --text: #3a3550;
  --text-soft: #8b84a3;
  --cream: #fff3da;
  --heading: #6a4fc4;
  --border: #e7def5;
  --radius: 18px;
  color-scheme: light;
}

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

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
  color: var(--text);
  min-height: 100dvh;
  min-height: 100vh;
  overflow-x: hidden;
}

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

#app {
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
}

.screen {
  width: 100%;
  min-height: 100dvh;
  min-height: 100vh;
  display: none;
  flex-direction: column;
}

.screen.active { display: flex; }

/* ===================== SETUP ===================== */

#setup-screen {
  align-items: center;
  justify-content: flex-start;
  padding: env(safe-area-inset-top, 16px) env(safe-area-inset-right, 16px) env(safe-area-inset-bottom, 16px) env(safe-area-inset-left, 16px);
  overflow-y: auto;
}

.setup-wrap {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.setup-header {
  text-align: center;
  margin-bottom: 20px;
}

.logo-emoji { font-size: 44px; line-height: 1; }

.setup-header h1 {
  margin: 8px 0 4px;
  font-size: clamp(22px, 5vw, 30px);
  color: var(--heading);
}

.tagline {
  margin: 0;
  color: var(--text-soft);
  font-size: 14px;
}

.steps {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 18px 0 22px;
  gap: 6px;
}

.step-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  color: var(--purple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  transition: background .2s, color .2s, transform .2s;
}

.step-dot.active {
  background: var(--accent);
  color: #fff;
  transform: scale(1.1);
}

.step-dot.done { background: var(--green); color: #fff; }

.step-line {
  width: 32px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
}

.step-panel {
  display: none;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px 18px 24px;
  box-shadow: 0 8px 24px rgba(140, 111, 230, .18);
}

.step-panel.active { display: block; animation: pop-in .25s ease; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.step-panel h2 {
  margin: 0 0 6px;
  font-size: 20px;
  color: var(--heading);
}

.hint {
  margin: 0 0 16px;
  color: var(--text-soft);
  font-size: 14px;
}

.big-btn {
  width: 100%;
  padding: 15px 16px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  transition: transform .12s ease, opacity .2s ease, box-shadow .2s ease;
}

.big-btn:active { transform: scale(.97); }

.big-btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 16px var(--accent-shadow);
}

.big-btn.secondary {
  background: var(--purple);
  color: #fff;
  box-shadow: 0 6px 16px var(--purple-shadow);
}

.big-btn.ghost {
  background: var(--cream);
  color: var(--heading);
}

.big-btn:disabled {
  opacity: .45;
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

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

.status-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #eef7ee;
  border: 1px solid #cfe9cf;
  color: #285c28;
  font-size: 14px;
  line-height: 1.4;
}

.status-box.error {
  background: #fdeceb;
  border-color: #f4c3bf;
  color: #9c2b22;
}

.status-box.loading {
  background: #eef3fb;
  border-color: #cddcf3;
  color: #2c4a75;
}

#dest-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

#dest-input {
  width: 100%;
  padding: 14px 14px;
  border-radius: 12px;
  border: 2px solid var(--border);
  font-size: 16px;
  outline: none;
  background: var(--cream);
  color: var(--text);
}

#dest-input:focus { border-color: var(--accent); }

.results-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.result-item {
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--cream);
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
}

.result-item:active { background: #ffe8cf; }

.result-item.selected {
  border-color: var(--green);
  background: #e3fbef;
}

.step-nav {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.step-nav .big-btn { margin-top: 10px; }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 8px;
}

.icon-choice {
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--cream);
  border: 3px solid transparent;
  font-size: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .12s ease, border-color .15s ease, background .15s ease;
}

.icon-choice:active { transform: scale(.92); }

.icon-choice.selected {
  border-color: var(--accent);
  background: #ffe3dc;
}

.custom-icon-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  font-size: 13px;
  color: var(--text-soft);
}

#custom-emoji {
  width: 56px;
  padding: 8px;
  border-radius: 10px;
  border: 2px solid var(--border);
  font-size: 18px;
  text-align: center;
  background: var(--cream);
  color: var(--text);
}

#custom-sound {
  padding: 8px 6px;
  border-radius: 10px;
  border: 2px solid var(--border);
  font-size: 13px;
  background: var(--cream);
  color: var(--text);
}

.mini-btn {
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--purple);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

/* ===================== GAME SCREEN ===================== */

#game-screen {
  position: relative;
  overflow: hidden;
  justify-content: space-between;
  padding: env(safe-area-inset-top, 14px) env(safe-area-inset-right, 14px) env(safe-area-inset-bottom, 14px) env(safe-area-inset-left, 14px);
}

.sky {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.cloud {
  position: absolute;
  font-size: 40px;
  opacity: .85;
  animation: drift 40s linear infinite;
}

.cloud.c1 { top: 8%; left: -10%; animation-duration: 55s; }
.cloud.c2 { top: 20%; left: -20%; font-size: 30px; animation-duration: 70s; animation-delay: -20s; }
.cloud.c3 { top: 4%; left: -30%; font-size: 26px; animation-duration: 85s; animation-delay: -45s; }

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(130vw); }
}

.sun {
  position: absolute;
  top: 4%;
  right: 6%;
  font-size: 46px;
  animation: pulse-sun 4s ease-in-out infinite;
}

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

.game-header {
  position: relative;
  z-index: 2;
  text-align: center;
  padding-top: 6px;
}

.dest-name {
  font-weight: 800;
  font-size: clamp(16px, 4vw, 22px);
  color: var(--heading);
  background: rgba(255,255,255,.85);
  display: inline-block;
  padding: 6px 16px;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(0,0,0,.08);
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-row {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-top: 10px;
}

.stat { display: flex; flex-direction: column; align-items: center; }

.stat-value {
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 800;
  color: var(--accent);
}

.stat-label {
  font-size: 12px;
  color: var(--heading);
  opacity: .8;
}

.track-wrap {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  align-items: center;
  padding: 10px 4vw 30px;
  min-height: 0;
}

.track {
  position: relative;
  width: 100%;
  height: 14px;
  background: repeating-linear-gradient(90deg, var(--road), var(--road) 18px, var(--road-dash) 18px, var(--road-dash) 20px);
  border-radius: 999px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.2), 0 4px 10px rgba(0,0,0,.12);
}

.track-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--road-fill-a), var(--road-fill-b));
  border-radius: 999px;
  transition: width .6s ease;
}

.marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(22px, 5vw, 30px);
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.25));
}

.start-marker { left: 0; }
.end-marker { left: 100%; }

.travel-icon {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  font-size: clamp(34px, 9vw, 54px);
  background: none;
  padding: 6px;
  line-height: 1;
  filter: drop-shadow(0 4px 5px rgba(0,0,0,.3));
  transition: left .6s cubic-bezier(.34,1.2,.4,1), transform .15s ease;
  z-index: 3;
  touch-action: manipulation;
}

.travel-icon:active { transform: translate(-50%, -50%) scale(1.2); }

.travel-icon.bounce { animation: bounce-icon .5s ease; }

@keyframes bounce-icon {
  0% { transform: translate(-50%, -50%) scale(1); }
  40% { transform: translate(-50%, -60%) scale(1.25); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

.arrived-banner {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: rgba(255, 253, 246, .96);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 20px;
}

.arrived-emoji {
  font-size: 48px;
  animation: pulse-sun 1.2s ease-in-out infinite;
}

.arrived-text {
  font-size: clamp(24px, 6vw, 34px);
  font-weight: 900;
  color: var(--green);
}

.arrived-banner .big-btn { max-width: 260px; }

.reset-btn {
  position: absolute;
  top: env(safe-area-inset-top, 12px);
  right: env(safe-area-inset-right, 12px);
  z-index: 6;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.85);
  color: var(--heading);
  font-size: 20px;
  box-shadow: 0 3px 8px rgba(0,0,0,.15);
}

.reset-btn:active { transform: scale(.9); }

.gps-warning {
  position: relative;
  z-index: 2;
  text-align: center;
  font-size: 13px;
  color: var(--heading);
  background: rgba(255,255,255,.85);
  border-radius: 999px;
  padding: 6px 14px;
  margin: 0 auto 8px;
  width: fit-content;
}

/* ===================== LANDSCAPE ADJUSTMENTS ===================== */

@media (orientation: landscape) {
  .setup-wrap { padding-top: 10px; padding-bottom: 20px; }
  .logo-emoji { font-size: 32px; }
  .setup-header h1 { font-size: 20px; margin: 4px 0; }
  .tagline { display: none; }
  .steps { margin: 10px 0 14px; }

  .game-header { padding-top: 2px; }
  .stat-row { margin-top: 6px; gap: 20px; }
  .track-wrap { padding: 6px 4vw 16px; }
  .cloud, .sun { display: none; }
}

@media (max-height: 480px) and (orientation: landscape) {
  .dest-name { font-size: 14px; padding: 4px 12px; }
  .stat-value { font-size: 18px; }
  .stat-label { font-size: 10px; }
}

/* ===================== DARK MODE (playful twilight, not corporate navy) ===================== */

@media (prefers-color-scheme: dark) {
  :root {
    --sky-top: #2b1f54;
    --sky-bottom: #6c4ba6;
    --card-bg: #3c2e63;
    --text: #fbf3e7;
    --text-soft: #c9b8e8;
    --heading: #ffd166;
    --cream: #4a3b78;
    --border: #5b4a8a;
  }

  body { background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom)); }

  .step-panel { box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
  #dest-input, .result-item, #custom-emoji, #custom-sound {
    background: var(--cream);
    border-color: var(--border);
    color: var(--text);
  }
  .result-item:active { background: #5a4890; }
  .icon-choice { background: var(--cream); }
  .status-box { background: #23472f; border-color: #386b45; color: #cdf2d6; }
  .status-box.error { background: #4a2420; border-color: #7a352d; color: #f6c3bc; }
  .status-box.loading { background: #23345c; border-color: #3a4f85; color: #cfdcf7; }
  .dest-name, .gps-warning, .reset-btn { background: rgba(60, 46, 99, .85); color: var(--heading); }
  .arrived-banner { background: rgba(43, 31, 84, .96); }
}
