:root[data-palette] {
  --theme-radius: 10px;
  --theme-ring: #0068d7;
  --theme-selected: #e7f1fd;
  --theme-selected-text: #134779;
  --theme-rail: #8dbce9;
  --theme-grain: none;
}
:root[data-palette="studio"][data-theme="dark"] {
  --theme-ring: #80baff;
  --theme-selected: #203b58;
  --theme-selected-text: #d2e7ff;
  --theme-rail: #80baff;
}
:root[data-palette="studio"][data-theme="dark"] .primary {
  background-color: #409cff;
  color: #091b32;
}

:root[data-palette="afterglow"] {
  --group: #f1e3dc;
  --surface: #fff7ee;
  --elevated: #fffaf4;
  --label: #34212a;
  --secondary: #695058;
  --line: #d6b8b4;
  --fill: #e9d4d0;
  --fill-hover: #dfbdb8;
  --accent: #7d2942;
  --primary: #efbc70;
  --on-primary: #301d22;
  --theme-selected: #f5dfbc;
  --theme-selected-text: #64243c;
  --theme-ring: #8c4b17;
  --theme-rail: #f0b86c;
  --theme-top: #472435;
  --theme-top-text: #fff1df;
  --theme-radius: 7px;
  --theme-grain: repeating-linear-gradient(164deg, transparent 0 4px, #f9c88416 4px 5px, transparent 5px 9px);
  --scroll-thumb: #a37376;
  --scroll-hover: #854e59;
}
:root[data-palette="afterglow"][data-theme="dark"] {
  --group: #1b1722;
  --surface: #242230;
  --elevated: #332b3b;
  --label: #ffeedd;
  --secondary: #dbc1c6;
  --line: #5d4457;
  --fill: #3b293a;
  --fill-hover: #513344;
  --accent: #ffd092;
  --theme-selected: #573b4e;
  --theme-selected-text: #ffdaaa;
  --theme-ring: #ffd092;
  --theme-top: #392030;
  --scroll-thumb: #997a93;
  --scroll-hover: #c8a3bc;
}

:root[data-palette="fox"] {
  --group: #fff2dd;
  --surface: #fffaf0;
  --elevated: #fffdf6;
  --label: #38231d;
  --secondary: #715143;
  --line: #ddbea5;
  --fill: #fae5d0;
  --fill-hover: #f3d5b6;
  --accent: #a32f29;
  --primary: #ab362e;
  --on-primary: #fff7eb;
  --theme-selected: #ffe2a0;
  --theme-selected-text: #553014;
  --theme-ring: #ad3929;
  --theme-rail: #d88e2e;
  --theme-top: #fff2d9;
  --theme-top-text: #56291f;
  --theme-radius: 17px;
  --theme-grain: repeating-linear-gradient(120deg, #f7b740 0 7px, #ffdb78 7px 14px);
  --scroll-thumb: #b88c70;
  --scroll-hover: #99553f;
}
:root[data-palette="fox"][data-theme="dark"] {
  --group: #271916;
  --surface: #34231d;
  --elevated: #452c24;
  --label: #fff1df;
  --secondary: #e0bcab;
  --line: #735042;
  --fill: #513329;
  --fill-hover: #684036;
  --accent: #ffab94;
  --primary: #ffad96;
  --on-primary: #351b15;
  --theme-selected: #694627;
  --theme-selected-text: #ffe5ab;
  --theme-ring: #ffbf80;
  --theme-top: #48251e;
  --theme-top-text: #fff0dc;
  --scroll-thumb: #a77b66;
  --scroll-hover: #d1a086;
}


:root[data-palette="tiga"] {
  --group: #e8eff5;
  --surface: #f6faff;
  --elevated: #fff;
  --label: #142c43;
  --secondary: #43586f;
  --line: #b2c7d8;
  --fill: #dce9f3;
  --fill-hover: #c7ddec;
  --accent: #125878;
  --primary: #166383;
  --on-primary: #f8fdff;
  --theme-selected: #cceafa;
  --theme-selected-text: #153e59;
  --theme-ring: #237398;
  --theme-rail: #67b9dc;
  --theme-top: #13283d;
  --theme-top-text: #e8f6ff;
  --scroll-thumb: #708da4;
  --scroll-hover: #466b86;
}
:root[data-palette="tiga"][data-theme="dark"] {
  --group: #0c1828;
  --surface: #142438;
  --elevated: #1b3047;
  --label: #e8f6ff;
  --secondary: #b7cadd;
  --line: #39536a;
  --fill: #24394e;
  --fill-hover: #304d65;
  --accent: #91dcfa;
  --primary: #84d8fa;
  --on-primary: #10253a;
  --theme-selected: #244c65;
  --theme-selected-text: #d7f4ff;
  --theme-ring: #9ae0fa;
  --theme-rail: #75c6eb;
  --theme-top: #101f32;
  --scroll-thumb: #57829e;
  --scroll-hover: #82b1c8;
}
:root[data-palette="sheep"] {
  --group: #f8f2db;
  --surface: #fffdf2;
  --elevated: #fffef8;
  --label: #303218;
  --secondary: #5e6047;
  --line: #d7d5b5;
  --fill: #ebeed3;
  --fill-hover: #dee7bf;
  --accent: #355b31;
  --primary: #9c3e52;
  --on-primary: #fff8f5;
  --theme-selected: #e1edbf;
  --theme-selected-text: #2f4f2b;
  --theme-ring: #4b7039;
  --theme-rail: #7e9f57;
  --theme-top: #f6efd4;
  --theme-top-text: #364929;
  --theme-radius: 15px;
  --scroll-thumb: #8f9c68;
  --scroll-hover: #667c46;
}
:root[data-palette="sheep"][data-theme="dark"] {
  --group: #20251c;
  --surface: #292f22;
  --elevated: #373d2c;
  --label: #f9f4dd;
  --secondary: #d0d5b7;
  --line: #58654c;
  --fill: #394531;
  --fill-hover: #4a5b3d;
  --accent: #c4e0a3;
  --primary: #f3b7c1;
  --on-primary: #492731;
  --theme-selected: #425a34;
  --theme-selected-text: #e8f5cb;
  --theme-ring: #c4e0a3;
  --theme-rail: #a6c97d;
  --theme-top: #293322;
  --theme-top-text: #f8f0d5;
  --scroll-thumb: #7c9261;
  --scroll-hover: #a1b876;
}

:root[data-palette="chiikawa"] {
  --group: #fff8ee;
  --surface: #fffdf8;
  --elevated: #ffffff;
  --label: #392b29;
  --secondary: #6f5652;
  --line: #e8d4cd;
  --fill: #edf4fa;
  --fill-hover: #dfedf8;
  --accent: #3d5a83;
  --primary: #a33e5b;
  --on-primary: #fff9fb;
  --theme-selected: #f8dce5;
  --theme-selected-text: #742841;
  --theme-ring: #a33e5b;
  --theme-rail: #d895aa;
  --theme-top: #fff3eb;
  --theme-top-text: #523730;
  --theme-radius: 16px;
  --scroll-thumb: #c899a6;
  --scroll-hover: #9e6476;
}
:root[data-palette="chiikawa"][data-theme="dark"] {
  --group: #272129;
  --surface: #332a34;
  --elevated: #413540;
  --label: #fff2eb;
  --secondary: #e0c8c6;
  --line: #6e5260;
  --fill: #3d394d;
  --fill-hover: #4c4560;
  --accent: #bbd5ff;
  --primary: #f8bbce;
  --on-primary: #47263a;
  --theme-selected: #644657;
  --theme-selected-text: #ffe8f0;
  --theme-ring: #f8bbce;
  --theme-rail: #bd829a;
  --theme-top: #372935;
  --theme-top-text: #ffede8;
  --scroll-thumb: #a17b93;
  --scroll-hover: #c497ac;
}

/* Both the outer toolbar and the embedded tools use the same color roles. */
:root[data-palette]:not([data-palette="studio"]) {
  --bg: var(--group);
  --ink: var(--label);
  --blue: var(--accent);
  --blue-hover: var(--accent);
  --on-accent: var(--on-primary);
  --selection: var(--theme-selected);
  --hover: var(--fill-hover);
  --surface-elevated: var(--elevated);
  --separator: var(--line);
  --edge: var(--line);
  --bar: var(--theme-top);
  --chrome: var(--theme-top);
}
:root[data-palette]:not([data-palette="studio"]) .global-bar {
  background: var(--theme-top);
  color: var(--theme-top-text);
  border-bottom: 2px solid var(--theme-rail);
}
:root[data-palette]:not([data-palette="studio"]) .global-bar > :is(a,button),
:root[data-palette]:not([data-palette="studio"]) .global-bar :is(.component-name,.component-controls > button,.reading-tools summary) {
  color: var(--theme-top-text);
}
:root[data-palette]:not([data-palette="studio"]) .global-bar :is(.settings-button,.component-segments) {
  background-color: color-mix(in srgb, var(--theme-top-text) 14%, transparent);
}
.component-controls > button:hover,.component-controls > button:focus-visible { background: var(--theme-selected); color: var(--theme-selected-text) !important; }

:root[data-palette] .global-bar .component-segments > button[aria-pressed="true"] {
  background: var(--theme-selected);
  color: var(--theme-selected-text);
  font-weight: 650;
  box-shadow: inset 0 -2px 0 var(--theme-rail);
}

:root[data-palette] :is(
  button, a[href], summary, input, select, textarea, [tabindex]
):focus-visible:not(.drill-input input) {
  outline: 2px solid var(--theme-ring);
  outline-offset: 2px;
}

/* Pointer feedback follows each control's own surface. Reserve the ring for the keyboard. */
@media (hover: hover) and (pointer: fine) {
  :root[data-palette] :is(
    button, summary, input[type="button"], input[type="submit"], input[type="reset"],
    [role="button"], [role="tab"], [role="option"], [role="menuitem"]
  ):hover:not(:disabled,[aria-disabled="true"],.drill-topic) { filter: brightness(.94); }
  :root[data-palette][data-theme="dark"] :is(
    button, summary, input[type="button"], input[type="submit"], input[type="reset"],
    [role="button"], [role="tab"], [role="option"], [role="menuitem"]
  ):hover:not(:disabled,[aria-disabled="true"],.drill-topic) { filter: brightness(1.12); }
}

:root[data-palette] :is(.segments,.component-segments) button[aria-pressed="true"],
:root[data-palette][data-red-tool] :is(button,[role="tab"]):is([aria-pressed="true"],[aria-selected="true"]),
:root[data-palette][data-red-tool] :is(a,button,[role="button"])[aria-current]:not([aria-current="false"]),
:root[data-palette][data-red-tool] :is(.nav-item.active,.toc a.active,.unit-grid .active,.batch-tabs button.active,.cmdk-item.active) {
  background: var(--theme-selected);
  color: var(--theme-selected-text);
  box-shadow: inset 0 -2px 0 var(--theme-rail);
}
:root[data-palette]:not([data-palette="studio"])[data-red-tool] :is(.nav-item.active,.toc a.active,.role-index a[aria-current],.batch-tabs button.active) {
  border-inline-start: 3px solid var(--theme-rail);
  border-radius: var(--theme-radius);
}
:root[data-palette="fox"] :is(.component-segments,.batch-tabs,.unit-grid) :is([aria-pressed="true"],.active) {
  background-image: linear-gradient(120deg,#f0bb5d3b 25%,transparent 25% 50%,#f0bb5d3b 50% 75%,transparent 75%);
  background-size: 16px 16px;
}
:root[data-palette]:not([data-palette="studio"]) :is(.track > span,.utrack > span,.batch-progress-fill) {
  background-color: var(--theme-rail);
}
:root[data-palette]:not([data-palette="studio"]) :is(.settings-button,.close,.round-button,.sheet-close) {
  border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
  border-radius: 50%;
}
:root[data-palette]:not([data-palette="studio"]) :is(.primary,.solid,#iosGenerate,.poster-action) {
  background-color: var(--primary);
  color: var(--on-primary);
  border: 1px solid color-mix(in srgb, var(--on-primary) 30%, transparent);
  border-radius: var(--theme-radius);
}
:root[data-palette="afterglow"] :is(.primary,.solid,#iosGenerate,.poster-action) { background-image: var(--theme-grain); }
:root[data-palette="fox"] :is(.primary,.solid,#iosGenerate,.poster-action) { box-shadow: 0 2px 0 #77291f45; }
:root[data-palette]:not([data-palette="studio"]) :is(.primary,.solid,#iosGenerate):hover:not(:disabled) { filter: brightness(.94); }
:root[data-palette]:not([data-palette="studio"]) :is(.primary,.solid,#iosGenerate):active:not(:disabled) { box-shadow: inset 0 2px 3px #351b1538; }
:root[data-palette="fox"] :is(.global-bar,dialog[open],.hero-editorial) { position: relative; }
:root[data-palette="fox"] .global-bar { position: sticky; }
:root[data-palette="fox"] dialog[open] { position: fixed; }
:root[data-palette="fox"] :is(.global-bar,dialog[open])::after {
  content: ""; position: absolute; inset: auto 0 0;
  height: 3px; pointer-events: none; background: var(--theme-grain);
}
:root[data-palette="afterglow"] .global-bar { background-image: var(--theme-grain); }

/* Each palette's artwork stays readable even with a manually overridden appearance. */
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .editorial-home {
  background: var(--group);
  color: var(--label);
}
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .editorial-home footer { color: var(--secondary); border-color: var(--line); }
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .hero-editorial,
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .hero-stage { background: var(--surface); }
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .hero-copy h1 { color: #231c20; text-shadow: 0 1px 13px #fff9,0 0 30px #fff8; }
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .hero-explore { color: var(--accent, var(--blue)); }
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .poster-card.tool { background: var(--surface); }
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .poster-art:after { background: linear-gradient(#fff9, #fff2 35%, transparent 57%); }
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .poster-cpp .poster-art:after { background: linear-gradient(90deg,#fffe,#fff5 39%,transparent 64%); }
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .poster-card.tool :is(h2,.poster-tagline) { color: #241d20; text-shadow: 0 1px 8px #fffd; }
:root[data-palette="studio"] .poster-action { background: #0068d7; color: white; }
:root[data-palette="fox"] .hero-stage { border-bottom: 4px solid #e8aa4f; }

/* Compact samples show both the palette and its control treatment. */
.palette-options { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.palette-options button {
  padding: 6px 5px 9px; min-width: 0; background: var(--surface);
  color: var(--label); border: 1px solid var(--line); border-radius: 11px;
  text-align: center; display: grid; gap: 2px; line-height: 1.3;
}
.palette-options button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--theme-ring); }
.palette-options button strong { font-size: .84rem; }
.palette-options button small { color: var(--secondary); font-size: .7rem; }
.palette-sample {
  display: grid; place-items: end end; height: 50px; padding: 5px; margin-bottom: 4px;
  border-radius: 7px; background: #edf5fc; border-bottom: 2px solid #8dbce9;
}
[data-palette-choice] .palette-sample { background-size: cover; background-position: center 64%; }
.palette-sample i { width: 17px; height: 7px; border-radius: 4px; background: #146cce; box-shadow: 0 0 0 1px #fff9; }
[data-palette-choice="afterglow"] .palette-sample { background: #432737; border-color: #d9985e; }
[data-palette-choice="afterglow"] .palette-sample i { background: #efbc70; border-radius: 3px; }
[data-palette-choice="fox"] .palette-sample {
  background: #ffedcc; border-color: #e2ab57;
  background-image: repeating-linear-gradient(120deg,transparent 0 8px,#fae1a8 8px 16px);
}
[data-palette-choice="fox"] .palette-sample i { background: #ad3929; border-radius: 10px; }
@media(max-width:760px) {
  :root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .poster-cpp .poster-art:after {
    background: linear-gradient(#fffd,#fff2 40%,transparent 64%);
  }
  .segments { flex-wrap: wrap; }
  .segments button { flex-basis: 40%; }
}
@media print {
  :root[data-palette] body { background: white; color: black; }
}

/* Tiga's artwork uses light text in either interface appearance. */
:root[data-palette="tiga"] .editorial-home { background: var(--group); color: var(--label); }
:root[data-palette="tiga"] .editorial-home footer { color: var(--secondary); border-color: var(--line); }
:root[data-palette="tiga"] :is(.hero-editorial,.hero-stage,.poster-card.tool) { background: #101f32; }
:root[data-palette="tiga"] .hero-copy h1,
:root[data-palette="tiga"] .poster-card.tool :is(h2,.poster-tagline) {
  color: #f0f9ff;
  text-shadow: 0 1px 12px #091321;
}
:root[data-palette="tiga"] .hero-explore { color: #a4e1fa; }
:root[data-palette="tiga"] .poster-art:after { background: linear-gradient(#101c30ec,#0c192b72 32%,transparent 60%); }
:root[data-palette="tiga"] .poster-cpp .poster-art:after { background: linear-gradient(90deg,#0c192bf0,#0c192b6b 36%,transparent 67%); }

.poster-drill .poster-art:after { background: linear-gradient(110deg,#170c19c4, #170c1940 37%, transparent 57%); }
:root:is([data-palette="studio"],[data-palette="fox"],[data-palette="sheep"]) .poster-drill .poster-art:after {
  background: linear-gradient(110deg,#fffce8bf,#fffce83b 41%,transparent 60%);
}
:root[data-palette="tiga"] .poster-drill .poster-art:after { background: linear-gradient(110deg, #101c30e6,#101c303b 40%,transparent 58%); }
[data-palette-choice="tiga"] .palette-sample { background-color: #13283d; border-color: #67b9dc; }
[data-palette-choice="tiga"] .palette-sample i { background: #84d8fa; }
[data-palette-choice="sheep"] .palette-sample { background-color: #f6efd4; border-color: #7e9f57; }
[data-palette-choice="sheep"] .palette-sample i { background: #9c3e52; }
@media(max-width:760px) {
  :root[data-palette="tiga"] .poster-cpp .poster-art:after { background: linear-gradient(#101c30ec,#0c192b72 32%,transparent 60%); }
  :root[data-palette="sheep"] .hero-image { object-position: 65% 50%; }
}

[data-palette-choice="chiikawa"] .palette-sample {
  background-color: #fff3eb;
  background-position: 77% 64%;
  border-color: #d895aa;
}
[data-palette-choice="chiikawa"] .palette-sample i { background: #a33e5b; }
:root[data-palette="chiikawa"][data-theme] .editorial-home {
  background: var(--group);
  color: var(--label);
}
:root[data-palette="chiikawa"][data-theme] .editorial-home footer {
  border-color: var(--line);
  color: var(--secondary);
}
:root[data-palette="chiikawa"][data-theme] .hero-editorial,
:root[data-palette="chiikawa"] :is(.hero-stage,.poster-card.tool) { background: var(--surface); }
:root[data-palette="chiikawa"] .hero-copy {
  inset: 21% auto auto max(6%, calc((100% - 1380px) / 2));
  width: 39%;
  text-align: start;
}
:root[data-palette="chiikawa"] .hero-copy h1 {
  color: #392b29;
  text-shadow: 0 1px 14px #fffc;
  text-wrap: balance;
}
:root[data-palette="chiikawa"] .hero-explore { color: var(--accent); }
:root[data-palette="chiikawa"] .editorial-tools .poster-art img { object-position: center 66%; }
:root[data-palette="chiikawa"] .editorial-tools .poster-art::after {
  background: linear-gradient(180deg, #fff8e9f5, #fff8e9de 15%, #fff8e978 33%, transparent 59%);
}
:root[data-palette="chiikawa"] .poster-card.tool :is(h2,.poster-tagline) {
  color: #392b29;
  text-shadow: 0 1px 8px #fffc;
}
:root[data-palette="chiikawa"] .poster-action {
  background: #a33e5b;
  color: #fff9fb;
}
@media (max-width: 760px) {
  :root[data-palette="chiikawa"] .hero-copy {
    inset: 20px 12px auto;
    width: auto;
    text-align: center;
  }
  :root[data-palette="chiikawa"] .hero-image { object-position: 89% center; }
}
