: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;
}

:root[data-palette="shinchan"] {
  --group: #fff4e5;
  --surface: #fffaf2;
  --elevated: #ffffff;
  --label: #362820;
  --secondary: #6b5045;
  --line: #e8d1bb;
  --fill: #e7f2fa;
  --fill-hover: #d8eaf8;
  --accent: #285675;
  --primary: #b72e32;
  --on-primary: #ffffff;
  --theme-selected: #f9dcdb;
  --theme-selected-text: #792527;
  --theme-ring: #a62a2d;
  --theme-rail: #cb766b;
  --theme-top: #fff1db;
  --theme-top-text: #3f2d23;
  --theme-radius: 16px;
  --scroll-thumb: #bd9d8b;
  --scroll-hover: #9f7766;
}
:root[data-palette="shinchan"][data-theme="dark"] {
  --group: #27201d;
  --surface: #352a25;
  --elevated: #43342d;
  --label: #fff3e5;
  --secondary: #e6cdb9;
  --line: #6d5146;
  --fill: #293b46;
  --fill-hover: #344b58;
  --accent: #acd6f3;
  --primary: #ff9c96;
  --on-primary: #3d1918;
  --theme-selected: #633833;
  --theme-selected-text: #ffe4d9;
  --theme-ring: #ffa9a0;
  --theme-rail: #cf8477;
  --theme-top: #33251f;
  --theme-top-text: #fff0e0;
  --scroll-thumb: #9d7465;
  --scroll-hover: #c59480;
}

/* 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);
}
@media (hover: hover) and (pointer: fine) {
  :root[data-palette] .component-controls > button:not(:disabled,[aria-pressed="true"],[aria-expanded="true"]):hover {
    background: color-mix(in srgb, var(--theme-top-text) 12%, transparent);
  }
}
:root[data-palette] .component-controls > button[aria-expanded="true"] {
  background: var(--theme-selected);
  color: var(--theme-selected-text);
}

: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) {
  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) { background-image: var(--theme-grain); }
:root[data-palette="fox"] :is(.primary,.solid,#iosGenerate) { 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"] .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); }

/* 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 var(--sample-position, 65%);
  background-repeat: no-repeat;
}
[data-palette-choice="afterglow"] { --sample-position: 87%; }
[data-palette-choice="tiga"] { --sample-position: 62%; }
[data-palette-choice="sheep"] { --sample-position: 72%; }
[data-palette-choice="chiikawa"] { --sample-position: 76%; }
[data-palette-choice="shinchan"] { --sample-position: 73%; }
.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-color: #432737; border-color: #d9985e; }
[data-palette-choice="afterglow"] .palette-sample i { background: #efbc70; border-radius: 3px; }
[data-palette-choice="fox"] .palette-sample {
  background-color: #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) {
  .segments { flex-wrap: wrap; }
  .segments button { flex-basis: 40%; }
}
@media print {
  :root[data-palette] body { background: white; color: black; }
}

[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; }

[data-palette-choice="chiikawa"] .palette-sample {
  background-color: #fff3eb;
  background-position: 77% var(--sample-position);
  border-color: #d895aa;
}
[data-palette-choice="chiikawa"] .palette-sample i { background: #a33e5b; }
[data-palette-choice="shinchan"] .palette-sample {
  background-color: #fff1db;
  border-color: #e9ba62;
}
[data-palette-choice="shinchan"] .palette-sample i { background: #b72e32; }
