/* KM Curve Extractor -- all page styling. */
  :root {
    --bg: #fbfbfa; --panel: #fff; --line: #e4e2dd; --ink: #1f1e1c;
    --muted: #6b6862; --accent: #2f6f4e; --warn: #9a5b1e; --danger: #a33a2a;
  }
  * { box-sizing: border-box; }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  }
  header {
    display: flex; align-items: baseline; gap: 12px; padding: 14px 20px;
    border-bottom: 1px solid var(--line); background: var(--panel);
  }
  header h1 { font-size: 16px; margin: 0; font-weight: 600; }
  header span { color: var(--muted); font-size: 13px; }
  main { padding: 20px; max-width: 1500px; margin: 0 auto; }

  .card {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 8px; padding: 18px; margin-bottom: 16px;
  }
  .row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
  label { font-size: 13px; color: var(--muted); }
  input[type=number], select, input[type=text] {
    font: inherit; padding: 6px 8px; border: 1px solid var(--line);
    border-radius: 5px; background: #fff; color: var(--ink);
  }
  input[type=number] { width: 72px; }
  button {
    font: inherit; padding: 7px 14px; border-radius: 6px; cursor: pointer;
    border: 1px solid var(--line); background: #fff; color: var(--ink);
  }
  button:hover:not(:disabled) { border-color: #c9c6bf; }
  button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  button.primary:hover:not(:disabled) { background: #275d41; }
  button:disabled { opacity: .5; cursor: not-allowed; }

  #drop {
    border: 2px dashed var(--line); border-radius: 8px; padding: 34px;
    text-align: center; color: var(--muted); cursor: pointer; background: #fff;
  }
  #drop.over { border-color: var(--accent); background: #f2f8f4; color: var(--accent); }

  #status { margin-top: 10px; font-size: 13px; min-height: 20px; }
  .err { color: var(--danger); }
  .warn { color: var(--warn); }
  .ok { color: var(--accent); }

  #editor { display: none; }
  .split { display: grid; grid-template-columns: 1fr 290px; gap: 16px; align-items: start; }
  @media (max-width: 980px) { .split { grid-template-columns: 1fr; } }

  #canvasWrap {
    position: relative; border: 1px solid var(--line); border-radius: 8px;
    overflow: hidden; background: #fff; line-height: 0;
  }
  canvas { display: block; width: 100%; cursor: crosshair; touch-action: none; }

  .side h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase;
             letter-spacing: .04em; color: var(--muted); font-weight: 600; }
  .curveItem {
    display: flex; align-items: center; gap: 8px; padding: 7px 8px;
    border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px;
    cursor: pointer; background: #fff;
  }
  .curveItem.active { border-color: var(--accent); background: #f2f8f4; }
  .swatch { width: 14px; height: 14px; border-radius: 3px; flex: none;
            border: 1px solid rgba(0,0,0,.2); }
  .curveItem .nm { flex: 1; overflow: hidden; text-overflow: ellipsis;
                   white-space: nowrap; font-size: 13px; }
  .curveItem .ct { color: var(--muted); font-size: 12px; }

  table.info { width: 100%; font-size: 12.5px; border-collapse: collapse; }
  table.info td { padding: 3px 0; vertical-align: top; }
  table.info td:first-child { color: var(--muted); padding-right: 10px; white-space: nowrap; }
  kbd {
    font: 11px ui-monospace, monospace; background: #f3f2ef; padding: 1px 5px;
    border: 1px solid var(--line); border-radius: 3px;
  }
  ul.help { margin: 6px 0 0; padding-left: 0; list-style: none; font-size: 12.5px; color: var(--muted); }
  ul.help li { margin-bottom: 4px; }
  /* Shortcuts, two columns: key on the left, what it does on the right.
     A grid rather than a list so the keys line up and the block stays short
     enough to scan without scrolling the sidebar. */
  dl.keys {
    display: grid; grid-template-columns: auto 1fr; gap: 3px 8px;
    margin: 4px 0 0; font-size: 12px; color: var(--muted); align-items: baseline;
  }
  dl.keys dt { text-align: right; white-space: nowrap; }
  dl.keys dd { margin: 0; }
  p.hint { margin: 2px 0 8px; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
  .sep { height: 1px; background: var(--line); margin: 14px 0; }

  /* --- progressive disclosure -----------------------------------------
     Everything an expert needs is still here; a first-time user should not
     have to read past it to find the four things that matter. */
  details.more { margin-top: 10px; }
  details.more > summary {
    cursor: pointer; font-size: 12.5px; color: var(--muted);
    padding: 5px 0; list-style: none; user-select: none;
  }
  details.more > summary::-webkit-details-marker { display: none; }
  details.more > summary::before { content: "▸ "; font-size: 10px; }
  details.more[open] > summary::before { content: "▾ "; }
  details.more > summary:hover { color: var(--ink); }
  details.more > .body { padding-top: 6px; }

  /* Toolbar popover for the view switches. */
  details.pop { position: relative; }
  details.pop > summary {
    cursor: pointer; list-style: none; font: inherit; padding: 7px 14px;
    border: 1px solid var(--line); border-radius: 6px; background: #fff;
  }
  details.pop > summary::-webkit-details-marker { display: none; }
  details.pop > .body {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 8px; padding: 12px; min-width: 230px;
    box-shadow: 0 6px 20px rgba(0,0,0,.09);
  }
  details.pop > .body label { display: block; margin-bottom: 7px; }

  /* The verdict: the first thing read after an extraction, and the only
     place that says whether the result can be trusted. */
  #verdict { font-size: 13px; line-height: 1.45; margin-bottom: 12px;
             padding: 10px 12px; border-radius: 7px; border: 1px solid var(--line); }
  #verdict.good { background: #f2f8f4; border-color: #cbe3d5; }
  #verdict.check { background: #fdf3e3; border-color: #e8d3a8; }
  #verdict b { font-weight: 600; }
  #verdict .sub { color: var(--muted); display: block; margin-top: 3px; }

  /* Re-reading a stretch takes 10-60s. With feedback only in the status
     strip at the top of the page the button looked dead, so the wait is
     shown where the click happened. Indeterminate, because the model gives
     no progress to report -- the elapsed seconds carry the "still working"
     signal instead. */
  #fixProgress { margin-top: 9px; }
  #fixProgress .bar {
    height: 4px; border-radius: 3px; background: #ece9e3; overflow: hidden;
  }
  #fixProgress .bar span {
    display: block; height: 100%; width: 38%; border-radius: 3px;
    background: var(--accent); animation: fixslide 1.15s ease-in-out infinite;
  }
  @keyframes fixslide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(300%); }
  }
  @media (prefers-reduced-motion: reduce) {
    #fixProgress .bar span { animation: none; width: 100%; opacity: .5; }
  }

  .cta { width: 100%; padding: 11px 14px; font-size: 14.5px; font-weight: 600; }
  .stack > button { width: 100%; margin-top: 7px; }
  .steps { counter-reset: s; }
