/* The same palette as the report page (stomata_detector/report_template.html), dark mode included. */
:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1d1f21;
  --muted: #626970;
  --faint: #8a8f96;
  --line: #dcdfe2;
  --soft: #eef0f2;
  --accent: #2459c4;
  --on-accent: #ffffff;
  --open: #1f77b4;
  --closed: #d9711b;
  --premature: #8a8f96;
  --bad: #c0392b;
  --aperture: #e07b1f; /* the outline colour in the measured pictures */
  --measure: #d42a1f;
  --cell-light: #e3e5e8;
  --cell-dark: #a9aeb5;
  --guard-line: #7c828a;
  --pore: #3b4046;
  /* Microscope slices sit on dark ground in both modes. Boxes drawn on them (bright or dark images) use
     saturated state colours with a dark halo. */
  --slide: #15171a;
  --slide-open: #3d9bff;
  --slide-closed: #ff8c1a;
  --slide-premature: #d5d9de;
  --display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --body: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --panel: #1e2125;
    --ink: #e8eaed;
    --muted: #9aa1a9;
    --faint: #7d848c;
    --line: #353a40;
    --soft: #272b30;
    --accent: #7aa7ff;
    --on-accent: #10141a;
    --open: #5aa9e6;
    --closed: #f0954a;
    --premature: #9aa1a9;
    --bad: #ff7b6b;
    --cell-light: #4a4f56;
    --cell-dark: #33373d;
    --guard-line: #6b7179;
    --pore: #0f1113;
    --slide: #0d0f11;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--body);
}

main {
  max-width: 54rem;
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
}

h1, h2 {
  font-family: var(--display);
  font-weight: 700;
  line-height: 1.1;
  margin: 0;
}

h1 {
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  letter-spacing: -0.02em;
}

h2 { font-size: 1.35rem; }

p { margin: 0.5rem 0 0; max-width: 40rem; }

a { color: var(--accent); }

code { font-size: 0.9em; }

.intro p { font-size: 1.1rem; color: var(--muted); margin-top: 0.9rem; }

/* Drop zone: the drawn stoma is the page's one big visual. */
.drop {
  margin-top: 2.25rem;
  display: grid;
  grid-template-columns: minmax(0, 15rem) 1fr;
  gap: 1.75rem;
  align-items: center;
  padding: 1.5rem;
  background: var(--panel);
  border: 2px dashed var(--line);
  border-radius: 1.5rem;
  transition: border-color 0.15s, background-color 0.15s;
}

.drop.over {
  border-color: var(--accent);
  background: var(--soft);
}

.drop.busy { opacity: 0.6; pointer-events: none; }

.stoma { width: 100%; height: auto; display: block; }
.stoma .guard { stroke: var(--guard-line); stroke-width: 2; }
.stoma .pore { fill: var(--pore); }
.stoma .outline { fill: none; stroke: var(--aperture); stroke-width: 4; }
.stoma .measure { stroke: var(--measure); stroke-width: 3; stroke-linecap: round; }

.drop.over .outline,
.drop.busy .outline {
  stroke-dasharray: 18 10;
  animation: trace 1.2s linear infinite;
}

@keyframes trace { to { stroke-dashoffset: -28; } }

.drop-text h2 { font-size: 1.55rem; }
.drop-text p { color: var(--muted); }

.link {
  font: inherit;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.options {
  margin-top: 1.25rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 0;
}

.options summary { cursor: pointer; font-weight: 600; }

.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem 1.5rem;
  margin-top: 1rem;
}

.option-grid label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 500; }
.option-grid label.check { flex-direction: row; align-items: center; gap: 0.5rem; }
.option-grid small { color: var(--muted); font-weight: 400; }

input[type="number"] {
  font: inherit;
  width: 8rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--panel);
  color: var(--ink);
}

input[type="checkbox"] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.status { margin-top: 1.5rem; color: var(--muted); }
.status.error { color: var(--bad); }

.loadbar { height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 0.5rem; }
.loadbar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
.loadbar.hidden { visibility: hidden; }

.run { margin-top: 2rem; }
.run-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.summary { margin: 0; color: var(--muted); }

.stacks { list-style: none; margin: 1rem 0 0; padding: 0; border-top: 1px solid var(--line); }

.stacks li {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr) minmax(0, 22rem);
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}

.stacks .name { overflow-wrap: anywhere; }
.stacks .from { display: block; color: var(--muted); font-size: 0.85rem; }
.stacks .result { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.stacks .error .result { color: var(--bad); }
.stacks .time { white-space: nowrap; margin-left: 0.5rem; color: var(--faint); }

/* State dot: waiting (hollow), working (pulsing accent), done (accent), failed (red). */
.dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; border: 2px solid var(--line); align-self: center; }
.working .dot { border-color: var(--accent); background: var(--accent); animation: pulse 1s ease-in-out infinite alternate; }
.done .dot { border-color: var(--accent); background: var(--accent); }
.error .dot { border-color: var(--bad); background: var(--bad); }
.stopped .dot { border-color: var(--muted); background: var(--muted); }
.not-run { opacity: 0.55; }
#stop { margin-left: auto; }
.downloads-note { color: var(--muted); font-size: 0.9rem; }

@keyframes pulse { to { opacity: 0.35; } }

.downloads { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.5rem; }

.button {
  font: inherit;
  cursor: pointer;
  display: inline-block;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  border: 2px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.button.primary { background: var(--accent); color: var(--on-accent); }
.button:hover { filter: brightness(1.1); }

.preview { margin-top: 2.5rem; }
.note { color: var(--muted); }

.table-wrap { margin-top: 1rem; overflow: auto; max-height: 34rem; background: var(--panel); border-radius: 0.75rem; border: 1px solid var(--line); }

table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 0.95rem; }
th, td { padding: 0.45rem 0.75rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 600; background: var(--soft); position: sticky; top: 0; }
td.num, th.num { text-align: right; }
td .unit { color: var(--muted); font-size: 0.85em; }
tbody tr:last-child td { border-bottom: 0; }
.state-open { color: var(--open); }
.state-closed { color: var(--closed); }
.state-premature { color: var(--premature); }

/* ---- viewer ---- */
.view-link { margin-left: 0.6rem; font-weight: 600; }

#rows tr { cursor: pointer; }
#rows tr:hover td, #rows tr:focus-visible td { background: var(--soft); }

/* The viewer breaks out of the reading column: slices need the room. */
.viewer {
  margin: 2.5rem min(0px, calc(50% - min(38rem, 50vw - 2rem))) 0;
  padding: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  scroll-margin-top: 1rem;
}
.viewer:focus { outline: none; }
.viewer:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.viewer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.viewer-head h2 { overflow-wrap: anywhere; }
.viewer-nav { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.chip {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
.chip:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.chip:disabled { opacity: 0.4; cursor: default; }

.viewer-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 19rem;
  gap: 1.25rem;
  margin-top: 1rem;
  align-items: start;
}

.slice-frame {
  position: relative;
  width: 100%;
  max-height: 75vh;
  background: var(--slide);
  border-radius: 0.75rem;
  overflow: hidden;
}
.slice-frame img, .slice-boxes { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.slice-frame img { object-fit: contain; transition: opacity 0.15s; }
.slice-frame.loading img { opacity: 0.45; }
.slice-message {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  margin: 0; padding: 0.4rem 0.8rem; border-radius: 0.5rem;
  background: rgba(13, 15, 17, 0.8); color: #fff; font-size: 0.9rem; text-align: center;
}

.box { cursor: pointer; --c: var(--muted); }
.box-open { --c: var(--slide-open); }
.box-closed { --c: var(--slide-closed); }
.box-premature { --c: var(--slide-premature); }
.box rect { fill: transparent; stroke: var(--c); stroke-width: 1.5; stroke-dasharray: 4 3; opacity: 0.7; filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, 0.9)); }
.box text { fill: var(--c); font-family: var(--body); font-weight: 700; opacity: 0.7; paint-order: stroke; stroke: var(--slide); stroke-width: 0.15em; }
.box.here rect { stroke-dasharray: none; stroke-width: 2; opacity: 1; }
.box.here text { opacity: 1; }
.box:hover rect, .box:focus rect { stroke-width: 3; opacity: 1; }
.box:focus { outline: none; }
.box.selected rect { stroke: var(--aperture); stroke-width: 3.5; stroke-dasharray: none; opacity: 1; }
.box.selected text { fill: var(--aperture); opacity: 1; }

.z-controls { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.75rem; flex-wrap: wrap; }
.z-controls input[type="range"] { flex: 1 1 12rem; accent-color: var(--accent); }
.z-label { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.9rem; min-width: 12rem; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 1rem; margin-top: 0.5rem; max-width: none; font-size: 0.85rem; color: var(--muted); }
.key::before { content: ""; display: inline-block; width: 0.8rem; height: 0.8rem; margin-right: 0.35rem; vertical-align: -0.1rem; border: 2px solid var(--c); border-radius: 0.2rem; background: var(--slide); }
.key-open { --c: var(--slide-open); }
.key-closed { --c: var(--slide-closed); }
.key-premature { --c: var(--slide-premature); }

.stoma-panel {
  position: sticky;
  top: 1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 1rem;
}
.stoma-empty { color: var(--muted); }
.stoma-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.stoma-head h3 { margin: 0; font-family: var(--display); font-size: 1.2rem; }
.badge { font-size: 0.8rem; font-weight: 700; padding: 0.15rem 0.6rem; border-radius: 999px; background: var(--soft); }
.badge-open { background: color-mix(in srgb, var(--open) 16%, var(--panel)); color: var(--open); }
.badge-closed { background: color-mix(in srgb, var(--closed) 16%, var(--panel)); color: var(--closed); }
.badge-premature { color: var(--premature); }
.stoma-img { display: block; width: 100%; height: auto; margin-top: 0.75rem; border-radius: 0.5rem; background: var(--slide); image-rendering: pixelated; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; margin: 0.9rem 0 0; font-variant-numeric: tabular-nums; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }
.stoma-nav { display: flex; justify-content: space-between; margin-top: 1rem; }

@media (max-width: 52rem) {
  .viewer { margin-left: 0; margin-right: 0; padding: 1rem; }
  .viewer-body { grid-template-columns: 1fr; }
  .stoma-panel { position: static; }
}

footer { margin-top: 3rem; color: var(--muted); font-size: 0.9rem; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

@media (max-width: 38rem) {
  .drop { grid-template-columns: 1fr; text-align: left; }
  .stoma { max-width: 12rem; }
  .stacks li { grid-template-columns: 1.25rem minmax(0, 1fr); }
  .stacks .result { grid-column: 2; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
