/* ══════════════════════════════════════════════════════════════════
   Physics Lab IDE Pro v3 — estilos
   Layout responsivo: desktop (painéis laterais), tablet (gavetas),
   celular retrato (navegação inferior + folhas) e paisagem.
   ══════════════════════════════════════════════════════════════════ */
:root {
    --bg: #0b0f1a; --surface: #111827; --surface2: #172033; --surface3: #1e293b;
    --border: #243049; --border2: #2f3d5c;
    --text: #e5e9f2; --muted: #8b97b0; --dim: #5d6b88;
    --accent: #0891b2; --accent2: #22d3ee; --accent-soft: rgba(34,211,238,.14); --amber: #f59e0b;
    --ok: #10b981; --warn: #f59e0b; --err: #ef4444;
    --top: 52px; --rail: 76px; --tools: 268px; --props: 312px;
    --radius: 12px; --shadow: 0 18px 50px rgba(0,0,0,.45);
    --font: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; -webkit-font-smoothing: antialiased; }
body { overscroll-behavior: none; touch-action: manipulation; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { opacity: .38; cursor: default; }
input, select, textarea { font: inherit; color: inherit; }
.ico { flex-shrink: 0; display: block; }
.emo { font-size: 20px; line-height: 1; font-family: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",var(--font); display: inline-grid; place-items: center; width: 24px; height: 24px; }
.emo.sm { font-size: 15px; width: 18px; height: 18px; }
.emo.big { font-size: 26px; width: 34px; height: 34px; }
kbd { font-family: var(--mono); font-size: 10px; padding: 1px 5px; border-radius: 4px; background: var(--surface3); border: 1px solid var(--border2); color: var(--muted); }
code { font-family: var(--mono); font-size: .9em; background: var(--surface3); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .pad { padding: 10px 14px; }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

/* ═════════════ Grade principal ═════════════ */
.app {
    height: 100vh; height: 100dvh; display: grid;
    grid-template-rows: var(--top) minmax(0, 1fr);
    grid-template-columns: var(--rail) 0 minmax(0, 1fr) 0;
    grid-template-areas: "top top top top" "rail tools stage props";
    transition: grid-template-columns .22s ease;
}
.app.tools-open { grid-template-columns: var(--rail) var(--tools) minmax(0, 1fr) 0; }
.app.props-open { grid-template-columns: var(--rail) 0 minmax(0, 1fr) var(--props); }
.app.tools-open.props-open { grid-template-columns: var(--rail) var(--tools) minmax(0, 1fr) var(--props); }

/* ═════════════ Barra superior ═════════════ */
.topbar { grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 10px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 30; min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 0; }
.logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: linear-gradient(135deg, #0891b2, #22d3ee 60%, #f59e0b); font-size: 20px; color: #04121a; flex-shrink: 0; box-shadow: 0 4px 14px rgba(34,211,238,.3); }
.scene-title { background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 5px 8px; font-weight: 600; min-width: 60px; width: 100%; max-width: 280px; text-overflow: ellipsis; }
.scene-title:hover, .scene-title:focus { border-color: var(--border2); background: var(--surface2); outline: none; }
.simctl { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.right { display: flex; align-items: center; gap: 4px; flex: 1 1 0; justify-content: flex-end; }
.divider { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--muted); transition: background .15s, color .15s; flex-shrink: 0; }
.icon-btn:hover:not(:disabled) { background: var(--surface3); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.danger:hover { color: #fff; background: var(--err); }
.icon-btn.active { color: #fff; background: var(--accent); }
.play-btn { height: 38px; padding: 0 16px 0 12px; border-radius: 11px; display: inline-flex; align-items: center; gap: 6px; background: var(--ok); color: #04130d; font-weight: 700; box-shadow: 0 4px 14px rgba(16,185,129,.3); transition: transform .1s, background .15s; }
.play-btn:active { transform: scale(.96); }
.play-btn.playing { background: var(--warn); box-shadow: 0 4px 14px rgba(245,158,11,.3); }
.sim-time { font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 86px; text-align: center; }
.inp { background: var(--surface2); border: 1px solid var(--border2); border-radius: 9px; padding: 7px 10px; width: 100%; color: var(--text); min-height: 34px; }
.inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.inp.sm { padding: 4px 8px; min-height: 30px; width: auto; font-size: 12px; }
select.inp { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b97b0' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 28px; }
textarea.inp { resize: vertical; min-height: 70px; line-height: 1.45; }
textarea.code { font-family: var(--mono); font-size: 12px; }
.rec-badge { display: none; color: #fff; background: var(--err); font-weight: 700; font-size: 11px; padding: 4px 8px; border-radius: 999px; animation: blink 1s infinite; cursor: pointer; }
.app.recording .rec-badge { display: inline-block; }
@keyframes blink { 50% { opacity: .5; } }
.show-sm { display: none; }

/* ═════════════ Trilho de categorias ═════════════ */
.rail { grid-area: rail; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 6px; overflow-y: auto; scrollbar-width: none; z-index: 25; }
.rail::-webkit-scrollbar { display: none; }
.rail-btn { width: 64px; min-height: 56px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); transition: background .15s, color .15s; flex-shrink: 0; padding: 4px 2px; }
.rail-btn:hover { background: var(--surface2); color: var(--text); }
.rail-btn.active { background: var(--accent-soft); color: #fff; box-shadow: inset 0 0 0 1px rgba(103,232,249,.45); }
.rail-btn .rl { font-size: 10px; font-weight: 600; letter-spacing: .01em; line-height: 1.1; text-align: center; max-width: 62px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ═════════════ Painéis ═════════════ */
.panel { background: var(--surface); display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; z-index: 20; }
.tools { grid-area: tools; border-right: 1px solid var(--border); }
.props { grid-area: props; border-left: 1px solid var(--border); }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--border); min-height: 48px; flex-shrink: 0; }
.panel-head b { flex: 1; font-size: 13px; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-grip { display: none; }
.panel-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 0 24px; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--border2) transparent; }
.sec-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); padding: 14px 14px 6px; display: flex; align-items: center; gap: 6px; }
.sec-title small { margin-left: auto; font-weight: 600; color: var(--dim); }
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; padding: 0 10px; }
.tool-btn { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 5px; padding: 10px 4px 8px; border-radius: 11px; background: var(--surface2); border: 1px solid transparent; color: var(--text); min-height: 72px; transition: border-color .15s, background .15s, transform .08s; }
.tool-btn span:not(.emo) { font-size: 11px; line-height: 1.2; text-align: center; color: var(--muted); }
.tool-btn:hover { border-color: var(--border2); background: var(--surface3); }
.tool-btn:active { transform: scale(.97); }
.tool-btn.active { border-color: var(--accent); background: var(--accent-soft); }
.tool-btn.active span:not(.emo) { color: var(--text); }
.tool-btn kbd { position: absolute; top: 4px; right: 4px; padding: 0 4px; font-size: 9px; opacity: .7; }
.tool-btn .ico { color: var(--accent2); margin: 2px 0; }
.empty { color: var(--muted); text-align: center; padding: 24px 16px; line-height: 1.6; font-size: 13px; }
.ext-head { padding: 12px; display: grid; gap: 8px; }

/* Lista de experimentos */
.exp-list { padding: 8px 10px; }
.search { margin-bottom: 4px; }
.exp-group .sec-title { padding-left: 4px; }
.exp-card { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; padding: 9px 10px; border-radius: 11px; margin-bottom: 4px; background: var(--surface2); border: 1px solid transparent; transition: border-color .15s, background .15s; }
.exp-card:hover { border-color: var(--border2); background: var(--surface3); }
.exp-card.active { border-color: var(--accent); background: var(--accent-soft); }
.exp-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.exp-txt b { font-size: 13px; font-weight: 600; }
.exp-txt small { font-size: 11.5px; color: var(--muted); line-height: 1.3; }

/* Caneta */
.pen-box { padding: 10px 14px 4px; display: grid; gap: 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sw { width: 26px; height: 26px; border-radius: 50%; background: var(--c); border: 2px solid var(--surface3); box-shadow: 0 0 0 1px var(--border2); }
.sw.on { box-shadow: 0 0 0 2px var(--accent2); }
.sw-pick { width: 30px; height: 30px; border: 0; background: none; padding: 0; cursor: pointer; }
.row { display: grid; grid-template-columns: 72px 1fr 36px; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.row b { font-weight: 600; color: var(--text); text-align: right; font-size: 12px; }

/* Menu Arquivo */
.menu-list { padding: 8px; display: grid; gap: 2px; }
.menu-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; text-align: left; color: var(--text); }
.menu-item:hover { background: var(--surface2); }
.menu-item .ico { color: var(--accent2); }

/* ═════════════ Propriedades ═════════════ */
.phead { display: flex; align-items: center; gap: 10px; padding: 10px 12px 12px 14px; border-bottom: 1px solid var(--border); }
.pname { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.pname b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pname small { color: var(--dim); font-family: var(--mono); font-size: 11px; }
.pacts { display: flex; gap: 2px; }
.psec { border-bottom: 1px solid var(--border); }
.psec > summary { list-style: none; cursor: pointer; padding: 12px 14px; font-size: 12px; font-weight: 700; letter-spacing: .03em; color: var(--muted); display: flex; align-items: center; gap: 6px; user-select: none; }
.psec > summary::-webkit-details-marker { display: none; }
.psec > summary::after { content: ''; margin-left: auto; width: 7px; height: 7px; border-right: 2px solid var(--dim); border-bottom: 2px solid var(--dim); transform: rotate(-45deg); transition: transform .15s; }
.psec[open] > summary::after { transform: rotate(45deg); }
.psec-body { padding: 0 14px 14px; display: grid; gap: 10px; }
.f { display: grid; gap: 5px; }
.f .lbl { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.f .unit { color: var(--dim); font-family: var(--mono); font-size: 11px; }
.f.inline { grid-template-columns: 1fr auto; align-items: center; }
.f.check { display: flex; align-items: center; gap: 9px; font-size: 13px; cursor: pointer; padding: 2px 0; }
.f.check input, .check input { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.check { display: flex; align-items: center; gap: 9px; font-size: 12.5px; cursor: pointer; }
.range-row { display: grid; grid-template-columns: 1fr 72px; gap: 8px; align-items: center; }
.inp.mini { padding: 5px 7px; min-height: 30px; font-size: 12px; text-align: right; font-family: var(--mono); }
input[type=range] { width: 100%; accent-color: var(--accent); height: 24px; }
.color { width: 44px; height: 30px; border: 1px solid var(--border2); border-radius: 8px; background: var(--surface2); padding: 2px; cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 14px; border-radius: 10px; background: var(--surface3); border: 1px solid var(--border2); color: var(--text); font-weight: 600; font-size: 13px; transition: background .15s, border-color .15s; min-height: 38px; }
.btn:hover { background: #26324a; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #5458e6; }
.btn.danger { background: transparent; border-color: rgba(239,68,68,.5); color: #fca5a5; }
.btn.danger:hover { background: var(--err); color: #fff; }
.btn.block { width: 100%; }
.btn.sm { padding: 5px 10px; min-height: 30px; font-size: 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 10px; border-radius: 999px; font-size: 12px; background: var(--surface2); border: 1px solid var(--border2); color: var(--muted); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: #fff; }
.kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.kv td { padding: 6px 0; border-bottom: 1px dashed var(--border); vertical-align: top; }
.kv td:first-child { color: var(--muted); padding-right: 10px; }
.kv td:last-child { text-align: right; font-family: var(--mono); font-size: 12px; }
.readout .kv td:last-child { color: #c7d2fe; }
.scene-intro { padding: 12px 14px 4px; }

/* ═════════════ Palco ═════════════ */
.stage { grid-area: stage; position: relative; overflow: hidden; min-width: 0; min-height: 0; background: #e9eef5; touch-action: none; user-select: none; -webkit-user-select: none; }
html[data-canvas=dark] .stage, html[data-canvas=board] .stage { background: #070b14; }
#cv { position: absolute; inset: 0; display: block; touch-action: none; }
.stage[data-tool=pan] { cursor: grab; }
.stage[data-tool=create], .stage[data-tool=joint] { cursor: crosshair; }
.stage[data-tool=draw] { cursor: crosshair; }
.stage[data-tool=erase] { cursor: cell; }
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.math-label { position: absolute; left: 0; top: 0; transform-origin: 0 0; white-space: nowrap; line-height: 1.25; pointer-events: none; }
.math-label .katex { font-size: 1em; }
.quickbar { position: absolute; left: 12px; top: 12px; display: flex; gap: 4px; background: rgba(17,24,39,.88); backdrop-filter: blur(8px); border: 1px solid var(--border); border-radius: 12px; padding: 4px; z-index: 5; }
.quickbar button { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--muted); }
.quickbar button.active { background: var(--accent); color: #fff; }
.zoomctl { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; background: rgba(17,24,39,.88); backdrop-filter: blur(8px); border: 1px solid var(--border); border-radius: 12px; padding: 4px; z-index: 5; }
.hint { position: absolute; left: 50%; bottom: 14px; transform: translate(-50%, 10px); max-width: min(620px, calc(100% - 140px)); background: rgba(15,23,42,.92); color: #e2e8f0; padding: 8px 14px; border-radius: 10px; font-size: 12.5px; line-height: 1.4; text-align: center; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 6; border: 1px solid var(--border); }
.hint.show { opacity: 1; transform: translate(-50%, 0); }
.coords { position: absolute; right: 64px; bottom: 16px; font-family: var(--mono); font-size: 11px; color: #64748b; pointer-events: none; z-index: 4; background: rgba(255,255,255,.6); padding: 2px 6px; border-radius: 6px; }
html[data-canvas=dark] .coords, html[data-canvas=board] .coords { background: rgba(0,0,0,.35); color: #94a3b8; }
.drop-hint { position: absolute; inset: 14px; border: 2px dashed var(--accent2); border-radius: 16px; display: none; place-items: center; background: rgba(34,211,238,.12); color: #fff; font-weight: 600; z-index: 9; pointer-events: none; }
.stage.drop .drop-hint { display: grid; }
.app.is-playing .quickbar { opacity: .85; }

/* Cartão de teoria */
.info-card { position: absolute; left: 12px; top: 60px; width: min(400px, calc(100% - 90px)); max-height: calc(100% - 140px); background: rgba(17,24,39,.94); backdrop-filter: blur(10px); border: 1px solid var(--border2); border-radius: 14px; box-shadow: var(--shadow); display: none; flex-direction: column; z-index: 7; overflow: hidden; }
.info-card.show { display: flex; }
.info-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 12px; border-bottom: 1px solid var(--border); }
.info-head b { flex: 1; font-size: 13.5px; cursor: pointer; }
.info-body { padding: 12px 14px 14px; overflow-y: auto; font-size: 13px; line-height: 1.6; color: #cbd5e1; }
.info-body h4 { font-size: 12px; margin: 12px 0 4px; color: var(--text); }
.info-body ul { padding-left: 18px; display: grid; gap: 3px; }
.info-body .katex { color: #fff; }
.info-card.min .info-body { display: none; }
.info-card.min .info-head { border-bottom: 0; }
.info-card.min [data-min] .ico { transform: rotate(180deg); }
code.tex { background: rgba(34,211,238,.18); color: #c7d2fe; }

/* ═════════════ Gráfico ═════════════ */
.graph { position: fixed; right: calc(var(--props) + 16px); bottom: 16px; width: min(500px, calc(100vw - 32px)); height: 270px; min-width: 300px; min-height: 200px; background: var(--surface); border: 1px solid var(--border2); border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; z-index: 40; resize: both; overflow: hidden; }
.app:not(.props-open) .graph { right: 16px; }
.graph.hidden { display: none; }
.g-head { padding: 8px 8px 6px 12px; border-bottom: 1px solid var(--border); cursor: move; display: grid; gap: 6px; touch-action: none; }
.g-row { display: flex; align-items: center; gap: 8px; }
.g-title { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.g-sp { flex: 1; }
.g-row select { max-width: 180px; }
.g-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.g-chips .chip { padding: 3px 9px; font-size: 11.5px; }
.g-chips .chip.on { background: color-mix(in srgb, var(--qc) 22%, transparent); border-color: var(--qc); }
.g-body { flex: 1; position: relative; min-height: 0; }
#graphCanvas { position: absolute; inset: 0; display: block; touch-action: none; }

/* ═════════════ Modais, toasts e menus ═════════════ */
.modal-back { position: fixed; inset: 0; background: rgba(3,6,14,.62); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 100; opacity: 0; transition: opacity .18s; padding: 16px; }
.modal-back.show { opacity: 1; }
.modal { width: min(460px, 100%); max-height: min(86vh, 100%); background: var(--surface); border: 1px solid var(--border2); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; transform: translateY(8px) scale(.98); transition: transform .18s; }
.modal.wide { width: min(780px, 100%); }
.modal-back.show .modal { transform: none; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 12px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { flex: 1; font-size: 16px; }
.modal-body { padding: 16px 18px; overflow-y: auto; line-height: 1.55; display: grid; gap: 10px; }
.modal-body ul { padding-left: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.lead { font-size: 14.5px; color: var(--text); }
.welcome-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.welcome-grid > div { background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 4px; }
.welcome-grid small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.toasts { position: fixed; top: calc(var(--top) + 10px); left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 200; pointer-events: none; width: min(440px, calc(100vw - 24px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; background: #1b2438; border: 1px solid var(--border2); box-shadow: var(--shadow); font-size: 13px; opacity: 0; transform: translateY(-8px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: none; }
.toast.ok .ico { color: var(--ok); } .toast.warn .ico { color: var(--warn); } .toast.error { border-color: rgba(239,68,68,.6); } .toast.error .ico { color: var(--err); } .toast.info .ico { color: var(--accent2); }
.ctxmenu { position: fixed; min-width: 220px; background: var(--surface); border: 1px solid var(--border2); border-radius: 12px; box-shadow: var(--shadow); padding: 5px; z-index: 150; display: grid; }
.ctxmenu button { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; text-align: left; font-size: 13px; }
.ctxmenu button span:nth-child(2) { flex: 1; }
.ctxmenu button:hover:not(:disabled) { background: var(--surface3); }
.ctxmenu button.danger { color: #fca5a5; }
.ctxmenu .ico { color: var(--muted); }
.ctxmenu .sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* Gerenciador de extensões */
.extmgr { display: grid; gap: 18px; }
.extmgr h4 { font-size: 13px; margin-bottom: 8px; }
.extmgr section { display: grid; gap: 10px; }
.ext-list { display: grid; gap: 8px; }
.ext-card { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; background: var(--surface2); border: 1px solid var(--border); }
.ext-card.err { border-color: rgba(239,68,68,.6); }
.ext-main { flex: 1; min-width: 0; }
.ext-main p { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.ext-main small { color: var(--dim); }
.errmsg { color: #fca5a5 !important; font-size: 12px; }
.ext-acts { display: flex; gap: 4px; align-items: center; }
.ext-example { background: linear-gradient(135deg, rgba(34,211,238,.14), rgba(168,85,247,.1)); border: 1px solid rgba(103,232,249,.35); border-radius: 14px; padding: 14px; }
.ext-example .btn-row { padding: 0; }
.inline-row { display: flex; gap: 8px; }
.gh-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 12px; }
.switch { position: relative; width: 38px; height: 22px; display: inline-block; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface3); border: 1px solid var(--border2); transition: background .15s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #cbd5e1; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); background: #fff; }
details > summary { cursor: pointer; }
.docs { font-size: 13px; line-height: 1.6; }
.docs h2 { font-size: 18px; margin: 6px 0; } .docs h3 { font-size: 15px; margin: 14px 0 4px; } .docs h4 { font-size: 13px; margin: 10px 0 2px; }
.docs pre { background: #0a0f1c; border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow-x: auto; font-size: 12px; line-height: 1.5; }
.docs pre code { background: none; padding: 0; }
.docs ul { padding-left: 20px; }

/* ═════════════ Tablet: gavetas sobre o palco ═════════════ */
@media (max-width: 1180px) and (min-width: 761px) {
    .app, .app.tools-open, .app.props-open, .app.tools-open.props-open { grid-template-columns: var(--rail) 0 minmax(0, 1fr) 0; }
    .tools, .props { position: fixed; top: var(--top); bottom: 0; width: min(var(--tools), 80vw); box-shadow: var(--shadow); transition: transform .22s ease; }
    .tools { left: var(--rail); transform: translateX(calc(-100% - var(--rail))); }
    .props { right: 0; width: min(var(--props), 86vw); transform: translateX(105%); }
    .app.tools-open .tools, .app.props-open .props { transform: none; }
    .graph, .app:not(.props-open) .graph { right: 16px; }
}

/* ═════════════ Celular (retrato): navegação inferior + folhas ═════════════ */
@media (max-width: 760px) {
    :root { --top: 52px; --nav: 62px; }
    .app, .app.tools-open, .app.props-open, .app.tools-open.props-open {
        grid-template-rows: var(--top) minmax(0, 1fr) calc(var(--nav) + var(--safe-b));
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "top" "stage" "rail";
    }
    .topbar { padding: 0 6px; gap: 4px; }
    .brand { flex: 0 1 auto; }
    .scene-title { display: none; }
    .logo { width: 32px; height: 32px; }
    .right { flex: 0 0 auto; gap: 0; }
    .simctl { flex: 1; justify-content: center; }
    .hide-sm { display: none !important; }
    .show-sm { display: inline-grid; }
    .play-btn { padding: 0 12px 0 10px; }
    .sim-time { min-width: 72px; font-size: 11px; }
    .rail { flex-direction: row; border-right: 0; border-top: 1px solid var(--border); padding: 4px 6px var(--safe-b); overflow-x: auto; overflow-y: hidden; gap: 2px; align-items: stretch; }
    .rail-btn { width: 66px; min-height: 52px; }
    .tools, .props {
        position: fixed; left: 0; right: 0; bottom: calc(var(--nav) + var(--safe-b)); top: auto; width: auto;
        max-height: min(64dvh, 560px); height: auto; border: 0; border-top: 1px solid var(--border2);
        border-radius: 18px 18px 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,.5); transform: translateY(105%); transition: transform .24s ease; z-index: 35;
    }
    .props { max-height: min(72dvh, 620px); }
    .app.tools-open .tools, .app.props-open .props { transform: none; }
    .panel-head { position: relative; padding-top: 16px; touch-action: none; }
    .sheet-grip { display: block; position: absolute; top: 6px; left: 50%; transform: translateX(-50%); width: 40px; height: 4px; border-radius: 4px; background: var(--border2); }
    .tool-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
    .info-card { top: 56px; left: 8px; width: calc(100% - 16px); max-height: 45%; }
    .quickbar { left: 8px; top: 8px; }
    .zoomctl { right: 8px; bottom: 8px; flex-direction: row; }
    .zoomctl .icon-btn { width: 34px; height: 34px; }
    .coords { display: none; }
    .hint { bottom: 58px; max-width: calc(100% - 24px); font-size: 12px; }
    .graph { left: 0; right: 0 !important; bottom: calc(var(--nav) + var(--safe-b)); width: 100%; height: 40dvh; min-width: 0; border-radius: 16px 16px 0 0; resize: none; z-index: 33; }
    .modal-back { place-items: end center; padding: 0; }
    .modal, .modal.wide { width: 100%; max-height: 92dvh; border-radius: 18px 18px 0 0; }
    .welcome-grid { grid-template-columns: 1fr; }
    .ctxmenu { min-width: 200px; }
}
@media (max-width: 400px) { .hide-xs { display: none !important; } .rail-btn { width: 60px; } .rail-btn .rl { font-size: 9.5px; } }

/* ═════════════ Celular deitado / telas baixas ═════════════ */
@media (max-height: 520px) and (min-width: 561px) {
    :root { --top: 44px; --rail: 60px; --tools: 250px; --props: 290px; }
    .app, .app.tools-open, .app.props-open, .app.tools-open.props-open {
        grid-template-rows: var(--top) minmax(0, 1fr); grid-template-columns: var(--rail) 0 minmax(0, 1fr) 0; grid-template-areas: "top top top top" "rail tools stage props";
    }
    .rail { flex-direction: column; border-top: 0; border-right: 1px solid var(--border); padding: 4px; }
    .rail-btn { width: 52px; min-height: 46px; } .rail-btn .rl { display: none; }
    .tools, .props { position: fixed; top: var(--top); bottom: 0; left: auto; right: auto; width: var(--tools); max-height: none; border-radius: 0; transition: transform .22s ease; z-index: 35; }
    .tools { left: var(--rail); transform: translateX(calc(-100% - var(--rail))); }
    .props { right: 0; width: var(--props); transform: translateX(105%); }
    .app.tools-open .tools, .app.props-open .props { transform: none; }
    .sheet-grip { display: none; } .panel-head { padding-top: 8px; min-height: 40px; }
    .info-card { top: 52px; max-height: calc(100% - 64px); width: min(340px, 50%); }
    .graph { height: 60dvh; width: min(480px, 60vw); left: auto; right: 12px !important; bottom: 12px; border-radius: 14px; }
    .modal-back { place-items: center; padding: 8px; }
    .modal, .modal.wide { border-radius: 14px; max-height: 94dvh; }
    .play-btn span { display: none; } .play-btn { padding: 0 10px; }
}

/* Painéis sobrepostos fechados não capturam toques */
@media (max-width: 1180px), (max-height: 520px) and (min-width: 561px) {
    .tools, .props { visibility: hidden; transition: transform .24s ease, visibility 0s linear .24s; }
    .app.tools-open .tools, .app.props-open .props { visibility: visible; transition: transform .24s ease, visibility 0s; }
}
@media (min-width: 1181px) and (min-height: 521px) {
    .app:not(.tools-open) .tools, .app:not(.props-open) .props { visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ═════════════ v4: ícones Material, conta, banners, premium ═════════════ */
.exp-ic, .ext-ic, .phead-ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface3); color: var(--accent2); flex-shrink: 0; }
.exp-card.active .exp-ic { background: var(--accent); color: #04121a; }
.exp-card { position: relative; }
.exp-card.locked { opacity: .78; }
.exp-card.locked .exp-ic { color: var(--amber); }
.badge-prem { display: inline-flex; align-items: center; gap: 3px; padding: 2px 6px; border-radius: 999px; background: rgba(245,158,11,.16); color: var(--amber); font-size: 10px; font-weight: 700; letter-spacing: .02em; flex-shrink: 0; }
.search-wrap { position: relative; margin-bottom: 6px; }
.search-wrap .mi { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--dim); pointer-events: none; }
.search-wrap .inp { padding-left: 36px; width: 100%; }
.account-btn { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px 0 10px; border-radius: 999px; border: 1px solid var(--border2); background: var(--surface2); color: var(--text); font-weight: 600; font-size: 13px; cursor: pointer; }
.account-btn:hover { background: var(--surface3); }
.account-btn.user { padding: 0 4px; border-radius: 999px; gap: 4px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; display: grid; place-items: center; background: var(--accent); color: #04121a; font-weight: 700; font-size: 13px; }
.menu-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--border); margin-bottom: 4px; display: flex; gap: 10px; align-items: center; }
.menu-head b { display: block; font-size: 13px; } .menu-head small { color: var(--muted); font-size: 11px; word-break: break-all; }
.menu-item.active { color: var(--accent2); }
.banner { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--safe-b)); z-index: 60; display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 24px)); padding: 10px 10px 10px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border2); box-shadow: var(--shadow); }
.banner .mi { color: var(--accent2); }
.banner-txt { flex: 1; font-size: 13px; line-height: 1.35; }
.banner-acts { display: flex; gap: 6px; flex-shrink: 0; }
.prem-hero { text-align: center; padding: 8px 4px 2px; }
.prem-hero .mi { font-size: 44px; color: var(--amber); font-variation-settings: 'FILL' 1; }
.admin-tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.admin-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.admin-row .grow { flex: 1; min-width: 0; } .admin-row .grow b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .admin-row .grow small { color: var(--muted); font-size: 11px; }
.seg { display: inline-flex; border: 1px solid var(--border2); border-radius: 999px; overflow: hidden; flex-shrink: 0; }
.seg button { padding: 5px 10px; font-size: 12px; font-weight: 600; background: transparent; color: var(--muted); border: 0; cursor: pointer; }
.seg button.on.free { background: rgba(16,185,129,.18); color: #34d399; }
.seg button.on.prem { background: rgba(245,158,11,.2); color: var(--amber); }
.admin-list { max-height: min(56vh, 520px); overflow: auto; }
.admin-stats { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.admin-stats span { background: var(--surface2); border: 1px solid var(--border); padding: 4px 10px; border-radius: 999px; font-size: 12px; color: var(--muted); }
.cloud-proj { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.cloud-proj:hover { background: var(--surface2); }
.cloud-proj .grow { flex: 1; min-width: 0; } .cloud-proj b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cloud-proj small { color: var(--muted); font-size: 11px; }
.lang-flag { font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .04em; }
.welcome-grid .mi { font-size: 28px; color: var(--accent2); margin-bottom: 6px; }
.lang-btn { width: auto !important; padding: 0 8px; gap: 4px; display: inline-flex; align-items: center; font-family: var(--mono); font-size: 11px; font-weight: 600; }
.account-btn img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.account-btn:not(.signin) { padding: 0 4px; }
.logo { text-decoration: none; }
.logo .mi { font-size: 22px; }
.ext-active { padding: 4px 10px 10px; }
.ext-mini { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; background: var(--surface2); margin-bottom: 4px; font-size: 13px; }
.ext-mini .mi { color: var(--accent2); }
.admin-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.admin-tools .search-wrap { flex: 1 1 220px; margin: 0; }
.admin-tools .btn { flex: 0 0 auto; white-space: nowrap; }
