/* CSC 482 HW4 - same look as /quicksort/ (HW3) so the two homework sites read as a pair,
   plus the pieces this page adds: visitor paths, the before/after check, the chart and the
   admin box. Light and dark both follow the visitor's system setting. */

:root {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #5c5c5c;
  --border: #e0e0e0;
  --accent: #1d4ed8;
  --accent-fg: #ffffff;
  --card-bg: #ffffff;
  --code-bg: #f2f2f2;
  --ok: #0f7a2e;
  --warn: #a14a00;
  --danger: #b42318;
  --notice-bg: #eef4ff;
  --grid: #e6e6e6;
  --axis: #b9b9b9;
  /* Chart series: four hues far enough apart to tell apart, each also given its own dash. */
  --s-radix: #1d4ed8;
  --s-radix16: #7c3aed;
  --s-array: #c2410c;
  --s-orderby: #0f766e;
  --max-width: 1040px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #eaeaea;
    --muted: #a3a3a3;
    --border: #2c2c2c;
    --accent: #6ea8fe;
    --accent-fg: #0b1220;
    --card-bg: #1b1b1b;
    --code-bg: #1e1e1e;
    --ok: #4ade80;
    --warn: #fbbf24;
    --danger: #f87171;
    --notice-bg: #172033;
    --grid: #2a2a2a;
    --axis: #4a4a4a;
    --s-radix: #6ea8fe;
    --s-radix16: #b39bfa;
    --s-array: #fb923c;
    --s-orderby: #2dd4bf;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.wrap { max-width: var(--max-width); margin: 0 auto; padding: 0 1rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--code-bg); border-radius: 4px; padding: 0.1em 0.35em; font-size: 0.9em; }

.site-header { border-bottom: 1px solid var(--border); padding: 0.9rem 0; }
.site-header .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
.site-header .brand { font-weight: 700; color: var(--fg); }
.site-header nav { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.92rem; }
.site-header nav a { color: var(--muted); }

main.wrap { padding-top: 2rem; padding-bottom: 3rem; min-height: 60vh; }
main section { margin-bottom: 2.5rem; }
h2 { margin: 0 0 0.5rem; }
h3 { margin: 1.25rem 0 0.4rem; font-size: 1.05rem; }

.site-footer { border-top: 1px solid var(--border); padding: 1.25rem 0; color: var(--muted); font-size: 0.85rem; }

.hero { padding: 0.5rem 0 0.5rem; }
.hero h1 { margin: 0 0 0.4rem; font-size: 2.1rem; line-height: 1.2; }
.hero .lede { color: var(--muted); font-size: 1.05rem; max-width: 68ch; }

.note { color: var(--muted); font-size: 0.9rem; }
.empty { color: var(--muted); font-style: italic; }
.ok { color: var(--ok); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }

/* Buttons - links and asp:Buttons (inputs) alike. */
.button {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}
.button.secondary { background: transparent; color: var(--accent); }
.button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0; }

/* Admin box. */
.admin { background: var(--card-bg); border: 1px dashed var(--accent); border-radius: 8px; padding: 1rem 1.1rem; margin-bottom: 2.5rem; }
.admin-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 1rem; }
.admin h3 { margin-top: 1rem; }
.notice { background: var(--notice-bg); border-radius: 6px; padding: 0.5rem 0.75rem; margin: 0.5rem 0; }
.progress { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin: 0.75rem 0; }
.progress[hidden] { display: none; }
.progress .bar { flex: 1 1 240px; height: 10px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.4s ease; }
.progress span { font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
/* The sort bar updates several times a second, so its slide has to keep up. */
.progress.fast .bar i { transition-duration: 0.12s; }
.placeholder { border: 1px dashed var(--border); border-radius: 8px; padding: 0.9rem 1rem; color: var(--muted); }

/* Visitor paths. */
.path-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 0 2rem; }
.paths { list-style: none; margin: 0; padding: 0; }
.path { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 0.85rem; margin-bottom: 0.75rem; }
.path-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem; margin-bottom: 0.4rem; }
.path-head .ip { font-weight: 600; }
.path-head .count { font-weight: 600; font-variant-numeric: tabular-nums; }
.path-head .when { color: var(--muted); font-size: 0.85rem; }
.tag { font-size: 0.75rem; padding: 0.05rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.3rem; font-size: 0.85rem; }
.steps li { background: var(--code-bg); border-radius: 4px; padding: 0.1rem 0.5rem; }
.steps li + li::before { content: "\203A"; color: var(--muted); margin: 0 0.45rem 0 -0.15rem; }
.steps .times { color: var(--muted); font-variant-numeric: tabular-nums; }
.steps .more { background: none; color: var(--muted); }

/* Tables. */
table { border-collapse: collapse; width: 100%; margin: 0.5rem 0 1rem; font-size: 0.92rem; }
th, td { border: 1px solid var(--border); padding: 0.4rem 0.6rem; text-align: left; }
th { background: var(--code-bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: 760px; }
.pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 1.5rem; }

pre.plain { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.9rem 1rem; overflow-x: auto; font-size: 0.85rem; line-height: 1.5; }

/* Chart. */
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; font-size: 0.88rem; color: var(--muted); margin: 1rem 0 0.25rem; }
.legend .key { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { display: inline-block; width: 18px; height: 3px; border-radius: 2px; }
.swatch.s-radix { background: var(--s-radix); }
.swatch.s-radix16 { background: repeating-linear-gradient(90deg, var(--s-radix16) 0 6px, transparent 6px 9px); }
.swatch.s-array { background: var(--s-array); }
.swatch.s-orderby { background: repeating-linear-gradient(90deg, var(--s-orderby) 0 2px, transparent 2px 5px); }
.swatch.guide { background: repeating-linear-gradient(90deg, var(--axis) 0 4px, transparent 4px 7px); }
svg.chart { display: block; width: 100%; height: auto; max-width: 820px; }
svg.chart line.grid { stroke: var(--grid); stroke-width: 1; }
svg.chart line.axis { stroke: var(--axis); stroke-width: 1; }
svg.chart line.guide { stroke: var(--axis); stroke-width: 1.5; stroke-dasharray: 5 4; }
svg.chart text.lbl { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
svg.chart polyline { fill: none; stroke-width: 2.25; stroke-linejoin: round; }
svg.chart polyline.s-radix16 { stroke-dasharray: 6 3; }
svg.chart polyline.s-orderby { stroke-dasharray: 2 3; }
svg.chart .s-radix { stroke: var(--s-radix); }
svg.chart .s-radix16 { stroke: var(--s-radix16); }
svg.chart .s-array { stroke: var(--s-array); }
svg.chart .s-orderby { stroke: var(--s-orderby); }
svg.chart circle { stroke: var(--card-bg); stroke-width: 1.5; }
svg.chart circle.s-radix { fill: var(--s-radix); }
svg.chart circle.s-radix16 { fill: var(--s-radix16); }
svg.chart circle.s-array { fill: var(--s-array); }
svg.chart circle.s-orderby { fill: var(--s-orderby); }

/* One n at a time: a button per n, then the four sorts as bars for the n that's pressed. */
.per-n { margin: 1.5rem 0 1rem; }
.per-n h3 { margin-bottom: 0.25rem; }
.per-n h4 { margin: 0 0 0.5rem; font-size: 0.98rem; }
.n-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.n-pick { font: inherit; font-size: 0.88rem; font-variant-numeric: tabular-nums; padding: 0.3rem 0.75rem; border-radius: 999px; border: 1px solid var(--border); background: var(--card-bg); color: var(--fg); cursor: pointer; }
.n-pick:hover { border-color: var(--accent); }
.n-pick.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.per-n.js .n-panel:not(.active) { display: none; }
.n-panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.7rem 0.9rem 0.5rem; margin-top: 0.6rem; }
.n-panel .note { margin: 0.6rem 0 0.2rem; }
.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: minmax(170px, 1.2fr) minmax(120px, 3fr) auto auto auto; align-items: center; gap: 0.2rem 0.8rem; padding: 0.35rem 0; border-top: 1px solid var(--border); font-size: 0.9rem; }
.bars li:first-child { border-top: 0; }
.bar-name { font-weight: 600; line-height: 1.3; }
.bar-name small { display: block; color: var(--muted); font-size: 0.76rem; font-weight: 400; }
.bar-track { display: block; height: 14px; background: var(--code-bg); border-radius: 4px; overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: 4px; }
.bar-track i.s-radix { background: var(--s-radix); }
.bar-track i.s-radix16 { background: var(--s-radix16); }
.bar-track i.s-array { background: var(--s-array); }
.bar-track i.s-orderby { background: var(--s-orderby); }
.bar-val, .bar-per, .bar-rel { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.bar-val { font-weight: 600; }
.bar-per, .bar-rel { color: var(--muted); font-size: 0.85rem; }
@media (max-width: 680px) {
  .bars li { grid-template-columns: 1fr 1fr 1fr; }
  .bar-name, .bar-track { grid-column: 1 / -1; }
  .bar-val, .bar-per, .bar-rel { text-align: left; }
}

/* Source code: one fold-out per file, numbered lines, light colouring. */
:root { --tk-c: #6e7781; --tk-s: #0a3069; --tk-k: #cf222e; }
@media (prefers-color-scheme: dark) {
  :root { --tk-c: #8b949e; --tk-s: #a5d6ff; --tk-k: #ff7b72; }
}
details.source { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 0.75rem; background: var(--card-bg); }
details.source > summary { cursor: pointer; padding: 0.6rem 0.85rem; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem; list-style: none; }
details.source > summary::-webkit-details-marker { display: none; }
/* A flex summary loses the browser's own triangle, so draw one: ▸ closed, ▾ open. */
details.source > summary::before { content: "\25B8"; color: var(--accent); width: 0.8em; }
details.source[open] > summary::before { content: "\25BE"; }
details.source > summary code { font-weight: 600; }
details.source[open] > summary { border-bottom: 1px solid var(--border); }
pre.code { margin: 0; padding: 0.75rem 0.85rem 0.75rem 0; overflow: auto; max-height: 75vh; background: var(--code-bg); border-radius: 0 0 8px 8px; font-size: 0.82rem; line-height: 1.5; counter-reset: line; }
pre.code code { background: none; padding: 0; font-size: inherit; }
pre.code .ln { counter-increment: line; }
pre.code .ln::before { content: counter(line); display: inline-block; width: 3em; padding-right: 1em; text-align: right; color: var(--muted); opacity: 0.7; user-select: none; }
.tk-c { color: var(--tk-c); font-style: italic; }
.tk-s { color: var(--tk-s); }
.tk-k { color: var(--tk-k); }

.prose { max-width: 74ch; }
.prose ul { padding-left: 1.25rem; }

@media (max-width: 560px) {
  .hero h1 { font-size: 1.6rem; }
  .path-lists { grid-template-columns: 1fr; }
}
