/* The frame shared by every demo page, plus the form controls the demos use.
   Demo pages load site.css first, so the palette, fonts, buttons (.btn),
   labels (.label), readouts and handwritten notes all come from there. */

.demo-page {
  display: grid;
  /* minmax(0, ...) keeps a wide table from stretching the whole page on a phone */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
}

/* ---------- top bar ---------- */

.demo-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 18px;
  min-height: 56px;
  padding: 8px var(--gutter);
  border-bottom: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);

  .brand svg {
    width: 30px;
    height: 30px;
  }

  /* On a phone the bar wraps to several lines, so it scrolls away instead of covering the demo. */
  @media (max-width: 640px) {
    position: static;
  }
}

.demo-back {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-2);
  text-decoration: none;
}

.demo-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  font-size: 1.4rem;
  font-stretch: 75%;
  font-weight: 600;
  line-height: 1.2;

  .label {
    font-stretch: 100%;
  }
}

.demo-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
  /* Same height as the text buttons beside it. */
  .music-link {
    width: 40px;
    height: auto;
    align-self: stretch;
  }
}

.demo-main {
  padding: clamp(16px, 2.5vw, 28px) var(--gutter) 48px;
}

/* What the demo is and what to try first. Shown on load; "About this demo" brings it back. */
.demo-intro {
  display: grid;
  gap: 8px;
  max-width: 60em;
  margin-bottom: clamp(16px, 2.5vw, 24px);
  padding: 16px 20px;
  border: var(--line) dashed var(--ink-3);
  border-radius: 12px;

  p {
    color: var(--ink-2);
  }

  .demo-try {
    color: var(--ink);
  }

  &[hidden] {
    display: none;
  }
}

/* ---------- buttons (sizes and variants on top of .btn) ---------- */

.btn-sm {
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
}

.btn-quiet {
  border-color: transparent;

  &:hover {
    border-color: var(--rule);
  }
}

.btn-danger {
  border-color: var(--danger);
  color: var(--danger);

  &:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: var(--paper);
  }
}

.btn:disabled,
.btn[aria-disabled="true"] {
  border-color: var(--rule);
  background: transparent;
  color: var(--ink-3);
  cursor: not-allowed;
}

/* ---------- form controls ---------- */

.field {
  display: grid;
  gap: 6px;

  > label,
  > .field-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-2);
  }
}

.input,
.select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: var(--line) solid var(--ink-3);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.3;

  &:hover {
    border-color: var(--ink);
  }

  &:focus-visible {
    border-color: var(--accent);
    outline-offset: 1px;
  }

  &[aria-invalid="true"] {
    border-color: var(--danger);
  }
}

.input[type="number"] {
  font-variant-numeric: tabular-nums;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;

  input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--accent);
  }
}

input[type="range"] {
  accent-color: var(--accent);
}

.hint {
  font-size: 0.9rem;
  color: var(--ink-3);
}

.error-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--danger);
}

/* ---------- surfaces ---------- */

.panel {
  padding: clamp(14px, 2vw, 20px);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
}

.panel-quiet {
  border-color: var(--rule);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 16px;
  margin-bottom: 12px;

  h2,
  h3 {
    font-size: 1.3rem;
    font-stretch: 78%;
    font-weight: 600;
  }
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  border-bottom: var(--line) solid var(--ink);

  [role="tab"] {
    flex: none;
    padding: 9px 14px 8px;
    border: 0;
    border-bottom: 3px solid transparent;
    background: none;
    color: var(--ink-2);
    font: inherit;
    font-weight: 600;
    cursor: pointer;

    &:hover {
      color: var(--ink);
    }

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

/* ---------- tables ---------- */

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;

  th {
    padding: 8px 10px;
    border-bottom: var(--line) solid var(--ink);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-align: left;
    text-transform: uppercase;
    color: var(--ink-3);
    white-space: nowrap;
  }

  td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--rule);
    vertical-align: top;
  }

  .num {
    text-align: right;
  }
}

/* ---------- small pieces ---------- */

.chip {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--ink-2);
}

.chip-accent {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.chip-ok {
  border-color: var(--ok);
  color: var(--ok);
}

.chip-danger {
  border-color: var(--danger);
  color: var(--danger);
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border: 1px solid var(--ink-3);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--paper);
  font-family: var(--font-mono);
  font-size: 0.8em;
  line-height: 1.4;
  text-align: center;
}

/* A plain bar for progress and fill levels; the number next to it carries the meaning. */
.bar {
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--paper-2);

  > span {
    display: block;
    height: 100%;
    background: var(--accent);
  }
}

.toast {
  position: fixed;
  right: var(--gutter);
  bottom: 20px;
  z-index: 30;
  max-width: min(90vw, 26rem);
  padding: 12px 16px;
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 6px 6px 0 var(--shade);

  &[hidden] {
    display: none;
  }
}

.demo-dialog {
  width: min(92vw, 34rem);
  padding: clamp(18px, 3vw, 26px);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 8px 8px 0 var(--shade);

  &::backdrop {
    background: rgb(8 10 12 / 0.55);
  }

  h2 {
    margin-bottom: 10px;
    font-size: 1.5rem;
    font-stretch: 75%;
    font-weight: 600;
  }
}

/* ---------- layout helpers ---------- */

.stack {
  display: grid;
  gap: var(--stack-gap, 12px);
  align-content: start;
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.split {
  display: grid;
  gap: clamp(16px, 2.5vw, 24px);

  @media (min-width: 900px) {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

@media (max-width: 560px) {
  .demo-title {
    font-size: 1.2rem;
  }

  .demo-tools {
    margin-left: 0;
  }
}
