:root { color-scheme: light dark; }
body { margin: 0; }
img { max-width: 100%; }
[hidden] { display: none !important; }

:root {
  --ground: #F0EFEA; --panel: #FAFAF7; --panel-2: #F1F0EB; --line: #D8D7CF; --track: #D3D2CA;
  --ink: #1C2220; --muted: #6A7370;
  --accent: #2F7E6B; --accent-ink: #FFFFFF; --accent-soft: #DCEDE6;
  --ok: #3C9A5E; --warn: #CF9A2A; --bad: #CF5438;
  --stage: #E7E6DF; --plate: #DAD9D1; --grid: #C6C5BC; --vol: #9B9A91;
  --hud: rgba(250, 250, 247, 0.82);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #131817; --panel: #1A201F; --panel-2: #202826; --line: #2B3432; --track: #303B38;
    --ink: #E5E8E4; --muted: #8C9793;
    --accent: #6DC3A7; --accent-ink: #0E1B17; --accent-soft: #1E3630;
    --ok: #58B67B; --warn: #E0AE47; --bad: #E36A4E;
    --stage: #171D1C; --plate: #1F2625; --grid: #2C3634; --vol: #4A5652;
    --hud: rgba(26, 32, 31, 0.82);
  }
}
:root[data-theme="dark"] {
  --ground: #131817; --panel: #1A201F; --panel-2: #202826; --line: #2B3432; --track: #303B38;
  --ink: #E5E8E4; --muted: #8C9793;
  --accent: #6DC3A7; --accent-ink: #0E1B17; --accent-soft: #1E3630;
  --ok: #58B67B; --warn: #E0AE47; --bad: #E36A4E;
  --stage: #171D1C; --plate: #1F2625; --grid: #2C3634; --vol: #4A5652;
  --hud: rgba(26, 32, 31, 0.82);
}
html, body { height: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 14px; line-height: 1.4;
  overflow: hidden;
}
* { box-sizing: border-box; }
button, input, select, textarea { font: inherit; color: inherit; }
.app { display: flex; flex-direction: column; height: 100%; }

header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap;
  padding-block: 10px; padding-inline: 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand .name { font-family: 'Bricolage Grotesque', 'IBM Plex Sans', system-ui, sans-serif; font-weight: 700; font-size: 22px; letter-spacing: -0.02em; }
.brand .tag { color: var(--muted); font-size: 12.5px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sel { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
select, input[type=number], input[type=text], textarea {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; color: var(--ink);
}
select { padding-right: 24px; }
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; cursor: pointer;
  font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary:disabled { opacity: 0.6; cursor: progress; }
.btn.ghost { background: transparent; }
.btn:focus-visible, .chip:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main { display: flex; flex: 1; min-height: 0; }
aside {
  width: 340px; flex: none; overflow-y: auto; overflow-x: hidden; border-right: 1px solid var(--line); background: var(--panel);
  padding-block: 8px 28px; padding-inline: 16px;
}
.stage { flex: 1; min-width: 0; position: relative; background: var(--stage); display: flex; }
.view { position: relative; flex: 1 1 0; min-width: 0; }
.view canvas { display: block; }

/* editor de silhueta */
.editor { flex: 1.15 1 0; min-width: 0; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
.ed-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding-block: 10px; padding-inline: 12px; border-bottom: 1px solid var(--line); }
.ed-title { display: flex; align-items: baseline; gap: 8px; }
.ed-title b { font-family: 'Bricolage Grotesque', 'IBM Plex Sans', system-ui, sans-serif; font-size: 16px; font-weight: 600; }
.ed-title span { color: var(--muted); font-size: 12.5px; }
.ed-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ed-sep { width: 1px; height: 22px; background: var(--line); }
.btn.icon { min-width: 30px; padding-inline: 0; text-align: center; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:disabled:hover { border-color: var(--line); }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.ed-canvas { flex: 1; min-height: 0; position: relative; background: var(--stage); }
.ed-canvas svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
.ed-canvas svg.panning { cursor: grabbing; }
.ed-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding-block: 8px 10px; padding-inline: 12px; border-top: 1px solid var(--line); }
.ed-point { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 12.5px; color: var(--muted); }
.ed-point b { color: var(--ink); font-weight: 600; }
.ed-point label { display: flex; align-items: center; gap: 6px; }
.ed-point input { width: 76px; padding: 3px 6px; text-align: right; font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.ed-point input:disabled { opacity: 0.5; }
.ed-actions { display: flex; gap: 6px; }
.ed-help { flex-basis: 100%; margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.only-phone { display: none; }
.back-ed { display: none; }
.stage.editing.peek .back-ed { display: inline-block; }
.eg-minor, .eg-major, .eg-plate, .eg-axis, .eg-limit, .eg-mirror, .eg-ok, .eg-warn, .eg-bad { fill: none; vector-effect: non-scaling-stroke; }
.eg-minor { stroke: var(--grid); stroke-width: 1; opacity: 0.45; }
.eg-major { stroke: var(--grid); stroke-width: 1; }
.eg-plate { stroke: var(--muted); stroke-width: 1.5; }
.eg-axis { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.eg-limit { stroke: var(--bad); stroke-width: 1; stroke-dasharray: 6 4; opacity: 0.8; }
.eg-ghost { fill: var(--accent-soft); opacity: 0.85; }
.eg-mirror { stroke: var(--accent); stroke-width: 1.5; opacity: 0.35; }
.eg-ok, .eg-warn, .eg-bad { stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.eg-ok { stroke: var(--ok); }
.eg-warn { stroke: var(--warn); }
.eg-bad { stroke: var(--bad); }
.eg-label { fill: var(--muted); font-family: 'IBM Plex Mono', ui-monospace, monospace; }
.eg-tag { fill: var(--ink); font-family: 'IBM Plex Mono', ui-monospace, monospace; paint-order: stroke; stroke: var(--stage); stroke-linejoin: round; }
.eh-hit { fill: transparent; }
.eh { fill: var(--panel); stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.eh-g { cursor: move; }
.eh-g.sel .eh { fill: var(--accent); }
.eh-g:focus { outline: none; }
.eh-g:focus-visible .eh { stroke: var(--ink); stroke-width: 3; }

/* silhueta */
.profile { display: flex; gap: 12px; align-items: center; padding-block: 6px 4px; }
.profile svg { width: 120px; height: 140px; flex: none; cursor: pointer; border-radius: 8px; }
.profile svg:hover { background: var(--panel-2); }
.profile svg:focus { outline: none; }
.profile svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pcol { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; min-width: 0; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.pinfo { border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); padding: 10px 12px; margin-block: 2px 12px; font-size: 12.5px; }
.pinfo h3 { margin: 0; font-family: 'Bricolage Grotesque', 'IBM Plex Sans', system-ui, sans-serif; font-size: 15px; font-weight: 600; }
.pinfo .where { color: var(--muted); margin: 1px 0 6px; }
.pinfo p { margin: 0 0 6px; line-height: 1.45; }
.pinfo ul { margin: 0; padding-left: 16px; }
.pinfo li + li { margin-top: 2px; }
.pinfo a { color: var(--accent); }
.pinfo .note { color: var(--muted); font-size: 11.5px; margin-top: 8px; line-height: 1.4; }
.profile .fill { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.profile .axis { stroke: var(--line); stroke-dasharray: 3 3; }
.profile .about { font-size: 12.5px; color: var(--muted); }
.profile .about b { color: var(--ink); font-weight: 600; }

/* presets salvos */
.saverow { display: flex; gap: 6px; padding-block: 6px 10px; }
.saverow input { flex: 1; min-width: 0; }

.manage { display: flex; flex-direction: column; gap: 6px; padding-block: 0 12px; }
.mline { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
details { border-top: 1px solid var(--line); }
details:last-of-type { border-bottom: 1px solid var(--line); }
summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between;
  padding-block: 10px; font-family: 'Bricolage Grotesque', 'IBM Plex Sans', system-ui, sans-serif; font-weight: 600; font-size: 15px;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: ''; width: 8px; height: 8px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; }
details[open] summary::after { transform: rotate(45deg); }
.group { padding-block: 0 10px; display: flex; flex-direction: column; gap: 2px; }
.help { font-size: 12px; color: var(--muted); padding-block: 2px 6px; }

.row { display: grid; grid-template-columns: 1fr 74px; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding-block: 3px; }
.row label { font-size: 12.5px; color: var(--muted); grid-column: 1; grid-row: 1; }
.row input[type=number] { grid-column: 2; grid-row: 1; width: 100%; text-align: right; padding: 3px 6px; font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.row input[type=range] { grid-column: 1 / span 2; grid-row: 2; }
.row .hint { grid-column: 1 / span 2; grid-row: 3; font-size: 11.5px; color: var(--muted); }
.row.single { grid-template-rows: auto; }
.row .unit { color: var(--muted); font-size: 11px; margin-left: 4px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; margin: 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--track); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); margin-top: -6px; box-shadow: 0 0 0 1px var(--line); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--track); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--panel); }
input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
input[type=color] { width: 40px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); cursor: pointer; }

.switch { grid-column: 2; grid-row: 1; justify-self: end; width: 40px; height: 22px; border-radius: 11px; background: var(--track); border: 0; position: relative; cursor: pointer; padding: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--panel); transition: left .15s; }
.switch[aria-pressed="true"] { background: var(--accent); }
.switch[aria-pressed="true"]::after { left: 21px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-block: 4px 6px; }
.seg button { flex: 1; background: var(--panel-2); border: 0; padding: 7px 8px; cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.hud { position: absolute; left: 12px; right: 12px; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud.top { top: 12px; justify-content: flex-end; }
.hud.bottom { bottom: 12px; align-items: center; }
.chip {
  background: var(--hud); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px;
  font-size: 12.5px; cursor: pointer; color: var(--ink);
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.stat, .pill {
  background: var(--hud); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px;
  font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.stat b { font-weight: 600; }
.stat.dim { color: var(--muted); }
.pill { font-weight: 600; }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 55%, transparent); }
.toast {
  z-index: 5; position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%); max-width: min(92%, 460px);
  background: var(--ink); color: var(--ground); padding: 9px 14px; border-radius: 8px; font-size: 13px; text-align: center;
  box-shadow: 0 6px 24px rgba(0,0,0,0.2);
}
.legend { display: none; position: absolute; right: 12px; top: 52px; background: var(--hud); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 11.5px; color: var(--muted); }
.legend .bar { height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--ok), var(--warn), var(--bad)); margin-block: 4px; }
.legend .ends { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.stage.heat .legend { display: block; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 20px; width: min(92vw, 520px); }
dialog::backdrop { background: rgba(0,0,0,0.35); }
dialog h2 { margin: 0 0 6px; font-family: 'Bricolage Grotesque', 'IBM Plex Sans', system-ui, sans-serif; font-size: 18px; }
dialog p { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
dialog textarea { width: 100%; font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 12px; resize: vertical; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }

@media (max-width: 760px) {
  main { flex-direction: column; }
  .stage { flex: none; height: 46vh; order: -1; }
  .stage.editing { height: 76vh; }
  .stage.editing .view { display: none; }
  .stage.editing.peek .view { display: block; }
  .stage.editing.peek .editor { display: none; }
  .ed-help { display: none; }
  .only-phone { display: inline-block; }
  aside { width: auto; flex: 1; min-height: 0; border-right: 0; border-top: 1px solid var(--line); }
  .brand { gap: 2px 10px; }
  .hud.bottom { bottom: 8px; gap: 4px; }
  .stat, .pill, .chip { font-size: 11.5px; padding: 4px 9px; }
  .stat.dim, .legend { display: none; }
  .sel { font-size: 0; gap: 0; }
  .sel select { font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  summary::after, .switch::after { transition: none; }
}
