:root {
  --paper: #f5faf9;
  --ink: #10242a;
  --line: #afc8c7;
  --muted: #415f64;
  --faint: var(--muted);
  --surface: #fff;
  --well: #eaf4f1;
  --badge: #e1eeec;
  --selected: #cef5e5;
  --hover: #d8efe8;
  --button-line: #91b1ad;
  --action: #ffce4c;
  --action-ink: #10242a;
  --primary-hover: #ffdb72;
  --accent: var(--action);
  --mint: #50edb5;
  --comparison: #fff3ce;
  --comparison-ink: #423615;
  --success: #00654c;
  --error: #a02c42;
  --notice: #614c0d;
  --focus: #00664c;
  --slider: #007858;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #09161b;
  --ink: #f4fbfa;
  --line: #3d5a62;
  --muted: #b2cdd0;
  --surface: #112328;
  --well: #0c1b21;
  --badge: #213a40;
  --selected: #113d39;
  --hover: #164740;
  --button-line: #698b91;
  --action: #ffd451;
  --primary-hover: #ffe18a;
  --comparison: #172f36;
  --comparison-ink: #e6f6f7;
  --success: #50edb5;
  --error: #ffa7b4;
  --notice: #ffdc83;
  --focus: #4ae8b4;
  --slider: #39dfaa;
  --thumb: #58777c;
}
:is(.wordmark, .brand) img { border-radius: 22%; aspect-ratio: 1; object-fit: contain; flex: none; }

header:has(.preferences-slot) { flex-wrap: wrap; }
.bar-in { flex-wrap: wrap; }
.bar-in nav { margin-inline-start: auto; }
.brand + #lock { margin-inline-start: auto; }
.preferences-slot { position: relative; display: flex; align-items: center; z-index: 4; }
.preferences-slot:empty { display: none; }
.preferences-slot > button, .preferences-slot summary {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}
.preferences-slot summary { list-style: none; }
.preferences-slot summary::-webkit-details-marker { display: none; }
.preferences-slot > button:hover:enabled, .preferences-slot summary:hover,
.preferences-slot details[open] summary { background: var(--badge, #e8e7de); }
.preferences-slot svg { width: 20px; height: 20px; }
.preferences-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: min(18rem, calc(100vw - 2rem));
  max-height: min(75vh, 34rem);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface, #fffef7);
  color: var(--ink);
  font: 600 0.92rem/1.4 Manrope, system-ui, sans-serif;
  box-shadow: 0 12px 28px #10281a24;
}
.preferences-panel fieldset { margin: 0; padding: 0; border: none; min-width: 0; }
.preferences-panel legend { padding: 0; margin-bottom: 8px; font-weight: 750; }
.palette-choices { display: flex; flex-wrap: wrap; gap: 4px; }
.preferences-panel label {
  position: relative; display: flex; align-items: center; gap: 8px;
  min-height: 44px; margin: 0; cursor: pointer; font-weight: 600;
}
.palette-choices label {
  flex: 1 1 auto; justify-content: center; flex-direction: column;
  gap: 4px; padding: 7px; border: 1px solid var(--line); border-radius: 7px;
}
.palette-choices label:has(:checked) { background: var(--selected); border-color: var(--focus); color: var(--ink); }
.palette-choices input { position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; opacity: 0; }
.palette-choices label:has(:focus-visible) { outline: 3px solid var(--focus, #176648); outline-offset: 2px; }
.preferences-panel .sound-choices { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 6px; }
.sound-choices input { width: 1.12rem; height: 1.12rem; min-height: 0; padding: 0; margin-inline-start: auto; accent-color: var(--slider, #1d6748); }
@media (max-width: 720px) {
  .bar-in { gap: 0 8px; }
  .bar-in .preferences-slot { order: 1; margin-inline-start: auto; }
  .bar-in nav { order: 2; width: 100%; justify-content: space-between; margin: 0 0 8px; }
  header:has(> .brand) { gap: 6px; }
}
@media (max-width: 360px) {
  header:has(> .brand) #lock { order: 2; margin-inline: 0; }
  header:has(> .brand) .preferences-slot { margin-inline-start: auto; }
}
