:root {
  --bg: #0d1117;
  --text: #c9d1d9;
  --blue: #58a6ff;
  --green: #3fb950;
  --orange: #ffa657;
  --red: #f85149;
  --purple: #d2a8ff;
  --link: #79c0ff;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: Inter, system-ui, -apple-system, sans-serif;
  --glass: rgba(20, 26, 36, 0.42);
  --line: rgba(201, 209, 217, 0.14);
  --pad: 14px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#stage, #stage canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
#stage canvas { opacity: 0; transition: opacity 0.6s ease; }
body.scene-ready #stage canvas { opacity: 1; }

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
button { font-family: inherit; }
.hud { position: fixed; z-index: 2; transition: opacity 0.8s ease; }
body.loading .hud, body.loading .grade { opacity: 0; pointer-events: none; }

/* "← Lab" and "Follow for more" (lab/lib/links.js): always visible. */
#lab-links { top: calc(8px + var(--safe-t)); left: var(--pad); right: var(--pad); justify-content: space-between; }

/* ---------- Title, tiles, coach ---------- */
.hud-top { top: calc(56px + var(--safe-t)); left: var(--pad); right: var(--pad); pointer-events: none; }
.eyebrow {
  margin: 0 0 4px;
  font: 500 9.5px/1 var(--mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--orange);
}
h1 { margin: 0; line-height: 0.95; text-transform: uppercase; }
h1 span { font-weight: 800; font-size: 15px; letter-spacing: 0.02em; color: #f0f6fc; }
h1 strong {
  font-weight: 900;
  font-size: 27px;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--link), var(--blue) 45%, var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tiles { display: flex; gap: 6px; margin-top: 10px; }
.tile {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: 7px 8px 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(13, 17, 23, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  overflow: hidden;
}
.tile-label { display: block; font: 500 8.5px/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: #8b949e; }
.tile b { font: 700 17px/1 var(--mono); font-variant-numeric: tabular-nums; color: #f0f6fc; display: inline-block; margin-top: 5px; }
.tile small { margin-left: 3px; font: 500 9.5px/1 var(--mono); color: #8b949e; }
#t-distance { color: var(--orange); }
#t-speed { color: var(--blue); }
#hull-bar { position: absolute; left: 0; bottom: 0; height: 2px; width: calc(var(--hull, 100) * 1%); background: var(--green); transition: width 0.3s, background 0.3s; }
#tile-hull.low #hull-bar { background: var(--red); }
#tile-hull.low #t-hull { color: var(--red); }

.sentence {
  position: relative;
  margin: 10px 0 0;
  padding: 10px 12px 10px 28px;
  font-size: 12.5px;
  line-height: 1.45;
  color: #e6edf3;
  pointer-events: none;
}
.sentence::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 16px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 10px var(--orange);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- The landing grade: a word that pops over the rover ---------- */
.grade {
  position: fixed;
  z-index: 2;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%) scale(0.8);
  font: 900 30px/1 var(--sans);
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: #f0f6fc;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
}
.grade small { display: block; margin-top: 6px; font: 600 12px/1 var(--mono); letter-spacing: 0.08em; text-align: center; }
.grade.show { animation: pop 1.1s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.grade.perfect { color: var(--green); }
.grade.good { color: #f0f6fc; }
.grade.hard { color: var(--red); }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  70% { opacity: 1; transform: translate(-50%, -60%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -75%) scale(0.98); }
}

/* ---------- Start and end cards ---------- */
.card {
  left: var(--pad);
  right: var(--pad);
  bottom: calc(18px + var(--safe-b));
  padding: 18px 18px 16px;
  background: rgba(13, 17, 23, 0.62);
}
.card[hidden] { display: none; }
.card-kicker { margin: 0 0 6px; font: 500 9.5px/1 var(--mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--orange); }
.card h2 { margin: 0 0 8px; font-size: 22px; font-weight: 800; color: #f0f6fc; }
.card h2 b { font-family: var(--mono); color: var(--orange); }
.card-text { margin: 0 0 14px; font-size: 13px; line-height: 1.5; color: #b7c0ca; }
.card-best { margin: 10px 0 0; font: 500 11px/1 var(--mono); color: #8b949e; text-align: center; }
.card-best:empty { display: none; }
.card-rows { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 4px 0 14px; font: 400 12px/1.3 var(--mono); }
.card-rows dt { color: #8b949e; }
.card-rows dd { margin: 0; color: #e6edf3; text-align: right; font-variant-numeric: tabular-nums; }
.go {
  display: block;
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 999px;
  background: #e6edf3;
  color: #0d1117;
  font: 800 15px/1 var(--sans);
  letter-spacing: 0.02em;
  cursor: pointer;
}
.go:active { transform: scale(0.98); }

/* ---------- The essay ---------- */
.round {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(13, 17, 23, 0.5);
  color: #e6edf3;
  font: 600 15px/1 var(--sans);
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
#about-open { right: var(--pad); bottom: calc(18px + var(--safe-b)); }
body.carded #about-open { opacity: 0; pointer-events: none; }
.essay {
  position: fixed;
  z-index: 4;
  top: 10px;
  right: 10px;
  bottom: 10px;
  width: calc(100vw - 20px);
  padding: 18px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(13, 17, 23, 0.92);
  transform: translateX(calc(100% + 40px));
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
  user-select: text;
  -webkit-user-select: text;
}
.essay.open { transform: none; }
.essay .close { position: sticky; top: 0; float: right; }
.essay h2 { margin: 6px 0 6px; font-size: 22px; font-weight: 800; color: #f0f6fc; }
.essay h3 { margin: 20px 0 6px; font: 500 11px/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--orange); }
.essay p, .essay li { font-size: 13.5px; line-height: 1.62; color: #b7c0ca; }
.essay p { margin: 0 0 8px; }
.essay ul { margin: 0 0 10px; padding-left: 18px; }
.essay li { margin-bottom: 6px; }
.essay b { color: var(--link); font-family: var(--mono); font-weight: 500; }
.essay i { color: #8b949e; }

/* ---------- Desktop and landscape ---------- */
@media (min-width: 760px) and (min-height: 520px) {
  :root { --pad: 24px; }
  .hud-top { left: 26px; right: auto; width: 400px; top: 24px; }
  #lab-links { top: auto; left: 26px; right: auto; bottom: 18px; }
  .eyebrow { font-size: 11px; margin-bottom: 6px; }
  h1 span { display: block; font-size: 22px; }
  h1 strong { display: block; font-size: 46px; }
  .tile b { font-size: 20px; }
  .card { left: 50%; right: auto; bottom: auto; top: 50%; width: 400px; transform: translate(-50%, -50%); }
  .essay { top: 22px; right: 22px; bottom: 22px; width: 460px; padding: 22px 26px; }
  #about-open { right: 24px; bottom: 24px; }
  .go:hover { background: #fff; }
  .round:hover { background: #e6edf3; color: #0d1117; }
  .grade { font-size: 40px; }
}
