:root {
  --bg: rgba(14, 20, 28, 0.82); --line: rgba(255, 255, 255, 0.12); --text: #eef2f6; --muted: #a8b3bf;
  --accent: #f2a93b; --accent2: #3fa0ff; --bad: #ff5a4f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0f1720; color: var(--text); touch-action: none; -webkit-user-select: none; user-select: none; }
#view, #view canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: var(--text); background: rgba(255,255,255,0.08); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; cursor: pointer; }
button:hover { background: rgba(255,255,255,0.16); }
button.primary { background: var(--accent); color: #1b1305; border-color: transparent; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
a { color: #8cc6ff; }
.row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

#menu, #pause, #connect, #help { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
#menu.hidden, #pause:not(.show), #connect:not(.show), #help:not(.show) { display: none; }
#menu { background: linear-gradient(180deg, rgba(10,16,24,0.25), rgba(10,16,24,0.6)); }
#connect, #help { z-index: 30; background: rgba(5, 9, 14, 0.45); }
.menu-card { background: var(--bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 16px; padding: 22px 24px; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.4); }
h1 { margin: 0 0 4px; font-size: 28px; letter-spacing: 0.2px; }
h2 { margin: 0 0 12px; font-size: 21px; }
.sub { margin: 0 0 16px; color: var(--muted); }
.fine { font-size: 12px; color: var(--muted); margin: 16px 0 0; line-height: 1.45; }
#planes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.plane-card { text-align: left; display: flex; flex-direction: column; gap: 6px; padding: 14px; border-radius: 12px; }
.plane-card b { font-size: 17px; }
.plane-card span { font-size: 13px; color: var(--muted); line-height: 1.35; }
.plane-card em { font-style: normal; font-size: 12px; color: var(--accent); }
.plane-card.sel { border-color: var(--accent); background: rgba(242, 169, 59, 0.12); }
.ctrl-line { margin: 14px 0 0; font-size: 14px; color: var(--muted); }
.ctrl-line b { color: var(--text); }
label { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; font-size: 14px; color: var(--muted); }
label.chk { flex-direction: row; align-items: center; }
select, input[type=range] { width: 100%; }
select { font: inherit; padding: 8px; border-radius: 8px; background: #1b2531; color: var(--text); border: 1px solid var(--line); }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; display: none; }
#hud.show { display: block; }
.stats { position: absolute; left: max(12px, env(safe-area-inset-left)); top: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; min-width: 150px; font-size: 13px; }
.stats div { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.stats span { color: var(--muted); }
.stats .thr i { position: relative; width: 70px; height: 8px; background: rgba(255,255,255,0.12); border-radius: 4px; overflow: hidden; display: block; transform: rotate(0); }
.stats .thr i b { position: absolute; left: 0; bottom: 0; top: 0; width: 100%; background: var(--accent); transform-origin: left; }
.stats .extra { color: var(--accent); font-weight: 600; justify-content: flex-start; }
.stats .extra:empty { display: none; }
.stats .src { font-size: 12px; color: var(--muted); justify-content: flex-start; }
#h-stall { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); background: var(--bad); color: white; font-weight: 800; padding: 6px 14px; border-radius: 8px; letter-spacing: 1px; display: none; }
#h-stall.show { display: block; }
.buttons { position: absolute; right: max(12px, env(safe-area-inset-right)); top: 12px; display: flex; gap: 8px; pointer-events: auto; }
.buttons button { background: var(--bg); padding: 9px 12px; min-width: 44px; min-height: 40px; }

#crash { position: fixed; left: 50%; top: 28%; transform: translateX(-50%); background: var(--bg); border: 1px solid var(--bad); border-radius: 14px; padding: 14px 18px; display: none; gap: 12px; align-items: center; z-index: 15; }
#crash.show { display: flex; }
#crash b { color: var(--bad); font-size: 18px; }
#crash span { color: var(--muted); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--bg); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; opacity: 0; transition: opacity .25s; z-index: 25; pointer-events: none; }
#toast.show { opacity: 1; }

#touch { position: fixed; inset: 0; pointer-events: none; z-index: 12; display: none; }
#touch.show { display: block; }
.stick { position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); width: min(38vw, 190px); height: min(38vw, 190px); border-radius: 22px; background: rgba(10,16,24,0.28); border: 1px solid rgba(255,255,255,0.22); pointer-events: auto; touch-action: none; }
.stick.left { left: max(18px, env(safe-area-inset-left)); }
.stick.right { right: max(18px, env(safe-area-inset-right)); }
.stick::before, .stick::after { content: ""; position: absolute; background: rgba(255,255,255,0.18); }
.stick::before { left: 50%; top: 10%; bottom: 10%; width: 1px; }
.stick::after { top: 50%; left: 10%; right: 10%; height: 1px; }
.knob { position: absolute; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; background: rgba(242,169,59,0.85); box-shadow: 0 2px 10px rgba(0,0,0,0.4); }

#connect .step { margin: 0 0 4px; color: var(--accent); font-size: 13px; }
#connect .status { color: var(--accent2); min-height: 1.3em; }
#connect .hint { color: var(--muted); font-size: 13px; }
#cw-bars { display: grid; gap: 6px; margin-top: 8px; }
.bar { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.bar i { position: relative; height: 10px; background: rgba(255,255,255,0.1); border-radius: 5px; display: block; }
.bar i::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: rgba(255,255,255,0.3); }
.bar i b { position: absolute; top: -3px; width: 8px; height: 16px; margin-left: -4px; background: var(--accent); border-radius: 3px; }
#help p { line-height: 1.5; color: #d5dde5; }

@media (max-width: 600px) {
  #planes { grid-template-columns: 1fr; }
  h1 { font-size: 23px; }
  .stats { font-size: 12px; min-width: 128px; padding: 8px 10px; }
  .buttons { gap: 6px; flex-direction: column; }
  .buttons button { padding: 8px 9px; font-size: 13px; }
  .bar { grid-template-columns: 110px 1fr; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .stick { width: min(30vh, 160px); height: min(30vh, 160px); }
}
