#performance-hud {
  position:fixed; left:max(8px,env(safe-area-inset-left)); right:max(8px,env(safe-area-inset-right));
  top:max(8px,env(safe-area-inset-top)); z-index:110; box-sizing:border-box;
  width:min(360px,calc(100vw - max(8px,env(safe-area-inset-left)) - max(8px,env(safe-area-inset-right))));
  margin:0; padding:0 4px; border:1px solid #477f7b;
  border-radius:6px; background:rgba(5,17,23,.88); color:#d7e8e5;
  font:11px/1.4 Consolas,ui-monospace,monospace; font-variant-numeric:tabular-nums;
  letter-spacing:0; text-shadow:none; pointer-events:none; contain:layout paint;
}
#performance-hud[hidden] { display:none; }
#performance-hud.is-expanded { width:auto; margin:0; }
.perf-heading { display:flex; align-items:center; gap:2px; color:#74e8d7; }
.perf-toolbar { grid-column:1/-1; display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:6px 12px; }
.perf-toolbar strong { font-size:9px; letter-spacing:.1em; color:#9cb8b4; }
.perf-expanded { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr) minmax(0,1.35fr); gap:6px 16px;
  box-sizing:border-box; padding:6px 8px 8px; border-top:1px solid #315052;
  max-height:min(320px,calc(50dvh - max(8px,env(safe-area-inset-top)) - 46px));
  overflow-y:auto; overscroll-behavior:contain; touch-action:pan-y; pointer-events:auto; }
.perf-expanded[hidden] { display:none; }
.perf-actions { display:flex; gap:4px; }
.perf-overview,.perf-details,.perf-diagnostics { min-width:0; }
#performance-hud button { margin:0; padding:2px 5px; width:auto; min-height:22px;
  border:1px solid #416363; border-radius:3px; background:#132b30; color:#cde7e3;
  font:10px/1.3 Consolas,monospace; cursor:pointer; pointer-events:auto; box-shadow:none; }
#performance-hud button:hover,#performance-hud button:focus-visible { background:#244b50; outline:1px solid #74e8d7; }
#performance-hud .perf-toggle { display:flex; align-items:center; gap:8px; flex:1; min-width:0;
  min-height:36px; padding:0 6px; border:0; background:none; text-align:left; }
#performance-hud .perf-close { flex:none; width:30px; min-height:36px; padding:0; border:0; background:none; font-size:18px; color:#9cb8b4; }
#performance-hud :is(.perf-toggle,.perf-close):hover { background:#244b50; }
.perf-compact-fps { flex:none; white-space:nowrap; color:#74e8d7; }
.perf-compact-fps b { font-size:17px; font-weight:600; }
.perf-compact-fps small { font-size:9px; color:#b2cbc7; }
.perf-compact-frame { flex:none; white-space:nowrap; color:#b2cbc7; font-size:10px; }
#performance-sparkline { flex:1; min-width:32px; width:80px; max-width:96px; height:22px; pointer-events:none; }
.perf-toggle-label { margin-left:auto; color:#b2cbc7; font-size:10px; }
.perf-chevron { display:block; flex:none; width:16px; height:16px; color:#74e8d7;
  fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round;
  transform-origin:center; transition:transform .16s ease; }
.is-expanded .perf-chevron { transform:rotate(180deg); }
@media (prefers-reduced-motion:reduce) { .perf-chevron { transition:none; } }
.perf-summary { display:flex; align-items:baseline; justify-content:space-between; gap:6px; margin:0 0 3px; }
.perf-fps { flex-shrink:0; white-space:nowrap; font-size:25px; line-height:1.1; color:#74e8d7; }
.perf-fps small { font-size:10px; color:#b2cbc7; }
.perf-window { font-size:10px; text-align:right; color:#b2cbc7; }
.perf-window,.perf-drop,.perf-context { white-space:pre-line; overflow-wrap:anywhere; }
#performance-chart { width:100%; height:66px; margin:0; }
.perf-timing { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:2px 8px; margin:0 0 5px; font-size:10px; }
.perf-timing span { color:#9cb8b4; white-space:nowrap; }
.perf-timing b { color:#e1eeeb; font-weight:400; float:right; }
.perf-counts,.perf-context { font-size:10px; color:#bbd1cd; overflow-wrap:anywhere; }
.perf-drop { margin-top:5px; padding-top:5px; border-top:1px solid #315052; color:#ffba79; font-size:10px; }
.perf-note { color:#8fa8a6; font-size:9px; margin-top:3px; }
@media (max-width:900px) {
  .perf-expanded { gap:5px 10px; padding:6px; }
  .perf-timing { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:600px) {
  .perf-expanded { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .perf-summary { flex-wrap:wrap; }
  .perf-window { flex-basis:100%; text-align:left; }
  .perf-diagnostics { grid-column:1/-1; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
  .perf-drop { margin:0; padding:0 0 0 8px; border-top:0; border-left:1px solid #315052; }
}
@media (max-height:500px) {
  .perf-expanded { gap:4px 10px; padding:4px 6px; }
  #performance-chart { height:42px; }
  .perf-fps { font-size:21px; }
}
@media (pointer:coarse) {
  #performance-hud button { min-height:36px; }
  #performance-hud :is(.perf-toggle,.perf-close) { min-height:42px; }
}
