:root {
  --green: #7cf07c;
  --green-dim: rgba(124, 240, 124, .35);
  --amber: #ffb000;
  --red: #ff5b4d;
  --bg-panel: rgba(3, 10, 5, .62);
  --font: "Courier New", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #000; }
#app { position: fixed; inset: 0; height: 100dvh; touch-action: none; }

#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* CRT scanlines */
#app::after {
  content: "";
  position: absolute; inset: 0; pointer-events: none; z-index: 40;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 1px, transparent 1px 3px);
  opacity: .5;
}

/* ---------- HUD panels ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; font-family: var(--font); }
#hud.hidden { display: none; }

.panel {
  position: absolute;
  background: var(--bg-panel);
  border: 1px solid var(--green-dim);
  padding: 8px 10px;
  color: #b8ffb8;
  font-size: 13px;
  letter-spacing: 1px;
  border-radius: 3px;
  box-shadow: 0 0 12px rgba(124,240,124,.08) inset;
}
.panel-title {
  color: var(--amber);
  font-size: 11px;
  letter-spacing: 3px;
  border-bottom: 1px solid var(--green-dim);
  padding-bottom: 4px;
  margin-bottom: 6px;
}

#left-panel { top: 12px; left: 12px; width: 250px; }
#right-panel { top: 12px; right: 12px; width: 190px; text-align: center; }

.row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.row label { width: 92px; color: #86c786; font-size: 11px; flex: none; }
.num { color: #d8ffd8; font-size: 14px; text-align: right; flex: 1; white-space: nowrap; }

.bar { flex: 1; height: 12px; border: 1px solid var(--green-dim); background: rgba(0,0,0,.5); }
.fill { height: 100%; width: 100%; background: var(--green); box-shadow: 0 0 8px rgba(124,240,124,.6); transition: width .08s linear; }
.fill.amber { background: var(--amber); box-shadow: 0 0 8px rgba(255,176,0,.6); }
.fill.low { background: var(--red); box-shadow: 0 0 8px rgba(255,91,77,.7); animation: blink 0.6s steps(2) infinite; }

.tilt-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.tilt-row label { width: 92px; color: #86c786; font-size: 11px; flex: none; }
#tilt { border: 1px solid var(--green-dim); background: rgba(0,0,0,.5); }

#hint {
  bottom: 10px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: #86c786; white-space: nowrap; border-color: rgba(124,240,124,.2);
}

#corner-btns { position: absolute; bottom: 10px; right: 12px; display: flex; gap: 8px; pointer-events: auto; }
.mini-btn {
  font-family: var(--font); font-size: 11px; letter-spacing: 2px;
  background: var(--bg-panel); color: #b8ffb8; border: 1px solid var(--green-dim);
  padding: 6px 10px; cursor: pointer; border-radius: 3px;
}
.mini-btn:hover { color: #fff; border-color: var(--green); }

#warn {
  position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
  font-family: var(--font); font-size: 22px; letter-spacing: 6px; font-weight: bold;
  color: var(--red); text-shadow: 0 0 12px rgba(255,91,77,.8); white-space: nowrap;
}
#warn.ok { color: var(--green); text-shadow: 0 0 12px rgba(124,240,124,.8); }
#warn.hidden { display: none; }

@keyframes blink { 50% { opacity: .35; } }

/* ---------- Overlay ---------- */
#overlay {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .58); backdrop-filter: blur(3px);
  font-family: var(--font);
}
#overlay.hidden { display: none; }
.card {
  background: rgba(3, 12, 6, .9); border: 1px solid var(--green-dim); border-radius: 4px;
  padding: 26px 34px; max-width: 560px; width: min(92vw, 560px); color: #b8ffb8;
  text-align: center; box-shadow: 0 0 30px rgba(124,240,124,.12);
}
.card h1 { color: var(--amber); font-size: 26px; letter-spacing: 8px; margin: 0 0 4px; }
.card h2 { color: var(--amber); font-size: 20px; letter-spacing: 5px; margin: 0 0 10px; }
.card p { font-size: 13px; color: #9ad39a; line-height: 1.6; margin: 8px 0; }
.card .big { font-size: 17px; color: #d8ffd8; }
.card .good { color: var(--green); }
.card .bad { color: var(--red); }
.card .stats { font-size: 14px; line-height: 1.9; text-align: left; display: inline-block; }
.card table { margin: 10px auto; border-collapse: collapse; font-size: 12px; color: #9ad39a; }
.card td { padding: 3px 10px; text-align: left; }
.card td:first-child { color: var(--amber); letter-spacing: 1px; }
.btn {
  font-family: var(--font); font-size: 15px; letter-spacing: 3px;
  background: #08160a; color: #b8ffb8; border: 1px solid var(--green);
  padding: 12px 30px; margin: 8px 6px 0; cursor: pointer; border-radius: 3px;
}
.btn:hover { background: #14290f; color: #fff; box-shadow: 0 0 12px rgba(124,240,124,.35); }
.btn.warn-btn { border-color: var(--amber); color: var(--amber); }
.legend { font-size: 12px; color: #9ad39a; margin-top: 10px; }
.legend span { margin: 0 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* ---------- Touch controls ---------- */
#touch { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
#touch.hidden { display: none; }
#t-left { position: absolute; bottom: 18px; left: 14px; display: grid; pointer-events: auto;
  grid-template-areas: ". up ." "left . right" ". down ."; gap: 8px; }
#t-right { position: absolute; bottom: 18px; right: 14px; display: flex; flex-direction: column; align-items: center; gap: 12px; pointer-events: auto; }
#yaw-label { font-family: var(--font); font-size: 10px; letter-spacing: 3px; color: #86c786; }
.tbtn {
  width: 58px; height: 58px; border-radius: 50%;
  background: rgba(3,10,5,.65); border: 1px solid var(--green-dim); color: #b8ffb8;
  font-size: 20px; -webkit-user-select: none; user-select: none; touch-action: none;
}
.tbtn:active, .tbtn.on { background: rgba(40,90,40,.85); border-color: var(--green); color: #fff; }
.t-up { grid-area: up; } .t-down { grid-area: down; } .t-left { grid-area: left; } .t-right { grid-area: right; }
.t-yaw { width: 46px; height: 46px; font-size: 16px; }
#t-thrust {
  width: 92px; height: 92px; border-radius: 50%;
  background: rgba(60,30,0,.7); border: 2px solid var(--amber); color: var(--amber);
  font-family: var(--font); font-size: 15px; letter-spacing: 2px;
  -webkit-user-select: none; user-select: none; touch-action: none;
}
#t-thrust.on { background: rgba(255,120,0,.45); color: #fff; box-shadow: 0 0 22px rgba(255,150,0,.55); }

/* ---------- Phone ---------- */
@media (max-width: 820px) {
  #left-panel { width: 205px; font-size: 11px; padding: 6px 8px; }
  .row label { width: 74px; font-size: 10px; }
  .num { font-size: 12px; }
  #right-panel { width: 136px; padding: 6px 8px; }
  #radar { width: 118px; height: 118px; }
  #hint { display: none; }
  #warn { font-size: 15px; letter-spacing: 3px; }
  #corner-btns { bottom: auto; top: 268px; right: 12px; flex-direction: column; }
  .card { padding: 18px 16px; }
  .card h1 { font-size: 19px; letter-spacing: 5px; }
  .card table { font-size: 11px; }
}
