:root {
  --ink: #17324d;
  --muted: #5b6b7a;
  --card: rgba(255, 255, 255, 0.94);
  --sun: #ffd166;
  --coral: #ef476f;
  --mint: #52b788;
  --sky: #3a86ff;
  --sea: #4cc9f0;
  --violet: #7b2cbf;
  --shadow: 0 18px 45px rgba(23, 50, 77, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Trebuchet MS", Arial, sans-serif;
  background: #e9fbff;
}

.background-layer {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 14% 18%, rgba(255, 209, 102, 0.45), transparent 26%),
    radial-gradient(circle at 88% 12%, rgba(76, 201, 240, 0.38), transparent 24%),
    linear-gradient(145deg, #dff7ff 0%, #f8fff1 45%, #fff3dd 100%);
}

.app {
  width: min(1160px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.screen { width: 100%; animation: appear 240ms ease both; }

.shell {
  display: grid;
  gap: 18px;
}

.card {
  background: var(--card);
  border: 3px solid rgba(255,255,255,0.78);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 30px);
}

.hero {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 22px;
  align-items: stretch;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2.1rem, 5vw, 4.8rem); line-height: 0.96; margin-bottom: 12px; }
h2 { font-size: clamp(1.45rem, 3vw, 2.3rem); margin-bottom: 12px; }
h3 { font-size: 1.08rem; margin-bottom: 8px; }
p { color: var(--muted); line-height: 1.45; }

.title-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff0b8;
  color: #8a5a00;
  border-radius: 999px;
  padding: 8px 13px;
  font-weight: 800;
  margin-bottom: 14px;
}

.form-grid, .choice-grid {
  display: grid;
  gap: 12px;
}

.choice-grid { grid-template-columns: repeat(auto-fit, minmax(142px, 1fr)); }

label { font-weight: 800; }
input, select {
  width: 100%;
  min-height: 48px;
  border: 2px solid #cfe5ef;
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: white;
}

button {
  border: 0;
  min-height: 48px;
  border-radius: 16px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 900;
  color: var(--ink);
  background: #e9f4ff;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

button:hover, button:focus-visible { transform: translateY(-1px); box-shadow: 0 8px 18px rgba(23, 50, 77, 0.14); }
button:disabled { opacity: 0.58; cursor: default; transform: none; }
.primary { background: var(--sun); }
.secondary { background: #d9f7e8; }
.danger { background: #ffe1eb; }
.selected { outline: 4px solid var(--sky); background: #fff7ce; }

.traveler-choice, .difficulty-choice, .answer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  text-align: center;
}

.traveler-emoji { font-size: 2rem; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(290px, 0.75fr);
  gap: 18px;
  align-items: stretch;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.75);
  font-weight: 900;
}

.map-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 24px;
  border: 4px solid #fff;
  background:
    linear-gradient(rgba(255,255,255,0.04), rgba(255,255,255,0.04)),
    radial-gradient(ellipse at 28% 42%, #94d2bd 0 8%, transparent 8% 100%),
    radial-gradient(ellipse at 51% 37%, #80ed99 0 12%, transparent 12% 100%),
    radial-gradient(ellipse at 75% 54%, #a7c957 0 8%, transparent 8% 100%),
    linear-gradient(180deg, #9be7ff, #c9f2ff);
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 999px rgba(255,255,255,0.04);
}

.marker {
  position: absolute;
  width: 26px;
  height: 26px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: white;
  border: 5px solid var(--coral);
  box-shadow: 0 4px 12px rgba(0,0,0,0.24);
}

.marker.current {
  border-color: var(--sun);
  animation: pulse 1s ease-in-out infinite;
}

.marker.done { border-color: var(--mint); }

.traveler {
  position: absolute;
  left: 45%;
  top: 42%;
  transform: translate(-50%, -82%);
  min-width: 46px;
  min-height: 46px;
  display: grid;
  place-items: center;
  font-size: 2.3rem;
  transition: left 700ms ease, top 700ms ease;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,0.22));
}

.traveler img { width: 54px; height: 54px; object-fit: contain; }

.question-panel {
  display: grid;
  gap: 12px;
  align-content: start;
  min-height: 560px;
}
.answers { display: grid; gap: 10px; }
.answer { justify-content: flex-start; background: white; border: 2px solid #d9ecf5; }
.answer.correct { background: #d9f7e8; border-color: var(--mint); }
.answer.wrong { background: #ffe1eb; border-color: var(--coral); }

.feedback {
  border-radius: 18px;
  padding: 14px;
  background: #fff7ce;
  border: 2px dashed #f4b942;
  min-height: 154px;
}

.passport-grid, .badge-grid, .leaderboard, .recap-list {
  display: grid;
  gap: 10px;
}

.stamp, .badge, .score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #fff;
  border: 2px solid #e7f1f5;
}

.stamp.new { animation: stampIn 420ms ease both; }
.stamp-emoji, .badge-emoji { font-size: 1.8rem; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

.tooltip-wrap {
  position: relative;
  display: inline-flex;
  width: fit-content;
}

.tooltip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: 230px;
  transform: translate(-50%, 6px);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.25;
  box-shadow: 0 10px 24px rgba(23, 50, 77, 0.22);
  transition: opacity 140ms ease, transform 140ms ease;
}

.tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--ink);
}

.tooltip-wrap:hover .tooltip,
.tooltip-wrap:focus-within .tooltip {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: white;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 900;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 5;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes appear { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { transform: translate(-50%, -50%) scale(1.22); } }
@keyframes stampIn { from { opacity: 0; transform: scale(1.25) rotate(-8deg); } to { opacity: 1; transform: none; } }

@media (max-width: 850px) {
  .app { padding: 12px; align-items: start; }
  .hero, .game-layout { grid-template-columns: 1fr; }
  .map-wrap { aspect-ratio: 16 / 9; }
}

@media (max-width: 640px) {
  .app { padding: 8px; }
  .shell { gap: 8px; }
  .card {
    border-width: 2px;
    border-radius: 16px;
    padding: 10px;
  }
  .topbar { gap: 6px; }
  .pill {
    padding: 5px 8px;
    font-size: 0.82rem;
  }
  .game-layout { gap: 8px; }
  .game-layout > .card:first-child h2 {
    font-size: 1rem;
    margin-bottom: 4px;
  }
  .game-layout > .card:first-child .topbar {
    align-items: start;
  }
  .game-layout > .card:first-child .pill {
    max-width: 100%;
  }
  .map-wrap {
    border-width: 2px;
    border-radius: 14px;
    max-height: 34vh;
  }
  .marker {
    width: 18px;
    height: 18px;
    border-width: 4px;
  }
  .traveler {
    min-width: 34px;
    min-height: 34px;
    font-size: 1.7rem;
  }
  .traveler img {
    width: 38px;
    height: 38px;
  }
  .question-panel {
    gap: 7px;
    min-height: auto;
  }
  .question-panel h2 {
    font-size: 1.12rem;
    margin-bottom: 2px;
  }
  .question-panel p {
    margin-bottom: 2px;
    line-height: 1.25;
  }
  .answers {
    gap: 7px;
  }
  button {
    min-height: 40px;
    border-radius: 12px;
    padding: 8px 10px;
  }
  .answer {
    min-height: 42px;
    font-size: 0.95rem;
  }
  .feedback {
    padding: 9px;
    border-radius: 12px;
    min-height: auto;
  }
  .tooltip {
    display: none;
  }
  .feedback h3 {
    font-size: 1rem;
    margin-bottom: 4px;
  }
}

@media (max-width: 640px) and (orientation: landscape) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 0.9fr);
    align-items: start;
  }
  .map-wrap {
    max-height: 58vh;
  }
}
