:root {
  --bg: #eef1f5;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #5b6b7b;
  --line: #d9e0e8;
  --accent: #1f4e9c;
  --accent-ink: #ffffff;
  --green: #0f8a5f;
  --orange: #d97706;
  --red: #c62828;
  --yellow: #b7791f;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .05);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 .7rem; letter-spacing: .01em; text-transform: uppercase; color: var(--muted); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre { background: #f5f7fa; border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; overflow-x: auto; font-size: .82rem; margin: .4rem 0 0; }

.topbar { display: flex; flex-wrap: wrap; gap: .6rem 1.5rem; align-items: center; justify-content: space-between; padding: .9rem 1.2rem; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar p { margin: .15rem 0 0; color: var(--muted); font-size: .9rem; }
.convention { display: flex; flex-wrap: wrap; gap: .4rem .9rem; font-size: .85rem; color: var(--muted); background: #f5f7fa; border: 1px solid var(--line); border-radius: 999px; padding: .35rem .9rem; }

.layout { display: grid; grid-template-columns: 370px minmax(0, 1fr); gap: 16px; padding: 16px; max-width: 1600px; margin: 0 auto; }
.controls { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.viewer-col { min-width: 0; position: sticky; top: 12px; align-self: start; }
.results-col { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.cards3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid2.small { font-size: .9rem; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .86rem; color: var(--muted); min-width: 0; }
input[type=number], select { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; font-size: 1rem; color: var(--ink); background: #fff; }
input[type=number]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.hint { color: var(--muted); font-size: .8rem; margin: .5rem 0 0; }
small.hint { margin: 0; }

fieldset.radios { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0 0; padding: 6px 12px 10px; display: flex; flex-wrap: wrap; gap: 4px 16px; }
fieldset.radios legend { font-size: .8rem; color: var(--muted); padding: 0 4px; }
fieldset.radios label, .checks label { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: .92rem; min-height: 36px; }
.checks { display: grid; grid-template-columns: 1fr; }
input[type=radio], input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }

.slider-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; margin-top: 6px; }
input[type=range] { width: 100%; height: 44px; margin: 0; accent-color: var(--accent); }
input[type=range]:disabled { opacity: .55; }
output { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 6ch; text-align: right; white-space: nowrap; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.val.warn { color: var(--orange); }

.banner { background: #fff4e5; border: 1px solid #f5c98a; color: #7a4100; border-radius: 8px; padding: 8px 10px; font-size: .88rem; margin-top: 10px; }
.joint { margin: 10px 0; padding: 8px 10px; border-radius: 8px; font-size: .88rem; border: 1px solid; }
.joint.ok { background: #eaf7f0; border-color: #b7e2cb; color: #0b5d3f; }
.joint.gap { background: #fff8e1; border-color: #f5dd8a; color: #6b4b00; }
.joint.overlap { background: #fdecea; border-color: #f5b5b0; color: #8a1c14; }
.joint.bad { background: #fdecea; border-color: #f5b5b0; color: #8a1c14; }

.warnings { margin: 10px 0 0; padding: 8px 12px 8px 28px; background: #fdecea; border: 1px solid #f5b5b0; color: #8a1c14; border-radius: 8px; font-size: .88rem; }

.btn { height: 40px; padding: 0 12px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.active { background: #e3ebf8; border-color: var(--accent); color: var(--accent); }
.btn.primary.active { background: #163c7a; }
.btn.small { height: 36px; padding: 0 10px; font-size: .85rem; }
#btnUseCalc { width: 100%; margin-top: 4px; }

.viewer-wrap { position: relative; height: clamp(440px, 72vh, 760px); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: #f3f5f8; box-shadow: var(--shadow); }
.viewer { position: absolute; inset: 0; }
.viewer canvas { width: 100% !important; height: 100% !important; display: block; }
.fallback { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); font-size: 1.05rem; text-align: center; padding: 20px; }
.fallback p { margin: 0; font-weight: 600; color: var(--ink); }
.hud { position: absolute; top: 10px; left: 10px; background: rgba(255,255,255,.9); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: .84rem; line-height: 1.5; font-variant-numeric: tabular-nums; pointer-events: none; max-width: calc(100% - 20px); }
.hud div:first-child { font-weight: 700; }
.hud-badge { margin-top: 6px; display: inline-block; padding: 3px 8px; border-radius: 999px; font-weight: 700; font-size: .78rem; letter-spacing: .02em; }
.hud-badge.ideal { background: #eaf7f0; color: #0b5d3f; }
.hud-badge.folga { background: #fff3c4; color: #6b4b00; }
.hud-badge.sobreposicao, .hud-badge.bad { background: #fdecea; color: #8a1c14; }
.legend { position: absolute; left: 10px; right: 10px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: .76rem; color: var(--muted); pointer-events: none; }
.legend span { display: inline-flex; align-items: center; gap: 5px; background: rgba(255,255,255,.75); padding: 1px 6px; border-radius: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.15); }
.sw.mandrel { background: #7d848c; } .sw.paper { background: #e9dcc3; } .sw.joint { background: #b3261e; }
.sw.axis { background: #1f4e9c; } .sw.perp { background: #0f8a5f; } .sw.strip { background: #d97706; }
.sw.gap { background: #f2c94c; } .sw.overlap { background: #e5484d; }
.scale-note { margin: 8px 2px 0; font-size: .82rem; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 10px; align-items: center; }
.group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.speed { display: inline-flex; gap: 4px; margin-left: 4px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: .86rem; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { background: #f5f7fa; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
#layerTable tbody tr { cursor: pointer; }
#layerTable tbody tr:hover { background: #f0f4fb; }
#layerTable tbody tr.current { background: #e3ebf8; outline: 2px solid var(--accent); outline-offset: -2px; font-weight: 600; }
#layerTable tbody tr:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
td.sim.folga { color: var(--yellow); } td.sim.sobreposicao { color: var(--red); } td.sim.ideal { color: var(--green); }
table.cmp th { text-align: left; font-weight: 500; color: var(--muted); }
table.cmp td.sel { background: #e3ebf8; font-weight: 700; }

.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 18px 12px 28px; }

@media (max-width: 1100px) {
  .cards3 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 10px; gap: 12px; }
  .viewer-col { position: static; }
  .viewer-wrap { height: 64vh; min-height: 380px; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .topbar { padding: .8rem 1rem; }
  .convention { font-size: .78rem; }
  .hud { font-size: .78rem; }
  .legend { display: none; }
}
@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { text-align: left; }
}
