:root {
  --cream: #fff7e7;
  --paper: rgba(255, 248, 231, 0.93);
  --sky: #b9dfe7;
  --green: #7e984d;
  --green-dark: #5f7838;
  --ochre: #e4aa39;
  --orange: #d9783e;
  --brown: #4e3524;
  --soft-brown: #73523b;
  --shadow: 0 20px 55px rgba(81, 59, 36, 0.2);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  color: var(--brown);
  background: #d8ebe5;
  font-family: "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
}
button, a { font: inherit; }
button:focus-visible, a:focus-visible { outline: 4px solid #fff; outline-offset: 4px; }

.flight-shell, #gameCanvas { position: fixed; inset: 0; width: 100%; height: 100%; }
#gameCanvas { display: block; touch-action: none; }
.flight-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.18;
  mix-blend-mode: multiply;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(102, 72, 45, .22) 0 .5px, transparent .8px),
    radial-gradient(circle at 80% 68%, rgba(255, 255, 255, .75) 0 .7px, transparent 1px);
  background-size: 9px 11px, 13px 15px;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  color: var(--soft-brown);
  background: linear-gradient(#cbe7eb, #f7e8c6);
  transition: opacity .3s ease, visibility .3s ease;
}
.loading-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-screen p { margin: 0; font-weight: 800; }
.loading-plane {
  width: 140px;
  height: 78px;
  background: url("/public/assets/endless-flight/plane-heroes.png") center / contain no-repeat;
  animation: float 1.4s ease-in-out infinite;
}
.loading-track { width: min(250px, 70vw); height: 8px; overflow: hidden; border-radius: 999px; background: rgba(94, 82, 55, .14); }
.loading-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--orange); transition: width .18s ease; }

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .35s ease, visibility .35s ease;
}
.screen.visible { opacity: 1; visibility: visible; pointer-events: auto; }
.menu-screen {
  display: grid;
  grid-template-columns: minmax(310px, .82fr) minmax(420px, 1.18fr);
  align-items: center;
  gap: 2vw;
  padding: clamp(24px, 6vw, 96px);
  background: linear-gradient(90deg, rgba(255, 249, 231, .88) 0 35%, rgba(255, 249, 231, .26) 64%, transparent);
}
.menu-copy { z-index: 1; max-width: 530px; text-align: center; }
.eyebrow { margin: 0 0 9px; color: var(--green-dark); font-size: 13px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
h1, h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; color: var(--brown); }
h1 { font-size: clamp(48px, 6vw, 91px); line-height: .91; letter-spacing: -.045em; text-wrap: balance; }
h2 { font-size: clamp(38px, 6vw, 62px); line-height: 1; }
.lead { max-width: 420px; margin: 24px auto 18px; font-size: clamp(17px, 1.65vw, 22px); line-height: 1.5; }
.best-result { display: inline-block; margin-bottom: 23px; padding: 8px 16px; border: 1px solid rgba(101, 74, 45, .18); border-radius: 18px 22px 17px 20px; background: rgba(255, 248, 232, .65); }
.menu-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 13px; }
.menu-plane {
  width: min(52vw, 760px);
  max-height: 62vh;
  object-fit: contain;
  justify-self: center;
  filter: drop-shadow(0 25px 25px rgba(77, 58, 38, .16));
  animation: float 4s ease-in-out infinite;
}

.paint-button {
  min-width: 138px;
  min-height: 54px;
  display: inline-grid;
  place-items: center;
  padding: 10px 24px;
  border: 2px solid rgba(78, 53, 36, .32);
  border-radius: 23px 28px 22px 27px;
  color: #fffdf4;
  box-shadow: inset 0 1px rgba(255,255,255,.45), 0 6px 0 rgba(82, 61, 38, .22), 0 13px 28px rgba(76, 55, 33, .15);
  font-weight: 900;
  text-decoration: none;
  text-shadow: 0 1px rgba(61, 43, 26, .28);
  cursor: pointer;
  transition: transform .16s ease, filter .16s ease;
}
.paint-button:hover { transform: translateY(-2px) rotate(-.4deg); filter: saturate(1.07); }
.paint-button:active { transform: translateY(3px); box-shadow: inset 0 1px rgba(255,255,255,.4), 0 2px 0 rgba(82,61,38,.22); }
.paint-button.primary { background: linear-gradient(145deg, #93a95a, #6f8c3d); }
.paint-button.secondary { color: var(--brown); background: linear-gradient(145deg, #fff4d8, #ead6ae); text-shadow: none; }
.round-button {
  width: 52px;
  min-width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(78, 53, 36, .42);
  border-radius: 47% 53% 49% 51%;
  color: var(--brown);
  background: linear-gradient(145deg, #fff8e7, #e8d7b6);
  box-shadow: 0 5px 0 rgba(82, 61, 38, .22), 0 10px 24px rgba(76, 55, 33, .16);
  cursor: pointer;
}
.sound-icon { position: relative; width: 22px; height: 18px; border-radius: 3px 0 0 3px; background: var(--brown); clip-path: polygon(0 35%, 32% 35%, 72% 0, 72% 100%, 32% 65%, 0 65%); }
.sound-icon::after { content: ""; position: absolute; left: 13px; top: 3px; width: 8px; height: 12px; border: 2px solid var(--brown); border-left: 0; border-radius: 0 60% 60% 0; }
.muted .sound-icon::after { width: 16px; height: 2px; left: 11px; top: 8px; border: 0; border-radius: 2px; background: var(--orange); transform: rotate(-45deg); }
.pause-icon { width: 19px; height: 23px; border-left: 6px solid var(--brown); border-right: 6px solid var(--brown); }

.hud {
  position: fixed;
  z-index: 8;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 12px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: .25s ease;
}
.hud.visible { opacity: 1; visibility: visible; pointer-events: auto; }
.score-card, .distance-card {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px;
  border: 1px solid rgba(99, 72, 45, .25);
  border-radius: 17px 20px 16px 19px;
  background: var(--paper);
  box-shadow: 0 7px 22px rgba(69, 55, 38, .14);
  font-size: 20px;
}
.distance-card { margin-left: auto; }
.pause-button { pointer-events: auto; }
.star-icon { width: 27px; height: 27px; display: block; background: url("/public/assets/endless-flight/collectible-star.png") center / contain no-repeat; }
.score-card.pulse { animation: scorePulse .28s ease-out; }

.control-hint {
  position: fixed;
  z-index: 7;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  display: grid;
  gap: 2px;
  min-width: min(420px, calc(100vw - 32px));
  padding: 12px 20px;
  border-radius: 22px 18px 23px 19px;
  background: var(--paper);
  box-shadow: var(--shadow);
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 18px);
  transition: .45s ease;
  pointer-events: none;
}
.control-hint.visible { opacity: 1; transform: translate(-50%, 0); }
.touch-hint { display: none; }

.modal-screen {
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(255, 247, 226, .47);
  backdrop-filter: blur(6px) sepia(.06);
}
.paper-card {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: clamp(28px, 6vw, 52px);
  border: 2px solid rgba(102, 73, 44, .2);
  border-radius: 43px 37px 46px 39px;
  background: var(--paper);
  box-shadow: var(--shadow), inset 0 0 38px rgba(215, 161, 73, .08);
}
.paper-card .paint-button { width: min(265px, 100%); }
.paper-card .round-button { margin-top: 5px; }
.record-badge { margin: -8px 0 0; padding: 6px 13px; border-radius: 14px; color: #fffaf0; background: var(--orange); font-weight: 900; transform: rotate(-2deg); }
.results-card dl { width: 100%; margin: 5px 0 10px; }
.results-card dl div { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 4px; border-bottom: 1px dashed rgba(105, 76, 47, .25); }
.results-card dt { color: var(--soft-brown); }
.results-card dd { margin: 0; font-size: 24px; }
.orientation-note { display: none; }

@keyframes float { 50% { transform: translateY(-9px) rotate(-.6deg); } }
@keyframes scorePulse { 50% { transform: scale(1.16) rotate(-1deg); } }

@media (pointer: coarse) {
  .desktop-hint { display: none; }
  .touch-hint { display: inline; }
}

@media (orientation: portrait) {
  .menu-screen {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(190px, 38vh);
    align-content: center;
    gap: 10px;
    padding: max(32px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
    background: linear-gradient(rgba(255,249,231,.78), rgba(255,249,231,.18));
  }
  .menu-copy { align-self: end; }
  h1 { font-size: clamp(43px, 13vw, 68px); }
  .lead { margin: 14px auto 11px; font-size: 16px; }
  .best-result { margin-bottom: 14px; }
  .menu-plane { grid-row: 2; width: min(82vw, 500px); max-height: 34vh; }
  .hud { gap: 7px; }
  .score-card, .distance-card { min-height: 46px; padding: 7px 11px; font-size: 17px; }
  .round-button { width: 48px; min-width: 48px; height: 48px; }
  .control-hint { bottom: max(17px, env(safe-area-inset-bottom)); font-size: 14px; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .menu-screen { padding: 18px 6vw; }
  h1 { font-size: clamp(43px, 7vw, 66px); }
  .lead { margin: 13px auto 10px; font-size: 16px; }
  .best-result { margin-bottom: 12px; }
  .paint-button { min-height: 48px; }
  .paper-card { padding: 20px 28px; gap: 9px; }
  .paper-card h2 { font-size: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
