:root {
  --bg: #f5f6f8; --panel: #ffffff; --text: #16191d; --muted: #5b6470; --line: #e1e4e9;
  --accent: #1d6fd8; --accent-ink: #ffffff; --ok: #17804a; --ok-bg: #e7f5ed; --warn: #a86400;
  --code-bg: #fafbfc; --kw: #a3337a; --str: #1f7a3a; --num: #b4590a; --com: #8a93a0; --fn: #2f5fc4;
  --model: #c9d3e0; --edge: #2a3038; --view-bg: #eef1f5; --pick: #e8590c; --hud: rgba(255,255,255,.94);
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1215; --panel: #171b20; --text: #e7eaee; --muted: #9aa4b1; --line: #29303a;
    --accent: #5b9bff; --accent-ink: #0b1220; --ok: #4cc27f; --ok-bg: #12291c; --warn: #f0a83a;
    --code-bg: #13171c; --kw: #e083c0; --str: #7fd49a; --num: #f0a86a; --com: #6f7987; --fn: #8fb4ff;
    --model: #9fb0c6; --edge: #0b0d10; --view-bg: #1b2028; --pick: #ff8a3d; --hud: rgba(23,27,32,.94);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1215; --panel: #171b20; --text: #e7eaee; --muted: #9aa4b1; --line: #29303a;
  --accent: #5b9bff; --accent-ink: #0b1220; --ok: #4cc27f; --ok-bg: #12291c; --warn: #f0a83a;
  --code-bg: #13171c; --kw: #e083c0; --str: #7fd49a; --num: #f0a86a; --com: #6f7987; --fn: #8fb4ff;
  --model: #9fb0c6; --edge: #0b0d10; --view-bg: #1b2028; --pick: #ff8a3d; --hud: rgba(23,27,32,.94);
  --shadow: none;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
       font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; }
a { color: var(--accent); }
button { font: inherit; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.ok { color: var(--ok); }

/* top bar */
.bar { display: flex; align-items: center; gap: 12px; padding: 14px 0; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; }
.spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--text);
       border-radius: 9px; padding: 7px 13px; font-size: 14px; text-decoration: none; cursor: pointer; min-height: 36px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn:focus-visible, .seg button:focus-visible, .tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }

/* landing */
.hero { padding: 28px 0 8px; }
.hero h1 { font-size: clamp(28px, 5vw, 44px); line-height: 1.1; margin: 0 0 12px; letter-spacing: -.02em; }
.hero p { font-size: 17px; color: var(--muted); max-width: 640px; margin: 0; }
.grid2 { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; margin: 24px 0; }
.drop { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.card h2, section h2 { font-size: 16px; margin: 0; }
section > h2 { margin-bottom: 4px; }
.zone { border: 2px dashed var(--line); border-radius: 12px; padding: 28px 16px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.zone:hover, .zone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.zone b { display: block; font-size: 15px; margin-bottom: 4px; }
.zone input { display: none; }
.notice { display: none; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 14px; background: var(--code-bg); }
.notice.show { display: block; }
.notice img { max-width: 100%; max-height: 180px; display: block; margin: 0 0 10px; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.steps { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.step { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; }
.step i { font-style: normal; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px;
          background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.step b { display: block; }
.step span { color: var(--muted); font-size: 14px; }

.samples { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 12px 0 28px; }
.sample { display: flex; flex-direction: column; overflow: hidden; text-decoration: none; color: inherit; transition: transform .12s, border-color .12s; }
.sample:hover { transform: translateY(-2px); border-color: var(--accent); }
.sample .thumb { aspect-ratio: 4 / 3; background: #fff; border-bottom: 1px solid var(--line); overflow: hidden; }
.sample .thumb img { width: 100%; height: 100%; object-fit: contain; transform: scale(1.3); }
.sample .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.sample h3 { margin: 0; font-size: 15px; }
.sample p { margin: 0; font-size: 13.5px; color: var(--muted); flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ok); background: var(--ok-bg);
        border-radius: 999px; padding: 3px 10px; width: fit-content; white-space: nowrap; }

.realnext { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 28px; }
.realnext .card { padding: 18px 20px; }
.realnext ul { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }
.realnext li { margin: 4px 0; }
footer { color: var(--muted); font-size: 13px; padding: 18px 0 32px; border-top: 1px solid var(--line); }

/* part view */
.vbar h1 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
.vmain { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 14px; padding-bottom: 18px; height: calc(100vh - 70px); min-height: 560px; }
.pane { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.tabs { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; min-height: 34px; }
.tabs button[aria-selected="true"] { background: var(--bg); color: var(--text); font-weight: 600; }
.tabbody { flex: 1; min-height: 0; overflow: auto; }
.tabbody[hidden] { display: none; }
.drawing { background: #fff; height: 100%; display: flex; align-items: center; justify-content: center; cursor: zoom-in; }
.drawing img { max-width: 100%; max-height: 100%; display: block; }
.drawing.zoom { display: block; cursor: zoom-out; overflow: auto; }
.drawing.zoom img { max-width: none; max-height: none; width: 220%; }
pre.code { margin: 0; padding: 12px 14px; background: var(--code-bg); min-height: 100%; counter-reset: ln;
           font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; tab-size: 4; }
pre.code .ln { display: inline-block; width: 2.4em; color: var(--muted); opacity: .55; text-align: right; margin-right: 12px; user-select: none; }
.k { color: var(--kw); } .s { color: var(--str); } .n { color: var(--num); } .c { color: var(--com); font-style: italic; } .f { color: var(--fn); }
.checks { padding: 14px 16px; }
.checks .sum { font-size: 15px; font-weight: 650; margin: 0 0 4px; }
.checks ol { list-style: none; padding: 0; margin: 12px 0 0; }
.checks li { display: flex; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.checks li .mark { color: var(--ok); font-weight: 700; flex: none; }
.checks li.bad .mark { color: var(--warn); }

.viewer { position: relative; flex: 1; min-height: 320px; background: var(--view-bg); }
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.viewer canvas.measure { cursor: crosshair; }
.nogl { padding: 24px; color: var(--muted); }
.tools { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 8px; pointer-events: none; }
.tools > * { pointer-events: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: transparent; color: var(--text); padding: 6px 10px; cursor: pointer; font-size: 13px; min-height: 32px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
#hud { position: absolute; top: 54px; right: 10px; width: min(300px, calc(100% - 20px)); background: var(--hud); border: 1px solid var(--line);
       border-radius: 10px; padding: 10px 12px; font-size: 12.5px; backdrop-filter: blur(6px); }
#hud[hidden] { display: none; }
#hud h3 { margin: 0 0 6px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
#hud .row { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
#hud .big { font-size: 18px; font-weight: 650; color: var(--pick); }
#hud hr { border: 0; border-top: 1px solid var(--line); margin: 7px 0; }
#hover { position: absolute; pointer-events: none; font-size: 12px; padding: 2px 6px; border-radius: 6px; background: var(--hud); border: 1px solid var(--line); white-space: nowrap; }
#hover[hidden] { display: none; }
.hint { position: absolute; bottom: 8px; left: 12px; color: var(--muted); font-size: 12px; pointer-events: none; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.stat { padding: 8px 12px; min-width: 0; } .stat + .stat { border-left: 1px solid var(--line); }
.stat small { display: block; color: var(--muted); font-size: 12px; }
.stat b { font-size: 14.5px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

/* replay overlay */
.replay { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(4px);
          display: grid; place-items: center; z-index: 10; padding: 16px; }
.replay[hidden] { display: none; }
.replay .card { width: min(440px, 100%); padding: 20px 22px; }
.replay h2 { margin: 0 0 2px; font-size: 16px; }
.replay ol { list-style: none; padding: 0; margin: 14px 0; }
.replay li { display: flex; gap: 10px; align-items: center; padding: 6px 0; color: var(--muted); font-size: 14.5px; }
.replay li .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); flex: none; display: grid; place-items: center; font-size: 11px; }
.replay li.run { color: var(--text); } .replay li.run .dot { border-color: var(--accent); border-top-color: transparent; animation: spin .8s linear infinite; }
.replay li.done { color: var(--text); } .replay li.done .dot { border-color: var(--ok); background: var(--ok); color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .replay li.run .dot { animation: none; } .sample { transition: none; } }

@media (max-width: 860px) {
  .grid2, .realnext { grid-template-columns: 1fr; }
  .samples { grid-template-columns: 1fr; }
  .vmain { grid-template-columns: 1fr; height: auto; }
  .pane.left { height: 62vh; }
  .viewer { min-height: 62vh; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-left: 0; } .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .hint { display: none; }
}
