/**
 * The reading panel.
 *
 * The site's argument, made by working rather than being described: somebody who
 * finds Mint easier has experienced the product instead of reading a claim.
 *
 * **It overlays rather than expands.** It began as a block that pushed the page
 * down, which was wrong twice over — it shoved the content away at the moment
 * somebody wanted to look at it, and every open and close reflowed the whole
 * document, which is a jarring thing to do to a reader who is here because
 * moving text is a problem for them.
 *
 * **Deliberately not modal.** No focus trap, no scrim, no inert background. The
 * whole point of these controls is watching real text change as you adjust them,
 * so the page has to stay readable, scrollable and truthfully coloured behind
 * the panel. A dimming backdrop would be actively misleading on a site about
 * colour comfort.
 *
 * Built by `scripts/panel.js` rather than written into every page, so a visitor
 * with JavaScript off gets no dead controls — only the default ground, which is
 * already correct.
 */

.panel-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  min-height: var(--touch);
  padding: var(--space-sm) var(--space-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--raised);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: calc(0.9375rem * var(--scale));
  font-weight: 600;
  letter-spacing: calc(var(--tracking) * 1em);
  cursor: pointer;
}

.panel-toggle[aria-expanded='true'] {
  background: var(--accent-ink);
  color: var(--ground);
  border-color: var(--accent-ink);
}

/* ---------- The drawer ---------------------------------------------------- */

.panel {
  position: fixed;
  z-index: 30;
  background: var(--raised);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.panel[hidden] {
  display: none;
}

/**
 * Phones get a sheet along the bottom, capped so a good strip of the page stays
 * visible above it — that strip is what the controls are being judged against.
 */
@media (max-width: 47.99rem) {
  .panel {
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 68vh;
    border-top: 2px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-base) var(--space-lg) var(--space-xl);
  }
}

/**
 * Wider screens get a column down the right, so the page is not merely visible
 * behind the panel but fully legible beside it.
 */
@media (min-width: 48rem) {
  .panel {
    top: 0;
    right: 0;
    bottom: 0;
    width: min(24rem, 92vw);
    border-left: 2px solid var(--border);
    padding: var(--space-lg) var(--space-lg) var(--space-xxl);
  }

  /**
   * The panel moves nothing.
   *
   * There was a rule here that padded the header row while the panel was open,
   * so the toggle was not left sitting behind the drawer. It worked, and it was
   * the wrong trade: opening the panel visibly relaid the header out from under
   * the reader. On this site nothing may reflow because a control was used — the
   * panel itself was rebuilt once for exactly that reason, and then this rule
   * quietly reintroduced it a layer up.
   *
   * So the drawer simply covers what it covers. The toggle is inert while the
   * panel is open — there is a close button and Escape — and a control being
   * overlapped is a far smaller thing than the page moving.
   */
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-base);
  margin-bottom: var(--space-sm);
}

.panel-head h2 {
  margin: 0;
  font-size: calc(1.1875rem * var(--scale));
  line-height: calc(1.3 * var(--leading));
}

.panel-close {
  flex: none;
  display: inline-grid;
  place-items: center;
  min-width: var(--touch);
  min-height: var(--touch);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--ground);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: calc(1.0625rem * var(--scale));
  cursor: pointer;
}

/**
 * The grab handle on the sheet. Decorative — the close button above is the
 * control, and this only signals which edge the panel came from.
 */
.panel-handle {
  display: none;
}

@media (max-width: 47.99rem) {
  .panel-handle {
    display: block;
    width: 2.5rem;
    height: 4px;
    border-radius: 999px;
    background: var(--border);
    margin: 0 auto var(--space-base);
  }
}

.panel-intro {
  color: var(--ink-muted);
  font-size: calc(0.875rem * var(--scale));
  margin-bottom: var(--space-lg);
}

.panel-grid {
  display: grid;
  gap: var(--space-lg);
  grid-template-columns: 1fr;
  margin-bottom: var(--space-lg);
}

.panel fieldset {
  border: none;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.panel legend,
.panel .field-label {
  font-size: calc(0.9375rem * var(--scale));
  font-weight: 600;
  padding: 0;
  margin-bottom: var(--space-sm);
  color: var(--ink-soft);
}

.panel .hint {
  font-size: calc(0.8125rem * var(--scale));
  color: var(--ink-muted);
  margin: 0 0 var(--space-sm);
}

/* ---------- Colour swatches ----------------------------------------------- */

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin: 0;
}

/**
 * The radio itself is hidden but present, so the browser keeps arrow-key
 * navigation, grouping and screen-reader semantics for free. Nothing here is a
 * custom widget.
 */
.swatches input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/**
 * The preview colours come from the attribute selectors in `tokens.css`.
 *
 * `[data-tint='mint']` sets `--ground` and `--ink` on *any* element carrying it,
 * not only on `:root` — so a swatch labelled with the tint name paints itself
 * from the same declaration the whole page uses. The nine pairs are written down
 * once on the site, and a swatch cannot drift from the theme it applies.
 *
 * A swatch with no `data-tint` is "follow the device", and inherits whatever the
 * page is currently in. That is exactly what choosing it does.
 */
.swatch {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 3.6rem;
  min-height: var(--touch);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--ground);
  color: var(--ink);
  font-size: calc(0.9375rem * var(--scale));
  font-weight: 600;
  cursor: pointer;
}

.swatches input:checked + .swatch {
  border-width: 3px;
  border-color: var(--accent);
}

/**
 * The checkmark is not decoration. A calibrated palette is low-chroma by design,
 * so a border colour alone would disappear in exactly the themes this product
 * exists to serve — selected state always carries a second signal.
 */
.swatches input:checked + .swatch::after {
  content: '✓';
  position: absolute;
  top: -0.55em;
  right: -0.35em;
  width: 1.5em;
  height: 1.5em;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-ink);
  color: var(--ground);
  font-size: calc(0.75rem * var(--scale));
  line-height: 1;
}

.swatches input:focus-visible + .swatch {
  outline: 3px solid var(--ink-soft);
  outline-offset: 2px;
}

/* ---------- Selects ------------------------------------------------------- */

.panel .field {
  margin-bottom: var(--space-base);
}

.panel .field:last-child {
  margin-bottom: 0;
}

.panel select {
  width: 100%;
  min-height: var(--touch);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--sunken);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: calc(0.9375rem * var(--scale));
  letter-spacing: calc(var(--tracking) * 1em);
}

.panel-actions {
  display: grid;
  gap: var(--space-md);
  padding-top: var(--space-base);
  border-top: 1px solid var(--border);
}

.panel-actions p {
  margin: 0;
  color: var(--ink-muted);
  font-size: calc(0.8125rem * var(--scale));
}
