/*
 * Shelf sandbox kit – components. Class shapes follow the platform's src/components/ui
 * (Button, Panel, Card, Input/Field, Chip, Badge, TableWrap, Feedback), written as plain CSS.
 * Tokens only: no raw colours, no font families.
 */

/* ── Top bar: dark in both themes, full width, inset by the gutter ─────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--top);
  color: var(--top-ink);
  border-bottom: 1px solid color-mix(in srgb, var(--top-gold) 22%, transparent);
}
.topbar__inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--header-h);
  padding-inline: var(--gutter);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--top-ink);
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover {
  color: var(--top-ink);
}
.brand__mark {
  width: 1.75rem;
  height: 1.75rem;
  color: var(--top-gold);
}
.brand__name {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1;
}
.brand__tag {
  font-family: var(--font-label);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--top-ink-2);
  padding: 0.15rem 0.45rem;
  border: 1px solid color-mix(in srgb, var(--top-ink-2) 45%, transparent);
  border-radius: var(--radius-sm);
}
.nav {
  display: flex;
  align-items: stretch;
  gap: var(--space-1);
  height: 100%;
}
.nav__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-3);
  color: var(--top-ink-2);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  border-top: 2px solid transparent;
}
.nav__link:hover {
  color: var(--top-ink);
}
.nav__link[aria-current="page"] {
  color: var(--top-ink);
  border-bottom-color: var(--top-gold);
}
.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.topbar .icon-btn {
  color: var(--top-ink-2);
}
.topbar .icon-btn:hover {
  color: var(--top-ink);
  background: color-mix(in srgb, var(--top-ink) 10%, var(--top));
}
.topbar .icon-btn[aria-current="page"] {
  color: var(--top-gold);
}
.topbar :focus-visible {
  box-shadow: 0 0 0 2px var(--top-gold);
}
.count {
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: var(--radius-pill);
  background: var(--top-gold);
  color: var(--top);
  font-size: var(--text-2xs);
  font-weight: 700;
  line-height: 1.25rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.count:empty,
.count[data-zero] {
  visibility: hidden;
}

/* Bottom tab bar for phones: the nav moves here instead of hiding behind a burger. */
.tabbar {
  position: sticky;
  bottom: 0;
  z-index: var(--z-header);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--top);
  border-top: 1px solid color-mix(in srgb, var(--top-gold) 22%, transparent);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar .nav__link {
  flex-direction: column;
  justify-content: center;
  gap: 0.15rem;
  min-height: 3.25rem;
  font-size: var(--text-2xs);
  border: 0;
  border-top: 2px solid transparent;
}
.tabbar .nav__link[aria-current="page"] {
  border-top-color: var(--top-gold);
  border-bottom: 0;
}
.tabbar svg {
  width: 1.25rem;
  height: 1.25rem;
}
@media (min-width: 960px) {
  .tabbar {
    display: none;
  }
}

/* ── Page head: title + one line, page-level action on the right ── */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-6);
  margin-bottom: var(--space-6);
}
.page-head__text {
  display: grid;
  gap: var(--space-2);
  min-width: 0;
}
.page-head .crumbs {
  margin-bottom: var(--space-1);
}
@media (max-width: 639px) {
  .page-head > * {
    width: 100%;
  }
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  --btn-h: var(--control-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--btn-h);
  padding: 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--edge);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:hover {
  background: var(--sunken);
  color: var(--ink);
}
.btn:focus-visible {
  box-shadow: inset 0 0 0 1px var(--edge), var(--focus-ring);
}
.btn[disabled],
.btn[aria-disabled="true"] {
  background: var(--sunken);
  color: var(--ink-3);
  box-shadow: none;
  cursor: default;
  pointer-events: none;
}
/* One primary action per screen: the only filled spot on the page. */
.btn--primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: none;
}
.btn--primary:hover {
  background: var(--accent-hover);
  color: var(--on-accent);
}
.btn--primary:focus-visible {
  box-shadow: var(--focus-ring);
}
.btn--ghost {
  box-shadow: none;
  color: var(--ink-2);
}
.btn--ghost:hover {
  color: var(--ink);
}
.btn--danger {
  color: var(--danger);
  box-shadow: inset 0 0 0 1px var(--danger);
}
.btn--danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn--danger-solid {
  background: var(--danger);
  color: var(--on-danger);
  box-shadow: none;
}
.btn--danger-solid:hover {
  color: var(--on-danger);
  background: color-mix(in srgb, var(--danger) 88%, var(--ink));
}
/* Kept for the seeded "wrong style" bug and for genuine confirmations of success. */
.btn--ok {
  color: var(--ok);
  box-shadow: inset 0 0 0 1px var(--ok);
}
.btn--ok:hover {
  background: var(--ok-soft);
  color: var(--ok);
}
.btn--link {
  height: auto;
  padding: 0;
  box-shadow: none;
  color: var(--accent);
  font-weight: 500;
}
.btn--link:hover {
  background: none;
  color: var(--accent-hover);
  text-decoration: underline;
}
.btn--sm {
  --btn-h: var(--control-h-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}
.btn--block {
  width: 100%;
}
.btn svg {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
}
/* The spinner is always in the markup and only toggled: nothing is inserted next to the label. */
.btn .spinner {
  display: none;
}
.btn[aria-busy="true"] .spinner {
  display: inline-block;
}
.btn[aria-busy="true"] {
  pointer-events: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  position: relative;
  text-decoration: none;
}
.icon-btn:hover {
  background: var(--sunken);
  color: var(--ink);
}
.icon-btn svg {
  width: 1.25rem;
  height: 1.25rem;
}
.icon-btn .count {
  position: absolute;
  top: 0.1rem;
  right: 0;
}

.spinner {
  width: 1em;
  height: 1em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: kit-spin 0.7s linear infinite;
}
@keyframes kit-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Fields ──────────────────────────────────────────────── */

.field {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}
.field > .label {
  display: block;
}
.input,
.select,
.textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--line-strong);
  border-bottom-color: var(--field);
  border-radius: var(--radius-control);
  background: var(--raised);
  color: var(--ink);
  font-size: var(--text-base);
  line-height: 1.35;
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--ink-3);
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--field);
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: inset 0 -2px 0 var(--danger);
}
.input[disabled],
.select[disabled],
.textarea[disabled] {
  background: var(--sunken);
  color: var(--ink-3);
}
.input--mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.textarea {
  min-height: 6rem;
  resize: vertical;
}
.select {
  appearance: none;
  padding-right: 2.25rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
    linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
  background-position: calc(100% - 1.15rem) 55%, calc(100% - 0.8rem) 55%;
  background-size: 0.35rem 0.35rem;
  background-repeat: no-repeat;
  cursor: pointer;
}
/* A hint and an error share one line of reserved space, so the form never jumps. */
.hint,
.error-text {
  min-height: 1.15rem;
  font-size: var(--text-xs);
  line-height: 1.15rem;
  color: var(--ink-3);
}
.error-text {
  color: var(--danger);
}
.field-row {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 8rem), 1fr));
}

.check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  cursor: pointer;
  font-size: var(--text-sm);
}
.check input {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  accent-color: var(--accent);
}

/* ── Surfaces ────────────────────────────────────────────── */

/* Panel: a section with a frame, title and optional action (platform Panel). */
.card {
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  min-width: 0;
}
.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
}
.card__title {
  font-size: var(--text-md);
  font-weight: 600;
  font-family: var(--font-sans);
}
.card__body {
  padding: var(--space-4);
}
.card__foot {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--line);
}
.card--flat {
  box-shadow: none;
}
.card--sunken {
  background: var(--sunken);
  box-shadow: none;
  border-color: transparent;
}

/* Plate: the visor reading plate – a line on the left edge, no frame (platform Card). */
.plate {
  padding: var(--space-4) var(--space-5);
  border-left: 2px solid var(--edge);
  border-radius: var(--radius-xl);
  background: var(--plate);
}

/* ── Badges, chips, place tag ────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  height: 1.375rem;
  padding: 0 0.625rem;
  border-radius: var(--radius-pill);
  background: var(--sunken);
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}
.badge--accent { background: var(--tint-soft); color: var(--accent); }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--violet { background: var(--violet-soft); color: var(--violet); }
.badge .dot {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: currentColor;
}

.place-tag {
  display: inline-flex;
  justify-self: start;
  align-self: start;
  align-items: center;
  height: 1.5rem;
  padding: 0 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--place, var(--sunken));
  color: var(--place-ink, var(--ink-2));
  font-family: var(--font-label);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
}

/*
 * Filter chips – one rule for every sandbox (platform: "equal-cell grid on mobile, inline row on
 * desktop, never flex-wrap"):
 *   .chips      a known set of options (categories, statuses). Phones: an equal-cell grid, every
 *               option visible without scrolling – set --chips-cols so the cells fit 390 px (6
 *               options → 3). Wide screens: one inline row.
 *   .chip-row   an unknown or growing set: one scrolling row. Kit.revealActive() keeps the selected
 *               chip in view (kit.js runs it on load; call it again after rendering chips).
 * A chip's text goes in .chip__label (it shortens with an ellipsis instead of pushing the grid).
 */
.chips {
  display: grid;
  grid-template-columns: repeat(var(--chips-cols, 2), minmax(0, 1fr));
  gap: var(--space-2);
}
.chips > .chip {
  min-width: 0;
  padding-inline: var(--space-3);
}
@media (min-width: 640px) {
  .chips {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .chips > .chip {
    flex: 0 0 auto;
  }
  .chips::-webkit-scrollbar {
    display: none;
  }
}
.chip-row {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chip-row::-webkit-scrollbar {
  display: none;
}
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  padding: 0 var(--space-4);
  border: 1px solid var(--field);
  border-radius: var(--radius-pill);
  background: var(--raised);
  color: var(--ink-2);
  font-size: var(--text-sm);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}
.chip:hover {
  background: var(--sunken);
  color: var(--ink);
}
/* Selection is an outline/fill change, never an added element. */
.chip[aria-pressed="true"],
.chip[aria-current="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}
.chip__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip .chip__n {
  font-size: var(--text-xs);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* ── Alerts ──────────────────────────────────────────────── */

.alert {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-control);
  border-left: 3px solid var(--edge);
  background: var(--sunken);
  color: var(--ink);
  font-size: var(--text-sm);
}
.alert > svg {
  width: 1.15rem;
  height: 1.15rem;
  margin-top: 0.1rem;
  color: var(--accent);
}
.alert__title {
  font-weight: 600;
}
.alert--ok { background: var(--ok-soft); border-left-color: var(--ok); }
.alert--ok > svg { color: var(--ok); }
.alert--warn { background: var(--warn-soft); border-left-color: var(--warn); }
.alert--warn > svg { color: var(--warn); }
.alert--danger { background: var(--danger-soft); border-left-color: var(--danger); }
.alert--danger > svg { color: var(--danger); }
.alert--violet { background: var(--violet-soft); border-left-color: var(--violet); }
.alert--violet > svg { color: var(--violet); }

/* ── Tables: shrink, then become cards (by container width, not viewport) ─── */

.table-wrap {
  container-type: inline-size;
  width: 100%;
  overflow-x: auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line-strong);
  font-family: var(--font-label);
  font-size: var(--text-2xs);
  font-weight: 600;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--label);
  white-space: nowrap;
}
.table td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tbody tr:hover td {
  background: color-mix(in srgb, var(--sunken) 55%, var(--raised));
}
.table .num {
  text-align: right;
}
.table th.num {
  text-align: right;
}
@container (max-width: 40rem) {
  .table--stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .table--stack,
  .table--stack tbody,
  .table--stack tr,
  .table--stack td {
    display: block;
    width: 100%;
  }
  .table--stack tr {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--line);
  }
  .table--stack td {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-1) 0;
    border: 0;
    text-align: right;
  }
  .table--stack td::before {
    content: attr(data-label);
    font-family: var(--font-label);
    font-size: var(--text-2xs);
    font-weight: 600;
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    color: var(--label);
    text-align: left;
    padding-top: 0.2rem;
  }
  .table--stack td.num {
    text-align: right;
  }
  .table--stack tbody tr:hover td {
    background: none;
  }
}

/* ── Pager, breadcrumbs, empty state, skeleton ────────────── */

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-top: var(--space-4);
  font-size: var(--text-sm);
  color: var(--ink-2);
}
.pager__pages {
  font-variant-numeric: tabular-nums;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--ink-3);
}
.crumbs a {
  color: var(--ink-2);
  text-decoration: none;
}
.crumbs a:hover {
  color: var(--accent);
  text-decoration: underline;
}
.crumbs > * + *::before {
  content: "/";
  margin-right: var(--space-2);
  color: var(--ink-3);
}

.empty {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-6);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-card);
  color: var(--ink-2);
}
.empty__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--ink);
}

.skeleton {
  border-radius: var(--radius-control);
  background: linear-gradient(90deg, var(--sunken), color-mix(in srgb, var(--sunken) 55%, var(--raised)), var(--sunken));
  background-size: 200% 100%;
  animation: kit-shimmer 1.2s ease-in-out infinite;
}
@keyframes kit-shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ── Copy field (tokens, ids) ─────────────────────────────── */

.copy {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--sunken);
  min-width: 0;
}
.copy__value {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.6rem 0.85rem;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
  color: var(--ink);
}
.copy .btn {
  height: auto;
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  box-shadow: inset 1px 0 0 var(--line-strong);
}

/* ── Code block: a command or a payload to read and copy ───── */

.codeblock {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--sunken);
}
.codeblock pre {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  padding-right: 5.5rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap; /* a long token or URL wraps instead of sliding under the Copy button */
  overflow-wrap: anywhere;
}
.codeblock .btn {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  background: var(--raised);
}
@media (max-width: 559px) {
  .codeblock pre {
    padding-right: var(--space-4);
    padding-top: 3rem;
  }
}

/* ── Toasts ───────────────────────────────────────────────── */

.toast-host {
  position: fixed;
  z-index: var(--z-toast);
  right: var(--gutter);
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  display: grid;
  gap: var(--space-2);
  width: min(24rem, calc(100vw - 2 * var(--gutter)));
  pointer-events: none;
}
@media (max-width: 959px) {
  .toast-host {
    bottom: calc(4.25rem + env(safe-area-inset-bottom));
  }
}
.toast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-control);
  background: var(--top);
  color: var(--top-ink);
  box-shadow: var(--shadow-pop);
  font-size: var(--text-sm);
  pointer-events: auto;
  animation: kit-toast-in 180ms var(--ease);
}
.toast::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  margin-top: 0.4rem;
  border-radius: 50%;
  background: var(--top-gold);
}
.toast--ok::before { background: var(--ok); }
.toast--danger::before { background: var(--danger); }
.toast a {
  color: var(--top-gold);
}
@keyframes kit-toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ── Dialog (no browser confirm/alert/prompt) ─────────────── */

.dialog {
  width: min(28rem, calc(100vw - 2 * var(--gutter)));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-card);
  background: var(--raised);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
}
.dialog::backdrop {
  background: var(--scrim);
}
.dialog__body {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-5);
}
.dialog__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
}
.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5) var(--space-5);
}

/* ── Footer ───────────────────────────────────────────────── */

.footer {
  border-top: 1px solid var(--line);
  padding: var(--space-5) var(--gutter);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
  align-items: center;
  font-size: var(--text-xs);
  color: var(--ink-3);
}
.footer a {
  color: var(--ink-2);
}
.footer__note {
  margin-right: auto;
}

/* Theme toggle icon: one button, the icon shows the theme you would switch to. */
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}

/* ══ Sandbox start page ═══════════════════════════
   Shared by the API sandbox and the protocol sandboxes: signed-in switch, header extras,
   address list, numbered steps, rules grid, task list, access card with keys and reset. */
[data-auth="in"] [data-when="out"],
[data-auth="out"] [data-when="in"] {
  display: none !important;
}
.nav__ext {
  width: 0.85rem;
  height: 0.85rem;
  color: var(--top-ink-2);
}
.who {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-right: var(--space-2);
  color: var(--top-ink-2);
  font-size: var(--text-sm);
}
.who svg {
  width: 1rem;
  height: 1rem;
}
@media (max-width: 420px) {
  .brand__tag {
    display: none;
  }
}

/* ── Start page ─────────────────────────────────── */
@media (max-width: 959px) {
  .start > .aside {
    order: -1; /* access first on phones: it is step one */
  }
}
.addresses {
  display: grid;
  gap: var(--space-3);
  margin: 0;
}
@media (min-width: 1200px) {
  .addresses {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.addresses > div {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}
.addresses dd {
  margin: 0;
}
.doc-links {
  margin-top: var(--space-4);
  gap: var(--space-2);
}
.step {
  display: grid;
  gap: var(--space-2);
}
.step__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
}
.step__n {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--tint-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}
.rules {
  display: grid;
  gap: var(--space-5);
}
@media (min-width: 1200px) {
  .rules {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.rules ul {
  display: grid;
  gap: var(--space-2);
  margin: var(--space-2) 0 0;
  padding-left: 1.1rem;
}

/* tasks */
.tasks {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}
.task {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
}
.task__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.task__title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
}
.task__code {
  display: grid;
  gap: var(--space-1);
}

/* access card */
.access .card__head .badge {
  max-width: 60%;
  overflow: hidden;
}
.auth-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}
.keys,
.reset {
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}
.key-list {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}
.key {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-width: 0;
}
.key__text {
  display: grid;
  min-width: 0;
}
.key__name {
  font-size: var(--text-sm);
  font-weight: 600;
}
.key-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
}

/* ══ QA Steps layer (redesign 16.10.2026, study-platform-en/docs/en/design/handoff) ═══════
   Every sandbox wears the same QA Steps strip on top and the same "Night shift tasks" panel;
   both are dark in both themes, like the platform's top bar. */

/* ── Sandbox strip: where you are, the test card, reset, the way back ── */
.strip {
  background: var(--top);
  color: var(--top-ink);
  border-bottom: 1px solid color-mix(in srgb, var(--top-gold) 22%, var(--top));
  font-size: var(--text-sm);
}
.strip__inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 2.5rem;
  padding-inline: var(--gutter);
}
.strip__coin {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  color: var(--top-gold);
}
.strip__where {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--top-ink);
}
.strip__where .strip__dim {
  color: var(--top-ink-2);
}
.strip__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}
.strip__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.5rem;
  padding: 0 var(--space-2);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--top);
  color: var(--top-ink);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.strip__link:hover {
  background: color-mix(in srgb, var(--top-ink) 10%, var(--top));
  color: var(--top-ink);
}
.strip__link--gold,
.strip__link--gold:hover {
  color: var(--top-gold);
  font-weight: 600;
}
.strip__link svg {
  width: 1rem;
  height: 1rem;
}
.strip :focus-visible {
  box-shadow: 0 0 0 2px var(--top-gold);
}
.strip .icon-btn {
  color: var(--top-ink-2);
}
.strip .icon-btn:hover {
  color: var(--top-ink);
  background: color-mix(in srgb, var(--top-ink) 10%, var(--top));
}
@media (max-width: 639px) {
  .strip__long {
    display: none;
  }
}

/* ── Tabs: one row, the open tab underlined in brass ── */
.tabs {
  display: flex;
  gap: var(--space-6);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar {
  display: none;
}
.tab {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 var(--space-1);
  border: 0;
  background: none;
  color: var(--ink-3);
  font-size: var(--text-md);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 transparent;
}
.tab:hover {
  color: var(--ink);
}
.tab[aria-selected="true"] {
  color: var(--ink);
  box-shadow: inset 0 -3px 0 var(--accent);
}
.tab:focus-visible {
  box-shadow: inset 0 -3px 0 var(--accent), var(--focus-ring);
}
@media (max-width: 559px) {
  .tabs {
    gap: var(--space-4);
  }
  .tab {
    font-size: var(--text-base);
  }
}
.tabpanel {
  padding-top: var(--space-5);
}
.tabpanel:focus-visible {
  box-shadow: none;
}

/* ── Night shift tasks: the missions panel (filled by Kit.missions, see kit.js) ──
   It stays `hidden` until a missions endpoint answers; nothing is drawn without real data. */
.missions {
  display: grid;
  align-content: start;
  gap: var(--space-4);
  padding: var(--space-6) var(--space-5);
  background: var(--top);
  color: var(--top-ink);
}
.missions__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}
.missions__title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 400;
  color: var(--top-ink);
}
.missions__count {
  color: var(--top-ink-2);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.missions__meter {
  display: flex;
  gap: 3px;
}
.missions__meter span {
  width: 0.5rem;
  height: 1.25rem;
  border-radius: 2px;
  border: 1px solid var(--top-ink-2);
  background: var(--top);
}
.missions__meter span[data-on] {
  background: var(--top-gold);
  border-color: var(--top-gold);
}
.mission-list {
  display: grid;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}
.mission {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr);
  gap: var(--space-1) var(--space-3);
  align-items: start;
  min-height: 2.75rem;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  color: var(--top-ink-2);
  font-weight: 600;
}
.mission__box {
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.1rem;
  border: 2px solid var(--top-ink-2);
  border-radius: var(--radius-sm);
  background: var(--top);
  color: var(--top);
}
.mission__box svg {
  width: 0.85rem;
  height: 0.85rem;
}
.mission[data-state="done"],
.mission[data-state="now"] {
  color: var(--top-ink);
}
.mission[data-state="done"] .mission__box {
  border-color: var(--top-gold);
  background: var(--top-gold);
}
.mission[data-state="now"] {
  background: color-mix(in srgb, var(--top-ink) 9%, var(--top));
  box-shadow: inset 0 0 0 2px var(--top-gold);
}
.mission[data-state="now"] .mission__box {
  border-color: var(--top-gold);
}
.mission--icon {
  grid-template-columns: 1.25rem 2.25rem minmax(0, 1fr);
}
.mission__icon {
  width: 2.25rem;
  height: 2.25rem;
  margin-top: -0.4rem;
  object-fit: contain;
}
.mission__hint {
  grid-column: 2;
  color: var(--top-ink-2);
  font-size: var(--text-sm);
  font-weight: 400;
}
.mission--icon .mission__hint {
  grid-column: 3;
}
.missions__foot {
  padding: var(--space-4);
  border-radius: var(--radius-card);
  background: color-mix(in srgb, var(--top-ink) 7%, var(--top));
  color: var(--top-ink-2);
  font-size: var(--text-sm);
}
.missions a {
  color: var(--top-gold);
}

/* A page with the missions panel on the right (the shop): the panel takes its column only when it
   has something to show; otherwise the page keeps the whole width. */
.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
}
.shell > * {
  grid-column: 1;
  min-width: 0;
}
.shell > main {
  min-height: 70vh;
}
@media (min-width: 1200px) {
  .shell:has(> .missions:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) 21rem;
  }
  .shell > .missions {
    grid-column: 2;
    grid-row: 1 / span 6;
    position: sticky;
    top: 0;
    max-height: 100dvh;
    overflow: auto;
  }
}

/* ── Stand head: the place's name on night blue, its picture beside it (never under the text) ── */
.stand-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  background: var(--top);
  color: var(--top-ink);
}
.stand-head__text {
  display: grid;
  align-content: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--gutter);
}
.stand-head__title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 400;
  color: var(--top-ink);
}
.stand-head__line {
  color: var(--top-ink-2);
  max-width: var(--measure);
}
.stand-head__art {
  display: none;
}
@media (min-width: 760px) {
  .stand-head {
    grid-template-columns: minmax(20rem, 1fr) minmax(0, 1.6fr);
    min-height: 10rem;
  }
  .stand-head__art {
    display: block;
    width: 100%;
    height: 100%;
    max-height: 10rem;
    object-fit: cover;
    object-position: center 40%;
  }
}

/* ── Stand: missions and tasks on the left, the workbench on the right ── */
.stand {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  flex: 1 0 auto;
}
.stand__side {
  display: grid;
  align-content: start;
  gap: var(--space-5);
  padding: var(--space-6) var(--gutter);
  background: var(--sunken);
  border-top: 1px solid var(--line);
  order: 2;
}
.stand__side > .missions {
  margin: calc(-1 * var(--space-6)) calc(-1 * var(--gutter)) 0;
}
.stand__work {
  min-width: 0;
  padding: var(--space-4) var(--gutter) var(--space-12);
}
@media (min-width: 960px) {
  .stand {
    grid-template-columns: 21rem minmax(0, 1fr);
  }
  .stand__side {
    order: 0;
    padding: var(--space-6) var(--space-5);
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .stand__side > .missions {
    margin: calc(-1 * var(--space-6)) calc(-1 * var(--space-5)) 0;
  }
}
@media (min-width: 1600px) {
  .stand {
    grid-template-columns: 24rem minmax(0, 1fr);
  }
}

/* ── Workbench: a request line, the request and the response side by side ── */
.req-line {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  gap: var(--space-2);
}
.req-line > .btn {
  grid-column: 1 / -1;
}
@media (min-width: 560px) {
  .req-line {
    grid-template-columns: 7.5rem minmax(0, 1fr) auto;
  }
  .req-line > .btn {
    grid-column: auto;
    min-width: 7rem;
  }
}
.req-line .input,
.req-line .select {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.panes {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-4);
}
@media (min-width: 1200px) {
  .panes {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.pane {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: var(--space-2);
  min-width: 0;
}
.pane__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 1.75rem;
}
.pane__head .label {
  color: var(--ink-2);
}
.pane__meta {
  font-size: var(--text-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}
.pane__meta[data-tone="ok"] { color: var(--ok); }
.pane__meta[data-tone="warn"] { color: var(--warn); }
.pane__meta[data-tone="danger"] { color: var(--danger); }
.code-surface {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 18rem;
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--vault);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  overflow: auto;
}
textarea.code-surface {
  resize: vertical;
}
textarea.code-surface:focus {
  outline: none;
  border-color: var(--accent);
}
.code-surface--short {
  min-height: 6rem;
}
pre.code-surface {
  max-height: 70vh;
}
.code-surface .j-key { color: var(--accent); }
.code-surface .j-str { color: var(--ok); }
.code-surface .j-num { color: var(--violet); }
.code-surface .j-lit { color: var(--warn); }
.code-surface .faint { color: var(--ink-3); }

/* A one-line result under the workbench ("Mission ticked", a hint). Solid, never see-through. */
.note-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-card);
  background: var(--raised);
  border: 1px solid var(--line);
  font-size: var(--text-sm);
}
.note-bar svg {
  flex-shrink: 0;
  width: 1.1rem;
  height: 1.1rem;
  color: var(--accent);
}

/* ── Live log (WebSocket frames): time, direction, message ── */
.log {
  display: grid;
  align-content: start;
  gap: 2px;
  min-height: 16rem;
  max-height: 32rem;
  margin: 0;
  padding: var(--space-2);
  overflow: auto;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--vault);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.log__row {
  display: grid;
  grid-template-columns: 4.75rem 1.25rem minmax(0, 1fr);
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
}
.log__time {
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.log__dir--out { color: var(--accent); }
.log__dir--in { color: var(--ok); }
.log__dir--sys { color: var(--ink-3); }
.log__msg {
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink);
}
.log__row--sys .log__msg {
  color: var(--ink-3);
  font-family: var(--font-sans);
}
.log__row--fresh {
  background: var(--ok-soft);
}
.log__row--error {
  background: var(--danger-soft);
}
.log__empty {
  padding: var(--space-4);
  color: var(--ink-3);
  font-family: var(--font-sans);
}
@media (max-width: 559px) {
  .log__row {
    grid-template-columns: 1.25rem minmax(0, 1fr);
  }
  .log__time {
    grid-column: 1 / -1;
  }
}
.conn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-h);
  padding: 0 var(--space-4);
  border-radius: var(--radius-control);
  background: var(--sunken);
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
}
.conn::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--ink-3);
}
.conn[data-state="open"] {
  color: var(--ink);
}
.conn[data-state="open"]::before {
  background: var(--ok);
}
.conn[data-state="closed"]::before {
  background: var(--danger);
}

/* ── Bottom sheet (Report a bug): a dialog that rises from the bottom, night blue ── */
.sheet {
  width: min(36rem, 100vw);
  max-width: 100vw;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  background: var(--top);
  color: var(--top-ink);
  box-shadow: var(--shadow-pop);
}
@media (min-width: 760px) {
  .sheet {
    margin: auto;
    border-radius: var(--radius-2xl);
  }
}
.sheet::backdrop {
  background: var(--scrim);
}
.sheet__grip {
  width: 2.75rem;
  height: 0.3rem;
  margin: var(--space-3) auto 0;
  border-radius: var(--radius-pill);
  background: var(--top-ink-2);
}
.sheet__body {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5) var(--space-5);
}
.sheet__title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 400;
  color: var(--top-ink);
}
.sheet .label,
.sheet .hint {
  color: var(--top-ink-2);
}
.sheet .label {
  font-size: var(--text-sm);
  letter-spacing: 0;
  text-transform: none;
}
.sheet .input,
.sheet .textarea {
  border-color: var(--top-ink-2);
  background: color-mix(in srgb, var(--top-ink) 6%, var(--top));
  color: var(--top-ink);
}
.sheet .input:focus,
.sheet .textarea:focus {
  border-color: var(--top-gold);
  box-shadow: inset 0 -2px 0 var(--top-gold);
}
.sheet .btn {
  color: var(--top-ink);
  box-shadow: inset 0 0 0 1px var(--top-ink-2);
}
.sheet .btn:hover {
  background: color-mix(in srgb, var(--top-ink) 10%, var(--top));
}
.sheet .btn--primary,
.sheet .btn--primary:hover {
  background: var(--top-gold);
  color: var(--top);
  box-shadow: none;
}
.sheet :focus-visible {
  box-shadow: 0 0 0 2px var(--top), 0 0 0 4px var(--top-gold);
}
.strip__home {
  color: var(--top-ink);
  text-decoration: none;
}
.strip__home:hover {
  color: var(--top-gold);
}
.strip__link[aria-current="page"] {
  box-shadow: inset 0 -2px 0 var(--top-gold);
  border-radius: 0;
}
.strip .who {
  margin-right: 0;
}
/* Task cards in a narrow side column: the title gets its own line under the badges. */
.stand__side .task__head {
  flex-wrap: wrap;
}
.stand__side .task__title {
  order: 3;
  flex-basis: 100%;
}
.stand__side .task__head .badge:last-child {
  margin-left: auto;
}
/* A stand page: banner, then the stand filling the rest of the window. */
.stand-main {
  display: flex;
  flex-direction: column;
}
/* A fixed part of a request line (method or address the student does not edit). */
.select--static,
.input--static {
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  background: var(--sunken);
  background-image: none;
  color: var(--ink-2);
  cursor: default;
}
/* The request editor of a pane: headers above, body below. */
.req-edit {
  display: grid;
  gap: var(--space-2);
  align-content: start;
}
