:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #14181f; --muted: #5b6472; --line: #e2e6ec;
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #e6f4f2;
  --ok: #157f3b; --ok-soft: #e7f6ec; --warn: #a15c00; --warn-soft: #fff4e0; --bad: #b42318; --bad-soft: #fdecea;
  --c1: #2563eb; --c2: #0f766e; --c3: #d97706; --c4: #9333ea; --c5: #db2777; --c6: #64748b; --c7: #0891b2; --c8: #65a30d;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1117; --panel: #161b22; --ink: #e6edf3; --muted: #9aa5b1; --line: #2a313c;
  --accent: #2dd4bf; --accent-ink: #062b27; --accent-soft: #123430;
  --ok: #4ade80; --ok-soft: #12301d; --warn: #fbbf24; --warn-soft: #33270b; --bad: #f87171; --bad-soft: #3a1414;
  --c1: #60a5fa; --c2: #2dd4bf; --c3: #fbbf24; --c4: #c084fc; --c5: #f472b6; --c6: #94a3b8; --c7: #22d3ee; --c8: #a3e635;
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
.hidden { display: none !important; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.backlink { text-decoration: none; color: var(--muted); white-space: nowrap; }
.backlink:hover { color: var(--ink); }
.sep { color: var(--line); }
.topactions { display: flex; align-items: center; gap: 10px; }
.freebadge { font-size: 12px; color: var(--ok); background: var(--ok-soft); padding: 3px 10px; border-radius: 99px; white-space: nowrap; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: 5px 10px; cursor: pointer; font: inherit; }
.ghost:hover { border-color: var(--muted); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 20px 40px; }
.hero h1 { font-size: clamp(26px, 4vw, 36px); line-height: 1.15; margin: 0 0 6px; letter-spacing: -.01em; }
.lede { color: var(--muted); margin: 0 0 14px; max-width: 680px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 20px; }
.exlabel { font-size: 13px; color: var(--muted); margin-right: 2px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 99px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.mini { padding: 3px 10px; font-size: 12px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.grid { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.results { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.controls { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
fieldset { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
legend { font-weight: 650; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; padding: 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); min-width: 0; }
.field small { font-weight: 400; }
input[type="number"], select, textarea {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; min-width: 0;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); margin: 4px 0 10px; cursor: pointer; }
.check.small { margin: 0; color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.shape { font-size: 12px; color: var(--muted); margin: -2px 0 8px; }
.custom { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin-bottom: 4px; }
.custom.drag { border-color: var(--accent); background: var(--accent-soft); }
.msg { font-size: 12px; color: var(--muted); margin: 4px 0 8px; min-height: 1em; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--ok); }

.seg { display: flex; flex-wrap: wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; margin-bottom: 12px; }
.seg label { flex: 1 1 auto; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 6px 8px; border-radius: 7px; font-size: 13px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg input:checked + span { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg.small { margin: 0; }
.seg.small span { padding: 3px 8px; font-size: 12px; }

.btn {
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn.ghost:hover { border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.filebtn { position: relative; overflow: hidden; display: inline-block; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.adv summary { cursor: pointer; font-size: 13px; color: var(--muted); margin-bottom: 10px; }

.verdict { scroll-margin-top: 72px; display: flex; gap: 14px; align-items: center; border-left: 5px solid var(--muted); }
.verdict.ok { border-left-color: var(--ok); background: linear-gradient(90deg, var(--ok-soft), var(--panel) 60%); }
.verdict.warn { border-left-color: var(--warn); background: linear-gradient(90deg, var(--warn-soft), var(--panel) 60%); }
.verdict.bad { border-left-color: var(--bad); background: linear-gradient(90deg, var(--bad-soft), var(--panel) 60%); }
.vbig { font-size: clamp(28px, 5vw, 40px); font-weight: 750; letter-spacing: -.02em; line-height: 1; white-space: nowrap; }
.vtext h2 { margin: 0 0 2px; font-size: 18px; }
.vtext p { margin: 0; color: var(--muted); font-size: 14px; }
.panel h2 { font-size: 16px; margin: 0 0 12px; }
.phead { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.phead h2 { margin: 0; }

.bar { position: relative; display: flex; height: 30px; border-radius: 8px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); }
.bar .seg-part { height: 100%; min-width: 2px; }
.bar .cap { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 2px dashed var(--ink); }
.bar .caplabel { position: absolute; top: 2px; font-size: 11px; padding: 1px 5px; background: var(--ink); color: var(--panel); border-radius: 4px; white-space: nowrap; transform: translateX(-100%); margin-left: -4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 10px 0 6px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: 12px; color: var(--muted); font-weight: 600; }
tfoot th { border-bottom: 0; font-size: 15px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.breakdown tr.prow td { border-bottom: 0; padding-bottom: 0; }
.breakdown tr.frow td { padding-top: 2px; }
.breakdown .formula { display: block; font-size: 12px; color: var(--muted); margin-top: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }
.breakdown.noformula tr.frow { display: none; }
.breakdown.noformula tr.prow td { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.breakdown .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }
.split { font-size: 11px; color: var(--muted); margin-left: 6px; }
.notes { margin: 10px 0 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.notes:empty { display: none; }

.limits { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.stat b { display: block; font-size: 20px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat small { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }

.tablewrap { overflow-x: auto; }
.gputable td:first-child { white-space: nowrap; }
.gputable tr.sel td { background: var(--accent-soft); }
.gputable button.linky { background: none; border: 0; padding: 0; color: var(--ink); font: inherit; cursor: pointer; text-align: left; }
.gputable button.linky:hover { color: var(--accent); text-decoration: underline; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; font-weight: 600; }
.pill.ok { color: var(--ok); background: var(--ok-soft); }
.pill.warn { color: var(--warn); background: var(--warn-soft); }
.pill.bad { color: var(--bad); background: var(--bad-soft); }
.neg { color: var(--bad); }

.exports { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.method { margin-top: 20px; }
.method dl { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
.method dt { font-weight: 600; }
.method dd { margin: 0; color: var(--muted); }
.fine { font-size: 12px; color: var(--muted); margin: 14px 0 0; }
.foot { max-width: 1240px; margin: 0 auto; padding: 0 20px 30px; font-size: 13px; color: var(--muted); display: flex; gap: 16px; flex-wrap: wrap; }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; }
  .method dl { grid-template-columns: 1fr; gap: 2px; }
  .method dd { margin-bottom: 10px; }
}
@media (max-width: 520px) {
  .wrap { padding: 16px 16px 32px; }
  .topbar { padding: 10px 16px; }
  .freebadge { display: none; }
  .verdict { flex-direction: column; align-items: flex-start; gap: 8px; }
  .panel { padding: 14px; }
  .cgrid { grid-template-columns: 1fr 1fr; }
  th, td { padding: 7px 4px; }
  .breakdown thead th:nth-child(3), .breakdown tfoot th:nth-child(3), .breakdown tr.prow td:nth-child(3) { display: none; }
  .breakdown .sw { margin-right: 5px; }
}
