:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel2: #ffffff;
  --line: #d5d9de;
  --text: #16191d;
  --muted: #5b6470;
  --accent: #E8731A;
  --accent2: #1f5fd1;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --err: #c0392b;
  --dro: #1f5fd1;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --title: "Space Grotesk", "IBM Plex Sans", sans-serif;
  --code-size: 14px;
  --code-lh: 21px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); display: flex; flex-direction: column; overflow: hidden; }
button, select, input { font: inherit; color: inherit; }
button, select {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 11px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
button:hover, select:hover { border-color: #16191d; background: #f3f4f6; }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--accent2); outline-offset: 1px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
button.primary:hover { background: #f5842e; }
.mono { font-family: var(--mono); }
.spacer { flex: 1; }

/* topo */
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text span { font-family: var(--title); font-weight: 700; font-size: 19px; letter-spacing: .2px; }
.brand-text b { color: #1f5fd1; }
.brand-text small { color: var(--muted); font-size: 11.5px; }
.topnav { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.challenge-bar { display: flex; align-items: center; gap: 12px; padding: 7px 14px; background: #e8f5ee; border-bottom: 1px solid #b9dfc9; color: #14532d; font-size: 13.5px; }
.challenge-bar > span { flex: 1; }
.challenge-bar[hidden] { display: none; }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: minmax(330px, 36%) 1fr; min-height: 0; }
.editor-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; background: var(--panel); }
.sim-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-head { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.pane-head button { padding: 4px 9px; font-size: 13px; }
.pane-title { font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 12px; letter-spacing: .8px; }

/* editor */
.editor { flex: 1; display: flex; min-height: 0; position: relative; background: #ffffff; }
.gutter { width: 46px; overflow: hidden; background: #f6f7f8; border-right: 1px solid var(--line); color: #9aa3ad; font: var(--code-size)/var(--code-lh) var(--mono); text-align: right; user-select: none; }
#gutterInner { padding: 8px 8px 40px 0; will-change: transform; }
#gutterInner div { height: var(--code-lh); }
#gutterInner div.cur { color: var(--accent); }
#gutterInner div.err { color: var(--err); font-weight: 700; }
.code-wrap { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.highlight, #code {
  font: var(--code-size)/var(--code-lh) var(--mono); tab-size: 2; white-space: pre; margin: 0; padding: 8px 12px 40px; letter-spacing: 0;
}
.highlight { position: absolute; inset: 0; pointer-events: none; overflow: hidden; color: var(--text); }
.highlight .hl-in { will-change: transform; min-width: 100%; width: max-content; }
.highlight .ln { height: var(--code-lh); padding-right: 12px; margin: 0 -12px; padding-left: 12px; }
.highlight .ln.run { background: rgba(31,95,209,.10); box-shadow: inset 3px 0 0 var(--accent2); }
.highlight .ln.err { background: rgba(192,57,43,.12); box-shadow: inset 3px 0 0 var(--err); }
.highlight .ln.caret { background: rgba(22,25,29,.04); }
#code {
  position: absolute; inset: 0; width: 100%; height: 100%; resize: none; border: 0; outline: none; background: transparent;
  color: transparent; caret-color: #16191d; overflow: auto;
}
#code::selection { background: rgba(31,95,209,.25); color: transparent; }
.t-n { color: #8a939d; }
.t-g { color: #1f5fd1; font-weight: 600; }
.t-m { color: #c45a0c; font-weight: 600; }
.t-t { color: #9a6a00; font-weight: 600; }
.t-sf { color: #1f7a45; }
.t-xz { color: #16191d; }
.t-p { color: #6b3fc4; }
.t-o { color: #9a6a00; }
.t-c { color: #7d8690; font-style: italic; }
.t-bad { color: var(--err); text-decoration: wavy underline; }

/* explicacao */
.explain { border-top: 1px solid var(--line); padding: 9px 12px; max-height: 34%; min-height: 96px; overflow: auto; background: var(--panel); font-size: 13px; }
.explain .ex-head { font-family: var(--mono); color: var(--accent); margin-bottom: 6px; white-space: pre-wrap; word-break: break-word; }
.explain .ex-head small { color: var(--muted); font-family: var(--sans); margin-right: 6px; }
.explain ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 3px; }
.explain li { display: grid; grid-template-columns: 74px 1fr; gap: 8px; }
.explain li code { font-family: var(--mono); color: #1f5fd1; }
.explain li.bad code, .explain li.bad span { color: var(--err); }
.explain .hint { color: var(--muted); }

/* toolbar */
.toolbar { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.speed { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; margin-left: 4px; }
.speed input { width: 120px; accent-color: var(--accent); }
.speed .mono { color: var(--text); min-width: 54px; }
.toggles { display: flex; align-items: center; gap: 10px; margin-left: auto; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.toggles label { display: flex; gap: 4px; align-items: center; cursor: pointer; }
.toggles input { accent-color: var(--accent2); }
.toggles button { padding: 4px 9px; font-size: 13px; }

/* viewport */
.viewport { position: relative; flex: 1; min-height: 220px; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.badge { position: absolute; top: 10px; left: 10px; font: 700 12px var(--mono); letter-spacing: 1px; padding: 4px 9px; border-radius: 6px; background: #fff; color: var(--muted); border: 1px solid var(--line); }
.badge.run { color: #fff; background: var(--accent2); border-color: var(--accent2); }
.badge.pause { color: #fff; background: var(--warn); border-color: var(--warn); }
.badge.err { color: #fff; background: #c0392b; border-color: #c0392b; }
.badge.end { color: #fff; background: var(--ok); border-color: var(--ok); }
.legend { position: absolute; top: 10px; right: 10px; display: flex; gap: 12px; font-size: 12px; color: var(--muted); background: rgba(255,255,255,.9); border: 1px solid var(--line); padding: 4px 9px; border-radius: 6px; flex-wrap: wrap; }
.legend span[hidden] { display: none; }
.lg { display: inline-block; width: 18px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 5px; }
.lg.rapid { border-color: #E8731A; border-top-style: dashed; }
.lg.feed { border-color: #1f5fd1; }
.lg.thread { border-color: #7b3fd1; }
.lg.plan { border-color: rgba(22,25,29,.35); }
.lg.target { border-color: #1f8a4c; border-top-style: dashed; }
.zoom { position: absolute; right: 10px; bottom: 34px; display: flex; flex-direction: column; gap: 4px; }
.zoom button { width: 32px; height: 32px; padding: 0; font-size: 18px; line-height: 1; background: rgba(255,255,255,.95); }

/* painel inferior */
.bottom { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; border-top: 1px solid var(--line); height: 210px; background: var(--panel); }
.dro { padding: 10px 12px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; overflow: auto; }
.dro .axis { display: flex; align-items: baseline; gap: 10px; background: #f6f7f8; border: 1px solid var(--line); border-radius: 6px; padding: 2px 10px; }
.dro .lbl { font: 700 20px var(--mono); color: var(--muted); width: 34px; }
.dro .lbl small { font-size: 12px; }
.dro .val { font: 600 26px/1.25 var(--mono); color: var(--dro); margin-left: auto; text-shadow: none; }
.dro-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 10px; margin-top: 4px; font-size: 12px; }
.dro-grid div { display: flex; flex-direction: column; }
.dro-grid div.wide { grid-column: 1 / -1; }
.dro-grid span { color: var(--muted); }
.dro-grid b { font: 600 13px var(--mono); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { overflow: auto; padding: 6px 8px; font-size: 13px; }
.msg { display: flex; gap: 8px; padding: 5px 8px; border-radius: 6px; margin-bottom: 3px; border-left: 3px solid transparent; background: #f8f9fa; }
.msg .ic { flex: none; }
.msg .ln-link { font-family: var(--mono); color: var(--accent2); cursor: pointer; white-space: nowrap; }
.msg .ln-link:hover { text-decoration: underline; }
.msg.error { border-left-color: var(--err); background: #fbecea; }
.msg.warn { border-left-color: var(--warn); background: #fbf3e3; }
.msg.ok { border-left-color: var(--ok); background: #e8f5ee; }
.msg.info { border-left-color: #1f5fd1; }
.messages .empty { color: var(--muted); padding: 6px; }

/* dialogo */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(860px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.18); }
dialog::backdrop { background: rgba(22,25,29,.45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.dlg-head h2 { margin: 0; font-size: 17px; }
.dlg-body { padding: 14px 18px 18px; overflow: auto; max-height: calc(100vh - 110px); }
.dlg-body h3 { color: var(--accent); margin: 16px 0 6px; font-size: 15px; }
.dlg-body pre { background: #f6f7f8; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow: auto; font: 13px/1.5 var(--mono); color: #16191d; }
.dlg-body p, .dlg-body li { color: #2a3038; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
table.ref { border-collapse: collapse; width: 100%; margin: 8px 0 12px; font-size: 13.5px; }
table.ref th, table.ref td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.ref th { color: var(--muted); font-weight: 600; }
table.ref td:first-child { font-family: var(--mono); color: #1f5fd1; white-space: nowrap; }
.tool-dot { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 8px 0 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.form-grid input { background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 8px; font-family: var(--mono); }
.actions { display: flex; gap: 8px; justify-content: flex-end; }
.cards { display: grid; gap: 10px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--panel2); display: flex; gap: 14px; align-items: center; }
.card h4 { margin: 0 0 4px; font-size: 15px; }
.card p { margin: 0; font-size: 13.5px; }
.card .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.card > div { flex: 1; }
.card canvas { flex: none; border-radius: 6px; background: #fff; border: 1px solid var(--line); }

/* responsivo */
@media (max-width: 980px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; }
  .sim-pane { order: -1; }
  .viewport { height: 46vh; flex: none; }
  .editor-pane { border-right: 0; border-top: 1px solid var(--line); }
  .editor { height: 46vh; flex: none; }
  .bottom { grid-template-columns: 1fr; height: auto; }
  .dro { border-right: 0; border-bottom: 1px solid var(--line); }
  .messages { max-height: 200px; }
  .toggles { margin-left: 0; }
}
@media (max-width: 560px) {
  .topbar { padding: 8px 10px; }
  .topnav { margin-left: 0; width: 100%; }
  .topnav > * { flex: 1 1 auto; padding: 6px 8px; font-size: 13px; }
  .brand-text small { display: none; }
  .speed input { width: 90px; }
  .form-grid { grid-template-columns: 1fr; }
  .dro .val { font-size: 22px; }
  .card { flex-direction: column; align-items: stretch; }
}

/* ---- estética do curso Torno CNC do Zero ---- */
*, *::before, *::after { border-radius: 0 !important; }
.brand { color: inherit; text-decoration: none; }
.brand svg { flex: none; }
.pane-title, .dlg-head h2 { font-family: var(--title); }
.topbar { border-bottom: 2px solid var(--accent); }
.topnav a.site-link { display: inline-flex; align-items: center; padding: 6px 11px; border: 1px solid var(--line); color: var(--text); text-decoration: none; background: transparent; }
.topnav a.site-link:hover { border-color: var(--accent); }
.topnav a.site-link.cta { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.topnav a.site-link.cta:hover { background: #f5842e; }
