:root {
  --shell-bg: #f3f8fb;
  --panel-bg: #ffffff;
  --matrix-surface: #f8fbfd;
  --surface-border: #c7dbe6;
  --ink-strong: #102033;
  --ink-muted: #5a6d7f;
  --accent: #d1006f;
  --accent-soft: #fad9ea;
  --accent-rgb: 209, 0, 111;
  --focus-ring: #102033;
  --focus-ring-gap: #ffffff;
  --ok-bg: #e6f7ec;
  --ok-ink: #0e6a34;
  --fail-bg: #fde8ea;
  --fail-ink: #8a2130;
  --pending-bg: #eef2f5;
  --pending-ink: #5a6d7f;
  --shadow-soft: 0 20px 50px rgba(16, 32, 51, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-pill: 999px;
  --ui-font: "Avenir Next", sans-serif;
  --display-font: "Avenir Next", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(circle at top left, rgba(var(--accent-rgb), 0.18), transparent 28rem),
    linear-gradient(180deg, #fcfeff 0%, var(--shell-bg) 100%);
  color: var(--ink-strong);
  font-family: var(--ui-font);
}

button,
select {
  font: inherit;
}

.theme-brand .brand-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-family: var(--ui-font);
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  outline: none;
}

.theme-brand .brand-button:focus-visible {
  box-shadow:
    0 0 0 3px var(--focus-ring-gap),
    0 0 0 6px var(--focus-ring);
}

.theme-brand .brand-button.btn-size-large {
  padding: 14px 44px;
  font-size: 18px;
  line-height: 24px;
}

.theme-brand .brand-button.btn-size-medium {
  padding: 12px 32px;
  font-size: 16px;
  line-height: 22px;
}

.theme-brand .brand-button.btn-size-small {
  padding: 8px 20px;
  font-size: 14px;
  line-height: 20px;
}

.page-shell {
  width: min(1620px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 20px;
}

.title-group {
  display: grid;
  gap: 8px;
}

h1 {
  margin: 0;
  font-family: var(--display-font);
  font-size: clamp(2rem, 3vw, 2.7rem);
  line-height: 1;
  letter-spacing: 0.02em;
}

h2 {
  margin: 0;
  font-family: var(--display-font);
  font-size: 1.2rem;
  letter-spacing: 0.02em;
}

.page-subtitle {
  margin: 0;
  color: var(--ink-muted);
  font-size: 1rem;
}

.header-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
}

.control {
  display: grid;
  gap: 8px;
  min-width: 160px;
  color: var(--ink-muted);
  font-size: 0.92rem;
}

.control span {
  font-weight: 700;
}

.control select,
.action-button {
  min-height: 46px;
  padding: 0 16px;
  border-radius: 14px;
}

.control select {
  border: 1px solid var(--surface-border);
  background: white;
  color: var(--ink-strong);
}

.control select:disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.action-button {
  border: 1px solid rgba(var(--accent-rgb), 0.2);
  background: var(--ink-strong);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

.workspace {
  display: block;
}

.panel {
  padding: 20px;
  background: var(--panel-bg);
  border: 1px solid rgba(199, 219, 230, 0.9);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
}

.matrix-shell {
  display: block;
}

.preview-summary-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.preview-card {
  display: grid;
  gap: 18px;
  height: 100%;
  padding: 18px;
  border: 1px solid rgba(16, 32, 51, 0.08);
  border-radius: 18px;
  background: white;
}

.preview-heading {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
}

.preview-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.section-label {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.preview-surface {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 24px;
  border: 1px solid rgba(16, 32, 51, 0.08);
  border-radius: 18px;
}

.wcag-summary-panel,
.usage-guide-panel {
  display: grid;
  gap: 18px;
  height: 100%;
  padding: 18px;
  border: 1px solid rgba(16, 32, 51, 0.08);
  border-radius: 18px;
}

.wcag-summary-panel {
  background:
    linear-gradient(180deg, rgba(var(--accent-rgb), 0.06) 0%, rgba(255, 255, 255, 0) 44%),
    white;
}

.usage-guide-panel {
  background: white;
}

.usage-guide-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.usage-guide-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.usage-guide-action {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(16, 32, 51, 0.12);
  border-radius: var(--radius-pill);
  background: rgba(var(--accent-rgb), 0.06);
  color: var(--ink-strong);
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.usage-guide-action:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.wcag-summary-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.wcag-summary-item {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 14px;
  border: 1px solid rgba(16, 32, 51, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
}

.wcag-summary-item-title {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink-strong);
}

.wcag-summary-item-description {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.wcag-summary-item-target {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--ink-strong);
  font-size: 0.76rem;
  font-weight: 700;
}

.wcag-summary-note {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(var(--accent-rgb), 0.06);
  color: var(--ink-muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.usage-guide-list {
  display: grid;
  gap: 10px;
  align-content: start;
}

.usage-guide-item {
  border: 1px solid rgba(16, 32, 51, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  overflow: hidden;
  transition:
    border-color 160ms ease,
    background 160ms ease;
}

.usage-guide-item.is-open {
  border-color: rgba(var(--accent-rgb), 0.22);
  background: white;
}

.usage-guide-item-heading {
  margin: 0;
}

.usage-guide-item-title {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink-strong);
}

.usage-guide-item-trigger {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 160ms ease;
}

.usage-guide-item-trigger:hover {
  background: rgba(var(--accent-rgb), 0.04);
}

.usage-guide-item-trigger:focus-visible {
  outline: 3px solid rgba(var(--accent-rgb), 0.18);
  outline-offset: -3px;
}

.usage-guide-item.is-open .usage-guide-item-trigger {
  background: rgba(var(--accent-rgb), 0.04);
  box-shadow: inset 0 -1px 0 rgba(16, 32, 51, 0.08);
}

.usage-guide-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(16, 32, 51, 0.12);
  border-radius: 50%;
  background: white;
  color: var(--ink-strong);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

.usage-guide-item-panel {
  padding: 14px 16px 16px;
}

.usage-guide-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.usage-guide-column {
  display: grid;
  gap: 8px;
  align-content: start;
}

.usage-guide-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  padding: 5px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.usage-guide-tag.is-do {
  background: var(--ok-bg);
  color: var(--ok-ink);
}

.usage-guide-tag.is-dont {
  background: var(--fail-bg);
  color: var(--fail-ink);
}

.usage-guide-bullets {
  margin: 0;
  padding-left: 18px;
  color: var(--ink-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.usage-guide-bullets li + li {
  margin-top: 4px;
}

.matrix-meta {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.surface-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(var(--accent-rgb), 0.18);
  background: white;
  color: var(--ink-strong);
  font-size: 0.84rem;
  font-weight: 700;
}

.design-matrix-wrap {
  overflow-x: auto;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  background: white;
}

.design-matrix {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

.design-matrix th,
.design-matrix td {
  border-right: 1px solid var(--surface-border);
  border-bottom: 1px solid var(--surface-border);
  vertical-align: top;
}

.design-matrix thead th {
  padding: 16px;
  background: var(--accent-soft);
  color: var(--ink-strong);
  text-align: left;
  font-size: 0.95rem;
  white-space: nowrap;
}

.design-matrix tr > *:last-child {
  border-right: 0;
}

.design-matrix tbody tr:last-child th,
.design-matrix tbody tr:last-child td {
  border-bottom: 0;
}

.matrix-size-heading,
.matrix-state-heading {
  padding: 16px 14px;
  background: #fbfdff;
}

.matrix-size-heading {
  width: 98px;
  vertical-align: middle;
  font-family: var(--display-font);
  letter-spacing: 0.04em;
}

.matrix-state-heading {
  width: 116px;
  font-size: 0.9rem;
}

.design-matrix-cell {
  min-width: 236px;
  padding: 12px;
  background: var(--matrix-surface);
}

.cell-stack {
  display: grid;
  gap: 10px;
}

.matrix-button-slot,
.matrix-placeholder {
  display: grid;
  place-items: center;
  min-height: 112px;
  padding: 16px 12px;
  border: 1px solid rgba(16, 32, 51, 0.08);
  border-radius: 16px;
  background: var(--matrix-surface);
}

.matrix-placeholder {
  border-style: dashed;
  color: var(--ink-muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cell-metrics {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(16, 32, 51, 0.08);
  border-radius: 14px;
  background: white;
}

.cell-metric-row,
.metric-status-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.cell-metric-row + .cell-metric-row {
  padding-top: 6px;
  border-top: 1px solid rgba(16, 32, 51, 0.08);
}

.cell-metric-block {
  display: grid;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(16, 32, 51, 0.08);
}

.metric-label {
  color: var(--ink-muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metric-ratio {
  color: var(--ink-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.compatible-backgrounds {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.compatible-background-chip {
  position: relative;
  display: block;
  width: 28px;
  height: 16px;
  border: 1px solid rgba(16, 32, 51, 0.18);
  border-radius: 6px;
  cursor: help;
  outline: none;
}

.compatible-background-chip::before,
.compatible-background-chip::after {
  position: absolute;
  left: 50%;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.compatible-background-chip::before {
  content: "";
  bottom: calc(100% + 4px);
  transform: translate(-50%, 8px);
  border-width: 6px 6px 0;
  border-style: solid;
  border-color: rgba(16, 32, 51, 0.96) transparent transparent;
  z-index: 21;
}

.compatible-background-chip::after {
  content: attr(data-tooltip);
  bottom: calc(100% + 10px);
  transform: translate(-50%, 8px);
  min-width: 176px;
  max-width: 220px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(16, 32, 51, 0.96);
  color: white;
  box-shadow: 0 12px 30px rgba(16, 32, 51, 0.24);
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.45;
  white-space: pre-line;
  z-index: 22;
}

.compatible-background-chip:hover::before,
.compatible-background-chip:hover::after,
.compatible-background-chip:focus-visible::before,
.compatible-background-chip:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.compatible-background-chip:focus-visible {
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.18);
}

.metric-empty {
  color: var(--ink-muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.metric-status-row {
  padding-top: 8px;
  border-top: 1px solid rgba(16, 32, 51, 0.08);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.status-badge.is-pass {
  color: var(--ok-ink);
  background: var(--ok-bg);
}

.status-badge.is-fail {
  color: var(--fail-ink);
  background: var(--fail-bg);
}

.status-badge.is-pending {
  color: var(--pending-ink);
  background: var(--pending-bg);
}

.runtime-message {
  padding: 18px;
  border: 1px solid rgba(16, 32, 51, 0.12);
  border-radius: 16px;
  background: white;
  color: var(--ink-strong);
}

@media (max-width: 1024px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-controls {
    width: 100%;
  }

  .control {
    min-width: 0;
    flex: 1 1 220px;
  }

  .preview-summary-grid {
    grid-template-columns: 1fr;
  }

  .preview-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .usage-guide-header {
    flex-direction: column;
  }

  .usage-guide-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .page-shell {
    width: min(100vw - 20px, 1620px);
    padding: 20px 0 28px;
  }

  .panel {
    padding: 16px;
  }

  .wcag-summary-cards {
    grid-template-columns: 1fr;
  }

  .usage-guide-item-trigger {
    padding: 14px;
  }

  .usage-guide-item-panel {
    padding: 12px 14px 14px;
  }

  .usage-guide-columns {
    grid-template-columns: 1fr;
  }

  .header-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .preview-controls {
    flex-direction: column;
  }

  .action-button {
    width: 100%;
  }

  .design-matrix,
  .design-matrix thead,
  .design-matrix tbody,
  .design-matrix tr,
  .design-matrix th,
  .design-matrix td {
    display: block;
  }

  .design-matrix-wrap {
    border: 0;
    background: transparent;
  }

  .design-matrix {
    width: 100%;
    min-width: 0;
  }

  .design-matrix thead {
    display: none;
  }

  .design-matrix tbody {
    display: grid;
    gap: 14px;
  }

  .design-matrix tr {
    overflow: hidden;
    border: 1px solid var(--surface-border);
    border-radius: 20px;
    background: white;
  }

  .design-matrix th,
  .design-matrix td {
    border-right: 0;
    border-bottom: 1px solid var(--surface-border);
  }

  .design-matrix tr > *:last-child {
    border-bottom: 0;
  }

  .matrix-size-heading,
  .matrix-state-heading,
  .design-matrix-cell {
    width: 100%;
    min-width: 0;
  }

  .matrix-size-heading {
    border-bottom: 1px solid var(--surface-border);
  }
}
