:root {
  --bg: #04060c;
  --panel: rgba(10, 18, 32, 0.72);
  --line: rgba(80, 220, 255, 0.22);
  --line-strong: rgba(80, 220, 255, 0.5);
  --txt: #d8ecff;
  --muted: #7d93ad;
  --cyan: #2ad4ff;
  --mag: #d946ef;
  --green: #3dff9e;
  --amber: #ffb020;
  --red: #ff2d55;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--txt);
  font-family: var(--sans); overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; cursor: pointer; }

#app {
  height: 100dvh; max-width: 620px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(42, 212, 255, 0.08), transparent 60%),
    radial-gradient(90% 50% at 50% 100%, rgba(217, 70, 239, 0.07), transparent 60%);
}

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
label { font: 600 9px/1 var(--mono); letter-spacing: 0.12em; color: var(--muted); }

/* topo */
.top { display: flex; align-items: center; gap: 10px; padding: 8px 12px 6px; }
.brand { display: flex; align-items: center; gap: 6px; font: 800 13px/1 var(--mono); letter-spacing: 0.14em; white-space: nowrap; }
.logo { color: var(--cyan); text-shadow: 0 0 12px var(--cyan); }
.kpis { flex: 1; display: flex; justify-content: flex-end; gap: 14px; }
.kpi { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.kpi b { font: 700 17px/1 var(--mono); font-variant-numeric: tabular-nums; }
#score { color: #fff; text-shadow: 0 0 10px rgba(42, 212, 255, 0.6); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); font-size: 12px; flex: none;
}

/* faixa */
.strip { display: flex; gap: 6px; padding: 0 10px 6px; }
.slot { padding: 6px 6px 4px; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.slot canvas { width: 54px; height: 42px; }
.slot.next canvas { width: 135px; height: 42px; }
#hold-panel.used { opacity: 0.45; }
.telem { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 6px 8px; }
.oee { display: flex; flex-direction: column; gap: 3px; }
.oee b { font: 800 18px/1 var(--mono); }
.bars { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 50px; }
.bar { display: flex; align-items: center; gap: 4px; font: 600 8px/1 var(--mono); color: var(--muted); }
.bar span { width: 26px; }
.bar i { flex: 1; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.bar em { display: block; height: 100%; width: 0; background: var(--green); transition: width 0.3s, background 0.3s; }
#spark { width: 60px; height: 30px; flex: none; }

/* palco */
.stage { position: relative; flex: 1; min-height: 0; touch-action: none; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.twin-map { position: absolute; top: 6px; right: 8px; padding: 5px; display: flex; flex-direction: column; gap: 4px; }
.twin-map canvas { width: 84px; height: 95px; image-rendering: pixelated; }
.twin-map label { font-size: 7px; }

.toast {
  position: absolute; left: 0; right: 0; top: 34%; text-align: center; pointer-events: none;
  font: 900 30px/1.1 var(--mono); letter-spacing: 0.08em; color: #fff;
  text-shadow: 0 0 18px var(--cyan), 0 0 40px var(--mag); opacity: 0;
}
.toast small { display: block; font-size: 14px; letter-spacing: 0.2em; color: var(--green); text-shadow: 0 0 10px var(--green); }
.toast.show { animation: toast 1.1s ease-out forwards; }
@keyframes toast {
  0% { opacity: 0; transform: scale(0.6); }
  15% { opacity: 1; transform: scale(1.12); }
  30% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-30px); }
}

.alarm {
  position: absolute; top: 8px; left: 10px; padding: 6px 10px; border-radius: 8px;
  font: 800 11px/1 var(--mono); letter-spacing: 0.1em; color: #fff;
  background: rgba(255, 45, 85, 0.85); box-shadow: 0 0 20px rgba(255, 45, 85, 0.6);
  animation: blink 0.5s steps(2) infinite;
}
.alarm.warn { background: rgba(255, 176, 32, 0.9); color: #1a1000; box-shadow: 0 0 20px rgba(255, 176, 32, 0.5); animation: none; }
@keyframes blink { 50% { opacity: 0.45; } }

.twin-btn {
  position: absolute; left: 10px; bottom: 10px; display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px; border-radius: 30px; border: 1px solid var(--line);
  background: var(--panel); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.twin-btn .ring { position: relative; width: 36px; height: 36px; display: grid; place-items: center; }
.twin-btn svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.twin-btn circle { fill: none; stroke-width: 3; }
.twin-btn .bg { stroke: rgba(255, 255, 255, 0.1); }
.twin-btn .fg { stroke: var(--green); stroke-linecap: round; stroke-dasharray: 97.4; stroke-dashoffset: 97.4; transition: stroke-dashoffset 0.3s; }
.twin-btn b { font-size: 16px; color: var(--green); }
.twin-btn .lbl { font: 700 11px/1 var(--mono); letter-spacing: 0.1em; }
.twin-btn:disabled { cursor: default; opacity: 0.75; }
.twin-btn.ready { border-color: var(--green); box-shadow: 0 0 22px rgba(61, 255, 158, 0.5); animation: pulse 1s ease-in-out infinite; opacity: 1; }
.twin-btn.active { border-color: var(--green); background: rgba(61, 255, 158, 0.18); }
@keyframes pulse { 50% { box-shadow: 0 0 6px rgba(61, 255, 158, 0.2); } }

/* controles */
.controls { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; padding: 6px 10px 10px; touch-action: none; }
.controls button {
  height: 58px; border-radius: 14px; border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20, 34, 56, 0.9), rgba(8, 14, 26, 0.9));
  font-size: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.controls button small { font: 700 7px/1 var(--mono); letter-spacing: 0.08em; color: var(--muted); }
.controls button.accent { border-color: var(--line-strong); color: var(--cyan); }
.controls button.on { background: rgba(42, 212, 255, 0.25); border-color: var(--cyan); transform: scale(0.96); }
body.no-buttons .controls { display: none; }
@media (hover: hover) and (pointer: fine) { .touch-only { display: none; } }
@media (pointer: coarse) { .kbd-only { display: none; } }

/* overlays */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(80% 60% at 50% 40%, rgba(4, 6, 12, 0.35), rgba(4, 6, 12, 0.85));
  z-index: 10; overflow-y: auto;
}
.overlay[hidden] { display: none; }
.card {
  width: min(400px, 100%); display: flex; flex-direction: column; gap: 10px;
  padding: 22px 18px; border-radius: 18px; border: 1px solid var(--line-strong);
  background: rgba(8, 14, 26, 0.82); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 0 60px rgba(42, 212, 255, 0.12);
}
.title { text-align: center; margin-bottom: 4px; }
.title h1 { margin: 4px 0 2px; font: 900 34px/1 var(--mono); letter-spacing: 0.16em; text-shadow: 0 0 22px var(--cyan); }
.title h2 { margin: 0 0 4px; font: 900 20px/1.1 var(--mono); letter-spacing: 0.12em; }
.title p { margin: 0; color: var(--muted); font-size: 13px; }
.logo.big { font-size: 26px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modes button {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px;
  border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03);
}
.modes .mi { font-size: 22px; line-height: 1; color: var(--muted); }
.modes b { font: 800 13px/1 var(--mono); letter-spacing: 0.12em; }
.modes small { font-size: 10px; color: var(--muted); }
.modes button[aria-pressed="true"] { border-color: var(--cyan); background: rgba(42, 212, 255, 0.12); box-shadow: 0 0 18px rgba(42, 212, 255, 0.25); }
.modes button[aria-pressed="true"] .mi { color: var(--cyan); text-shadow: 0 0 10px var(--cyan); }
body.mode-plano .twin-map { display: none; }
#best-mode { color: var(--txt); margin-left: 4px; }
.best { text-align: center; font: 600 11px/1 var(--mono); letter-spacing: 0.14em; color: var(--muted); }
.best b { color: var(--amber); font-size: 15px; margin-left: 6px; }
.primary, .ghost { height: 50px; border-radius: 12px; font: 800 14px/1 var(--mono); letter-spacing: 0.12em; }
.primary { border: 0; color: #00131a; background: linear-gradient(90deg, var(--cyan), var(--green)); box-shadow: 0 0 24px rgba(42, 212, 255, 0.4); }
.ghost { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); }
.ghost.link { display: flex; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: 12px; }
.ghost.link[hidden] { display: none; }
details { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 13px; color: #b9cbe0; }
summary { cursor: pointer; font: 700 12px/1 var(--mono); letter-spacing: 0.1em; color: var(--txt); }
details ul { margin: 10px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; line-height: 1.4; }
.settings { display: flex; flex-wrap: wrap; gap: 8px 14px; justify-content: center; font-size: 13px; color: #b9cbe0; }
.settings label { font: inherit; letter-spacing: 0; color: inherit; display: flex; align-items: center; gap: 5px; }
.settings select { background: #0b1424; color: var(--txt); border: 1px solid var(--line); border-radius: 6px; padding: 3px 4px; }
.report { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.report div { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.report label { display: block; margin-bottom: 5px; }
.report b { font: 800 18px/1 var(--mono); }
.report .wide { grid-column: span 2; text-align: center; }
.report .wide b { font-size: 28px; color: #fff; text-shadow: 0 0 14px var(--cyan); }
.record { color: var(--amber) !important; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); font: 600 12px/1 var(--mono); letter-spacing: 0.14em; color: var(--muted); z-index: 20; transition: opacity 0.4s; }
.boot.done { opacity: 0; pointer-events: none; }

@media (max-width: 380px) {
  .brand span:last-child { display: none; }
  .kpi b { font-size: 15px; }
  .slot.next canvas { width: 108px; }
  #spark { display: none; }
  .controls button { height: 52px; font-size: 19px; }
}
@media (max-height: 640px) { .controls button { height: 46px; } .strip { padding-bottom: 4px; } }
@media (min-width: 621px) { #app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }
