/* =====================================================================
 * Sky Courier — HUD and menu styling.
 * ===================================================================== */

:root {
  --ink: #0e1a2c;
  --paper: #f7fbff;
  --gold: #ffc83d;
  --green: #5de08a;
  --red: #ff6b5e;
  --blue: #4db6ff;
  --panel: rgba(10, 24, 44, 0.78);
  --stroke: rgba(255, 255, 255, 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;                 /* iOS: the bit that is actually visible */
  overflow: hidden;
  overscroll-behavior: none;      /* no pull-to-refresh mid-barrel-roll */
  touch-action: none;             /* no pinch zoom, no double-tap zoom */
  background: #0b1a2e;
  color: var(--paper);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* menus are the one place a finger is allowed to scroll */
#screens, .card, .shop-list { touch-action: pan-y; }
button { touch-action: manipulation; }

.hidden { display: none !important; }

/* ============================== HUD ============================== */
#hud { position: absolute; inset: 0; pointer-events: none; }

.corner { position: absolute; display: flex; flex-direction: column; gap: 8px; padding: 14px; }
.top-left { top: env(safe-area-inset-top, 0); left: 0; }
.top-right { top: env(safe-area-inset-top, 0); right: 0; align-items: flex-end; }
.top-centre { top: env(safe-area-inset-top, 0); left: 50%; transform: translateX(-50%); align-items: center; }
.bottom-left { bottom: env(safe-area-inset-bottom, 0); left: 0; }

.chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 2px solid var(--stroke);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 16px;
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}
.chip .ico { font-size: 18px; }
.chip.money b { font-size: 22px; color: var(--gold); letter-spacing: 0.5px; }
.chip.gauges { gap: 14px; font-size: 15px; }
.chip.gauges b { color: var(--blue); }
.chip.cargo { background: rgba(255, 200, 61, 0.22); border-color: rgba(255, 200, 61, 0.6); font-size: 15px; }

.bar {
  width: 120px; height: 11px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 999px;
  overflow: hidden;
}
.bar .fill { height: 100%; width: 100%; border-radius: 999px; background: var(--green); transition: width 0.12s linear; }
.fill.gold { background: linear-gradient(90deg, #ffb03a, #ffe58a); }
.fill.green { background: linear-gradient(90deg, #35c96b, #9df5bd); }
.chip.fuel .fill { background: linear-gradient(90deg, #35c96b, #9df5bd); }
.chip.fuel .fill.low { background: linear-gradient(90deg, #ff5b4d, #ffb46b); }
.goal .bar { width: 96px; height: 8px; }
.tiny { font-size: 12px; opacity: 0.85; }

/* target compass */
.chip.target { padding: 6px 18px 6px 8px; gap: 12px; }
.arrow {
  font-size: 26px; line-height: 1;
  color: var(--gold);
  transform-origin: 50% 50%;
  transition: transform 0.08s linear;
  text-shadow: 0 0 10px rgba(255, 200, 61, 0.7);
}
.arrow.ontarget { color: var(--green); text-shadow: 0 0 14px rgba(93, 224, 138, 0.9); }
.target-text { display: flex; flex-direction: column; line-height: 1.15; }
.target-text b { font-size: 16px; }
.bar.timer { width: 210px; height: 6px; }
.note { font-size: 13px; opacity: 0.8; font-style: italic; }

#radar { border-radius: 50%; border: 2px solid var(--stroke); background: rgba(8, 18, 34, 0.5); }
.mood { padding-right: 4px; }

.warn {
  position: absolute; top: 28%; left: 50%; transform: translateX(-50%);
  font-size: 24px; font-weight: bold; color: #ffe06b;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
  animation: pulse 0.6s infinite alternate;
}
@keyframes pulse { from { opacity: 0.55; } to { opacity: 1; } }

.crash {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  font-size: 54px; font-weight: bold; text-shadow: 0 4px 16px rgba(0, 0, 0, 0.7);
}
.crash.show { display: flex; }
.crash span { font-size: 20px; font-weight: normal; opacity: 0.9; margin-top: 10px; }

#hint {
  position: absolute; bottom: calc(12px + env(safe-area-inset-bottom, 0)); left: 50%;
  transform: translateX(-50%);
  font-size: 13px; opacity: 0.72;
  background: rgba(8, 18, 34, 0.5);
  padding: 6px 14px; border-radius: 999px;
  white-space: nowrap;
}

#pauseBtn, #hangarBtn {
  position: absolute; top: calc(14px + env(safe-area-inset-top, 0));
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--panel); border: 2px solid var(--stroke);
  color: var(--paper); font-size: 20px; cursor: pointer;
  pointer-events: auto;
}
#pauseBtn { right: 168px; }
#hangarBtn { right: 218px; }
#pauseBtn:hover, #hangarBtn:hover { background: rgba(30, 60, 100, 0.85); }

/* toasts and floaters */
#toasts {
  position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: min(620px, 92vw);
}
.toast {
  background: var(--panel); border: 2px solid var(--stroke);
  border-radius: 14px; padding: 10px 16px; font-size: 15px; text-align: center;
  animation: rise 0.25s ease-out;
  transition: opacity 0.5s, transform 0.5s;
}
.toast.good { border-color: rgba(93, 224, 138, 0.7); }
.toast.bad { border-color: rgba(255, 107, 94, 0.8); }
.toast.out { opacity: 0; transform: translateY(-10px); }
.toast .bonus { color: var(--green); }
.toast .late { opacity: 0.7; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

#floaters { position: absolute; inset: 0; }
.floater {
  position: absolute; font-size: 26px; font-weight: bold;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  animation: float 1.4s ease-out forwards;
}
.floater.coin { color: var(--gold); }
.floater.pay { color: var(--green); font-size: 34px; }
.floater.fuel { color: #9df5bd; font-size: 20px; }
@keyframes float {
  from { opacity: 1; transform: translateY(0) scale(0.9); }
  to { opacity: 0; transform: translateY(-80px) scale(1.15); }
}

#flash {
  position: absolute; inset: 0; pointer-events: none;
  background: #fff; opacity: 0; transition: opacity 0.25s;
}

/* ============================ SCREENS ============================ */
#screens { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#screens.hidden { display: none; }
.screen { display: none; width: 100%; height: 100%; align-items: center; justify-content: center; padding: 16px; }
.screen.show { display: flex; }

.card {
  background: linear-gradient(180deg, rgba(14, 30, 54, 0.95), rgba(8, 20, 38, 0.96));
  border: 2px solid var(--stroke);
  border-radius: 22px;
  padding: 24px 26px;
  width: min(680px, 96vw);
  max-height: 92vh;
  max-height: 92dvh;              /* iOS counts toolbars out of dvh */
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.card.wide { width: min(760px, 96vw); }
.card.narrow { width: min(440px, 96vw); }

/* keyboard users must be able to see which answer they are about to give */
.btn:focus-visible, .tab:focus-visible, .buy:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.logo { font-size: clamp(40px, 8vw, 68px); margin: 0 0 4px; letter-spacing: 3px; color: var(--paper); }
.logo span { color: var(--gold); }
.tagline { opacity: 0.88; margin: 0 auto 16px; max-width: 54ch; line-height: 1.5; }

h2 { margin: 0 0 6px; font-size: 26px; }
.sub { opacity: 0.85; margin: 0 0 12px; }
.win { color: var(--gold); }

.howto { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 14px 0; }
.how {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--stroke);
  border-radius: 12px; padding: 8px 12px; min-width: 120px;
  display: flex; flex-direction: column; gap: 2px;
}
.how b { color: var(--gold); font-size: 15px; }
.how span { font-size: 13px; opacity: 0.85; }

.rules { text-align: left; max-width: 52ch; margin: 6px auto 16px; line-height: 1.65; opacity: 0.92; }
.gold-t { color: var(--gold); }
.green-t { color: var(--green); }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row.center { justify-content: center; }

.btn {
  background: linear-gradient(180deg, #2f86d8, #1e5fa8);
  border: 2px solid rgba(255, 255, 255, 0.28);
  color: #fff; font-family: inherit; font-size: 17px; font-weight: bold;
  padding: 11px 22px; border-radius: 14px; cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.08s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.huge { font-size: 22px; padding: 14px 34px; background: linear-gradient(180deg, #ffbb3a, #e8892a); color: #2a1a00; }
.btn.ghost { background: rgba(255, 255, 255, 0.1); }
.btn.danger { background: linear-gradient(180deg, #e2574a, #a8352b); }

.fineprint { font-size: 13px; opacity: 0.65; margin: 14px 0 0; }

.statsline { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font-size: 14px; opacity: 0.9; margin-bottom: 12px; }
.statsline b { color: var(--blue); }

.tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.tab {
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--stroke);
  color: var(--paper); font-family: inherit; font-size: 15px;
  padding: 8px 18px; border-radius: 999px; cursor: pointer;
}
.tab.active { background: var(--gold); color: #2a1a00; font-weight: bold; }
.tabpane { display: none; }
.tabpane.show { display: block; }

.shop-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.item {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
  border-radius: 14px; padding: 12px 14px;
}
.item.poor { opacity: 0.55; }
.item.maxed { border-color: rgba(93, 224, 138, 0.6); }
.item.flying { border-color: var(--gold); background: rgba(255, 200, 61, 0.12); }
.item .ico { font-size: 30px; width: 40px; text-align: center; }
.item .body { flex: 1; }
.item h4 { margin: 0 0 3px; font-size: 17px; }
.item .lvl { font-size: 13px; color: var(--gold); letter-spacing: 2px; }
.item p { margin: 0; font-size: 13px; opacity: 0.82; line-height: 1.35; }
.item .eff { color: var(--blue); opacity: 0.95; margin-top: 3px; }
.item .buy {
  background: linear-gradient(180deg, #35c96b, #1e9b4c);
  border: 2px solid rgba(255, 255, 255, 0.25); color: #fff;
  font-family: inherit; font-weight: bold; font-size: 15px;
  padding: 10px 14px; border-radius: 12px; cursor: pointer; min-width: 86px;
}
.item .buy:disabled { background: rgba(255, 255, 255, 0.12); cursor: default; color: rgba(255, 255, 255, 0.6); }

/* The hangar list is longer than a phone screen, so the way out rides
   along at the bottom of it instead of hiding under six upgrade cards. */
#closeHangar {
  position: sticky;
  bottom: -2px;
  display: block;
  width: 100%;
  margin-top: 4px;
  box-shadow: 0 -14px 22px rgba(8, 20, 38, 0.95);
}

.report { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 16px; }
.report .row {
  display: flex; justify-content: space-between;
  background: rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 8px 14px; font-size: 15px;
}
.report .row b { color: var(--gold); }

/* ========================= ROTATE PROMPT ========================= */
#rotate {
  position: absolute; inset: 0; z-index: 40;
  display: none; align-items: center; justify-content: center;
  background: rgba(6, 14, 28, 0.94);
  padding: 20px; text-align: center;
}
#rotate.show { display: flex; }
.rotate-card { max-width: 340px; }
.rotate-card .phone {
  font-size: 64px; display: block; margin-bottom: 10px;
  animation: tip 1.8s ease-in-out infinite;
}
.rotate-card h3 { margin: 0 0 6px; font-size: 22px; }
.rotate-card p { margin: 0 0 18px; opacity: 0.8; font-size: 15px; }
@keyframes tip {
  0%, 45% { transform: rotate(0deg); }
  60%, 90% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

/* =========================== TOUCH UI =========================== */
.touch-only { display: none; }
body.touch .keyhint { display: none; }   /* no keyboard, no key hints */
body.touch .touch-only { display: flex; }
body.touch #hint { display: none; }
body.touch #pauseBtn { right: 12px; top: calc(78px + env(safe-area-inset-top, 0)); }
body.touch #hangarBtn { right: 12px; top: calc(128px + env(safe-area-inset-top, 0)); }
body.touch .top-right { padding-right: 62px; }

#touchLeft { position: absolute; left: 0; top: 0; bottom: 0; width: 50%; pointer-events: auto; }
#touchStick {
  position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px;
  border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.35);
  background: rgba(10, 24, 44, 0.35);
  align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s; pointer-events: none;
}
#touchStick.show { opacity: 1; }
#touchKnob {
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 2px solid rgba(255, 255, 255, 0.8);
}
#touchBoost {
  position: absolute; right: 22px; bottom: calc(26px + env(safe-area-inset-bottom, 0));
  width: 96px; height: 96px; border-radius: 50%;
  background: rgba(255, 187, 58, 0.85); border: 3px solid rgba(255, 255, 255, 0.5);
  font-size: 38px; pointer-events: auto; cursor: pointer;
  align-items: center; justify-content: center;
}
#touchBoost:active { background: rgba(255, 140, 40, 0.95); }

@media (max-width: 640px) {
  .bar.timer { width: 150px; }
  #radar { width: 96px; height: 96px; }
  .chip { font-size: 14px; padding: 6px 11px; }
  .chip.money b { font-size: 18px; }
}

/* Landscape phones are short, not narrow — shrink the HUD by height. */
@media (max-height: 480px) {
  .corner { padding: 8px; gap: 5px; }
  .chip { font-size: 12px; padding: 4px 10px; gap: 6px; }
  .chip .ico { font-size: 14px; }
  .chip.money b { font-size: 16px; }
  .chip.gauges { gap: 9px; font-size: 12px; }
  .bar { width: 82px; height: 8px; }
  .goal .bar { width: 66px; height: 6px; }
  .bar.timer { width: 140px; height: 5px; }
  .tiny { font-size: 10px; }
  .target-text b { font-size: 13px; }
  .arrow { font-size: 19px; }
  .note { font-size: 11px; }
  #radar { width: 84px; height: 84px; }
  .warn { font-size: 18px; top: 22%; }
  .crash { font-size: 34px; }
  .crash span { font-size: 14px; }
  #toasts { bottom: 12px; width: min(460px, 70vw); gap: 5px; }
  .toast { font-size: 12px; padding: 7px 12px; }
  .floater { font-size: 18px; }
  .floater.pay { font-size: 24px; }
  body.touch #pauseBtn, body.touch #hangarBtn { width: 36px; height: 36px; font-size: 16px; }
  body.touch #pauseBtn { top: calc(8px + env(safe-area-inset-top, 0)); right: 8px; }
  body.touch #hangarBtn { top: calc(50px + env(safe-area-inset-top, 0)); right: 8px; }
  body.touch .top-right { padding-right: 52px; }
  #touchBoost { width: 70px; height: 70px; font-size: 28px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom, 0)); }
  #touchStick { width: 92px; height: 92px; margin: -46px 0 0 -46px; }
  #touchKnob { width: 42px; height: 42px; }
  /* A phone held sideways has ~340px of height for the whole title card,
     so everything that is not the point gets smaller or goes away — the
     Take Off button must never end up below the fold. */
  .card { padding: 12px 16px; border-radius: 16px; }
  .logo { font-size: 30px; letter-spacing: 2px; margin-bottom: 2px; }
  .tagline { font-size: 12px; line-height: 1.35; margin-bottom: 8px; }
  .howto { gap: 6px; margin: 8px 0; }
  body.touch .howto.keys { display: none; }
  .rules { font-size: 12px; line-height: 1.4; margin: 4px auto 10px; }
  .fineprint { display: none; }
  .how { min-width: 84px; padding: 4px 8px; }
  .how b { font-size: 12px; }
  .how span { font-size: 10px; }
  .btn { font-size: 15px; padding: 9px 16px; }
  .btn.huge { font-size: 18px; padding: 10px 24px; }
  h2 { font-size: 20px; }
  .sub { font-size: 13px; margin-bottom: 8px; }
  .statsline { font-size: 12px; margin-bottom: 8px; }
  .tab { font-size: 13px; padding: 6px 14px; }
  .item { padding: 9px 11px; gap: 10px; }
  .item .ico { font-size: 24px; width: 30px; }
  .item h4 { font-size: 15px; }
  .item p { font-size: 12px; }
  .item .buy { font-size: 14px; padding: 8px 12px; min-width: 74px; }
  /* two columns of stats instead of one tall stack, so the buttons under
     them stay on screen */
  .report { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 8px 0 10px; }
  .report .row { padding: 6px 10px; font-size: 12px; }
  #hangarScreen h2 { display: none; }      /* the tabs say where you are */
  #hangarScreen .sub { margin-bottom: 4px; }
  .rotate-card .phone { font-size: 46px; }
  .rotate-card h3 { font-size: 18px; }
}

/* Really short screens (a small phone held sideways) get the title card in
   two columns: reading matter on the left, the controls and the button on
   the right, so nothing important is ever below the fold. */
@media (max-height: 400px) {
  #titleScreen .card.wide {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    column-gap: 18px;
    align-items: center;
    text-align: left;
  }
  #titleScreen .logo { grid-column: 1 / -1; text-align: center; font-size: 26px; margin: 0; }
  #titleScreen .tagline { grid-column: 1; margin: 0 0 6px; }
  #titleScreen .rules { grid-column: 1; margin: 0; padding-left: 18px; }
  #titleScreen .howto { grid-column: 2; margin: 0 0 8px; justify-content: flex-start; }
  #titleScreen .row.center { grid-column: 2; justify-content: flex-start; }
  #titleScreen .how { min-width: 76px; }
}
