/* bucket: styles. the palette, faces and radius live in tokens.css, generated from the catalog record */

:root {
  /* derived, not in the record: refused requests read as coral, focus is the accent */
  --bad: #FF8F7A;
  --focus: var(--accent);
  --line: color-mix(in srgb, var(--ink) 14%, transparent);
  --line-strong: color-mix(in srgb, var(--ink) 30%, transparent);
  --card-bg: color-mix(in srgb, var(--surface) 84%, transparent);
  --well: color-mix(in srgb, var(--ink) 7%, transparent);
  --shadow: 0 24px 60px -24px color-mix(in srgb, #000 55%, transparent);
  --font-display: var(--font-display-stack);
  --font-body: var(--font-body-stack);
  --gutter: 16px;
  --tap: 44px;
  --chart-h: 44px;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bad: #C2381F;
    --shadow: 0 24px 60px -28px color-mix(in srgb, #291D27 38%, transparent);
  }
}

:root[data-theme="light"] {
  --bad: #C2381F;
  --shadow: 0 24px 60px -28px color-mix(in srgb, #291D27 38%, transparent);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark light;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.4;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

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

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  position: fixed;
  z-index: 5;
  left: var(--gutter);
  right: var(--gutter);
  top: 72px;
  margin: 0;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
}

/* stage: the canvas fills the viewport, with a faint film grain on top of it */
.stage {
  position: fixed;
  inset: 0;
  overflow: clip;
  background: var(--bg);
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .stage::after {
    opacity: 0.07;
    filter: invert(1);
  }
}

:root[data-theme="light"] .stage::after {
  opacity: 0.07;
  filter: invert(1);
}

/* layout: header, the three lanes, the card, the footer. on a phone they stack; wide screens put the card at the right */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 0 var(--gutter);
  pointer-events: none;
}

.app > * {
  pointer-events: auto;
}

@media (min-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 372px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    column-gap: 24px;
    padding: 0 24px;
    --chart-h: 60px;
  }

  .bar,
  .foot {
    grid-column: 1 / -1;
  }

  .lanes {
    grid-column: 1;
    grid-row: 2;
  }

  .card {
    grid-column: 2;
    grid-row: 2;
  }
}

/* header: wordmark left, one icon button right */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 0;
  transition: opacity 0.5s ease;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  color: var(--ink);
  text-decoration: none;
  border-radius: 12px;
}

.wordmark__water {
  stroke: var(--accent);
}

.wordmark__text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* the level line under the b */
.wordmark__b {
  display: inline-block;
  padding-bottom: 3px;
  background: linear-gradient(var(--accent), var(--accent)) left bottom / 100% 2px no-repeat;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--ink);
}

.icon-btn:hover {
  border-color: var(--line-strong);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* lanes: a head, the stage the canvas draws the stream and bucket in, the chart, a one-line note */
.lanes {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.lane {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) var(--chart-h) auto;
  gap: 2px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}

.lane:first-of-type {
  border-top: 0;
}

.lane__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.lane__titles {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.lane__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.lane__note {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lane__legend {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.lane__num {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: right;
}

.lane__word + .key {
  margin-left: 8px;
}

.key {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: none;
}

.key--ok {
  background: var(--accent);
}

.key--no {
  border: 2px solid var(--bad);
}

.lane__stage,
.lane__chart {
  min-width: 0;
  min-height: 0;
}

.lane__foot {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  display: none;
}

@media (min-width: 600px) and (min-height: 640px) {
  .lane__foot {
    display: block;
  }
}

@media (max-width: 599px) {
  .lane__note {
    display: none;
  }

  /* the words drop out of sight on a phone, the swatches and counts stay, and screen readers still hear them */
  .lane__word {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .lane__num + .lane__word + .key,
  .lane__word + .key {
    margin-left: 8px;
  }
}

.hint {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* the one floating translucent card */
.card {
  min-height: 0;
  max-height: 46dvh;
  overflow-y: auto;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card-bg);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  box-shadow: var(--shadow);
  transition: opacity 0.5s ease;
}

@media (min-width: 860px) {
  .card {
    max-height: none;
    margin-bottom: 4px;
  }
}

.card__label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12.5px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  font-weight: 600;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.transport {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: transparent;
  font-weight: 600;
}

.btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  min-width: 96px;
}

.time {
  margin-left: auto;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  min-width: 6ch;
  text-align: right;
}

.speed {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;
  margin-top: 4px;
}

.speed .knob__head {
  gap: 10px;
}

@media (max-width: 859px) {
  /* a phone has no room to spare: the group label stays for screen readers, the chips get tighter */
  .card__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .chip {
    padding: 0 11px;
    font-size: 14px;
  }

  .card {
    padding: 8px 14px;
  }

  .transport {
    margin-top: 6px;
  }
}

.knob__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
}

.speed output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* sliders */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: var(--tap);
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill, 0%), var(--line-strong) var(--fill, 0%));
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--fill, 0%), var(--line-strong) var(--fill, 0%));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border-radius: 999px;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line-strong);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line-strong);
}

/* folds */
.fold {
  margin-top: 8px;
  border-top: 1px solid var(--line);
}

.fold__title {
  margin: 0;
  font-size: inherit;
}

.fold__btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: var(--tap);
  padding: 0;
  border: 0;
  background: transparent;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  text-align: left;
}

.fold__btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.fold__btn[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.fold__body[hidden] {
  display: none;
}

/* the tuning cards: a small label over a big numeral, a slider under it */
.knobs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-bottom: 6px;
}

.knob {
  min-width: 0;
  padding: 10px 12px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--well);
}

.knob--wide {
  grid-column: 1 / -1;
}

.knob__out {
  display: block;
  min-height: 32px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  line-height: 32px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.knob__out small {
  margin-left: 0;
  color: var(--muted);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 12.5px;
  letter-spacing: 0;
}

/* explain */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: var(--tap);
  padding: 0;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.explain {
  display: grid;
  padding: 10px 0 6px;
}

.explain__panel {
  grid-area: 1 / 1;
  min-width: 0;
}

.explain__panel[data-active="false"] {
  visibility: hidden;
}

.explain__text {
  margin: 0 0 8px;
}

.explain__code {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--well);
  border: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  overflow-x: auto;
}

/* footer: one quiet line, one link, no hover styling */
.foot {
  display: flex;
  justify-content: center;
  padding: 0 0 8px;
  font-size: 12px;
}

.foot a {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  color: var(--muted);
  text-decoration: none;
}

/* idle: the header and card fade out of the way of the picture, and any input brings them back */
[data-idle="true"] .bar,
[data-idle="true"] .card:not(:focus-within) {
  opacity: 0.14;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
