:root {
  --pn-vh: 1vh;
  --bg: #0d1b2a;
  --panel: #112437;
  --ink: #e8f1f5;
  --muted: #8fa7b5;
  --accent: #ffd166;
  --good: #2ec4b6;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}
#app {
  min-height: calc(var(--pn-vh) * 100);
  display: flex;
  flex-direction: column;
  max-width: 980px;
  margin: 0 auto;
  padding: 8px 12px 12px;
}
.topbar, #statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.topbar { padding: 4px 2px 8px; }
.title { font-size: 18px; font-weight: 800; letter-spacing: .2px; }
.title small { color: var(--muted); font-weight: 500; font-size: 11px; margin-left: 4px; }
.spacer { flex: 1; }
.hud { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.hud .opt { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.hud b { color: var(--accent); font-variant-numeric: tabular-nums; }
#stage { position: relative; width: 100%; }
canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 900 / 420;
  background: var(--bg);
  border-radius: 10px;
  touch-action: none;
  user-select: none;
}
#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 15, 24, .55);
  border-radius: 10px;
}
.card, .modal-card {
  background: var(--panel);
  border: 1px solid #24455c;
  border-radius: 12px;
  padding: 16px 20px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}
.card { min-width: 240px; text-align: center; }
.card-label { font-size: 20px; font-weight: 800; color: var(--good); }
.card-body { display: flex; justify-content: center; gap: 18px; margin: 12px 0; }
.card-body div { display: flex; flex-direction: column; }
.card-body span { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.card-body b { color: var(--ink); font-size: 16px; font-variant-numeric: tabular-nums; }
#lean-wrap {
  position: relative;
  height: 18px;
  margin: 8px 0 2px;
  border: 1px solid #24455c;
  border-radius: 9px;
  background: linear-gradient(90deg, #7a243c 0%, #173149 30%, #173149 70%, #7a243c 100%);
  overflow: hidden;
}
#lean-safe {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 40%;
  transform: translateX(-50%);
  background: rgba(46, 196, 182, .22);
  border-left: 1px solid rgba(46, 196, 182, .5);
  border-right: 1px solid rgba(46, 196, 182, .5);
}
#lean-marker {
  position: absolute;
  top: 1px;
  bottom: 1px;
  left: 50%;
  width: 4px;
  margin-left: -2px;
  background: #fff;
  border-radius: 2px;
  transition: left .05s linear;
}
#lean-text { color: var(--muted); font-size: 12px; text-align: center; font-variant-numeric: tabular-nums; }
#statusbar { padding-top: 10px; }
#status { flex: 1 1 100%; min-height: 18px; color: var(--muted); font-size: 13px; }
#status[data-tone="warn"] { color: var(--accent); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; }
.btn {
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid #2c5369;
  border-radius: 8px;
  background: #173149;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { background: #1e3e59; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b1300; }
.btn.icon { min-width: 48px; padding: 8px; font-size: 18px; }
.btn.held { background: var(--good); color: #06231f; }
.hidden { display: none !important; }
.hint { flex: 1 1 100%; color: var(--muted); font-size: 12px; }
#modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 10, 18, .78);
  padding: 20px;
  z-index: 10;
}
.modal-card { max-width: 520px; line-height: 1.5; }
.modal-card h2 { margin-top: 0; }
.modal-card ol { padding-left: 20px; }
.modal-card .muted { color: var(--muted); font-size: 12px; }
#toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #173149;
  border: 1px solid #2c5369;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: 1; }
@media (max-width: 480px) {
  .title { font-size: 16px; }
  .hud { gap: 5px; font-size: 12px; }
  .btn { min-height: 48px; font-size: 13px; padding: 8px 10px; }
}
