@layer reset, tokens, base, layout, components;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  button, input, select, textarea { font: inherit; color: inherit; }
  svg { display: block; }
}

@layer tokens {
  :root {
    --bg-light: oklch(98.4% 0.004 275);
    --bg-dark: oklch(16.5% 0.012 275);
    --surface-light: oklch(100% 0 0);
    --surface-dark: oklch(22% 0.014 275);
    --text-light: oklch(22% 0.02 275);
    --text-dark: oklch(95% 0.008 275);
    --muted-light: oklch(50% 0.02 275);
    --muted-dark: oklch(70% 0.02 275);
    --border-light: oklch(90% 0.008 275);
    --border-dark: oklch(31% 0.016 275);
    --accent-light: oklch(54% 0.21 285);
    --accent-dark: oklch(74% 0.15 285);

    --bg: var(--bg-light);
    --surface: var(--surface-light);
    --text: var(--text-light);
    --muted: var(--muted-light);
    --border: var(--border-light);
    --accent: var(--accent-light);

    /* Fallback for browsers without light-dark() */
    @media (prefers-color-scheme: dark) {
      --bg: var(--bg-dark);
      --surface: var(--surface-dark);
      --text: var(--text-dark);
      --muted: var(--muted-dark);
      --border: var(--border-dark);
      --accent: var(--accent-dark);
    }

    @supports (color: light-dark(white, black)) {
      --bg: light-dark(var(--bg-light), var(--bg-dark));
      --surface: light-dark(var(--surface-light), var(--surface-dark));
      --text: light-dark(var(--text-light), var(--text-dark));
      --muted: light-dark(var(--muted-light), var(--muted-dark));
      --border: light-dark(var(--border-light), var(--border-dark));
      --accent: light-dark(var(--accent-light), var(--accent-dark));
    }

    --radius: 14px;
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;

    color-scheme: light dark;
    accent-color: var(--accent);
  }

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

@layer base {
  html { -webkit-text-size-adjust: none; text-size-adjust: none; }

  body {
    min-height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr auto auto;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
  }

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

  kbd {
    font-family: var(--mono);
    font-size: 0.85em;
    padding: 0.1em 0.45em;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--surface);
  }

  .visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .i {
    width: 1.15em;
    height: 1.15em;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
}

@layer layout {
  .toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    padding: 0.75rem 1rem;
    background: color-mix(in oklch, var(--bg) 80%, transparent);
    backdrop-filter: blur(16px) saturate(1.4);
    border-bottom: 1px solid var(--border);
  }

  .controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }

  .stage {
    container: stage / inline-size;
    display: flex;
    padding: 1rem;
    min-height: 0;
  }

  .palette {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    min-height: min(68dvh, 680px);
  }

  .hint {
    padding: 0 1rem 1rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
    text-wrap: balance;
  }

  @media (hover: none) {
    .hint { display: none; }
  }
}

@layer components {
  /* Brand */
  .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: inherit;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
  }

  .brand-mark {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
    width: 26px;
    aspect-ratio: 1;

    i {
      border-radius: 3px;
      background: oklch(70% 0.17 var(--h));
      &:nth-child(1) { --h: 25; border-top-left-radius: 8px; }
      &:nth-child(2) { --h: 145; border-top-right-radius: 8px; }
      &:nth-child(3) { --h: 250; border-bottom-left-radius: 8px; }
      &:nth-child(4) { --h: 320; border-bottom-right-radius: 8px; opacity: 0.55; }
    }
  }

  /* Buttons */
  .btn, .icon-btn, select {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: 2.4rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, transform 0.15s var(--ease-out);

    &:hover { border-color: color-mix(in oklch, var(--text) 30%, var(--border)); }
    &:active { transform: scale(0.97); }
  }

  .btn {
    padding-inline: 0.9rem;
    font-weight: 550;

    &.primary {
      background: var(--text);
      border-color: var(--text);
      color: var(--bg);
      &:hover { background: color-mix(in oklch, var(--text) 85%, var(--bg)); }
    }
  }

  .icon-btn {
    width: 2.4rem;
    padding: 0;
  }

  select {
    padding-inline: 0.75rem 2rem;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                      linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
  }

  /* Customizable <select> where supported */
  @supports (appearance: base-select) {
    select, ::picker(select) { appearance: base-select; }

    select {
      padding-inline: 0.75rem 0.6rem;
      background-image: none;
      &::picker-icon { transition: rotate 0.2s var(--ease-out); }
      &:open::picker-icon { rotate: 180deg; }
    }

    ::picker(select) {
      margin-block: 6px;
      padding: 4px;
      border: 1px solid var(--border);
      border-radius: 12px;
      background: var(--surface);
      box-shadow: 0 12px 32px oklch(0% 0 0 / 0.18);
    }

    option {
      padding: 0.45rem 0.6rem;
      border-radius: 8px;
      &:hover, &:focus-visible { background: color-mix(in oklch, var(--text) 8%, transparent); }
      &:checked { font-weight: 600; }
      &::checkmark { color: var(--accent); }
    }
  }

  .stepper {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);

    .icon-btn { border: 0; background: transparent; height: 2.3rem; }
    output {
      min-width: 1.5ch;
      text-align: center;
      font-variant-numeric: tabular-nums;
      font-weight: 600;
    }
  }

  #theme {
    .moon { display: none; }
    :root[data-scheme="dark"] & .sun { display: none; }
    :root[data-scheme="dark"] & .moon { display: block; }
    @media (prefers-color-scheme: dark) {
      :root:not([data-scheme="light"]) & .sun { display: none; }
      :root:not([data-scheme="light"]) & .moon { display: block; }
    }
  }

  /* Swatches */
  .swatch {
    --fg: white;
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    display: grid;
    grid-template-rows: auto 1fr auto;
    justify-items: center;
    gap: 0.75rem;
    padding: 1rem 0.75rem;
    border-radius: var(--radius);
    background: var(--swatch);
    color: var(--fg);
    box-shadow: inset 0 0 0 1px oklch(0% 0 0 / 0.06);
    transition: flex-grow 0.35s var(--ease-out);

    &:hover, &:focus-within { flex-grow: 1.35; }
  }

  /* Relative color syntax fallback: black or white text based on OKLCH lightness */
  @supports (color: oklch(from red l c h)) {
    .swatch {
      --threshold: 0.623;
      --l: max(0, sign(var(--threshold) - l));
      --fg: oklch(from var(--swatch) var(--l) 0 h);
    }
  }

  @supports (color: contrast-color(red)) {
    .swatch { --fg: contrast-color(var(--swatch)); }
  }

  .swatch-tools {
    display: flex;
    gap: 0.25rem;

    .icon-btn {
      border: 0;
      color: inherit;
      background: color-mix(in oklch, currentColor 12%, transparent);
      &:hover { background: color-mix(in oklch, currentColor 22%, transparent); }
    }

    .lock {
      .locked { display: none; }
      &[aria-pressed="true"] {
        background: color-mix(in oklch, currentColor 26%, transparent);
        .locked { display: block; }
        .unlocked { display: none; }
      }
    }
  }

  @media (hover: hover) {
    .swatch-tools > :not(.lock[aria-pressed="true"]) {
      opacity: 0;
      transition: opacity 0.2s;
    }
    .swatch:is(:hover, :focus-within) .swatch-tools > * { opacity: 1; }
  }

  .swatch-info {
    align-self: center;
    display: grid;
    justify-items: center;
    gap: 0.3rem;
    text-align: center;
    min-width: 0;
  }

  .hex {
    border: 0;
    padding: 0.2rem 0.5rem;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    font-family: var(--mono);
    font-size: clamp(1rem, 2.2cqi, 1.6rem);
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: copy;
    &:hover { background: color-mix(in oklch, currentColor 12%, transparent); }
  }

  .oklch, .ratio {
    font-family: var(--mono);
    font-size: 0.72rem;
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .ratio {
    padding: 0.1rem 0.45rem;
    border-radius: 99px;
    border: 1px solid color-mix(in oklch, currentColor 30%, transparent);
  }

  .shades {
    display: flex;
    width: 100%;
    max-width: 220px;
    padding: 0;
    list-style: none;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 0 1px color-mix(in oklch, currentColor 20%, transparent);

    li { flex: 1; }

    button {
      display: block;
      width: 100%;
      height: 28px;
      border: 0;
      padding: 0;
      background: var(--shade);
      cursor: copy;
      transition: scale 0.15s var(--ease-out);
      &:hover, &:focus-visible { scale: 1 1.25; }
      &[aria-current="true"] { box-shadow: inset 0 0 0 2px var(--fg); }
    }
  }

  /* Stack swatches as rows in narrow containers */
  @container stage (width < 640px) {
    .palette { flex-direction: column; gap: 0.4rem; }

    .swatch {
      grid-template-columns: 1fr auto;
      grid-template-rows: auto auto;
      grid-template-areas: "info tools" "shades shades";
      justify-items: start;
      align-items: center;
      padding: 0.75rem;
      gap: 0.5rem;
      &:hover, &:focus-within { flex-grow: 1; }
    }

    .swatch-info {
      grid-area: info;
      justify-items: start;
      text-align: start;
      grid-template-columns: auto auto;
      align-items: center;
      column-gap: 0.5rem;
    }
    .hex { grid-row: span 2; font-size: 1.15rem; padding-inline: 0.25rem; }
    .oklch, .ratio { justify-self: start; }
    .swatch-tools { grid-area: tools; }
    .swatch-tools > * { opacity: 1 !important; }
    .shades { grid-area: shades; max-width: none; }
    .shades button { height: 18px; }
  }

  /* Export dialog */
  dialog {
    width: min(560px, 100% - 2rem);
    margin: auto;
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 24px 64px oklch(0% 0 0 / 0.25);

    opacity: 0;
    translate: 0 12px;
    scale: 0.98;
    transition: opacity 0.2s, translate 0.25s var(--ease-out), scale 0.25s var(--ease-out),
                overlay 0.25s allow-discrete, display 0.25s allow-discrete;

    &[open] { opacity: 1; translate: 0; scale: 1; }

    @starting-style {
      &[open] { opacity: 0; translate: 0 12px; scale: 0.98; }
    }

    &::backdrop {
      background: oklch(0% 0 0 / 0);
      backdrop-filter: blur(0);
      transition: background-color 0.25s, backdrop-filter 0.25s,
                  overlay 0.25s allow-discrete, display 0.25s allow-discrete;
    }
    &[open]::backdrop { background: oklch(0% 0 0 / 0.35); backdrop-filter: blur(4px); }
    @starting-style {
      &[open]::backdrop { background: oklch(0% 0 0 / 0); backdrop-filter: blur(0); }
    }
  }

  .dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    h2 { font-size: 1.1rem; letter-spacing: -0.01em; }
  }

  .segmented {
    display: flex;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);

    label {
      flex: 1;
      padding: 0.4rem 0.6rem;
      border-radius: 8px;
      text-align: center;
      font-size: 0.9rem;
      font-weight: 550;
      color: var(--muted);
      cursor: pointer;
      transition: background-color 0.15s, color 0.15s;

      &:has(:checked) {
        background: var(--surface);
        color: var(--text);
        box-shadow: 0 1px 3px oklch(0% 0 0 / 0.12);
      }
      &:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
    }

    input { position: absolute; opacity: 0; pointer-events: none; }
  }

  .code {
    margin-block: 1rem;
    padding: 1rem;
    max-height: 50dvh;
    overflow: auto;
    border-radius: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.6;
    tab-size: 2;
    scrollbar-width: thin;
  }

  .dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
  }

  /* Toast */
  #toast {
    inset: auto auto 1.5rem 50%;
    translate: -50% 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem 0.6rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 99px;
    background: var(--text);
    color: var(--bg);
    font-weight: 550;
    box-shadow: 0 10px 30px oklch(0% 0 0 / 0.25);

    opacity: 0;
    translate: -50% 12px;
    transition: opacity 0.2s, translate 0.3s var(--ease-out),
                overlay 0.3s allow-discrete, display 0.3s allow-discrete;

    &::before {
      content: "";
      width: 1.3rem;
      aspect-ratio: 1;
      border-radius: 50%;
      background: var(--chip, var(--accent));
      box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--bg) 30%, transparent);
    }

    &:is(:popover-open, .\:popover-open) {
      opacity: 1;
      translate: -50% 0;
      @starting-style { opacity: 0; translate: -50% 12px; }
    }
  }

  /* Token badges on swatches */
  .swatch-tokens {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    margin-top: 0.25rem;
    padding: 0;
    list-style: none;

    &:empty { display: none; }

    li {
      padding: 0.1rem 0.45rem;
      border-radius: 99px;
      background: color-mix(in oklch, currentColor 14%, transparent);
      font-family: var(--mono);
      font-size: 0.68rem;
      font-weight: 600;
    }
  }

  /* Design tokens */
  .tokens-section {
    container: tokens / inline-size;
    padding: 0.5rem 1rem 2rem;
  }

  .tokens-head {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;

    h2 { font-size: 1.35rem; letter-spacing: -0.02em; }
    p { color: var(--muted); text-wrap: pretty; }
  }

  .tokens-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: 1rem;
    align-items: start;
  }

  @container tokens (width < 960px) {
    .tokens-layout { grid-template-columns: minmax(0, 1fr); }
  }

  .token-list {
    container: token-list / inline-size;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
  }

  .token-group h3 {
    padding: 0.75rem 0.5rem 0.25rem;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 650;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .token-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.4rem 0.75rem;
    padding: 0.45rem 0.5rem;
    border-radius: 10px;
    &:hover { background: color-mix(in oklch, var(--text) 4%, transparent); }
  }

  .tokens-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
  }

  .mode-switch {
    label {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 0.4rem;
      min-width: 5.5rem;
    }
  }

  /* Diagonal split: light value top-left, dark value bottom-right */
  .token-chip {
    width: 2.1rem;
    aspect-ratio: 1;
    border: 0;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--c-light) 50%, var(--c-dark) 50%);
    box-shadow: inset 0 0 0 1px oklch(0% 0 0 / 0.12);
    cursor: copy;
    transition: scale 0.15s var(--ease-out);
    &:hover { scale: 1.08; }
  }

  .token-meta {
    display: grid;
    min-width: 0;

    code { font-family: var(--mono); font-size: 0.88rem; font-weight: 650; }
    span {
      overflow: hidden;
      color: var(--muted);
      font-family: var(--mono);
      font-size: 0.72rem;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
  }

  .token-picks {
    display: flex;
    flex-wrap: wrap;
    justify-content: end;
    gap: 5px;
    min-width: 0;
    padding: 0;
    border: 0;
  }

  .pick {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 1.45rem;
    height: 1.45rem;
    border-radius: 7px;
    background: var(--c);
    box-shadow: inset 0 0 0 1px oklch(0% 0 0 / 0.14);
    cursor: pointer;
    transition: scale 0.15s var(--ease-out);

    input {
      position: absolute;
      inset: 0;
      margin: 0;
      opacity: 0;
      cursor: pointer;
    }

    &:hover { scale: 1.12; }
    &:has(:checked) { outline: 2px solid var(--text); outline-offset: 2px; }
    &[data-auto] { outline: 2px dashed color-mix(in oklch, var(--text) 45%, transparent); outline-offset: 2px; }
    &:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
  }

  .pick-auto {
    width: auto;
    padding-inline: 0.5rem;
    background: var(--bg);
    box-shadow: inset 0 0 0 1px var(--border);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 650;
    &:hover { scale: 1.05; }
    &:has(:checked) { color: var(--text); }
  }

  @container token-list (width < 520px) {
    .token-row { grid-template-columns: auto minmax(0, 1fr); }
    .token-picks { grid-column: 1 / -1; justify-content: start; }
  }

  /* Live preview, painted entirely with token variables */
  .preview-wrap {
    container: preview / inline-size;
    position: sticky;
    top: 5rem;
  }

  .preview {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--t-bg);
    color: var(--t-text);
    font-size: 13px;
    box-shadow: 0 20px 50px oklch(0% 0 0 / 0.1);

    h3 { font-size: 1.15rem; letter-spacing: -0.02em; }
    .tone-success { --tone: var(--t-success); }
    .tone-warning { --tone: var(--t-warning); }
    .tone-danger { --tone: var(--t-danger); }
    .tone-info { --tone: var(--t-info); }
  }

  .pv-side {
    display: grid;
    align-content: start;
    gap: 0.2rem;
    padding: 1rem 0.7rem;
    background: var(--t-panel);
    border-right: 1px solid var(--t-border);
  }

  .pv-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.75rem 0.4rem;
    font-weight: 700;

    i {
      width: 18px;
      aspect-ratio: 1;
      border-radius: 6px;
      background: linear-gradient(135deg, var(--t-primary), var(--t-accent));
    }
  }

  .pv-nav {
    padding: 0.45rem 0.6rem;
    border-radius: 8px;
    color: var(--t-muted);

    &.active {
      background: color-mix(in oklch, var(--t-primary) 15%, transparent);
      color: var(--t-text);
      font-weight: 600;
      box-shadow: inset 3px 0 0 var(--t-primary);
    }
  }

  .pv-main {
    display: grid;
    align-content: start;
    gap: 0.85rem;
    min-width: 0;
    padding: 1.1rem;
  }

  .pv-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .pv-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }

  .pv-muted { color: var(--t-muted); }

  .pv-btn {
    padding: 0.45rem 0.8rem;
    border: 0;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;

    &.primary { background: var(--t-primary); color: var(--t-on-primary); }
    &.secondary { background: var(--t-secondary); color: var(--t-on-secondary); }
    &.ghost { background: var(--t-card); color: var(--t-text); box-shadow: inset 0 0 0 1px var(--t-border); }
  }

  .pv-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .pv-card {
    display: grid;
    gap: 0.35rem;
    min-width: 0;
    padding: 0.8rem;
    border: 1px solid var(--t-border);
    border-radius: 12px;
    background: var(--t-card);
  }

  .pv-big { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }

  .pv-badge {
    justify-self: start;
    padding: 0.1rem 0.5rem;
    border-radius: 99px;
    background: color-mix(in oklch, var(--tone) 16%, var(--t-card));
    color: color-mix(in oklch, var(--tone) 75%, var(--t-text));
    font-size: 11px;
    font-weight: 650;
  }

  .pv-row { display: flex; justify-content: space-between; }

  .pv-progress {
    height: 6px;
    margin-bottom: 0.35rem;
    border-radius: 99px;
    background: color-mix(in oklch, var(--t-accent) 18%, var(--t-card));

    span {
      display: block;
      width: var(--w);
      height: 100%;
      border-radius: inherit;
      background: var(--t-accent);
    }
  }

  .pv-alerts { display: grid; gap: 0.4rem; }

  .pv-alert {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
    border-left: 3px solid var(--tone);
    background: color-mix(in oklch, var(--tone) 12%, var(--t-card));

    i { width: 8px; aspect-ratio: 1; border-radius: 50%; background: var(--tone); }
  }

  .pv-base {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;

    div {
      padding: 0.75rem;
      border-radius: 10px;
      font-family: var(--mono);
      font-weight: 600;
    }
    .pv-light { background: var(--t-light); color: var(--t-on-light); box-shadow: inset 0 0 0 1px var(--t-border); }
    .pv-dark { background: var(--t-dark); color: var(--t-on-dark); box-shadow: inset 0 0 0 1px var(--t-border); }
  }

  @container preview (width < 560px) {
    .preview { grid-template-columns: minmax(0, 1fr); }
    .pv-side { display: none; }
    .pv-stats { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .pv-stats > :last-child { grid-column: 1 / -1; }
  }

  @container stage (width < 640px) {
    .swatch-tokens { grid-column: 1 / -1; justify-content: start; }
  }

  /* View transitions */
  ::view-transition-group(*) {
    animation-duration: 0.45s;
    animation-timing-function: var(--ease-out);
  }

  @media (prefers-reduced-motion: reduce) {
    *, ::view-transition-group(*) { transition-duration: 0s !important; animation-duration: 0s !important; }
  }
}
