/* ==========================================================================
   Growth Curve Analyzer on bryanchen.net (/tools/growth-curves/)

   Loaded after /ui/site.css and /ui/notebook.css. Fonts, page colours, buttons,
   header and footer all come from site.css; this file only lays out the tool.
   The tool's own colour names point at the site palette, so the header toggle
   and the system light/dark setting both work.
   ========================================================================== */

:root {
  --text-muted: var(--faint);   /* app.js draws ungrouped wells with this */
  --hover: color-mix(in oklab, var(--ink) 7%, transparent);
  --warn: #fab219;
  --error: #d03b3b;
  /* Group / curve colours, used in this fixed order (checked for colour-blind safety
     in the original tool). These are data colours, not the site accent. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
}

/* Same eight hues, re-stepped for the dark surface. Two blocks, like site.css:
   system dark (unless the toggle pinned light), and the toggle pinning dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}
:root[data-theme="dark"] {
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

@layer sections {

  /* ---------- Page text around the tool ---------- */
  .gc-intro { margin-block-start: clamp(1.5rem, 1rem + 2vw, 2.5rem); }

  /* The tool needs JavaScript. Without it the page still explains itself. */
  html:not(.js) .gc { display: none; }
  .gc-nojs {
    margin-block-start: 2rem; padding: 1rem;
    border: 1px solid var(--rule); border-radius: var(--radius); color: var(--soft);
  }

  /* ---------- The tool ---------- */
  /* The tool's layout assumes border-box sizing (site.css's reset ends up content-box). */
  .gc, .gc *, .gc *::before, .gc *::after { box-sizing: border-box; }
  .gc {
    margin-block-start: clamp(2rem, 1.5rem + 2vw, 3rem);
    display: grid; gap: 1rem;
    font-size: 0.9375rem; line-height: 1.5;
  }
  .gc h2 { font-size: 1.45rem; }
  .gc .btn { white-space: nowrap; }
  .gc .btn:disabled { opacity: 0.45; cursor: default; pointer-events: none; }

  .help, .note, .file-info, .gc-hint { color: var(--soft); font-size: 0.875rem; }
  .help { max-inline-size: 70ch; }
  .note:empty { display: none; }
  .note { font-style: italic; }
  .file-info { font-family: var(--font-mono); font-size: 0.8125rem; overflow-wrap: anywhere; }
  .gc-hint strong { color: var(--ink); font-weight: 600; }

  .toolbar {
    display: flex; flex-wrap: wrap; gap: 0.75rem 1rem; align-items: end;
    padding: 1rem; background: var(--raised);
    border: 1px solid var(--rule); border-radius: var(--radius);
  }
  .toolbar .gc-hint { flex-basis: 100%; }

  .field { display: grid; gap: 0.2rem; font-size: 0.8125rem; color: var(--soft); }
  .field input, .field select, .group-form input {
    font: inherit; font-size: 0.9375rem; color: var(--ink);
    background: var(--paper); border: 1px solid var(--faint); border-radius: var(--radius);
    padding: 0 0.6rem; block-size: 2.25rem;
  }
  .field input { inline-size: 6.5rem; }

  /* ---------- Banner (parser warnings and errors) ---------- */
  .banner {
    padding: 0.65rem 0.75rem;
    background: var(--raised); border: 1px solid var(--rule); border-inline-start: 4px solid var(--warn);
    border-radius: var(--radius); display: flex; gap: 0.75rem; align-items: start;
  }
  .banner.is-error { border-inline-start-color: var(--error); }
  .banner ul { margin: 0; padding: 0; list-style: none; flex: 1; min-width: 0; overflow-wrap: anywhere; }
  .banner li + li { margin-block-start: 0.25rem; }

  /* ---------- Layout ---------- */
  .empty-state {
    border: 2px dashed var(--rule); border-radius: var(--radius);
    padding: 3rem 1rem; text-align: center; display: grid; gap: 0.5rem; justify-items: center;
  }
  .empty-state p { color: var(--soft); max-inline-size: 60ch; }

  .workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
  .workspace[hidden], .empty-state[hidden], .banner[hidden] { display: none; }
  .panel.wide { grid-column: 1 / -1; }
  @media (max-width: 62.5rem) { .workspace { grid-template-columns: minmax(0, 1fr); } }

  .panel {
    background: var(--raised); border: 1px solid var(--rule); border-radius: var(--radius);
    padding: 1rem; display: grid; gap: 0.65rem; min-width: 0;
  }
  .panel-head { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: space-between; }
  .check { font-size: 0.9375rem; display: inline-flex; gap: 0.4rem; align-items: center; min-block-size: 2.25rem; }

  /* ---------- Plate ---------- */
  .actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
  .sel-count { font-size: 0.875rem; font-weight: 600; margin-inline-end: 0.25rem; min-width: 9.5em; }
  .group-form { display: flex; flex-wrap: wrap; gap: 0.4rem; }
  .group-form input { inline-size: 11rem; }
  #group-input::placeholder { color: var(--faint); opacity: 1; } /* the browser grey is under 4.5:1 */

  .plate-scroll, .plot-scroll, .table-scroll { overflow-x: auto; max-width: 100%; }
  .plate-scroll { padding: 3px; } /* room for the selection ring */

  #plate { display: grid; gap: 4px; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
  #plate.is-plate { grid-template-columns: 1.3rem repeat(var(--cols), minmax(20px, 1fr)); } /* 20px + 4px gap: centres 24px apart (WCAG 2.5.8) */
  #plate.is-list { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }

  .axis {
    font-family: var(--font-mono); font-size: 0.6875rem; color: var(--soft);
    background: none; border: 0; border-radius: 4px; padding: 0; cursor: pointer; min-block-size: 1.3rem;
  }
  .axis:hover { background: var(--hover); color: var(--ink); }

  /* --c is the well's colour (its group colour), set inline by app.js. */
  .well {
    --c: var(--soft);
    position: relative; display: block; min-width: 0; padding: 1px; cursor: pointer;
    font: inherit; color: var(--c);
    background: var(--paper); border: 1px solid var(--rule); border-radius: 4px;
  }
  .well svg { display: block; width: 100%; height: auto; pointer-events: none; }
  .well:hover { border-color: var(--faint); }
  .well.is-grouped {
    background: color-mix(in srgb, var(--c) 13%, var(--raised));
    border-color: color-mix(in srgb, var(--c) 55%, var(--raised));
    box-shadow: inset 0 3px 0 var(--c);
  }
  .well.is-blank {
    --c: var(--faint);
    border-style: dashed; border-color: var(--faint);
    background: repeating-linear-gradient(45deg, transparent 0 4px, var(--hover) 4px 6px);
  }
  .well.is-selected { outline: 2px solid var(--ink); outline-offset: 0; z-index: 1; }
  .well.is-selected:focus-visible { outline-color: var(--accent); }
  .well-empty { border: 1px dotted var(--rule); border-radius: 4px; }
  .well-name {
    display: block; font-size: 0.6875rem; color: var(--ink); text-align: left; padding: 0 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none;
  }

  .plate-legend {
    list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem;
    font-size: 0.8125rem; color: var(--soft);
  }
  .plate-legend:empty { display: none; }
  .plate-legend li { display: inline-flex; gap: 0.4rem; align-items: center; min-width: 0; overflow-wrap: anywhere; }
  .swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--c); flex: none; }
  .swatch.is-blank {
    background: repeating-linear-gradient(45deg, transparent 0 3px, var(--hover) 3px 5px);
    border: 1px dashed var(--faint);
  }

  /* ---------- Detail plot ---------- */
  .detail-plot { min-width: 520px; } /* below this the axis text gets too small; the box scrolls instead */
  .detail-plot svg { display: block; }
  .plot-empty {
    min-height: 220px; display: grid; place-items: center; text-align: center;
    color: var(--soft); border: 1px dashed var(--rule); border-radius: var(--radius); padding: 1rem;
  }
  .detail-plot:has(.plot-empty) { min-width: 0; }

  /* ---------- Tables ---------- */
  .gc table { border-collapse: collapse; width: 100%; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
  .gc th, .gc td { padding: 0.3rem 0.6rem; text-align: left; border-bottom: 1px solid var(--rule); white-space: nowrap; }
  .gc th { font-weight: 600; color: var(--soft); font-size: 0.8125rem; }
  .gc th.num, .gc td.num { text-align: right; }
  .gc th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
  .gc th button:hover { color: var(--ink); text-decoration: underline; }
  .gc th[aria-sort="ascending"] button::after { content: " ▲"; font-size: 0.7em; }
  .gc th[aria-sort="descending"] button::after { content: " ▼"; font-size: 0.7em; }
  .gc th[aria-sort] { color: var(--ink); }
  .gc tbody tr:hover { background: var(--hover); }
  .gc td .reason { display: block; color: var(--soft); font-size: 0.8125rem; white-space: normal; min-width: 16rem; max-width: 28rem; }
  .gc td.muted { color: var(--soft); }
  .gc td .swatch { display: inline-block; vertical-align: -1px; margin-inline-end: 0.4rem; }
  .table-empty { color: var(--soft); font-style: italic; white-space: normal; }

  /* ---------- Glossary ---------- */
  .glossary summary { cursor: pointer; font-weight: 600; }
  .glossary dl { margin: 0.25rem 0 0; max-width: 75ch; font-size: 0.9375rem; }
  .glossary dt { font-weight: 600; margin-block-start: 0.5rem; }
  .glossary dd { margin: 0; color: var(--soft); }
}

/* The whole page is a drop target: this overlay shows while a file is dragged over it. */
body.is-dragging::after {
  content: "Drop the CSV file to load it";
  position: fixed; inset: 8px; z-index: 30;
  display: grid; place-items: center;
  font-family: var(--font-display); font-size: 1.6rem; color: var(--ink);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  border: 3px dashed var(--accent); border-radius: 12px;
  pointer-events: none;
}
