:root {
  --ink: #1d2c44;
  --panel: rgba(20, 34, 60, 0.42);
  --cream: #fff8ea;
  --gold: #ffd36a;
  --orange: #f3a43a;
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bcd6e6; color: #fff; overscroll-behavior: none; }
button { font: inherit; touch-action: manipulation; cursor: pointer; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#scene3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#flash { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(transparent 40%, rgba(255, 230, 210, 0.7)); opacity: 0; }
body.loading #stage { background: #bcd6e6; }

/* drag-to-steer ring */
#stick {
  position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none;
}
#stick::before {
  content: ''; position: absolute; left: -11vmin; top: -11vmin; width: 22vmin; height: 22vmin;
  border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.55); background: rgba(255, 255, 255, 0.08);
}
#knob {
  position: absolute; left: -4vmin; top: -4vmin; width: 8vmin; height: 8vmin; border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
}

/* ---------- HUD ---------- */
#hud-top, #hud-bottom, #marker, #toast, #hint { transition: opacity 0.4s; }
body[data-phase=menu] #hud-top, body[data-phase=menu] #hud-bottom, body[data-phase=menu] #marker,
body[data-phase=arrived] #hud-bottom, body[data-phase=arrived] #marker { opacity: 0; pointer-events: none; }

#hud-top {
  position: fixed; left: 0; right: 0; top: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(20, 30, 60, 0.6);
}
.tools { display: flex; gap: 8px; pointer-events: auto; }
.tools button {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--panel); color: #fff; font-size: 17px; display: grid; place-items: center;
  backdrop-filter: blur(6px);
}
.where { text-align: center; line-height: 1.15; }
.where b { display: block; font-size: clamp(20px, 3.6vmin, 30px); font-weight: 700; letter-spacing: 0.02em; }
.where > span { font-size: clamp(13px, 2vmin, 16px); opacity: 0.92; }
#progress { margin: 6px auto 0; width: min(46vw, 320px); height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.3); overflow: hidden; }
#progress-fill { height: 100%; background: var(--cream); transform-origin: left; transform: scaleX(0); }
.right { justify-self: end; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#clock-box { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; background: var(--panel); padding: 4px 12px; border-radius: 14px; backdrop-filter: blur(6px); }
#clock { font-size: 20px; font-variant-numeric: tabular-nums; }
#clock-box small { font-size: 13px; opacity: 0.9; }
#clock-box small:empty { display: none; }
#clock-gap.ahead { color: #bff0b0; }
#clock-gap.behind { color: #ffd0b8; }
#ghost-marker span { background: rgba(190, 140, 20, 0.85); }
.flock { justify-self: end; display: flex; align-items: center; gap: 6px; background: var(--panel); padding: 4px 14px 4px 10px; border-radius: 22px; backdrop-filter: blur(6px); }
.flock b { font-size: 24px; }

#hud-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 0 max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  pointer-events: none;
}
.meters { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.meter { display: flex; align-items: center; gap: 10px; background: var(--panel); padding: 6px 14px; border-radius: 22px; backdrop-filter: blur(6px); text-shadow: 0 1px 4px rgba(20, 30, 60, 0.5); }
.meter > span { width: 4.2em; }
.meter .bar { width: min(36vw, 220px); height: 12px; border-radius: 6px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
#leader .bar { height: 8px; }
#leader-fill { height: 100%; background: #bfe6ff; transform-origin: left; transition: transform 0.1s linear; }
#leader.low #leader-fill { background: #ff9a6a; animation: blink 0.7s ease-in-out infinite; }
#energy-fill { height: 100%; background: linear-gradient(90deg, #ffe6a0, #fff8ea); transform-origin: left; transition: transform 0.1s linear; }
#energy.low #energy-fill { background: #ff9a6a; animation: blink 0.7s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.4; } }

#flap {
  pointer-events: auto; width: clamp(92px, 20vmin, 140px); height: clamp(92px, 20vmin, 140px); border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.8); background: rgba(255, 248, 234, 0.25); color: #fff;
  font-size: clamp(20px, 4vmin, 28px); font-weight: 700; text-shadow: 0 1px 6px rgba(20, 30, 60, 0.6);
  backdrop-filter: blur(4px); -webkit-tap-highlight-color: transparent;
}
#flap.down { background: rgba(255, 248, 234, 0.6); transform: scale(0.95); }
.buttons-right { display: flex; align-items: flex-end; gap: 12px; }
#swap {
  pointer-events: auto; width: clamp(64px, 13vmin, 92px); height: clamp(64px, 13vmin, 92px); border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.6); background: rgba(20, 34, 60, 0.35); color: #fff;
  font-size: clamp(15px, 2.8vmin, 20px); font-weight: 700; line-height: 1; display: grid; place-content: center;
  text-shadow: 0 1px 6px rgba(20, 30, 60, 0.6); backdrop-filter: blur(4px); -webkit-tap-highlight-color: transparent;
  opacity: 0.55; transition: opacity 0.3s, background 0.3s, border-color 0.3s;
}
#swap small { font-size: 11px; opacity: 0.8; margin-top: 3px; }
#swap.ready { opacity: 1; border-color: #bfe6ff; }
#swap.urgent { opacity: 1; border-color: var(--gold); background: rgba(255, 196, 80, 0.45); animation: pulse 0.8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@media (pointer: coarse) { #swap small { display: none; } }
@media (hover: hover) and (pointer: fine) {
  #flap { width: 96px; height: 96px; font-size: 18px; }
}

#marker {
  position: fixed; left: 0; top: 0; z-index: 9; pointer-events: none;
  display: flex; flex-direction: column; align-items: center;
  margin-left: -60px; width: 120px; margin-top: -52px;
  text-shadow: 0 1px 5px rgba(20, 30, 60, 0.7); font-size: 15px;
}
#marker b { font-size: 17px; }
#marker-arrow { font-size: 18px; color: var(--gold); line-height: 1; order: 2; }
#marker.edge #marker-arrow { order: 0; }
#marker.here { opacity: 0; }
.tag {
  position: fixed; left: 0; top: 0; z-index: 9; pointer-events: none; opacity: 0; transition: opacity 0.3s;
  margin: -58px 0 0 -60px; width: 120px; text-align: center;
}
.tag span { display: inline-block; padding: 2px 10px; border-radius: 12px; background: rgba(170, 40, 30, 0.75); font-size: 14px; font-weight: 700; white-space: nowrap; }
#goose-marker span { background: rgba(200, 140, 20, 0.85); }
.tag.on { opacity: 1; }
body:not([data-phase=fly]) .tag { opacity: 0; }

#toast, #hint {
  position: fixed; left: 50%; z-index: 11; pointer-events: none; text-align: center; opacity: 0;
  transform: translate(-50%, 0); max-width: 86vw;
  text-shadow: 0 1px 8px rgba(20, 30, 60, 0.7);
}
#toast { top: 22vh; font-size: clamp(22px, 4.2vmin, 38px); font-weight: 700; transition: opacity 0.4s, transform 0.4s; }
#toast.on { opacity: 1; transform: translate(-50%, -6px); }
#toast.gold { color: var(--gold); }
#toast.warn { color: #ffb4a0; }
#hint { bottom: max(130px, 18vh); font-size: clamp(16px, 2.6vmin, 22px); background: var(--panel); padding: 6px 16px; border-radius: 18px; backdrop-filter: blur(6px); }
#hint.on { opacity: 1; }
body:not([data-phase=fly]) #hint { opacity: 0; }

/* ---------- cards ---------- */
.card-wrap {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  overflow: auto;
}
#pause { background: rgba(20, 30, 50, 0.25); }
/* the arrival card sits low, so the lake and the flock on it stay in view */
#arrive { place-items: end center; padding-bottom: max(20px, env(safe-area-inset-bottom)); background: linear-gradient(transparent 55%, rgba(20, 30, 50, 0.3)); animation: rise 0.6s ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
.card {
  width: min(560px, 100%); background: rgba(255, 250, 240, 0.94); color: var(--ink);
  border-radius: 24px; padding: 22px 26px; box-shadow: 0 18px 50px rgba(20, 30, 60, 0.35);
}
.card.small { width: min(340px, 100%); }
#menu { place-items: center start; padding-left: max(16px, 5vw); }
#menu .card { background: rgba(255, 250, 240, 0.88); }
h1 { margin: 0; font-size: clamp(40px, 8vmin, 64px); line-height: 1; color: #24467a; letter-spacing: 0.01em; }
h2 { margin: 0 0 8px; font-size: 28px; line-height: 1.1; color: #24467a; }
.lede { margin: 8px 0 14px; font-size: 18px; line-height: 1.35; }
#legs { display: grid; gap: 8px; }
.leg {
  display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center; text-align: left;
  padding: 8px 14px; border-radius: 14px; border: 0; background: #24467a; color: #fff;
}
.leg b { grid-row: span 2; width: 36px; height: 36px; border-radius: 50%; background: var(--cream); color: #24467a; display: grid; place-items: center; font-size: 20px; }
.leg span { font-size: 20px; font-weight: 700; line-height: 1.1; }
.leg small { font-size: 14px; opacity: 0.85; }
.leg:hover:not(:disabled) { background: #2f5a9a; }
.leg:disabled { background: #c9ccd4; color: #6b7280; cursor: default; }
.leg:disabled b { background: #e5e7eb; color: #9aa0aa; }
.how { margin-top: 14px; font-size: 15px; line-height: 1.35; }
.how p { margin: 6px 0; }
#arrive-facts p { font-size: 18px; line-height: 1.4; margin: 8px 0; }
#arrive-stats { font-size: 15px; color: #4b5a72; margin: 12px 0 16px; }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.buttons.column { flex-direction: column; }
.btn { border: 0; border-radius: 14px; padding: 10px 20px; background: #24467a; color: #fff; font-size: 19px; font-weight: 700; }
.btn.ghost { background: transparent; color: #24467a; box-shadow: inset 0 0 0 2px #24467a; font-weight: 600; }

@media (max-height: 520px) {
  #menu { place-items: start; padding: 10px; }
  .card { padding: 14px 18px; }
  h1 { font-size: 34px; }
  .how { display: none; }
  .lede { font-size: 15px; margin: 4px 0 10px; }
  /* the five legs side by side in two rows, without the small print */
  #legs { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .leg { grid-template-columns: 30px 1fr; padding: 6px 8px; column-gap: 8px; }
  .leg b { width: 28px; height: 28px; font-size: 16px; }
  .leg span { font-size: 16px; }
  .leg small { display: none; }
  #menu .card { width: min(640px, 100%); }
}

/* streak counter, bottom middle */
#streak {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); z-index: 11; pointer-events: none;
  transform: translateX(-50%); display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: 8px;
  color: var(--gold); text-shadow: 0 1px 8px rgba(20, 30, 60, 0.7); opacity: 0; transition: opacity 0.4s;
  background: var(--panel); padding: 4px 16px 8px; border-radius: 18px; backdrop-filter: blur(6px);
}
#streak span { font-size: 18px; font-weight: 700; }
#streak b { font-size: 44px; line-height: 1; }
#streak .bar { grid-column: span 2; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
#streak-fill { height: 100%; background: var(--gold); transform-origin: left; }
#streak.on { opacity: 1; }
#streak.on.fading { opacity: 0.5; }
#streak.pop b { animation: pop 0.45s ease-out; }
@keyframes pop { 30% { transform: scale(1.45); color: #fff; } }
body:not([data-phase=fly]) #streak { opacity: 0; }

/* feathers: on the leg buttons and the arrival card */
.feathers { grid-column: 3; grid-row: 1 / span 2; display: flex; gap: 2px; font-style: normal; }
.leg { grid-template-columns: 40px 1fr auto; }
.feathers i, #arrive-feathers i { display: inline-block; width: 22px; height: 22px; color: rgba(255, 255, 255, 0.25); }
.feathers i.won { color: var(--gold); }
.feathers svg, #arrive-feathers svg { width: 100%; height: 100%; }
#arrive-feathers { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 4px; }
#arrive-feathers li { display: flex; align-items: center; gap: 10px; font-size: 17px; color: #8a93a4; animation: rise 0.5s ease-out both; }
#arrive-feathers li i { width: 28px; height: 28px; color: #d3d7de; }
#arrive-feathers li.won { color: var(--ink); font-weight: 600; }
#arrive-feathers li.won i { color: #e0a020; animation: pop 0.5s ease-out both; animation-delay: inherit; }
#arrive-best { margin: 6px 0 0; font-weight: 700; color: #c07a10; min-height: 0; }
#arrive-best:empty { display: none; }
@media (max-height: 520px) {
  .leg { grid-template-columns: 30px 1fr auto; }
  .feathers i { width: 14px; height: 14px; }
}

/* the dust storm on the progress bar, and how far behind it is */
#progress { position: relative; overflow: visible; }
#progress-fill { border-radius: 3px; }
#storm-mark { position: absolute; top: -3px; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: #d89a52; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.7); }
#storm-line { font-size: 14px; margin-top: 4px; min-height: 0; color: #ffe2b8; }
#storm-line.close { color: #ffb08a; font-weight: 700; animation: blink 0.8s ease-in-out infinite; }

/* things to spot */
#sight-marker span { background: rgba(40, 110, 90, 0.8); }
#spot {
  position: fixed; left: max(12px, env(safe-area-inset-left)); top: 70px; z-index: 11; width: min(340px, 70vw); pointer-events: none;
  background: rgba(255, 250, 240, 0.94); color: var(--ink); border-radius: 18px; padding: 12px 16px; box-shadow: 0 10px 30px rgba(20, 30, 60, 0.3);
  opacity: 0; transform: translateX(-20px); transition: opacity 0.5s, transform 0.5s;
}
#spot.on { opacity: 1; transform: none; }
#spot small { display: block; font-size: 13px; font-weight: 700; color: #2f8a6e; text-transform: uppercase; letter-spacing: 0.04em; }
#spot b { display: block; font-size: 22px; color: #24467a; line-height: 1.15; }
#spot p { margin: 4px 0 0; font-size: 15px; line-height: 1.35; }
body:not([data-phase=fly]) #spot { opacity: 0; }

/* the journal */
.journal-btn { margin-top: 10px; width: 100%; }
.journal-btn span { font-weight: 400; opacity: 0.8; margin-left: 4px; }
#journal .card { max-height: calc(100vh - 32px); overflow: auto; }
#journal h3 { margin: 14px 0 6px; color: #24467a; font-size: 19px; }
#journal-pages { display: grid; gap: 0; }
.page { border-radius: 12px; padding: 8px 12px; margin: 0 0 6px; background: #eef0f3; color: #6b7280; }
.page b { font-size: 17px; }
.page p { margin: 2px 0 0; font-size: 15px; line-height: 1.35; font-style: italic; }
.page.seen { background: #fff3d6; color: var(--ink); box-shadow: inset 0 0 0 2px #e8c060; }
.page.seen b { color: #24467a; }
.page.seen p { font-style: normal; }
body.looking-back #marker, body.looking-back .tag { opacity: 0 !important; }
#journal { background: rgba(20, 30, 50, 0.5); }
.how summary { cursor: pointer; font-weight: 700; color: #24467a; font-size: 17px; }
#journal .card { background: #fffaf0; }
@media (max-height: 520px) {
  .meter { padding: 4px 12px; font-size: 14px; }
  .meter .bar { width: min(24vw, 150px); }
  .journal-btn { margin-top: 6px; padding: 6px 16px; font-size: 16px; }
  #spot { top: 60px; width: min(300px, 60vw); }
  #spot p { font-size: 13px; }
}
#ghost-marker { margin-top: 18px; }
