* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d1238;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game-canvas {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

.hidden {
  display: none !important;
}

/* The HUD covers exactly the game picture (js/game.js sizes it), so everything in it lines up
   with the game on any screen shape */
#hud {
  position: fixed;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
}

/* ── Info bar ── */
/* Top left on desktop; phones move it (see the small-screen and upright rules below) */
#info-display {
  position: absolute;
  top: 16px;
  left: 16px;
  max-width: 32%;
  padding: 7px 10px;
  background: #ffffffe0;
  border: 4px solid #000000;
  box-shadow: -8px 8px 0px 0px #00000040;
  color: #000;
  pointer-events: none;
  z-index: 10;
  opacity: 1;
  transition: opacity 0.4s;
}

#info-display.fade {
  opacity: 0;
}

#info-display.alert {
  background: #fff6c9e8;
}

.fun-fact-label {
  font-family: "Sometype Mono", monospace;
  font-weight: bold;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
  color: #111;
}

#fun-fact {
  font-family: "Sometype Mono", monospace;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 17px;
  letter-spacing: -0.03em;
}

/* ── Score + meters ── */
#score-display {
  position: absolute;
  top: 24px;
  right: 16px;
  font-family: "Jersey 10", sans-serif;
  font-size: clamp(48px, 9vw, 100px);
  line-height: 0.8;
  color: #ffffff;
  text-shadow: 2px 4px 0px #000000;
  z-index: 10;
}

#meters {
  position: absolute;
  right: 16px;
  top: calc(36px + clamp(40px, 7.5vw, 82px));
  width: 210px;
  padding: 8px 10px;
  background: #ffffff;
  border: 4px solid #000;
  box-shadow: -8px 8px 0 #00000040;
  font-family: "Sometype Mono", monospace;
  font-size: 12px;
  font-weight: 700;
  z-index: 10;
  pointer-events: none;
}

.meter {
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
}

.m-bar {
  height: 12px;
  border: 2px solid #000;
  background: #e8e8e8;
}

.m-fill {
  height: 100%;
  width: 0;
}

.m-fill.warm { background: #ff5a3c; }
.m-fill.fuel { background: #ffc933; }
.m-fill.comfort { background: #3cc46b; }

.meter.danger .m-bar {
  animation: blink 0.5s steps(2) infinite;
}

@keyframes blink {
  50% { border-color: #ff2a2a; background: #ffd0d0; }
}

#fl-display {
  margin-top: 6px;
  font-family: "Jersey 10", sans-serif;
  font-size: 22px;
  font-weight: 400;
  line-height: 1;
}

#fl-display.warn {
  color: #e0202a;
  animation: blink 0.5s steps(2) infinite;
}

#tailwind-display {
  margin-top: 4px;
  font-family: "Jersey 10", sans-serif;
  font-size: 18px;
  color: #0e9f63;
  animation: blink 0.6s steps(2) infinite;
}

#headwind-display {
  margin-top: 4px;
  font-family: "Jersey 10", sans-serif;
  font-size: 18px;
  color: #e0202a;
  animation: blink 0.6s steps(2) infinite;
}

/* ── Bonus pop-ups ── */
#bonus-layer {
  position: absolute;
  right: 16px;
  top: 340px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  z-index: 15;
  pointer-events: none;
}

.bonus-pop {
  padding: 2px 12px;
  font-family: "Jersey 10", sans-serif;
  font-size: 40px;
  white-space: nowrap;
  color: #fff;
  border: 4px solid #000;
  box-shadow: -6px 6px 0 #00000060;
  animation: pop-in 0.25s ease-out;
}
.bonus-pop.pulse { animation: pop-pulse 0.25s ease-out; }
.bonus-pop.out { animation: pop-out 0.4s ease-in forwards; }

.bonus-pop.time { background: #18b26b; }
.bonus-pop.data { background: #2f8fd6; }
.bonus-pop.penalty { background: #e0202a; }
.bonus-pop.penalty.night { background: #4b1fa8; color: #ffe066; font-size: 50px; }

#score-display.hit {
  animation: hit 0.35s ease-out;
}

@keyframes hit {
  40% { transform: translateX(-6px); color: #ff8a8a; }
  70% { transform: translateX(4px); }
}

@keyframes pop-in {
  0% { transform: translateY(16px) scale(0.6); opacity: 0; }
  70% { transform: scale(1.12); opacity: 1; }
}
@keyframes pop-pulse {
  40% { transform: scale(1.12); }
}
@keyframes pop-out {
  100% { transform: translateY(-40px); opacity: 0; }
}

#score-display.bump {
  animation: bump 0.35s ease-out;
}

@keyframes bump {
  40% { transform: scale(1.25); color: #9dffc9; }
}

/* ── Progress bar ── */
#progress {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(56%, 520px);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Jersey 10", sans-serif;
  font-size: 22px;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
  z-index: 10;
  pointer-events: none;
}

#progress-track {
  position: relative;
  flex: 1;
  height: 10px;
  border: 3px solid #000;
  background: #fff;
}

#progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: #7fd6ff;
}

#progress-plane {
  position: absolute;
  top: -16px;
  left: 0;
  transform: translateX(-50%);
  font-size: 20px;
}

/* ── Countdown ── */
#countdown-display {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: "Jersey 10", sans-serif;
  font-size: 120px;
  color: white;
  text-shadow: 4px 4px 0px #000000;
  z-index: 20;
  pointer-events: none;
  opacity: 0;
}

/* Takeoff tips: one at a time, big and centred above the runway, styled like the info bar */
#briefing {
  position: fixed;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 32px));
  padding: 16px 24px 18px;
  background: #ffffffe8;
  border: 4px solid #000000;
  box-shadow: -8px 8px 0px 0px #00000040;
  color: #000;
  text-align: center;
  pointer-events: none;
  z-index: 15;
  transition: opacity 0.45s;
}
#briefing.hidden { display: block; opacity: 0; }
.briefing-title {
  font-family: "Jersey 10", sans-serif;
  font-size: clamp(34px, 6vw, 68px);
  line-height: 0.95;
  margin: 4px 0 6px;
}
.briefing-sub {
  font-family: "Sometype Mono", monospace;
  font-size: clamp(14px, 1.8vw, 20px);
  line-height: 1.3;
}

/* ── Screens ── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  text-align: center;
  z-index: 30;
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

/* centre when it fits, scroll from the top when it doesn't (instead of clipping the top) */
/* (spacers rather than :first/:last-child margins, which break when the last child is hidden) */
.screen::before { content: ""; margin-top: auto; }
.screen::after { content: ""; margin-bottom: auto; }
.screen { justify-content: flex-start; }

#start-screen {
  background: linear-gradient(180deg, rgba(13, 18, 56, 0.1), rgba(13, 18, 56, 0.55));
}

.logo {
  margin: 0;
  font-family: "Jersey 10", sans-serif;
  font-weight: 400;
  font-size: clamp(48px, 8.5vw, 104px);
  line-height: 0.82;
  letter-spacing: 0.02em;
  color: #ffffff;
  text-shadow: 0 6px 0 #42425f;
}

.logo span {
  color: #ffcc33;
}

.tap-hint {
  margin: 0;
  max-width: min(720px, 90vw);
  font-family: "Jersey 10", sans-serif;
  font-size: clamp(20px, 3vw, 34px);
  line-height: 1.1;
  letter-spacing: 0.02em;
  color: #ffffff;
  text-shadow: 0px 4px 0px #42425f;
}

.legend {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: 820px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: "Sometype Mono", monospace;
  font-size: 13px;
  font-weight: 500;
}

.legend li {
  padding: 4px 8px;
  background: #fff;
  border: 3px solid #000;
  box-shadow: -4px 4px 0 #00000040;
}

.legend b {
  margin-right: 4px;
  padding: 0 4px;
  border: 2px solid #000;
}

.k-issr { background: #bfe9ff; }
.k-weather { background: #ffb02e; }
.k-traffic { background: #2a2230; color: #fff; }

.controls-hint {
  margin: 0;
  font-family: "Sometype Mono", monospace;
  font-weight: 700;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
}

.rotate-hint {
  display: none;
  margin: 0;
  font-family: "Sometype Mono", monospace;
  color: #ffcc33;
  text-shadow: 2px 2px 0 #000;
}

@media (orientation: portrait) and (max-width: 700px) {
  .rotate-hint { display: block; }
}

/* ── Pilot name + leaderboard ── */
.name-row-end {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}


.name-row-end input {
  width: 190px;
  padding: 6px 10px;
  font-family: "Sometype Mono", monospace;
  font-size: 16px;
  font-weight: 700;
  border: 4px solid #000;
  box-shadow: -4px 4px 0 #00000040;
  user-select: text;
  -webkit-user-select: text;
}

.name-note {
  min-height: 1em;
  margin: 0;
  font-family: "Sometype Mono", monospace;
  font-size: 13px;
  font-weight: 700;
  color: #ffe066;
  text-shadow: 1px 1px 0 #000;
}

.name-label {
  display: block;
  margin: 8px 0 4px;
  font-family: "Jersey 10", sans-serif;
  font-size: 22px;
}

.name-row-end {
  justify-content: flex-start;
}

.end-panel .name-note {
  color: #1b6b3a;
  text-shadow: none;
}


.daily-hint {
  margin: 0;
  text-align: center;
  line-height: 1.5;
  font-family: "Sometype Mono", monospace;
  font-size: 13px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}

.btn-small {
  padding: 2px 14px;
  font-size: 24px;
  box-shadow: -4px 4px 0 #00000060;
}


.end-grid {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  text-align: left;
}

.end-grid > div {
  flex: 1 1 230px;
  min-width: 0;
}

.section-label {
  font-family: "Jersey 10", sans-serif;
  font-size: 24px;
  border-bottom: 3px solid #000;
  margin-bottom: 4px;
}

.tally table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Sometype Mono", monospace;
  font-size: 13px;
}

.tally td {
  padding: 1px 0;
  animation: row-in 0.25s ease-out;
}

.tally td:last-child {
  text-align: right;
  font-weight: 700;
  color: #0e7f4f;
}

.tally tr.minus td:last-child {
  color: #d01820;
}

.tally tr.zero td:last-child {
  color: #999;
}

@keyframes row-in {
  from { opacity: 0; transform: translateX(-8px); }
}

.total-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-top: 3px solid #000;
  margin-top: 4px;
}

.board {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  font-family: "Sometype Mono", monospace;
  font-size: 14px;
}

.board li {
  display: flex;
  gap: 8px;
  padding: 2px 4px;
}

.board li.me {
  background: #ffe066;
  font-weight: 700;
}

.board li.muted {
  color: #777;
}

.board .rank {
  width: 1.6em;
  font-weight: 700;
}

.board .who {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board .pts {
  font-weight: 700;
}



/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 4px 34px;
  font-family: "Jersey 10", sans-serif;
  font-size: clamp(28px, 4vw, 42px);
  color: #000;
  text-decoration: none;
  background: #ffcc33;
  border: 4px solid #000;
  box-shadow: -6px 6px 0 #00000060;
  cursor: pointer;
}

.btn:hover { filter: brightness(1.06); }

.btn:active {
  transform: translate(-3px, 3px);
  box-shadow: -3px 3px 0 #00000060;
}

.btn-copy { background: #7fd6ff; }
.btn-learn { background: #ff9fc0; }

.button-div {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
}

/* ── End screen ── */
#end-screen {
  background: rgba(13, 18, 56, 0.55);
}

.end-panel {
  max-width: min(560px, 92vw);
  padding: 14px 22px;
  background: #ffffff;
  border: 4px solid #000;
  box-shadow: -8px 8px 0 #00000040;
}

#end-screen.win .end-panel { background: #fffbe6; }
.win-only { display: none; }
#end-screen.win .win-only { display: block; }

.emoji-row { font-size: 20px; }

.credit {
  margin: 8px 0 0;
  font-family: "Sometype Mono", monospace;
  font-size: 11px;
  color: #666;
}
.credit a { color: inherit; }
.credit + .credit { margin-top: 2px; }

.end-title {
  font-family: "Jersey 10", sans-serif;
  font-size: clamp(36px, 6vw, 64px);
  line-height: 0.9;
}

.end-fact {
  margin: 12px 0 8px;
  font-family: "Sometype Mono", monospace;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
}

.end-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  font-family: "Sometype Mono", monospace;
  font-size: 13px;
}

.score-label {
  font-family: "Jersey 10", sans-serif;
  font-size: 26px;
}

.best-value {
  font-family: "Jersey 10", sans-serif;
  font-size: 80px;
  line-height: 0.8;
}

.best-label {
  font-family: "Sometype Mono", monospace;
  font-size: 13px;
  margin-top: 6px;
}

#btn-mute {
  position: fixed;
  left: 16px;
  bottom: 14px;
  z-index: 40;
  width: 40px;
  height: 40px;
  font-size: 18px;
  background: #fff;
  border: 3px solid #000;
  box-shadow: -4px 4px 0 #00000040;
  cursor: pointer;
}

#btn-pause {
  position: fixed;
  left: 64px;
  bottom: 14px;
  z-index: 40;
  width: 40px;
  height: 40px;
  font-size: 18px;
  background: #fff;
  border: 3px solid #000;
  box-shadow: -4px 4px 0 #00000040;
  cursor: pointer;
}

#pause-screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0d123899;
  color: #fff;
  font-family: "Sometype Mono", monospace;
  text-align: center;
  z-index: 35;
}
#pause-screen.active { display: flex; }
.pause-title {
  font-family: "Jersey 10", sans-serif;
  font-size: clamp(64px, 12vw, 140px);
  line-height: 1;
  text-shadow: 4px 4px 0 #000;
}

/* small corner button on the start screen */
.btn-toggle {
  position: fixed;
  left: 16px;
  top: 14px;
  font-family: "Sometype Mono", monospace;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  background: #fff;
  border: 3px solid #000;
  box-shadow: -3px 3px 0 #00000060;
  cursor: pointer;
}
.btn-toggle[aria-pressed="true"] { background: #9be7b4; }

/* Reduce motion: no blinking, flashing or bouncing */
body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  animation: none !important;
  transition: none !important;
}

/* ── Phone held upright: the game is a strip across the middle, so the facts go in the
   space above it and the meters in the space below ── */
body.tall #info-display { top: auto; bottom: calc(100% + 8px); left: 8px; right: 8px; max-width: none; }
body.tall #meters { top: calc(100% + 12px); bottom: auto; left: auto; right: 8px; }
body.tall #bonus-layer { top: 35%; }

/* ── Small screens ── */
@media (max-width: 800px), (max-height: 500px) {
  /* facts: one long strip across the top, over the stall zone, where the plane can't fly */
  #info-display { top: 4px; bottom: auto; left: 8px; right: 84px; max-width: none; padding: 3px 8px; border-width: 2px; box-shadow: none; line-height: 1.25; }
  .fun-fact-label { display: inline; font-size: 0.68rem; margin: 0 6px 0 0; }
  #fun-fact { display: inline; font-size: 0.68rem; line-height: 1.25; }
  #score-display { top: 8px; right: 8px; font-size: 36px; }
  /* meters: bottom right, out of the way of the cruise band */
  #meters { right: 8px; top: auto; bottom: 28px; width: 160px; padding: 5px 7px; border-width: 3px; font-size: 10px; box-shadow: -5px 5px 0 #00000040; }
  .meter { grid-template-columns: 76px 1fr; margin: 1px 0; }
  .m-bar { height: 9px; }
  #fl-display { font-size: 16px; margin-top: 2px; }
  #progress { bottom: 6px; font-size: 16px; }
  #countdown-display { font-size: 80px; }
  #briefing { padding: 8px 14px 10px; border-width: 3px; }
  .screen { gap: 10px; }
  .legend { font-size: 10px; gap: 5px 6px; }
  .end-panel { padding: 10px 14px; }
  .end-fact { font-size: 12px; margin: 6px 0; }
  .best-value { font-size: 52px; }
  .bonus-pop { font-size: 26px; }
  .bonus-pop.penalty.night { font-size: 32px; }
  #bonus-layer { top: calc(var(--stall-y, 50px) + 14px); right: 8px; }
  .end-grid { gap: 10px; }
  .tally table, .board { font-size: 11px; }
  .name-row-end input { width: 150px; font-size: 14px; padding: 4px 8px; }
  .btn { font-size: 24px; padding: 2px 20px; }
}
