:root {
  color-scheme: light;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --rune-bg: #f7f8fc;
  --rune-surface: #ffffff;
  --rune-text: #101828;
  --rune-muted: #667085;
  --rune-border: #d9dee8;
  --rune-accent: #3f46d8;
  --rune-tint: #eef2ff;
}

[data-theme="dark"] {
  color-scheme: dark;
  --rune-bg: #10131a;
  --rune-surface: #171b24;
  --rune-text: #f0f2f7;
  --rune-muted: #9ba5b5;
  --rune-border: #2e3542;
  --rune-accent: #7c83f2;
  --rune-tint: #20263a;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--rune-bg);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--rune-bg);
  color: var(--rune-text);
  font-family: Inter, "Avenir Next", "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
}

#app {
  min-height: 100dvh;
  background: var(--rune-bg);
  color: var(--rune-text);
}

.shell {
  width: min(100%, 1440px);
  margin: 0 auto;
  padding: 20px 40px 28px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rune-border);
}

.identity {
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: flex-start;
  gap: 12px;
}

.identity > svg {
  flex: none;
  margin-top: 2px;
  color: var(--rune-accent);
}

h1, h2, h3, p { margin: 0; }

h1 {
  font-size: clamp(28px, 3vw, 34px);
  line-height: 1.05;
  font-weight: 650;
}

.identity p,
.section-heading p {
  color: var(--rune-muted);
  font-size: 14px;
  line-height: 1.55;
}

.identity p { margin-top: 3px; font-size: 14px; }

.repo-link {
  display: inline-flex;
  width: 32px;
  height: 32px;
  flex: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--rune-muted);
  text-decoration: none;
}

.repo-link svg { flex: none; }
.repo-link:hover { background: var(--rune-tint); color: var(--rune-accent); }
.repo-link:focus-visible { outline: 2px solid var(--rune-accent); outline-offset: 3px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 32px;
  padding: 20px 0;
  border-bottom: 1px solid var(--rune-border);
}

.control {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.control legend,
.control-group > span,
.control-search > span,
.control-color-mode > span,
.color-swatch > span,
.context-group h3 {
  margin-bottom: 8px;
  color: var(--rune-muted);
  font-size: 12px;
  line-height: 1.2;
  font-weight: 650;
}

.control-group {
  display: grid;
  align-content: start;
  width: 220px;
}

.control-search {
  display: grid;
  align-content: start;
  width: 220px;
}

.control-color-mode {
  display: grid;
  align-content: start;
  width: 176px;
}

.control-color-mode > span,
.color-swatch > span {
  display: block;
}

.control-group > span {
  display: block;
}

.control-search > span {
  display: block;
}

.control-group select,
.control-search input,
.control-color-mode select {
  min-height: 40px;
  width: 100%;
  padding: 0 34px 0 12px;
  border: 1px solid var(--rune-border);
  border-radius: 6px;
  background: var(--rune-surface);
  color: var(--rune-text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
}

.control-group select:focus-visible,
.control-search input:focus-visible,
.control-color-mode select:focus-visible {
  outline: 2px solid var(--rune-accent);
  outline-offset: 2px;
}

.empty-state {
  grid-column: 1 / -1;
  margin: 0;
  padding: 40px 24px;
  color: var(--rune-muted);
  text-align: center;
}

.color-controls {
  display: flex;
  flex: 1 1 100%;
  min-width: 0;
  align-items: flex-end;
  gap: 16px;
  padding-top: 2px;
}

.inherit-toggle {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  color: var(--rune-text);
  font-size: 13px;
  font-weight: 600;
}

.inherit-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--rune-accent);
}

.color-swatches {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.color-swatch {
  width: 76px;
}

.color-swatch.is-hidden {
  display: none;
}

.color-swatch input {
  display: block;
  width: 100%;
  height: 40px;
  padding: 3px;
  border: 1px solid var(--rune-border);
  border-radius: 6px;
  background: var(--rune-surface);
  cursor: pointer;
}

.color-swatch input:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.contrast-status {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 0 12px;
  border: 1px solid var(--rune-border);
  border-radius: 6px;
  background: var(--rune-surface);
  color: var(--rune-muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.contrast-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--rune-muted);
}

.contrast-status[data-result="pass"] .contrast-dot { background: #21a66b; }
.contrast-status[data-result="warn"] .contrast-dot { background: #d58b24; }

.segments {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--rune-border);
  border-radius: 6px;
  background: var(--rune-surface);
}

.segments button {
  min-width: 48px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-right: 1px solid var(--rune-border);
  background: transparent;
  color: var(--rune-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.segments button:last-child { border-right: 0; }
.segments button:hover { background: var(--rune-tint); color: var(--rune-text); }
.segments button[aria-pressed="true"] { background: var(--rune-accent); color: white; }
.segments button:focus-visible { outline: 2px solid var(--rune-accent); outline-offset: -3px; }

.control-size .segments button {
  min-width: 44px;
  padding-inline: 8px;
}

.control-stroke {
  width: 232px;
}

.stroke-control-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  align-items: center;
  gap: 12px;
  min-height: 40px;
}

.stroke-control-row input {
  width: 100%;
  accent-color: var(--rune-accent);
}

.stroke-control-row output {
  display: flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rune-border);
  border-radius: 6px;
  background: var(--rune-surface);
  color: var(--rune-text);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.stroke-help {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  color: var(--rune-muted);
  font-size: 10px;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0;
}

.section-heading h2 { margin-bottom: 4px; font-size: 18px; line-height: 1.3; font-weight: 650; }
.section-heading code, .context-row code { color: var(--rune-muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }

.selection-bar {
  display: flex;
  min-height: 64px;
  align-items: center;
  gap: 20px;
  padding: 10px 12px;
  border-top: 1px solid var(--rune-border);
  border-bottom: 1px solid var(--rune-border);
  background: var(--rune-surface);
}

.selection-bar.is-empty {
  color: var(--rune-muted);
  font-size: 13px;
}

.selection-bar:not(.is-empty) {
  position: sticky;
  z-index: 10;
  top: 0;
}

.selection-preview {
  display: flex;
  min-width: 176px;
  align-items: center;
  gap: 12px;
}

.selection-preview svg { flex: none; }
.selection-preview strong { display: block; font-size: 14px; }
.selection-preview code { display: block; margin-top: 2px; color: var(--rune-muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }

.selection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selection-actions button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--rune-border);
  border-radius: 6px;
  background: var(--rune-surface);
  color: var(--rune-text);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.selection-actions button:hover { background: var(--rune-tint); }
.selection-actions button:focus-visible { outline: 2px solid var(--rune-accent); outline-offset: 2px; }
.selection-actions button:disabled { cursor: wait; opacity: 0.55; }
.selection-actions .action-primary { border-color: var(--rune-accent); background: var(--rune-accent); color: white; }
.selection-actions .action-primary:hover { background: var(--rune-accent); filter: brightness(0.94); }

[data-export-status] {
  min-width: 0;
  margin-left: auto;
  color: var(--rune-muted);
  font-size: 12px;
  font-weight: 600;
}

[data-export-status][data-result="success"] { color: #16794c; }
[data-export-status][data-result="error"] { color: #c93b3b; }

.icon-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-top: 1px solid var(--rune-border);
}

.specimen {
  min-width: 0;
  border-bottom: 1px solid var(--rune-border);
  text-align: center;
}

.specimen-select {
  width: 100%;
  min-height: 100%;
  padding: 24px 12px;
  border: 0;
  background: transparent;
  color: var(--rune-text);
  text-align: center;
  cursor: pointer;
}

.specimen-select:hover { background: var(--rune-tint); }
.specimen-select:focus-visible { position: relative; outline: 2px solid var(--rune-accent); outline-offset: -3px; }
.specimen.is-selected .specimen-select { background: var(--rune-tint); box-shadow: inset 0 0 0 1px var(--rune-accent); }

.icon-stage {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: center;
}

.specimen-title { display: block; overflow: hidden; margin-top: 10px; font-size: 14px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.specimen-detail { display: block; overflow: hidden; margin-top: 4px; color: var(--rune-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

[data-labels="hide"] .blind-label,
[data-labels="hide"] .calibration-specimen h3 {
  color: var(--rune-muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  font-weight: 500;
}

.calibration { padding-top: 12px; }
.calibration-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--rune-border); border-bottom: 1px solid var(--rune-border); }
.calibration-specimen { min-width: 0; padding: 24px; border-right: 1px solid var(--rune-border); }
.calibration-specimen:last-child { border-right: 0; }
.calibration-large { display: flex; min-height: 152px; align-items: center; justify-content: center; }
.calibration-specimen h3 { margin-top: 12px; font-size: 15px; font-weight: 650; text-align: center; }
.calibration-specimen > p { margin-top: 4px; color: var(--rune-muted); font-size: 12px; text-align: center; }
.calibration-scale { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 8px; margin-top: 20px; }
.calibration-scale span { display: flex; min-width: 0; min-height: 144px; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px; }
.calibration-scale code { color: var(--rune-muted); font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }

.context { padding: 12px 0 32px; }
.context-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--rune-border); border-bottom: 1px solid var(--rune-border); }
.context-group { min-width: 0; padding: 18px 24px 10px; border-right: 1px solid var(--rune-border); }
.context-group:last-child { border-right: 0; }
.context-row { display: flex; min-height: 52px; align-items: center; gap: 12px; border-bottom: 1px solid var(--rune-border); }
.context-row:last-child { border-bottom: 0; }
.context-row svg { flex: none; }
.context-row span { min-width: 0; overflow: hidden; font-size: 14px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.context-row code { margin-left: auto; }

footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; padding: 18px 0; border-top: 1px solid var(--rune-border); color: var(--rune-muted); font-size: 12px; }

@media (max-width: 900px) {
  .shell { padding: 24px; }
  .icon-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .context-grid { grid-template-columns: 1fr; }
  .calibration-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calibration-specimen:nth-child(2) { border-right: 0; }
  .calibration-specimen:nth-child(-n + 2) { border-bottom: 1px solid var(--rune-border); }
  .context-group { border-right: 0; border-bottom: 1px solid var(--rune-border); }
  .context-group:last-child { border-bottom: 0; }
  .color-controls { flex-wrap: wrap; }
  .contrast-status { margin-left: 0; }
  .selection-bar { flex-wrap: wrap; }
  [data-export-status] { width: 100%; margin-left: 0; }
}

@media (max-width: 560px) {
  .shell { padding: 14px 16px 20px; }
  .shell.has-selection { padding-bottom: calc(188px + env(safe-area-inset-bottom)); }
  .page-header { gap: 12px; padding-bottom: 12px; }
  .identity { align-items: center; }
  .identity > svg { margin-top: 0; }
  .identity p { display: none; }
  .toolbar { gap: 16px; }
  .control-size { width: 100%; }
  .control-size .segments { display: flex; width: 100%; }
  .control-size .segments button { min-width: 0; flex: 1; padding-inline: 4px; }
  .control-stroke { width: 100%; }
  .control-group { width: 100%; }
  .control-search { width: 100%; }
  .color-controls { align-items: stretch; }
  .control-color-mode { width: 100%; }
  .inherit-toggle { width: 100%; }
  .color-swatches { width: 100%; }
  .color-swatch { flex: 1; }
  .contrast-status { width: 100%; white-space: normal; }
  .section-heading code { display: none; }
  .icon-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .specimen-select { padding-inline: 6px; }
  .specimen-detail { font-size: 11px; }
  .selection-bar { align-items: stretch; gap: 12px; padding: 12px 0; background: transparent; }
  .selection-bar:not(.is-empty) {
    position: fixed;
    inset: auto 0 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-bottom: 0;
    background: var(--rune-surface);
  }
  .selection-preview { width: 100%; padding-inline: 4px; }
  .selection-actions { display: grid; width: 100%; grid-template-columns: 1fr 1fr; }
  .selection-actions .action-primary { grid-column: 1 / -1; }
  .calibration-grid { grid-template-columns: 1fr; }
  .calibration-specimen { border-right: 0; border-bottom: 1px solid var(--rune-border); }
  .calibration-specimen:last-child { border-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
