:root {
  --host-top: 0px; --host-right: 0px; --host-bottom: 0px; --host-left: 0px;
  --safe-top: max(env(safe-area-inset-top, 0px), var(--host-top));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--host-right));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--host-bottom));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--host-left));
}
html, body { height: var(--app-height, 100dvh); }
#stage, #plates { top: var(--safe-top); right: var(--safe-right); bottom: var(--safe-bottom); left: var(--safe-left); }
/* Stage.project returns viewport coordinates for all HUD overlays. */
#plates { inset: 0; }
#stage { height: calc(var(--app-height, 100dvh) - var(--safe-top) - var(--safe-bottom)); }
#topbar { top: var(--safe-top); left: var(--safe-left); right: var(--safe-right); padding-top: 12px; }
#actions { bottom: calc(16px + var(--safe-bottom)); }
#splash, #lobby, #results { padding-top: calc(24px + var(--safe-top)); padding-bottom: calc(24px + var(--safe-bottom)); }
.stats-dialog { width: min(420px, calc(100vw - 32px)); max-height: calc(var(--app-height, 100dvh) - var(--safe-top) - var(--safe-bottom) - 32px); overflow: auto; background: #141c21; color: var(--ink); border: 1px solid var(--line); border-radius: 20px; padding: 24px; box-shadow: var(--shadow); }
.stats-dialog::backdrop { background: #000a; }
.stats-close { float: right; min-width: 44px; min-height: 44px; }
.stats-dialog h2 { margin: 12px 0 24px; }
.stats-dialog dl > div { display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid #ffffff12; padding: 10px 0; }
.stats-dialog dd { color: var(--gold); font-weight: 700; }
.stats-note { font-size: 12px; line-height: 1.6; }
@media (max-width: 800px) {
  #actions { bottom: calc(8px + var(--safe-bottom)); }
  #topbar { padding-top: 8px; }
  #log { top: calc(8px + var(--safe-top)); }
}
