/* ============ demo: themeforge — a live theme editor in miniature ============
   The panel speaks in site tokens (surface-1, hairlines, ink, mono). Theme colour
   exists only inside the mini browser and on the swatches: those read the --tf-*
   properties written by js/demos/themeforge.js. The properties are registered, so
   colours, the backdrop gradient and every radius interpolate together in a single
   260ms glide — the product's "instant preview". */

@property --tf-accent { syntax: '<color>'; inherits: true; initial-value: #8b5cf6; }
@property --tf-chrome { syntax: '<color>'; inherits: true; initial-value: #0f0e14; }
@property --tf-bar { syntax: '<color>'; inherits: true; initial-value: #19181f; }
@property --tf-omni { syntax: '<color>'; inherits: true; initial-value: #0f0e14; }
@property --tf-edge { syntax: '<color>'; inherits: true; initial-value: transparent; }
@property --tf-ink { syntax: '<color>'; inherits: true; initial-value: rgba(236, 232, 245, 0.32); }
@property --tf-sky-a { syntax: '<color>'; inherits: true; initial-value: #1a1428; }
@property --tf-sky-b { syntax: '<color>'; inherits: true; initial-value: #66449f; }
@property --tf-ridge-a { syntax: '<color>'; inherits: true; initial-value: #33245a; }
@property --tf-ridge-b { syntax: '<color>'; inherits: true; initial-value: #15101f; }
@property --tf-search { syntax: '<color>'; inherits: true; initial-value: #f2eefb; }
@property --tf-search-ink { syntax: '<color>'; inherits: true; initial-value: rgba(20, 18, 28, 0.3); }
@property --tf-tile { syntax: '<color>'; inherits: true; initial-value: rgba(255, 255, 255, 0.1); }
@property --tf-glyph { syntax: '<color>'; inherits: true; initial-value: #c5adfb; }
@property --tf-r { syntax: '<length>'; inherits: true; initial-value: 12px; }

.tf {
  --tf-pad: 12px;
  --tf-hit: 26px; /* swatch / segment / slider hit height */
  --tf-chip: 14px; /* visible swatch */
  --tf-thumb: 9px;

  container: tf / inline-size;
  position: relative;
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  color: var(--ink-2);
  font: 450 10px / 1 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

:where(.tf) p { margin: 0; }
:where(.tf) i { display: block; font-style: normal; }
:where(.tf) :is(button, label) {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
}

.tf__frame {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  aspect-ratio: 4 / 3;
}

/* ---------- header ---------- */

.tf__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px var(--tf-pad) 10px;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}

.tf__live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
}
.tf__live::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-3);
  transition: background-color var(--d-ui) var(--ease-ui);
}
.tf.is-running .tf__live::before { background: var(--signal); }
.tf.is-auto .tf__live::before { animation: tf-beat 1.6s var(--ease-in-out) infinite; }

@keyframes tf-beat {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.tf__tag { color: var(--ink-4); }

/* ---------- body: stage (the browser) + editor ---------- */

.tf__body {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
}

.tf__stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  padding: 14px 14px 12px;
  background: var(--bg-deep);
  border-right: 1px solid var(--hairline);
}

.tf__cap {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink-4);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: none;
  white-space: nowrap;
}
.tf__cap-b {
  display: none;
  align-items: center;
  gap: 6px;
  color: var(--ink-3);
  transition: color var(--d-ui) var(--ease-ui);
}
.tf[data-status="saved"] .tf__cap-b { color: var(--ink); }

/* ---------- the mini browser (theme colour lives only in here) ---------- */

.tf__win {
  /* the miniature scales with its own width; --u stays an unresolved token so
     children resolve it against this container (stacked layout shrinks it) */
  --u: 1cqi;
  container-type: inline-size;
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--tf-bar);
  border-radius: calc(var(--tf-r) * 0.5);
  outline: 1px solid var(--tf-edge);
  outline-offset: -1px;
  transition-property:
    --tf-accent, --tf-chrome, --tf-bar, --tf-omni, --tf-edge, --tf-ink,
    --tf-sky-a, --tf-sky-b, --tf-ridge-a, --tf-ridge-b,
    --tf-search, --tf-search-ink, --tf-tile, --tf-glyph, --tf-r;
  transition-duration: var(--d-ui);
  transition-timing-function: var(--ease-ui);
}

.tf__line {
  height: max(1px, calc(0.9 * var(--u)));
  background: var(--tf-ink);
}

/* tab strip */
.tf__tabs {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: calc(3 * var(--u));
  height: calc(8.5 * var(--u));
  padding: 0 calc(3.4 * var(--u));
  background: var(--tf-chrome);
}
.tf__lights {
  display: flex;
  gap: calc(1.5 * var(--u));
  align-self: center;
  margin-right: calc(1 * var(--u));
}
.tf__lights i {
  width: calc(2.1 * var(--u));
  height: calc(2.1 * var(--u));
  border-radius: 50%;
  background: var(--tf-ink);
}
.tf__tab {
  display: flex;
  align-items: center;
  gap: calc(2.2 * var(--u));
  width: 36%;
  height: calc(6 * var(--u));
  padding: 0 calc(2.8 * var(--u));
  background: var(--tf-bar);
  border-radius: calc(var(--tf-r) * 0.3) calc(var(--tf-r) * 0.3) 0 0;
}
.tf__fav {
  flex: none;
  width: calc(2.6 * var(--u));
  height: calc(2.6 * var(--u));
  background: var(--tf-accent);
  border-radius: calc(var(--tf-r) * 0.12);
}
.tf__tab .tf__line { width: 58%; }
.tf__plus {
  position: relative;
  align-self: center;
  width: calc(2.6 * var(--u));
  height: calc(2.6 * var(--u));
}
.tf__plus::before,
.tf__plus::after {
  content: "";
  position: absolute;
  background: var(--tf-ink);
}
.tf__plus::before { left: 0; right: 0; top: calc(50% - 0.5px); height: 1px; }
.tf__plus::after { top: 0; bottom: 0; left: calc(50% - 0.5px); width: 1px; }

/* toolbar */
.tf__bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: calc(3.2 * var(--u));
  height: calc(9.5 * var(--u));
  padding: 0 calc(3.4 * var(--u));
}
.tf__nav {
  display: flex;
  gap: calc(3 * var(--u));
  padding-left: calc(0.6 * var(--u));
}
.tf__nav i {
  width: calc(1.9 * var(--u));
  height: calc(1.9 * var(--u));
  border-left: 1px solid var(--tf-ink);
  border-bottom: 1px solid var(--tf-ink);
  transform: rotate(45deg);
}
.tf__nav i + i { transform: rotate(-135deg); opacity: 0.55; }
.tf__omni {
  display: flex;
  align-items: center;
  gap: calc(2 * var(--u));
  flex: 1;
  height: calc(6 * var(--u));
  padding: 0 calc(3 * var(--u));
  background: var(--tf-omni);
  border-radius: calc(var(--tf-r) * 0.45);
}
.tf__lock {
  width: calc(1.8 * var(--u));
  height: calc(1.8 * var(--u));
  border-radius: 50%;
  border: 1px solid var(--tf-ink);
}
.tf__omni .tf__line { width: 36%; }
.tf__ext {
  flex: none;
  width: calc(3 * var(--u));
  height: calc(3 * var(--u));
  background: var(--tf-accent);
  border-radius: calc(var(--tf-r) * 0.18);
}

/* viewport + new-tab page */
.tf__view {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0 calc(2 * var(--u)) calc(2 * var(--u));
}
.tf__backdrop {
  position: relative;
  height: 100%;
  overflow: hidden;
  border-radius: calc(var(--tf-r) * 0.5);
  background: linear-gradient(180deg, var(--tf-sky-a) 0%, var(--tf-sky-b) 80%);
}
.tf__ridges {
  position: absolute;
  inset: auto 0 0 0;
  width: 100%;
  height: 46%;
}
.tf__ridge-a { fill: var(--tf-ridge-a); }
.tf__ridge-b { fill: var(--tf-ridge-b); }

.tf__ntp {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(5.5 * var(--u));
  padding-bottom: 10%;
}
.tf__search {
  display: flex;
  align-items: center;
  gap: calc(2.4 * var(--u));
  width: 66%;
  height: calc(8.5 * var(--u));
  padding: 0 calc(3.6 * var(--u));
  background: var(--tf-search);
  border-radius: calc(var(--tf-r) * 0.75);
}
.tf__glass {
  flex: none;
  width: calc(2.8 * var(--u));
  height: calc(2.8 * var(--u));
  border: 1px solid var(--tf-search-ink);
  border-radius: 50%;
}
.tf__search .tf__line { width: 34%; background: var(--tf-search-ink); }
.tf__caret {
  width: 1px;
  height: calc(3.8 * var(--u));
  margin-left: calc(-1.2 * var(--u));
  background: var(--tf-accent);
}
.tf__tiles {
  display: flex;
  gap: calc(3.6 * var(--u));
}
.tf__tiles i {
  display: grid;
  place-items: center;
  width: calc(7.2 * var(--u));
  height: calc(7.2 * var(--u));
  background: var(--tf-tile);
  border-radius: calc(var(--tf-r) * 0.6);
}
.tf__tiles i::before,
.tf__tiles i::after {
  content: "";
  grid-area: 1 / 1;
}
.tf__tiles i::before {
  width: calc(2.4 * var(--u));
  height: calc(2.4 * var(--u));
  background: var(--tf-glyph);
  border-radius: calc(var(--tf-r) * 0.15);
}
.tf__tiles .tf__add::before { width: calc(2.6 * var(--u)); height: 1px; border-radius: 0; background: var(--tf-glyph); }
.tf__tiles .tf__add::after { width: 1px; height: calc(2.6 * var(--u)); background: var(--tf-glyph); }

/* Apply → a page-load line runs across the top of the viewport */
.tf__load {
  position: absolute;
  inset: 0 0 auto 0;
  height: 1.5px;
  background: var(--tf-accent);
  transform: scaleX(0);
  transform-origin: 0 50%;
  pointer-events: none;
}

/* ---------- editor column (site tokens only) ---------- */

.tf__editor {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 14px var(--tf-pad) 12px;
}

.tf__grp {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.tf__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink-3);
  white-space: nowrap;
}
.tf__val { color: var(--ink-2); }

/* swatches: the visible chip aligns with the label; the hit area overhangs */
.tf__swatches {
  display: flex;
  justify-content: space-between;
  margin-inline: calc((var(--tf-chip) - var(--tf-hit)) / 2);
}
.tf__sw {
  display: grid;
  place-items: center;
  flex: none;
  width: var(--tf-hit);
  height: var(--tf-hit);
  border-radius: 50%;
}
.tf__chip {
  position: relative;
  width: var(--tf-chip);
  height: var(--tf-chip);
  border-radius: 50%;
  background: var(--sw);
  transition: transform var(--d-micro) var(--ease-ui);
}
.tf__chip::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity var(--d-ui) var(--ease-out), transform var(--d-ui) var(--ease-out);
}
.tf__sw[aria-pressed="true"] .tf__chip::after { opacity: 1; transform: none; }
.is-fine .tf__sw:hover .tf__chip { transform: scale(1.14); }
.tf__sw:focus-visible { outline-offset: -1px; border-radius: 50%; }

/* mode: a segmented control with a sliding tonal thumb */
.tf__seg {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: var(--tf-hit);
  border: 1px solid var(--hairline-strong);
}
.tf__seg::before {
  content: "";
  position: absolute;
  inset: 0 50% 0 0;
  background: var(--surface-3);
  transition: transform var(--d-ui) var(--ease-out);
}
.tf__seg[data-v="dark"]::before { transform: translateX(100%); }
.tf__seg button {
  position: relative;
  color: var(--ink-3);
  transition: color var(--d-micro) var(--ease-ui);
}
.tf__seg button[aria-pressed="true"] { color: var(--ink); }
.is-fine .tf__seg button[aria-pressed="false"]:hover { color: var(--ink-2); }
.tf__seg button:focus-visible { outline-offset: -4px; }

/* radius: hairline track, ink fill, a dot thumb with a surface gap ring */
.tf__slider { position: relative; display: block; }
.tf__range {
  --p: 0.75;
  --fill: calc(var(--tf-thumb) / 2 + (100% - var(--tf-thumb)) * var(--p));
  display: block;
  width: 100%;
  height: var(--tf-hit);
  margin: 0;
  background:
    linear-gradient(var(--ink-2), var(--ink-2)) 0 50% / var(--fill) 1px no-repeat,
    linear-gradient(var(--hairline-strong), var(--hairline-strong)) 0 50% / 100% 1px no-repeat;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.tf__range::-webkit-slider-runnable-track { height: 100%; background: transparent; }
.tf__range::-moz-range-track { height: 100%; background: transparent; }
.tf__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
  width: var(--tf-thumb);
  height: var(--tf-thumb);
  margin-top: calc((var(--tf-hit) - var(--tf-thumb)) / 2);
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  outline: 2px solid var(--surface-1);
  transition: transform var(--d-micro) var(--ease-ui);
}
.tf__range::-moz-range-thumb {
  box-sizing: border-box;
  width: var(--tf-thumb);
  height: var(--tf-thumb);
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  outline: 2px solid var(--surface-1);
}
.is-fine .tf__range:hover::-webkit-slider-thumb { transform: scale(1.25); }
.tf__range:focus-visible { outline-offset: 2px; }

.tf__ticks {
  position: absolute;
  inset: calc(50% + 4px) calc(var(--tf-thumb) / 2) auto;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}
.tf__ticks i { width: 1px; height: 3px; background: var(--hairline-strong); }

/* apply + status */
.tf__act {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tf__apply {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  border: 1px solid var(--hairline-strong);
  color: var(--ink);
  letter-spacing: 0.14em;
  transition:
    background-color var(--d-micro) var(--ease-ui),
    border-color var(--d-micro) var(--ease-ui),
    color var(--d-micro) var(--ease-ui);
}
.is-fine .tf__apply:hover { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.tf__apply:active { background: var(--surface-3); border-color: var(--hairline-strong); color: var(--ink); }

.tf__status {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--ink-3);
  font-size: 9px;
  white-space: nowrap;
  transition: color var(--d-ui) var(--ease-ui);
}
.tf__sdot {
  flex: none;
  width: 5px;
  height: 5px;
  border: 1px solid currentColor;
  border-radius: 50%;
  transition: background-color var(--d-ui) var(--ease-ui);
}
.tf[data-status="saved"] .tf__status { color: var(--ink); }
.tf[data-status="saved"] .tf__sdot { background: currentColor; }

/* ---------- ghost reticle: the auto-demo's "cursor" ---------- */

.tf__ghost {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--d-ui) var(--ease-ui);
}
.tf__ghost.is-on { opacity: 1; }
.tf__ghost i {
  position: absolute;
  top: 0;
  left: 0;
  width: 6px;
  height: 6px;
  border: 0 solid var(--signal);
  transition: transform 520ms var(--ease-out);
  will-change: transform;
}
.tf__ghost i:nth-child(1) { border-width: 1.5px 0 0 1.5px; }
.tf__ghost i:nth-child(2) { border-width: 1.5px 1.5px 0 0; }
.tf__ghost i:nth-child(3) { border-width: 0 0 1.5px 1.5px; }
.tf__ghost i:nth-child(4) { border-width: 0 1.5px 1.5px 0; }
.tf__ghost.is-press i { transition-duration: 140ms; transition-timing-function: var(--ease-ui); }
.tf__ghost.is-snap i { transition: none; }

/* ---------- tighter / roomier containers ---------- */

@container tf (max-width: 399px) {
  .tf__editor { gap: 12px; }
  .tf__apply { height: 28px; }
  .tf__opt { display: none; } /* "saved · local" fits the narrow column */
}

@container tf (min-width: 440px) {
  .tf__frame { --tf-pad: 14px; }
  .tf__head,
  .tf__editor { font-size: 10.5px; }
  .tf__swatches { --tf-hit: 30px; --tf-chip: 15px; }
}

/* touch, side by side (tablets): every target at least 34px */
html.is-touch .tf:not(.tf--stack) { --tf-hit: 34px; }
html.is-touch .tf:not(.tf--stack) .tf__swatches { --tf-hit: 34px; }
html.is-touch .tf:not(.tf--stack) .tf__apply { height: 34px; }

/* ---------- stacked: phones and very narrow containers ---------- */

.tf--stack {
  --tf-hit: 40px;
  --tf-chip: 18px;
  --tf-thumb: 13px;
}
.tf--stack .tf__swatches { --tf-hit: 40px; --tf-chip: 18px; }
.tf--stack .tf__frame { aspect-ratio: auto; }
.tf--stack .tf__body { grid-template-columns: minmax(0, 1fr); }
.tf--stack .tf__stage {
  aspect-ratio: 16 / 9.6;
  padding: 14px 16px 12px;
  border-right: 0;
  border-bottom: 1px solid var(--hairline);
}
.tf--stack .tf__win { --u: 0.72cqi; }
.tf--stack .tf__search { width: 54%; }
/* stacked, the status rides in the caption under the browser instead of its own row */
.tf--stack .tf__status { display: none; }
.tf--stack .tf__cap-b { display: inline-flex; }
.tf--stack .tf__editor {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 16px 18px;
  padding: 14px var(--tf-pad) 14px;
}
.tf--stack .tf__act { display: contents; }
.tf--stack .tf__apply { grid-column: 2; grid-row: 2; align-self: end; height: var(--tf-hit); }
.tf--stack .tf__opt { display: inline; }
.tf--stack .tf__ticks { inset-block-start: calc(50% + 6px); }

/* ---------- still: reduced motion ---------- */

.tf--still *,
.tf--still *::before,
.tf--still *::after {
  transition: none !important;
  animation: none !important;
}
@media (prefers-reduced-motion: reduce) {
  .tf *,
  .tf *::before,
  .tf *::after {
    transition: none !important;
    animation: none !important;
  }
}
