/* Liftoff: one night-sky theme. Amber is the only accent; there is no red anywhere. */
:root {
  --bg: #0E1530;
  --bg-2: #18224A;
  --card: rgba(255, 255, 255, .06);
  --line: rgba(255, 255, 255, .14);
  --ink: #F4F1EA;
  --muted: #A9B0D0;
  --accent: #F2A541;
  --accent-ink: #231705;
  --water-top: #3FA8AE;
  --water-bottom: #24707F;
  --firefly: #FFE08A;
  --gw: 118px; /* gator width; the river maths depends on it */
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, #1C2A5C 0%, var(--bg) 62%) fixed, var(--bg);
  color: var(--ink);
  font: 17px/1.4 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { cursor: pointer; touch-action: manipulation; font: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.defs { position: absolute; }

/* ---------- stars ---------- */
#stars { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
#stars i {
  position: absolute; width: var(--s); height: var(--s); border-radius: 50%;
  background: #fff; opacity: .55; animation: twinkle var(--d) ease-in-out infinite; animation-delay: var(--delay);
}
@keyframes twinkle { 50% { opacity: .12; } }

/* ---------- layout ---------- */
main {
  position: relative; z-index: 1; display: flex;
  max-width: 520px; min-height: 100dvh; margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.screen { flex: 1; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.screen[hidden] { display: none; }
/* Each screen is split into two panes for the open Duo; on one screen the panes melt away. */
.pane { display: contents; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font-size: 30px; letter-spacing: .01em; }
h2 { margin: 0; font-size: 28px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* ---------- controls ---------- */
.label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 14px; font-weight: 600; }
.label em { font-style: normal; font-weight: 400; opacity: .8; }
input, textarea {
  width: 100%; font: inherit; font-size: 17px; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px 16px; outline: none;
}
textarea { resize: none; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
input:focus, textarea:focus { border-color: var(--accent); }
.chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); gap: 8px; }
.chip {
  min-height: 48px; padding: 10px 4px; font-weight: 700; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.chip small { display: block; font-size: 12px; font-weight: 600; opacity: .7; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.primary { font-weight: 800; color: var(--accent-ink); background: var(--accent); border: 0; border-radius: 20px; }
.primary:active { transform: scale(.98); }
.big { min-height: 72px; font-size: 24px; letter-spacing: .02em; }
.huge { width: 100%; min-height: 104px; font-size: 26px; }
.ghost {
  min-height: 48px; padding: 12px 16px; font-weight: 600; color: var(--ink);
  background: transparent; border: 1px solid var(--line); border-radius: 14px;
}
.ghost.small { min-height: 44px; padding: 8px 12px; font-size: 15px; }
.ghost.armed { border-color: var(--accent); color: var(--accent); }
.ghost:disabled { opacity: .35; }

/* ---------- home ---------- */
.today { min-height: 1.4em; margin: -4px 0 0; text-align: center; color: var(--muted); font-size: 15px; }
.settings summary { padding: 6px 0; color: var(--muted); font-weight: 600; list-style: none; cursor: pointer; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary::before { content: "▸ "; }
.settings[open] summary::before { content: "▾ "; }
.settings .group { margin-top: 10px; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.pond { --gw: 140px; position: relative; height: 84px; margin-top: auto; flex-shrink: 0; }
.pond .gator-slot { left: 12%; }

/* ---------- gator + water (shared) ---------- */
.gator-slot { position: absolute; bottom: 8px; width: var(--gw); z-index: 1; }
.gator-slot svg { display: block; width: 100%; height: auto; overflow: visible; }
.water {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--wh, 22px); z-index: 2;
  background: linear-gradient(180deg, var(--water-top), var(--water-bottom));
}
.water::before {
  content: ""; position: absolute; left: 0; right: 0; top: -7px; height: 8px;
  background: radial-gradient(circle at 50% 100%, var(--water-top) 7px, transparent 7.5px) 0 0 / 18px 8px repeat-x;
}

.gator .g-jaw-up, .gator .g-mouth { transform-origin: 146px 67px; }
.gator .g-lid { transform-origin: 153px 34px; transform: scaleY(0); animation: blink 5.5s infinite; }
.idle svg, .swim svg { animation: bob 2.4s ease-in-out infinite; }
.idle .g-jaw-up, .idle .g-mouth { animation: yawn 8s ease-in-out infinite; }
.gulp .g-jaw-up, .gulp .g-mouth { animation: chomp .32s ease-in-out; }
.chomping .g-jaw-up, .chomping .g-mouth { animation: chomp .38s ease-in-out 3; }
.content .g-lid { animation: none; transform: scaleY(.55); }
@keyframes bob { 50% { transform: translateY(-3px); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(0); } 97% { transform: scaleY(1); } }
@keyframes chomp { 0%, 100% { transform: rotate(0); } 45% { transform: rotate(-30deg); } }
@keyframes yawn { 0%, 70%, 100% { transform: rotate(0); } 78%, 88% { transform: rotate(-16deg); } }

/* ---------- countdown ---------- */
#countdown { align-items: center; text-align: center; }
.tminus { margin: 18px 0 0; color: var(--muted); font-size: 14px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; }
.count { font-size: clamp(110px, 42vw, 220px); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.count.word { font-size: clamp(52px, 17vw, 96px); line-height: 2; color: var(--accent); }
.count.tick { animation: tick .35s ease-out; }
@keyframes tick { 0% { transform: scale(1.18); opacity: .6; } 100% { transform: scale(1); opacity: 1; } }
.launchpad { position: relative; flex: 1; width: 100%; min-height: 230px; display: flex; align-items: flex-end; justify-content: center; }
.rocket-fly { position: relative; z-index: 2; margin-bottom: -50px; }
.rocket { display: block; width: 84px; height: auto; overflow: visible; }
.rocket .flame { opacity: 0; transform-origin: 30px 100px; transform: scaleY(.45); transition: opacity .2s, transform .35s; }
.ignite .rocket .flame { opacity: 1; animation: flicker .09s infinite alternate; }
.lift .rocket .flame { opacity: 1; transform: scaleY(1.5); animation: flicker .07s infinite alternate; }
@keyframes flicker { to { opacity: .78; } }
.rumble .rocket-shake { animation: shake .09s linear infinite; }
@keyframes shake { 25% { transform: translate(-1.5px, 1px); } 50% { transform: translate(1px, -1px); } 75% { transform: translate(1.5px, 1px); } }
.lift .rocket-fly { animation: lift 1.6s cubic-bezier(.55, 0, .85, .35) forwards; }
@keyframes lift { to { transform: translateY(-125vh); } }
.ground { position: absolute; left: 0; right: 0; bottom: 0; height: 18px; z-index: 1; background: #2A3460; border-radius: 8px; }
.smoke { position: absolute; left: 50%; bottom: 8px; width: 0; z-index: 3; }
.puff {
  position: absolute; bottom: 0; width: 48px; height: 48px; margin-left: -24px;
  border-radius: 50%; background: #D9DCEB; opacity: 0;
}
.puff:nth-child(1) { --dx: -78px; --n: 0; } .puff:nth-child(2) { --dx: 78px; --n: 1; }
.puff:nth-child(3) { --dx: -44px; --n: 2; } .puff:nth-child(4) { --dx: 44px; --n: 3; }
.puff:nth-child(5) { --dx: -110px; --n: 4; } .puff:nth-child(6) { --dx: 110px; --n: 5; }
.ignite .puff { animation: puff 1.1s ease-out infinite; animation-delay: calc(var(--n) * .17s); }
.lift .puff { animation: puff 1.5s ease-out infinite; animation-delay: calc(var(--n) * .1s); }
@keyframes puff {
  0% { opacity: 0; transform: translateX(0) scale(.3); }
  30% { opacity: .75; }
  100% { opacity: 0; transform: translateX(var(--dx)) translateY(-14px) scale(1.5); }
}
#scrub { margin-top: 8px; min-width: 60%; }
.lift .tminus, .lift #scrub { visibility: hidden; }

/* ---------- sprint ---------- */
.sprint-top { margin-top: 4px; text-align: center; }
.mission-label { min-height: 1.4em; margin: 0; color: var(--muted); font-weight: 600; overflow-wrap: anywhere; }
.clock { margin: 4px 0; font-size: clamp(64px, 24vw, 120px); font-weight: 800; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.sub { margin: 0; color: var(--muted); }
#sprint.close .clock, #sprint.close .sub { color: var(--accent); }
#sprint.paused .clock { opacity: .4; }
#sprint.paused .swim svg, #sprint.paused .fly { animation-play-state: paused; }

.river {
  --p: 0; --gw: 168px; --wh: 16px;
  position: relative; flex: 1 1 140px; min-height: 124px; max-height: 190px; overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, .02), rgba(255, 255, 255, .07));
  border: 1px solid var(--line); border-radius: 22px;
}
.river .gator-slot { left: calc(var(--p) * (100% - var(--gw))); transition: left .3s linear; }
.fireflies { position: absolute; inset: 0; z-index: 1; }
.fly {
  position: absolute; bottom: calc(2px + var(--gw) * .15); width: 12px; height: 12px; margin-left: -6px;
  left: calc(var(--gw) * .96 + var(--k) * (100% - var(--gw)));
  border-radius: 50%; background: var(--firefly); box-shadow: 0 0 10px 3px rgba(255, 224, 138, .5);
  animation: hover 2.4s ease-in-out infinite; animation-delay: calc(var(--i) * -.37s);
  transition: scale .25s ease-in, opacity .25s ease-in;
}
.fly.last { width: 18px; height: 18px; margin: 0 0 -3px -9px; box-shadow: 0 0 14px 5px rgba(255, 224, 138, .55); }
.fly.eaten { scale: 0; opacity: 0; }
@keyframes hover { 50% { translate: 0 -7px; } }

.tally { display: flex; flex-direction: column; gap: 12px; margin-top: auto; }
.tally-count { margin: 0; text-align: center; color: var(--muted); font-weight: 600; }
#tally { display: inline-block; font-size: 44px; font-weight: 800; color: var(--ink); vertical-align: -5px; font-variant-numeric: tabular-nums; }
.pop { animation: pop .3s ease-out; }
@keyframes pop { 40% { transform: scale(1.35); } }
.spark {
  position: fixed; z-index: 5; pointer-events: none; margin: -14px 0 0 -16px;
  color: var(--firefly); font-size: 24px; font-weight: 800; animation: spark .8s ease-out forwards;
}
@keyframes spark { to { transform: translateY(-90px); opacity: 0; } }

/* ---------- landed ---------- */
#landed { text-align: center; }
.landed-art { position: relative; height: 150px; margin-top: 12px; flex-shrink: 0; }
.landed-art .gator-slot { --gw: 230px; left: 50%; margin-left: -115px; }
.landed-art .water { border-radius: 0 0 14px 14px; }
.result { margin: 0; color: var(--muted); font-size: 20px; }
#landed .field { text-align: left; }
#again { margin-top: auto; }

/* ---------- log ---------- */
dialog {
  width: min(520px, calc(100vw - 24px)); max-height: 82dvh; padding: 16px;
  color: var(--ink); background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px;
}
dialog::backdrop { background: rgba(5, 8, 20, .65); }
#logList h3 { margin: 16px 0 4px; color: var(--muted); font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.entry { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.entry .time { color: var(--muted); font-variant-numeric: tabular-nums; }
.entry .what { overflow-wrap: anywhere; }
.entry .n { font-weight: 800; text-align: right; }
.entry .note { grid-column: 2 / -1; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.empty { color: var(--muted); }
.log-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.ver { color: var(--muted); font-size: 13px; }

/* ---------- Two panes: the open Duo (and anything 700+ wide) ----------
   What you watch goes on the left, what you tap on the right, so nothing sits across the fold. */
@media (min-width: 700px), (horizontal-viewport-segments: 2), (vertical-viewport-segments: 2) {
  main { max-width: 1100px; }
  .screen { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 48px; }
  .screen[hidden] { display: none; }
  .pane { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

  #home .pane-a { justify-content: center; }
  #home #launch { min-height: 96px; margin-top: auto; font-size: 28px; }
  #countdown { align-items: stretch; }
  #countdown .pane { align-items: center; }
  #countdown .pane-a { justify-content: center; }
  #countdown .pane-b { padding-top: 24px; }
  #sprint .pane-a { justify-content: center; }
  #sprint .river { max-height: 240px; }
  #sprint .pane-b { justify-content: center; }
  #sprint .tally { margin-top: 0; }
  #sprint .huge { min-height: 168px; font-size: 30px; }
  #landed .pane-a { justify-content: center; }
  #landed .pane-b { justify-content: center; }
  #landed #again { margin-top: 0; }
}

/* ---------- Half-folded like a book: each pane snaps to its own half ---------- */
@media (horizontal-viewport-segments: 2) {
  :root { --fold: calc(env(viewport-segment-left 1 0, 0px) - env(viewport-segment-right 0 0, 0px)); }
  main { max-width: none; padding-left: 0; padding-right: 0; }
  .screen { grid-template-columns: env(viewport-segment-width 0 0) var(--fold) env(viewport-segment-width 1 0); column-gap: 0; }
  .pane-a { grid-column: 1; padding-left: max(16px, env(safe-area-inset-left)); padding-right: 24px; }
  .pane-b { grid-column: 3; padding-left: 24px; padding-right: max(16px, env(safe-area-inset-right)); }
  dialog { inset-inline-start: env(viewport-segment-left 1 0); inset-inline-end: 0; width: calc(env(viewport-segment-width 1 0) - 24px); }
}

/* ---------- Half-folded like a laptop: watch on the top half, tap on the bottom half ---------- */
@media (vertical-viewport-segments: 2) {
  :root { --fold-h: calc(env(viewport-segment-top 0 1, 0px) - env(viewport-segment-bottom 0 0, 0px)); }
  main { max-width: none; padding-top: 0; padding-bottom: 0; }
  .screen {
    grid-template-columns: minmax(0, 1fr); row-gap: 0;
    grid-template-rows: env(viewport-segment-height 0 0) var(--fold-h) env(viewport-segment-height 0 1);
  }
  .pane-a { grid-row: 1; padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: 12px; gap: 10px; }
  .pane-b { grid-row: 3; padding-top: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); gap: 10px; }
  #countdown .count { font-size: clamp(72px, 20vh, 160px); }
  .clock { font-size: clamp(44px, 10vh, 96px); }
  #sprint .river { min-height: 84px; max-height: 150px; }
  #sprint .huge { min-height: 96px; }
  .landed-art { height: 110px; }
  dialog { inset-block-end: calc(100dvh - env(viewport-segment-bottom 0 0)); max-height: calc(env(viewport-segment-height 0 0) - 24px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important;
  }
}
