:root {
  --ink: #16191d;
  --ink-2: #4a4f5a;
  --ink-3: #7c828e;
  --paper: #f4f5f7;
  --card: #ffffff;
  --line: #dedad0;
  --line-2: #ebe8e0;
  --accent: #039289;
  --accent-ink: #ffffff;
  --accent-soft: #e2f4f2;
  --ok: #1f7a53;
  --warn: #b7791f;
  --warn-soft: #fdf3dc;
  --err: #c0322a;
  --err-soft: #fde3e0;
  --head-soft: #eef0f4;
  --total-soft: #e8f2ec;
  --focus: #2457d6;
  --radius: 10px;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --serif: 'IBM Plex Serif', Georgia, serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 0 20px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* header */
.top { background: var(--paper); color: var(--ink); border-bottom: 1px solid var(--line); }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 84px; flex-wrap: wrap; padding-top: 12px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.brand-mark { display: block; width: 58px; height: 58px; border-radius: 14px; background: #fff; box-shadow: 0 0 0 1px #e3e5ea, 0 1px 3px rgba(22,25,29,.06); overflow: hidden; flex: none; }
.brand-mark img { width: 100%; height: 100%; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font: 700 27px/1.05 Sora, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; letter-spacing: -.005em; white-space: nowrap; }
.wm-n { color: #111; }
.wm-t { color: var(--accent); }
.wm-bar { display: inline-block; width: 4px; height: .92em; background: #111; margin-left: 2px; vertical-align: -.12em; }
.brand-text small { font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: #5b636d; margin-top: 4px; }
.privacy { margin: 0; font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.privacy .dot { width: 8px; height: 8px; border-radius: 50%; background: #3ccf8e; box-shadow: 0 0 0 3px rgba(60,207,142,.2); }

.intro { padding: 40px 0 18px; max-width: 820px; }
.intro h1 { font: 600 clamp(28px, 4vw, 42px)/1.1 var(--serif); margin: 0 0 12px; letter-spacing: -.015em; }
.intro h1 em { font-style: normal; color: var(--accent); }
.intro p { margin: 0; color: var(--ink-2); font-size: 16.5px; }

/* steps */
.steps { list-style: none; display: flex; gap: 6px; padding: 0; margin: 18px 0 20px; flex-wrap: wrap; }
.steps li { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--ink-3); font-weight: 500; font-size: 14px; }
.steps li span { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--line-2); font-size: 12.5px; font-weight: 600; }
.steps li.on { color: var(--ink); border-color: var(--ink); }
.steps li.on span { background: var(--ink); color: #fff; }
.steps li.done span { background: var(--ok); color: #fff; }

/* drop */
.drop { border: 2px dashed #c6c1b4; border-radius: 16px; background: var(--card); padding: 48px 20px; text-align: center; transition: border-color .15s, background .15s; cursor: pointer; }
.drop:hover, .drop.over { border-color: var(--accent); background: #f2fbfa; }
.drop.compact { padding: 14px; }
.drop.compact .drop-in > :not(.drop-title) { display: none; }
.drop.compact svg { display: none; }
.drop-in svg { color: var(--accent); }
.drop-title { font-size: 20px; font-weight: 600; margin: 8px 0 4px; }
.drop-sub { margin: 0 0 6px; color: var(--ink-2); }
.drop-meta { margin: 0 0 16px; font-size: 13px; color: var(--ink-3); }
kbd { font: 12px var(--mono); border: 1px solid var(--line); border-bottom-width: 2px; padding: 1px 5px; border-radius: 4px; background: var(--paper); }

/* buttons */
.btn { border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--card); transition: background .12s, border-color .12s, transform .05s; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #027a72; }
.btn.ghost { border-color: var(--line); background: var(--card); }
.btn.ghost:hover:not(:disabled) { border-color: var(--ink-3); }
.btn.small { padding: 5px 10px; font-size: 13.5px; font-weight: 500; }
.btn.block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; cursor: pointer; }

/* panels */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin: 18px 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.num { width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; display: inline-grid; place-items: center; font-size: 13px; }

/* reader */
.reader-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
.stage-col { padding: 14px; border-right: 1px solid var(--line); min-width: 0; }
.stage-bar { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.stage-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stage { background: #e6e3dc; border-radius: 8px; overflow: auto; height: min(72vh, 820px); position: relative; touch-action: none; }
.stage-inner { position: relative; margin: 0 auto; transform-origin: 0 0; }
.stage canvas { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 1px 8px rgba(0,0,0,.12); }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
#overlay.cols { cursor: copy; }
.hint { font-size: 13px; color: var(--ink-3); margin: 8px 2px 0; }

.controls { padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.ctl-block { display: flex; flex-direction: column; gap: 9px; padding-bottom: 14px; border-bottom: 1px solid var(--line-2); }
.ctl-block h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row select { flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field input, .field select, .row select { border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: #fff; font-weight: 400; color: var(--ink); min-width: 0; }
.field.inline input[type=number] { width: 64px; }
.chk { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; cursor: pointer; }
.chk input { margin-top: 3px; accent-color: var(--accent); }
.slider { display: grid; grid-template-columns: 1fr auto; font-size: 13px; font-weight: 500; color: var(--ink-2); gap: 2px 8px; }
.slider input { grid-column: 1 / -1; accent-color: var(--accent); }
.slider output { font-family: var(--mono); font-size: 12px; }
.note { font-size: 12.5px; color: var(--ink-3); margin: 0; }
.note.good { color: var(--ok); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--paper); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; font-size: 13.5px; font-weight: 500; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: #fff; }
.seg.small button { padding: 4px 10px; font-size: 13px; }

.progress { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.progress .bar { height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* overlay graphics */
.crop-rect { fill: rgba(3,146,137,.06); stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-dasharray: 6 4; }
.crop-shade { fill: rgba(21,23,28,.35); pointer-events: none; }
.col-line { pointer-events: none; stroke: #2457d6; stroke-width: 2; vector-effect: non-scaling-stroke; }
.col-hit { stroke: transparent; stroke-width: 14; vector-effect: non-scaling-stroke; cursor: ew-resize; }
.col-hit:hover + .col-line, .col-line.drag { stroke: var(--accent); stroke-width: 3; }
.row-line { stroke: rgba(36,87,214,.35); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.word-box { fill: rgba(31,122,83,.08); stroke: rgba(31,122,83,.6); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.word-box.low { fill: rgba(192,50,42,.1); stroke: rgba(192,50,42,.7); }

/* cleaner */
.stats { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.stats span { background: var(--paper); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; }
.stats .bad { background: var(--err-soft); border-color: #f2b7b1; color: var(--err); font-weight: 600; cursor: pointer; }
.stats .warn { background: var(--warn-soft); border-color: #efd59a; color: #7a5310; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; padding: 14px 20px; flex-wrap: wrap; border-bottom: 1px solid var(--line-2); }
.tgroup { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.legend { display: flex; gap: 16px; padding: 10px 20px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.lg { width: 14px; height: 14px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.08); }
.lg.err { background: var(--err-soft); box-shadow: inset 3px 0 0 var(--err); }
.lg.fuzzy { background: var(--warn-soft); box-shadow: inset 3px 0 0 var(--warn); }
.lg.total { background: var(--total-soft); }
.lg.head { background: var(--head-soft); }

.grid-wrap { overflow: auto; max-height: 70vh; border-top: 1px solid var(--line-2); }
.grid { border-collapse: separate; border-spacing: 0; font-size: 13.5px; min-width: 100%; }
.grid th, .grid td { border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); padding: 0; }
.grid thead th { position: sticky; top: 0; z-index: 2; background: #faf9f6; text-align: left; vertical-align: top; padding: 8px; min-width: 170px; max-width: 240px; font-weight: 500; }
.grid thead th.gut { min-width: 46px; width: 46px; left: 0; z-index: 3; }
.colhead { display: flex; flex-direction: column; gap: 5px; }
.colhead input { min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px; font-weight: 600; font-size: 13px; width: 100%; background: #fff; }
.colhead .ctl { display: flex; gap: 4px; }
.colhead select[data-scale] { flex: 0 0 74px; }
.colhead select { flex: 1; border: 1px solid var(--line); border-radius: 6px; padding: 3px 5px; font-size: 12.5px; background: #fff; min-width: 0; }
.colhead .mini { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 26px; cursor: pointer; font-size: 13px; padding: 0; }
.colhead .mini:hover { border-color: var(--accent); color: var(--accent); }
.colhead .scale { font: 11.5px var(--mono); color: var(--ink-3); }
.grid td.gut { position: sticky; left: 0; background: #faf9f6; z-index: 1; font: 11.5px var(--mono); color: var(--ink-3); text-align: right; padding: 0 6px; white-space: nowrap; }
.grid td.gut button { border: 0; background: none; color: var(--ink-3); cursor: pointer; padding: 0 2px; font-size: 14px; line-height: 1; visibility: hidden; }
.grid tr:hover td.gut button { visibility: visible; }
.grid td.gut button:hover { color: var(--err); }
.grid td.c { padding: 6px 8px; outline: none; white-space: nowrap; max-width: 380px; overflow: hidden; text-overflow: ellipsis; }
.grid td.c:focus { box-shadow: inset 0 0 0 2px var(--focus); background: #fff; white-space: normal; text-overflow: clip; }
.grid td.nr { text-align: right; font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.grid td.err { background: var(--err-soft); box-shadow: inset 3px 0 0 var(--err); }
.grid td.fuzzy { background: var(--warn-soft); box-shadow: inset 3px 0 0 var(--warn); }
.grid td.skip { color: #bbb; background: repeating-linear-gradient(-45deg, #fff, #fff 6px, #f6f6f6 6px, #f6f6f6 12px); }
.grid tr.head td.c { background: var(--head-soft); font-weight: 600; font-family: var(--sans); text-align: left; }
.grid tr.total td.c:not(.err) { background: var(--total-soft); font-weight: 600; }
.grid td .sub { display: block; font: 10.5px var(--sans); color: var(--ink-3); }

/* export */
.export-grid { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 0; }
.meta { padding: 16px 20px; border-right: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 10px; }
.opts { border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; margin: 4px 0 0; }
.opts legend { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); padding: 0 4px; }
.outs { padding: 16px 20px; min-width: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 14px; cursor: pointer; font-weight: 600; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.cards.two { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin: 10px 0; }
.card { text-align: left; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; transition: border-color .12s, box-shadow .12s; }
.card:hover:not(.static) { border-color: var(--accent); box-shadow: 0 2px 10px rgba(3,146,137,.08); }
.card.static { cursor: default; }
.card strong { font-size: 15px; }
.card span { font-size: 13px; color: var(--ink-2); }
.card .row { margin-top: 6px; }
.howto { padding-left: 20px; display: flex; flex-direction: column; gap: 10px; margin: 0 0 14px; }
.howto li { line-height: 1.9; }
.api { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.api summary { font-weight: 600; cursor: pointer; }
.api[open] { display: flex; flex-direction: column; gap: 10px; }
.api .btn { align-self: flex-start; }
.result { border-radius: 8px; padding: 10px 12px; background: var(--total-soft); font-size: 13.5px; }
.result.bad { background: var(--err-soft); color: var(--err); }
.result textarea { width: 100%; font: 12px var(--mono); margin-top: 6px; min-height: 90px; border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.code { background: #16181d; color: #e6e6e6; font: 12px/1.55 var(--mono); padding: 12px 14px; border-radius: 8px; overflow: auto; max-height: 320px; white-space: pre; }
.preview-det { margin-top: 14px; }
.preview-det summary { cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }
.embed-preview { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 8px; margin-top: 12px; background: #fff; }

.foot { padding: 24px 20px 40px; font-size: 12.5px; color: var(--ink-3); }
.foot p { margin: 0; max-width: 900px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--err); }

@media (max-width: 960px) {
  .reader-grid, .export-grid { grid-template-columns: 1fr; }
  .stage-col { border-right: 0; border-bottom: 1px solid var(--line); }
  .meta { border-right: 0; border-bottom: 1px solid var(--line-2); }
  .stage { height: 60vh; }
}
@media (max-width: 560px) {
  .wrap { padding: 0 14px; }
  .privacy { display: none; }
  .toolbar, .legend, .panel-head, .outs, .meta { padding-left: 14px; padding-right: 14px; }
}
