:root {
  --bg: #eef0f3;
  --surface: #ffffff;
  --surface-2: #f2f4f6;
  --border: #d9dde3;
  --text: #1c2025;
  --muted: #69717c;
  --accent: #0b6bcb;
  --accent-soft: #0b6bcb1f;
  --canvas: #e4e7eb;
  --paper: #ffffff;
  --paper-edge: #9aa3ad;
  --grid: #0b6bcb22;
  --ink: #1c2025;
  --sel: #0b6bcb;
  --hover: #e8590c;
  --snap: #e8590c;
  --preview: #0b6bcb;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317; --surface: #181b20; --surface-2: #20242a; --border: #2c3138;
    --text: #e6e8eb; --muted: #959ca6; --accent: #4ea1ff; --accent-soft: #4ea1ff26;
    --canvas: #0c0e11; --paper: #1b1f25; --paper-edge: #4a525c; --grid: #4ea1ff22; --ink: #e6e8eb;
    --sel: #4ea1ff; --hover: #ff8b3e; --snap: #ffb224; --preview: #4ea1ff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --surface: #181b20; --surface-2: #20242a; --border: #2c3138;
  --text: #e6e8eb; --muted: #959ca6; --accent: #4ea1ff; --accent-soft: #4ea1ff26;
  --canvas: #0c0e11; --paper: #1b1f25; --paper-edge: #4a525c; --grid: #4ea1ff22; --ink: #e6e8eb;
  --sel: #4ea1ff; --hover: #ff8b3e; --snap: #ffb224; --preview: #4ea1ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.45 system-ui, "Segoe UI", sans-serif; display: flex; flex-direction: column; overflow: hidden; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 7px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.top { display: flex; align-items: center; gap: 14px; padding: 7px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.group { display: flex; align-items: center; gap: 6px; }
.paper input { width: 76px; }
.spacer { flex: 1; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.sm { padding: 2px 9px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 64px 1fr 300px; }
.tools { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 1px; padding: 4px; overflow-y: auto; scrollbar-width: thin; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 1px; border: 1px solid transparent; border-radius: 8px; background: none; cursor: pointer; color: var(--text); }
.tool svg { width: 20px; height: 20px; }
.tool span { font-size: 10px; color: var(--muted); line-height: 1.1; text-align: center; }
.tool:hover { background: var(--surface-2); }
.tool.active { background: var(--accent-soft); border-color: var(--accent); }
.tool.active span { color: var(--text); }
.tools hr { border: 0; border-top: 1px solid var(--border); margin: 2px; width: auto; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.canvasWrap { position: relative; flex: 1; min-height: 0; background: var(--canvas); overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; cursor: none; outline: none; touch-action: none; }
canvas.panning { cursor: grabbing; }
.drop { position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 10px; display: none; place-content: center; font-size: 16px; background: var(--accent-soft); }
.drop.on { display: grid; }
.toast { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 14px; box-shadow: 0 6px 24px #0003; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 80%; }
.toast.on { opacity: 1; }
.toast.err { border-color: #e5484d; }

.cmdbar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--surface); border-top: 1px solid var(--border); }
.prompt { white-space: nowrap; font-weight: 600; max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
#cmd { flex: 1; font-family: var(--mono); font-size: 12.5px; }
.coords { min-width: 150px; text-align: right; color: var(--muted); }
.tog { border: 1px solid var(--border); background: var(--surface-2); border-radius: 5px; padding: 2px 7px; font-size: 11px; font-weight: 600; letter-spacing: .03em; cursor: pointer; color: var(--muted); }
.tog.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.panel { background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; padding: 10px 12px 20px; }
.panel h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 8px; font-weight: 600; }
.panel h3:first-child { margin-top: 2px; }
.row { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; margin-bottom: 7px; }
.row > label { color: var(--muted); }
.row textarea { resize: vertical; min-height: 54px; font-family: inherit; }
.inline { display: flex; gap: 6px; align-items: center; }
.inline input { width: 100%; }
.pens { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.pens button { height: 22px; border-radius: 5px; border: 2px solid transparent; cursor: pointer; font-size: 10px; font-weight: 700; color: #fff; text-shadow: 0 0 2px #000a; padding: 0; }
.pens button.on { border-color: var(--text); }
.just { display: grid; grid-template-columns: repeat(3, 26px); gap: 3px; }
.just button { height: 22px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 4px; cursor: pointer; font-size: 9px; color: var(--muted); padding: 0; }
.just button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.stat { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; }
.stat dt { color: var(--muted); }
.stat dd { margin: 0; font-family: var(--mono); font-size: 12px; text-align: right; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0; }
.kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--surface-2); }
.help { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 12px; align-items: center; }
.help .kbd { justify-self: start; white-space: nowrap; }
.warn { border: 1px solid #e8590c88; background: #e8590c14; border-radius: 6px; padding: 6px 8px; font-size: 12px; margin: 6px 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 56px 1fr; }
  .panel { display: none; }
  .paper input { width: 60px; }
}

/* ---- janela de importar imagem ---- */
dialog#imgDlg, dialog#impDlg { padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); width: min(1180px, 96vw); height: min(780px, 92vh); box-shadow: 0 20px 60px #0006; }
dialog#imgDlg::backdrop, dialog#impDlg::backdrop { background: #0008; }
dialog#impDlg { width: min(1040px, 94vw); height: min(640px, 90vh); }
.imgdlg { display: flex; flex-direction: column; height: 100%; }
.imgdlg header, .imgdlg footer { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.imgdlg footer { border-bottom: 0; border-top: 1px solid var(--border); }
.imgdlg footer .btn[disabled] { opacity: .5; cursor: not-allowed; }
.ibody { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 330px; }
.iprev { position: relative; min-height: 0; padding: 12px; background: var(--canvas); display: flex; flex-direction: column; gap: 8px; }
.iprev canvas { flex: 1; min-height: 0; width: 100%; border-radius: 6px; cursor: default; box-shadow: 0 1px 6px #0003; }
.ishow { font-size: 12px; color: var(--muted); }
.ictl { overflow-y: auto; padding: 12px 14px; border-left: 1px solid var(--border); }
.ictl h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 8px; font-weight: 600; }
.ictl .row { grid-template-columns: 104px 1fr; }
.ictl input[type=range] { flex: 1; padding: 0; border: 0; background: none; accent-color: var(--accent); }
.ictl .mono { min-width: 52px; text-align: right; color: var(--muted); }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chk input { width: auto; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.seg button { border: 0; background: var(--surface-2); padding: 6px 4px; cursor: pointer; color: var(--muted); font-size: 12px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
@media (max-width: 900px) { .ibody { grid-template-columns: 1fr; grid-template-rows: 45% 1fr; } .ictl { border-left: 0; border-top: 1px solid var(--border); } }
