:root {
  --bg: #eee8dc; --ink: #1d1f22; --ink2: #5d6167; --ink3: #8a8d91; --line: #d8cfbe;
  --panel: rgba(250, 248, 243, 0.86); --panel-solid: #f8f5ee; --accent: #ff6a13; --accent-ink: #b84300;
  --ok: #3c7a52; --bad: #c62f1c; --r: 12px; --gap: 12px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
#gl { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; touch-action: none; outline: none; }
#callouts { position: fixed; inset: 0; width: 100vw; height: 100dvh; pointer-events: none; overflow: visible; }
#callouts .co-line { stroke: var(--ink); stroke-width: 1; fill: none; opacity: 0.75; }
#callouts .co-dot { fill: var(--bg); stroke: var(--ink); stroke-width: 1.5; }
#callouts .co-dot.hot { fill: var(--accent); stroke: var(--accent-ink); }
#callouts .co-name { font: 600 11px/1 var(--sans); letter-spacing: 0.04em; text-transform: uppercase; fill: var(--ink2); }
#callouts .co-val { font: 600 15px/1 var(--mono); fill: var(--ink); }
#callouts .co-bg { fill: var(--panel-solid); opacity: 0.9; }

/* ---------- desktop: console em volta da máquina ---------- */
#ui { position: fixed; inset: 0; display: grid; pointer-events: none; padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(14px + var(--sab)) calc(16px + var(--sal));
  grid-template-columns: 248px 1fr 292px; grid-template-rows: auto 1fr auto; gap: var(--gap); transition: opacity .3s; }
#ui.hidden { opacity: 0; }
#ui.hidden * { pointer-events: none !important; }
#ui > *, #sheet > *, .panes > * , .card, .top > * { pointer-events: auto; }
.top { grid-column: 1 / -1; display: grid; grid-template-columns: auto auto 1fr auto; align-items: end; gap: 28px; pointer-events: none !important; }
.brand .kicker { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink2); margin-bottom: 4px; }
.brand h1 { margin: 0; font-size: 34px; line-height: 1; letter-spacing: -0.02em; font-weight: 800; }
.readout .big { font: 700 56px/0.9 var(--mono); letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.readout .big small { font: 600 16px var(--sans); color: var(--ink2); margin-left: 6px; letter-spacing: 0; }
.readout .cap { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink2); margin-top: 6px; }
.readout.hot .big { color: var(--accent-ink); }
.status { align-self: end; font-size: 13px; color: var(--ink2); display: flex; align-items: center; gap: 8px; padding-bottom: 4px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(255,106,19,.18); flex: none; }
.status.live .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(60,122,82,.18); }
.top-actions { display: flex; gap: 8px; align-self: start; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-size: 13px; font-weight: 600; }
.chip svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chip svg path:first-child { fill: currentColor; stroke: none; }
#act-check svg path:first-child { fill: none; stroke: currentColor; }
.chip[aria-pressed="false"] .wave { opacity: .25; }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-ink); }

#sheet, .panes { display: contents; }
.col-left { grid-column: 1; grid-row: 2; display: flex; flex-direction: column; gap: var(--gap); min-height: 0; overflow: auto; scrollbar-width: none; }
.col-right { grid-column: 3; grid-row: 2; display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow: auto; scrollbar-width: none; }
.dock { grid-column: 1 / -1; grid-row: 3; }
.tourbar { grid-column: 2; grid-row: 2; align-self: end; justify-self: center; width: min(520px, 100%); display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 6px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.tabs, .grab, .fab { display: none; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.card h2 { margin: 0 0 4px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink2); }
.card h3 { margin: 0 0 6px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink2); font-weight: 600; }
.card h3 .unit { font-family: var(--mono); text-transform: none; letter-spacing: 0; color: var(--ink); float: right; }
.hint { margin: 0 0 10px; font-size: 12px; color: var(--ink3); line-height: 1.35; }
.chart canvas { width: 100%; display: block; }
.legend { font-size: 12px; color: var(--ink2); margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.legend b { font-family: var(--mono); color: var(--ink); font-variant-numeric: tabular-nums; min-width: 3ch; display: inline-block; }
.legend .k { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .k1 { background: var(--accent); } .legend .k2 { background: var(--ink); }

.btns { display: grid; gap: 6px; }
.subs { grid-template-columns: 1fr 1fr; }
.subs button { min-height: 46px; padding: 6px 9px; }
.views { grid-template-columns: 1fr 1fr; }
.btns button { text-align: left; border: 1px solid var(--line); background: rgba(255,255,255,.55); border-radius: 9px; padding: 8px 10px; min-height: 40px; display: flex; flex-direction: column; justify-content: center; gap: 1px; transition: background .15s, border-color .15s, transform .1s; }
.btns button b { font-size: 13px; font-weight: 650; }
.btns button span { font-size: 11px; color: var(--ink3); }
.btns button:hover { border-color: #bfb39e; background: #fff; }
.btns button:active, .btns button.pressed { transform: scale(.97); }
.btns button[aria-pressed="true"], .btns button.on { border-color: var(--accent); background: #fff3ea; }
.btns button[aria-pressed="true"] b, .btns button.on b { color: var(--accent-ink); }
.btns button .mode { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent-ink); }
.views button { align-items: center; text-align: center; font-size: 13px; font-weight: 600; }
.btns button.hot { background: var(--ink); color: #fff; border-color: var(--ink); }
.btns button.hot span { color: #c9c4ba; }
.btns button.hot:hover { background: #33363b; }

.dock .card { display: grid; grid-template-columns: auto minmax(260px, 1fr) auto; gap: 8px 18px; align-items: center; padding: 10px 12px; }
.dock .sliders { grid-template-columns: 1fr 1fr; gap: 16px; }
.actions { grid-template-columns: repeat(6, auto); }
.actions button { min-width: 92px; }
.sliders { display: grid; gap: 8px; }
.slider { display: grid; gap: 2px; font-size: 12px; color: var(--ink2); }
.slider .lab { display: flex; justify-content: space-between; }
.slider output { font-family: var(--mono); color: var(--ink); font-weight: 600; }
.slider .ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--ink3); font-style: normal; }
.slider .ticks i { font-style: normal; } .slider .ticks .warn { color: var(--accent-ink); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: linear-gradient(90deg, var(--ink) var(--fill, 0%), var(--line) var(--fill, 0%)); border-radius: 4px; }
input[type=range]::-moz-range-track { height: 4px; background: var(--line); border-radius: 4px; }
input[type=range]::-moz-range-progress { height: 4px; background: var(--ink); border-radius: 4px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.18); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); }
input.over::-webkit-slider-thumb { border-color: var(--bad); }
.pad { display: grid; grid-template-columns: repeat(4, 44px); gap: 6px; }
.pad button { height: 44px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.6); font-size: 14px; touch-action: none; user-select: none; -webkit-user-select: none; }
.pad button.down { background: var(--ink); color: #fff; }
.keys { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--ink3); }
@media (min-width: 900px) { .keys { position: absolute; } .dock { position: relative; } .dock .keys { display: none; } }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; color: var(--ink2); margin: 0 1px; }

.play { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; display: grid; place-items: center; flex: none; }
.play svg { width: 16px; height: 16px; fill: currentColor; }
.play .i-play { display: none; } .play.paused .i-play { display: block; } .play.paused .i-pause { display: none; }
.tb-main { flex: 1; min-width: 0; }
.beat { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 5px; }
.prog { position: relative; height: 4px; background: var(--line); border-radius: 4px; cursor: pointer; }
.prog i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 4px; width: 0; }
.prog .tick { position: absolute; top: -3px; width: 2px; height: 10px; background: var(--ink3); border-radius: 1px; transform: translateX(-1px); }
.tourbar.live .prog i { background: var(--ink3); }

#cursor { position: fixed; left: 0; top: 0; width: 26px; height: 26px; pointer-events: none; z-index: 40; opacity: 0; transition: opacity .3s; will-change: transform; }
#cursor.on { opacity: 1; }
#cursor svg { width: 26px; height: 26px; fill: var(--ink); stroke: #fff; stroke-width: 1.5; filter: drop-shadow(0 2px 3px rgba(0,0,0,.25)); }
#cursor .ring { position: absolute; left: -14px; top: -14px; width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; transform: scale(.4); }
#cursor.click .ring { animation: ring .45s ease-out; }
@keyframes ring { 0% { opacity: 1; transform: scale(.4); } 100% { opacity: 0; transform: scale(1.4); } }
#toast { position: fixed; left: 50%; top: calc(110px + var(--sat)); transform: translateX(-50%) translateY(-8px); background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 30; white-space: nowrap; }
#toast.on { opacity: 1; transform: translateX(-50%); }

dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(760px, calc(100vw - 24px)); max-height: min(86dvh, 820px); background: var(--panel-solid); color: var(--ink); box-shadow: 0 20px 60px rgba(30,20,0,.25); }
dialog::backdrop { background: rgba(40,34,24,.35); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel-solid); }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-head button { border: 0; background: transparent; font-size: 18px; width: 40px; height: 40px; border-radius: 50%; }
#check-body { padding: 4px 16px 18px; overflow: auto; }
#check-body table { width: 100%; border-collapse: collapse; font-size: 13px; }
#check-body td, #check-body th { padding: 9px 6px; border-bottom: 1px solid #e6dece; vertical-align: top; text-align: left; }
#check-body th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); font-weight: 600; }
#check-body .f { font-family: var(--mono); font-size: 12px; color: var(--ink2); }
#check-body .v { font-family: var(--mono); font-weight: 700; white-space: nowrap; }
.tag { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.tag.fis { background: #e3efe6; color: var(--ok); } .tag.prem { background: #f1ebdc; color: #7a6223; } .tag.inv { background: #fde6dd; color: var(--bad); }
#check-body p { font-size: 13px; color: var(--ink2); line-height: 1.5; }

#loader { position: fixed; inset: 0; background: var(--bg); display: grid; place-content: center; justify-items: center; gap: 14px; z-index: 50; transition: opacity .5s; }
#loader.done { opacity: 0; pointer-events: none; }
.ld-title { font-weight: 800; font-size: 28px; letter-spacing: -0.02em; }
.ld-bar { width: 180px; height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; }
.ld-bar i { display: block; height: 100%; width: 40%; background: var(--accent); animation: ld 1s ease-in-out infinite; }
@keyframes ld { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
.ld-txt { font-size: 12px; color: var(--ink2); }
#fade { position: fixed; inset: 0; background: var(--bg); opacity: 0; pointer-events: none; z-index: 20; }

@media (max-width: 1180px) and (min-width: 900px) {
  #ui { grid-template-columns: 210px 1fr 252px; }
  .readout .big { font-size: 46px; }
  .actions { grid-template-columns: repeat(3, auto); }
  .dock .card { grid-template-columns: auto 1fr; }
  .pad { display: none; }
}

/* ---------- celular e tablet estreito: gaveta inferior com abas ---------- */
@media (max-width: 899px) {
  #ui { display: block; padding: 0; }
  .only-desk { display: none !important; }
  .top { position: fixed; left: 0; right: 0; top: 0; padding: calc(10px + var(--sat)) calc(14px + var(--sar)) 0 calc(14px + var(--sal)); grid-template-columns: 1fr auto; grid-template-areas: "brand read" "status act"; gap: 2px 10px; align-items: start; }
  .brand { grid-area: brand; } .readout { grid-area: read; text-align: right; } .status { grid-area: status; padding: 0; font-size: 12px; } .top-actions { grid-area: act; justify-self: end; }
  .brand .kicker { font-size: 10px; } .brand h1 { font-size: 22px; }
  .readout .big { font-size: 34px; } .readout .big small { font-size: 13px; } .readout .cap { font-size: 9px; margin-top: 3px; }
  .chip { height: 32px; padding: 0 10px; font-size: 12px; }
  #act-check span { display: none; }
  #sheet { display: flex; flex-direction: column; position: fixed; left: 0; right: 0; bottom: 0; background: var(--panel-solid); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(40,30,10,.12); padding: 0 calc(12px + var(--sar)) calc(8px + var(--sab)) calc(12px + var(--sal)); max-height: 48dvh; transition: max-height .3s cubic-bezier(.16,1,.3,1); }
  #sheet.collapsed { max-height: 132px; }
  #sheet.collapsed .panes { display: none; }
  .grab { display: block; height: 22px; border: 0; background: none; width: 100%; padding: 0; flex: none; }
  .grab i { display: block; width: 40px; height: 4px; border-radius: 4px; background: #cfc5b2; margin: 8px auto 0; }
  .tourbar { width: 100%; background: transparent; border: 0; padding: 2px 0 8px; backdrop-filter: none; -webkit-backdrop-filter: none; flex: none; }
  .play { width: 34px; height: 34px; }
  .tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: #ece5d6; border-radius: 10px; padding: 3px; flex: none; }
  .tabs button { border: 0; background: transparent; height: 34px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink2); }
  .tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
  .panes { display: block; overflow-y: auto; overscroll-behavior: contain; margin-top: 10px; flex: 1; min-height: 0; -webkit-overflow-scrolling: touch; }
  .col-left, .col-right, .dock { display: contents; }
  .card { display: none; background: transparent; border: 0; padding: 0 0 12px; backdrop-filter: none; -webkit-backdrop-filter: none; }
  #sheet[data-active="painel"] .card[data-tab="painel"], #sheet[data-active="controle"] .card[data-tab="controle"], #sheet[data-active="sistemas"] .card[data-tab="sistemas"], #sheet[data-active="camera"] .card[data-tab="camera"] { display: block; }
  #sheet[data-active="painel"] .col-right { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
  #sheet[data-active="painel"] .card.chart { background: #fff; border: 1px solid #e7dfcf; border-radius: 10px; padding: 8px; }
  .card.wide { grid-column: 1 / -1; }
  .card h2 { display: none; }
  .subs { grid-template-columns: 1fr 1fr; }
  .views { grid-template-columns: 1fr 1fr 1fr; }
  .views button { min-height: 44px; }
  .btns button { min-height: 48px; }
  .dock .card { display: none; }
  #sheet[data-active="controle"] .dock .card { display: grid; grid-template-columns: 1fr; gap: 12px; padding: 0 0 8px; }
  .actions { grid-template-columns: repeat(3, 1fr); }
  .actions button { min-width: 0; }
  .actions [data-act="pincerL"], .actions [data-act="pincerR"], .actions [data-act="strike"] { display: none; }
  .dock .sliders { grid-template-columns: 1fr; gap: 6px; }
  .slider .ticks { font-size: 10px; }
  .pad { grid-template-columns: 1fr 1.6fr 1fr; gap: 8px; }
  .pad button { height: 52px; font-size: 18px; }
  .pad [data-hold="back"] { display: none; }
  .fab { display: flex; position: absolute; left: 50%; transform: translateX(-50%); top: -62px; gap: 8px; white-space: nowrap; }
  .fab button { height: 46px; padding: 0 16px; border-radius: 999px; white-space: nowrap; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-weight: 650; font-size: 14px; box-shadow: 0 4px 14px rgba(40,30,10,.12); }
  .fab button.hot { background: var(--ink); color: #fff; border-color: var(--ink); }
  .fab button.pressed, .fab button:active { transform: scale(.95); }
  #toast { top: calc(96px + var(--sat)); }
  #callouts .co-name { font-size: 9px; } #callouts .co-val { font-size: 12px; }
}
@media (max-width: 440px) { .brand .kicker { display: none; } }
@media (max-width: 380px) {
  .readout .big { font-size: 30px; }
  .fab button { padding: 0 12px; font-size: 13px; }
}
/* celular deitado: gaveta vira coluna à direita */
@media (max-width: 899px) and (orientation: landscape) and (max-height: 520px) {
  .top { right: 340px; grid-template-columns: auto auto 1fr; grid-template-areas: "brand read act"; align-items: center; padding-top: calc(8px + var(--sat)); }
  .brand .kicker, .status, .readout .cap { display: none; }
  .brand h1 { font-size: 18px; } .readout { text-align: left; } .readout .big { font-size: 28px; }
  .actions { grid-template-columns: repeat(3, 1fr); } .actions button span { display: none; }
  .tourbar { padding-bottom: 4px; } .panes { margin-top: 6px; }
  .pad button { height: 44px; }
  #sheet { left: auto; top: 0; width: calc(330px + var(--sar)); max-height: none; height: 100dvh; border-radius: 18px 0 0 18px; border-top: 0; border-left: 1px solid var(--line); padding-top: calc(6px + var(--sat)); }
  #sheet.collapsed { max-height: none; }
  #sheet.collapsed .panes { display: block; }
  .grab { display: none; }
  .fab { top: auto; bottom: calc(12px + var(--sab)); left: auto; right: calc(100% + 12px); transform: none; }
}
@media (prefers-reduced-motion: reduce) { #sheet { transition: none; } #cursor { transition: none; } }
