:root {
  --ink: #493d3a;
  --cream: #fff5df;
  --coral: #db6b52;
  --glass: rgba(255, 247, 225, .72);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #e9a27d;
  color: var(--ink);
  font-family: Inter, ui-rounded, "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button { font: inherit; }

#game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 360px;
  overflow: hidden;
  isolation: isolate;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#sky {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.brand {
  position: absolute;
  z-index: 4;
  top: max(24px, env(safe-area-inset-top));
  left: max(28px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
  text-shadow: 0 1px 12px rgba(255,255,255,.2);
}

.brand-mark {
  width: 30px;
  height: 23px;
  display: block;
  clip-path: polygon(0 42%, 100% 0, 63% 100%, 45% 58%);
  background: var(--cream);
  filter: drop-shadow(0 4px 7px rgba(83,54,45,.12));
  transform: rotate(-7deg);
}

.brand h1 {
  margin: 0;
  color: var(--cream);
  font-size: clamp(17px, 1.7vw, 23px);
  line-height: .9;
  letter-spacing: .19em;
  font-weight: 800;
}

.brand p {
  margin: 6px 0 0;
  color: rgba(255,245,223,.76);
  font-size: 9px;
  letter-spacing: .23em;
  text-transform: uppercase;
}

.dash-toggle {
  position: absolute;
  z-index: 6;
  top: max(22px, env(safe-area-inset-top));
  right: max(28px, env(safe-area-inset-right));
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 13px;
  color: var(--cream);
  background: transparent;
  cursor: pointer;
  transition: transform .2s ease, opacity .18s ease, visibility 0s linear 0s;
}

.dash-toggle:active { transform: scale(.94); }
.dash-toggle:focus-visible { outline: 2px solid var(--cream); outline-offset: 3px; }
.dash-toggle[aria-expanded="true"] {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(.82);
  transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
}

.dash-icon {
  width: 16px;
  height: 14px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 3px;
}

.dash-icon i {
  display: block;
  width: 2px;
  border-radius: 2px;
  background: currentColor;
}

.dash-icon i:nth-child(1) { height: 7px; }
.dash-icon i:nth-child(2) { height: 13px; }
.dash-icon i:nth-child(3) { height: 9px; }

.hud {
  position: absolute;
  z-index: 5;
  top: max(22px, env(safe-area-inset-top));
  right: max(28px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: clamp(15px, 2.4vw, 34px);
  padding: 12px 17px 11px;
  border: 1px solid rgba(255,250,235,.36);
  border-radius: 18px;
  background: rgba(92, 69, 62, .10);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 9px 30px rgba(70,45,36,.06);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateX(10px) scale(.98);
  transform-origin: right center;
  transition: opacity .2s ease, transform .25s cubic-bezier(.2,.8,.2,1), visibility 0s linear .25s;
}

.hud[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  cursor: pointer;
  transform: translateX(0) scale(1);
  transition-delay: 0s;
}

.hud:focus-visible { outline: 2px solid var(--cream); outline-offset: 3px; }

.instrument {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.instrument .label {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .2em;
  color: rgba(255,245,223,.63);
}

.instrument strong {
  color: var(--cream);
  font-size: 24px;
  line-height: 1;
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
}

.instrument.compact strong { font-size: 16px; }
.instrument small { margin-left: 3px; font-size: 7px; letter-spacing: .09em; opacity: .65; }
.rule { width: 1px; height: 31px; background: rgba(255,250,235,.26); }

.reticle {
  --tilt: 0deg;
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 43%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%) rotate(var(--tilt));
  border: 1px solid var(--cream);
  border-radius: 50%;
  opacity: .48;
  pointer-events: none;
}

.toast {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 24%;
  transform: translate(-50%, 12px);
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,245,223,.88);
  color: #705348;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .15em;
  opacity: 0;
  transition: opacity .25s ease, transform .35s cubic-bezier(.2,.8,.2,1);
  pointer-events: none;
}

.toast span { margin-right: 6px; color: var(--coral); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.footer {
  position: absolute;
  z-index: 5;
  left: max(28px, env(safe-area-inset-left));
  right: max(28px, env(safe-area-inset-right));
  bottom: max(23px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.compass-ribbon {
  position: relative;
  display: flex;
  align-items: center;
  height: 29px;
  overflow: hidden;
  color: rgba(255,245,223,.78);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .14em;
  border: 1px solid rgba(255,250,235,.3);
  border-radius: 9px;
  background: rgba(92,69,62,.11);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.compass-ribbon::after {
  content: "";
  position: absolute;
  left: calc(50% + 18.5px);
  top: 0;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--cream);
  opacity: .85;
}

.compass-speed {
  align-self: stretch;
  display: grid;
  place-items: center;
  min-width: 45px;
  padding-left: 2px;
  color: rgba(255,245,223,.64);
  border-right: 1px solid rgba(255,250,235,.22);
  font-variant-numeric: tabular-nums;
}

.compass-window {
  position: relative;
  width: 126px;
  align-self: stretch;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
}

.compass-tape {
  position: absolute;
  left: 50%;
  inset-block: 0;
  display: flex;
  align-items: center;
  will-change: transform;
}

.compass-mark {
  position: relative;
  flex: 0 0 32px;
  align-self: stretch;
  display: grid;
  place-items: center;
  padding-top: 5px;
  text-align: center;
  color: rgba(255,245,223,.58);
  font-size: 7px;
  letter-spacing: .08em;
}

.compass-mark::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 50%;
  width: 1px;
  height: 4px;
  background: rgba(255,245,223,.38);
}

.compass-mark.major { color: var(--cream); font-size: 8px; }
.compass-mark.major::before { height: 6px; background: rgba(255,245,223,.7); }

.wingman {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 0;
  color: rgba(255,245,223,.72);
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  transition: color .2s ease, transform .2s ease;
}

.wingman:hover,
.wingman[aria-pressed="true"] { color: var(--cream); }
.wingman:active { transform: scale(.95); }
.wingman:focus-visible { outline: 2px solid var(--cream); outline-offset: 3px; border-radius: 9px; }
.wingman-label { font-size: 8px; font-weight: 700; letter-spacing: .16em; }
.formation-icon {
  position: relative;
  width: 25px;
  height: 15px;
  display: block;
}
.formation-icon i {
  position: absolute;
  display: block;
  width: 13px;
  height: 10px;
  clip-path: polygon(0 40%, 100% 0, 64% 100%, 45% 59%);
  background: currentColor;
  filter: drop-shadow(0 2px 3px rgba(70,45,36,.12));
  transition: transform .32s cubic-bezier(.2,.8,.2,1), opacity .2s ease;
}
.formation-icon i:first-child { left: 0; bottom: 0; }
.formation-icon i:last-child { right: 0; top: 0; opacity: .42; transform: translate(-3px, 3px) scale(.72); }
.wingman[aria-pressed="true"] .formation-icon i:last-child { opacity: 1; transform: translate(0, 0) scale(.82); color: #89ee91; }

.touch-joystick {
  --knob-x: 0px;
  --knob-y: 0px;
  position: absolute;
  z-index: 7;
  left: 0;
  top: 0;
  width: 112px;
  height: 112px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(.82);
  transition: opacity .12s ease, transform .16s cubic-bezier(.2,.8,.2,1), visibility 0s linear .16s;
  will-change: left, top, transform;
}

.touch-joystick[data-active="true"] {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
  transition-delay: 0s;
}

.joystick-base {
  position: absolute;
  inset: 0;
  display: block;
  border: 1px solid rgba(255,250,235,.58);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(255,245,223,.06) 0 36%, transparent 37%),
    rgba(92,69,62,.12);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 8px 24px rgba(70,45,36,.12);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.joystick-base::before,
.joystick-base::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: rgba(255,245,223,.2);
  transform: translate(-50%, -50%);
}

.joystick-base::before { width: 1px; height: 72%; }
.joystick-base::after { width: 72%; height: 1px; }

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  display: block;
  border: 1px solid rgba(255,255,255,.66);
  border-radius: 50%;
  background: rgba(255,245,223,.78);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.72), 0 5px 15px rgba(70,45,36,.16);
  transform: translate(calc(-50% + var(--knob-x)), calc(-50% + var(--knob-y)));
  will-change: transform;
}

@media (max-width: 620px) {
  .brand { top: 18px; left: 18px; }
  .brand p { display: none; }
  .brand-mark { width: 23px; height: 18px; }
  .dash-toggle { top: 17px; right: 16px; }
  .hud { top: 17px; right: 16px; padding: 10px 12px; gap: 13px; }
  .instrument strong { font-size: 19px; }
  .instrument.compact strong { font-size: 13px; }
  .footer { left: 18px; right: auto; bottom: max(20px, env(safe-area-inset-bottom)); }
  .footer { right: 16px; }
  .wingman-label { display: none; }
  .wingman { padding-right: 0; }
  .reticle { top: 45%; }
}

@media (prefers-reduced-motion: reduce) {
  .toast, .hud, .dash-toggle, .touch-joystick { transition: none; }
}
