#cw-viz.cw {
  width: 100%;
  max-width: 1680px;
  margin: clamp(1.1rem, 2.8vw, 2.2rem) auto;
  display: flex;
  flex-direction: column;
  gap: clamp(1.5rem, 3vw, 2.5rem);
}

.cw-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
  gap: clamp(1.25rem, 3vw, 2.5rem);
  align-items: start;
}

.cw-figure {
  background: color-mix(in oklab, var(--tile, #fff) 86%, transparent 14%);
  border-radius: 1.35rem;
  padding: clamp(1.15rem, 2.4vw, 2.15rem);
  box-shadow: 0 22px 55px rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: clamp(1rem, 1.6vw, 1.4rem);
  border: 1px solid color-mix(in srgb, var(--fg, #0f172a) 12%, transparent 88%);
  margin: 0;
}

body.dark .cw-figure,
html[data-theme="dark"] .cw-figure {
  background: color-mix(in oklab, rgba(30, 41, 59, 0.94) 92%, transparent 8%);
  border-color: rgba(148, 163, 184, 0.24);
  box-shadow: 0 25px 60px rgba(2, 6, 23, 0.55);
}

.cw-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.1rem 1.35rem;
}

.cw-caption-text h2 {
  margin: 0;
  font-size: clamp(1.2rem, 1.1vw + 1rem, 1.55rem);
}

.cw-caption-text p {
  margin: 0.3rem 0 0;
  font-size: clamp(0.95rem, 0.45vw + 0.85rem, 1.02rem);
  color: color-mix(in srgb, var(--fg, #0f172a) 78%, transparent 22%);
  line-height: 1.6;
  max-width: 70ch;
}

body.dark .cw-caption-text p,
html[data-theme="dark"] .cw-caption-text p {
  color: rgba(226, 232, 240, 0.78);
}

.cw-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 0.7rem;
  align-items: center;
  justify-content: flex-start;
}

.cw-legend-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--fg, #0f172a) 14%, transparent 86%);
  background: color-mix(in oklab, var(--bg, #fff) 88%, transparent 12%);
  color: inherit;
  min-height: 2.65rem;
  padding: 0.45rem 0.78rem;
  font-size: 0.83rem;
  line-height: 1;
  letter-spacing: 0.01em;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.cw-legend-btn:hover {
  transform: translateY(-1px);
  background: color-mix(in oklab, var(--bg, #fff) 78%, transparent 22%);
}

.cw-legend-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #3b82f6) 30%, transparent 70%);
}

.cw-legend-btn[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent, #3b82f6) 70%, transparent 30%);
  background: color-mix(in oklab, var(--accent, #3b82f6) 14%, var(--bg, #fff) 86%);
}

.cw-legend-label {
  font-weight: 560;
}

.cw-legend-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  height: 1.35rem;
  border-radius: 999px;
  padding: 0 0.45rem;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  border: 1px solid color-mix(in srgb, var(--fg, #0f172a) 13%, transparent 87%);
  background: color-mix(in oklab, var(--bg, #fff) 92%, transparent 8%);
}

.cw-legend-swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 0.25rem;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.18);
}

body.dark .cw-legend-btn,
html[data-theme="dark"] .cw-legend-btn {
  border-color: rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.32);
}

body.dark .cw-legend-btn:hover,
html[data-theme="dark"] .cw-legend-btn:hover {
  background: rgba(15, 23, 42, 0.46);
}

body.dark .cw-legend-count,
html[data-theme="dark"] .cw-legend-count {
  border-color: rgba(148, 163, 184, 0.36);
  background: rgba(15, 23, 42, 0.42);
}

body.dark .cw-legend-swatch,
html[data-theme="dark"] .cw-legend-swatch {
  box-shadow: inset 0 0 0 1px rgba(248, 250, 252, 0.18);
}

.cw-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.6fr);
  gap: 0.9rem 1rem;
  align-items: end;
}

.cw-search {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.cw-search span {
  font-size: 0.77rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  font-weight: 620;
  color: color-mix(in srgb, var(--fg, #0f172a) 72%, transparent 28%);
}

.cw-search input {
  width: 100%;
  min-height: 2.75rem;
  border-radius: 0.86rem;
  border: 1px solid color-mix(in srgb, var(--fg, #0f172a) 16%, transparent 84%);
  background: color-mix(in oklab, var(--bg, #fff) 92%, transparent 8%);
  color: inherit;
  padding: 0.62rem 0.82rem;
  font: inherit;
  font-size: 0.92rem;
}

.cw-search input::placeholder {
  color: color-mix(in srgb, var(--fg, #0f172a) 56%, transparent 44%);
}

.cw-search input:focus-visible {
  outline: none;
  border-color: color-mix(in srgb, var(--accent, #3b82f6) 70%, transparent 30%);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #3b82f6) 24%, transparent 76%);
}

body.dark .cw-search span,
html[data-theme="dark"] .cw-search span {
  color: rgba(226, 232, 240, 0.78);
}

body.dark .cw-search input,
html[data-theme="dark"] .cw-search input {
  border-color: rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.4);
}

body.dark .cw-search input::placeholder,
html[data-theme="dark"] .cw-search input::placeholder {
  color: rgba(226, 232, 240, 0.56);
}

.cw-year-chips {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.6rem;
  align-items: center;
}

.cw-year-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.65rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--fg, #0f172a) 14%, transparent 86%);
  background: color-mix(in oklab, var(--bg, #fff) 90%, transparent 10%);
  color: inherit;
  padding: 0.45rem 0.78rem;
  font-size: 0.8rem;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}

.cw-year-chip:hover {
  transform: translateY(-1px);
}

.cw-year-chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #3b82f6) 30%, transparent 70%);
}

.cw-year-chip[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent, #3b82f6) 68%, transparent 32%);
  background: color-mix(in oklab, var(--accent, #3b82f6) 16%, var(--bg, #fff) 84%);
}

.cw-year-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.7rem;
  height: 1.32rem;
  border-radius: 999px;
  padding: 0 0.42rem;
  font-size: 0.71rem;
  font-variant-numeric: tabular-nums;
  background: rgba(148, 163, 184, 0.16);
  border: 1px solid rgba(148, 163, 184, 0.32);
}

body.dark .cw-year-chip,
html[data-theme="dark"] .cw-year-chip {
  border-color: rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.36);
}

body.dark .cw-year-count,
html[data-theme="dark"] .cw-year-count {
  background: rgba(148, 163, 184, 0.2);
  border-color: rgba(148, 163, 184, 0.42);
}

.cw-stats {
  margin: 0;
  grid-column: 1 / -1;
  font-size: 0.87rem;
  line-height: 1.5;
  color: color-mix(in srgb, var(--fg, #0f172a) 74%, transparent 26%);
}

body.dark .cw-stats,
html[data-theme="dark"] .cw-stats {
  color: rgba(226, 232, 240, 0.78);
}

.cw .viz-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 6 / 5;
  height: auto;
  min-height: clamp(360px, 57vw, 700px);
  max-height: min(82vh, 880px);
  border-radius: 1.6rem;
  background:
    radial-gradient(circle at 18% 12%, rgba(59, 130, 246, 0.10) 0%, transparent 55%),
    radial-gradient(circle at 80% 92%, rgba(148, 163, 184, 0.14) 0%, transparent 60%),
    linear-gradient(140deg,
      color-mix(in oklab, var(--tile, #fff) 92%, transparent 8%) 0%,
      color-mix(in oklab, rgba(226, 232, 240, 1) 82%, transparent 18%) 100%);
  border: 1px solid color-mix(in srgb, var(--fg, #0f172a) 12%, transparent 88%);
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.14);
  overflow: hidden;
}

body.dark .cw .viz-canvas,
html[data-theme="dark"] .cw .viz-canvas {
  background:
    radial-gradient(circle at 18% 18%, rgba(125, 211, 252, 0.16) 0%, transparent 58%),
    radial-gradient(circle at 85% 92%, rgba(59, 130, 246, 0.10) 0%, transparent 60%),
    linear-gradient(160deg, rgba(15, 23, 42, 0.96) 0%, rgba(9, 14, 23, 0.92) 100%);
  border-color: rgba(100, 116, 139, 0.32);
  box-shadow: 0 28px 70px rgba(2, 6, 23, 0.58);
}

.cw .viz-canvas::after {
  content: '';
  position: absolute;
  inset: clamp(0.55rem, 0.9vw, 0.9rem);
  border-radius: 1.3rem;
  border: 1px solid color-mix(in srgb, var(--fg, #0f172a) 6%, transparent 94%);
  pointer-events: none;
  opacity: 0.6;
}

body.dark .cw .viz-canvas::after,
html[data-theme="dark"] .cw .viz-canvas::after {
  border-color: rgba(148, 163, 184, 0.22);
}

.cw .viz-canvas svg {
  width: 100%;
  height: 100%;
  display: block;
}

.cw .viz-canvas svg text {
  font-family: var(--font-sans);
  fill: rgba(15, 23, 42, 0.92);
}

body.dark .cw .viz-canvas svg text,
html[data-theme="dark"] .cw .viz-canvas svg text {
  fill: rgba(241, 245, 249, 0.92);
}

.cw-subject-bg {
  stroke: rgba(148, 163, 184, 0.24);
  stroke-width: 1;
}

body.dark .cw-subject-bg,
html[data-theme="dark"] .cw-subject-bg {
  stroke: rgba(148, 163, 184, 0.32);
}

.cw-subject-label,
.cw-subject-label-line {
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.92;
  pointer-events: none;
}

.cw-tile {
  cursor: pointer;
}

.cw-tile:focus-visible {
  outline: none;
}

.cw-tile-rect {
  stroke: rgba(15, 23, 42, 0.12);
  stroke-width: 1;
  transition: filter 0.2s ease, stroke 0.2s ease, stroke-width 0.2s ease;
}

body.dark .cw-tile-rect,
html[data-theme="dark"] .cw-tile-rect {
  stroke: rgba(148, 163, 184, 0.22);
}

.cw-tile:hover .cw-tile-rect {
  filter: drop-shadow(0 10px 20px rgba(15, 23, 42, 0.18));
  stroke: rgba(15, 23, 42, 0.22);
  stroke-width: 1.25;
}

body.dark .cw-tile:hover .cw-tile-rect,
html[data-theme="dark"] .cw-tile:hover .cw-tile-rect {
  filter: drop-shadow(0 12px 24px rgba(2, 6, 23, 0.55));
  stroke: rgba(226, 232, 240, 0.28);
}

.cw-tile.is-selected .cw-tile-rect {
  stroke: color-mix(in srgb, var(--accent, #3b82f6) 80%, transparent 20%);
  stroke-width: 2;
  filter: drop-shadow(0 14px 30px rgba(59, 130, 246, 0.22));
}

.cw-tile:focus-visible .cw-tile-rect {
  stroke: color-mix(in srgb, var(--accent, #3b82f6) 85%, transparent 15%);
  stroke-width: 2;
}

.cw-tile-label {
  font-size: clamp(0.66rem, 0.18vw + 0.62rem, 0.78rem);
  font-weight: 650;
  letter-spacing: 0.02em;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

#cw-viz.cw.cw-focused .cw-tile-label {
  font-size: clamp(0.7rem, 0.22vw + 0.66rem, 0.88rem);
}

.cw-tile-label tspan.cw-tile-code {
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.7rem;
}

#cw-viz.cw.cw-focused .cw-tile-label tspan.cw-tile-code {
  font-size: 0.8rem;
}

.cw-tile-label tspan.cw-tile-name {
  font-weight: 520;
  letter-spacing: 0.005em;
  opacity: 0.82;
  font-size: 0.62rem;
  text-transform: none;
}

#cw-viz.cw.cw-focused .cw-tile-label tspan.cw-tile-name {
  font-size: 0.7rem;
  opacity: 0.86;
}

.cw-details {
  position: sticky;
  top: clamp(1rem, 4vw, 2.5rem);
}

.cw-details-card {
  border: 1px solid color-mix(in srgb, var(--fg, #0f172a) 12%, transparent 88%);
  border-radius: 1.35rem;
  padding: clamp(1.1rem, 2vw, 1.55rem);
  background: color-mix(in oklab, var(--tile, #fff) 90%, transparent 10%);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.06);
}

body.dark .cw-details-card,
html[data-theme="dark"] .cw-details-card {
  border-color: rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.34);
  box-shadow: 0 20px 50px rgba(2, 6, 23, 0.45);
}

.cw-details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.cw-details-header h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cw-details-clear {
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--fg, #0f172a) 14%, transparent 86%);
  background: transparent;
  color: inherit;
  min-height: 2.5rem;
  padding: 0.5rem 0.8rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.cw-details-clear:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #3b82f6) 30%, transparent 70%);
}

.cw-details-clear:hover {
  background: color-mix(in oklab, var(--bg, #fff) 85%, transparent 15%);
}

body.dark .cw-details-clear,
html[data-theme="dark"] .cw-details-clear {
  border-color: rgba(148, 163, 184, 0.28);
}

body.dark .cw-details-clear:hover,
html[data-theme="dark"] .cw-details-clear:hover {
  background: rgba(15, 23, 42, 0.5);
}

.cw-details-body {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  font-size: 0.96rem;
}

.cw-details-empty {
  margin: 0;
  color: color-mix(in srgb, var(--fg, #0f172a) 74%, transparent 26%);
}

body.dark .cw-details-empty,
html[data-theme="dark"] .cw-details-empty {
  color: rgba(226, 232, 240, 0.72);
}

.cw-detail-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
}

.cw-detail-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.92rem;
  color: color-mix(in srgb, var(--fg, #0f172a) 72%, transparent 28%);
}

body.dark .cw-detail-subtitle,
html[data-theme="dark"] .cw-detail-subtitle {
  color: rgba(226, 232, 240, 0.72);
}

.cw-detail-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.5rem;
  margin-top: 0.65rem;
}

.cw-detail-chips span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.24rem 0.55rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.06);
  border: 1px solid rgba(148, 163, 184, 0.28);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

body.dark .cw-detail-chips span,
html[data-theme="dark"] .cw-detail-chips span {
  background: rgba(15, 23, 42, 0.34);
  border-color: rgba(148, 163, 184, 0.35);
}

.cw-detail-section h3 {
  margin: 0 0 0.45rem;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.cw-detail-section p {
  margin: 0;
  color: color-mix(in srgb, var(--fg, #0f172a) 78%, transparent 22%);
}

body.dark .cw-detail-section p,
html[data-theme="dark"] .cw-detail-section p {
  color: rgba(226, 232, 240, 0.78);
}

.cw-detail-section ul {
  margin: 0;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.cw-detail-section li {
  line-height: 1.45;
}

.cw-detail-section a {
  text-decoration: none;
}

.cw-detail-section a:hover {
  text-decoration: underline;
}

.cw-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.94);
  color: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.38);
  padding: 0.75rem 0.9rem;
  border-radius: 0.85rem;
  font-size: 0.86rem;
  max-width: min(22rem, 82vw);
  box-shadow: 0 20px 48px rgba(15, 23, 42, 0.28);
  display: none;
  z-index: 5;
  line-height: 1.55;
  transition: opacity 0.18s ease;
  opacity: 0;
}

.cw-tooltip[data-visible="true"] {
  display: block;
  opacity: 1;
}

.cw-tooltip .cw-tip-title {
  font-weight: 650;
  font-size: 0.98rem;
  margin-bottom: 0.25rem;
}

.cw-tooltip .cw-tip-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
  color: rgba(248, 250, 252, 0.85);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  margin-bottom: 0.6rem;
}

.cw-tooltip .cw-tip-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.24rem 0.55rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.32);
  border: 1px solid rgba(148, 163, 184, 0.42);
  text-transform: uppercase;
}

.cw-tooltip .cw-tip-desc {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  color: rgba(226, 232, 240, 0.86);
  line-height: 1.45;
}

.cw-tooltip .cw-tip-empty {
  margin: 0;
  font-size: 0.78rem;
  color: rgba(226, 232, 240, 0.78);
}

body.dark .cw-tooltip,
html[data-theme="dark"] .cw-tooltip {
  background: rgba(15, 23, 42, 0.9);
  color: #f1f5f9;
  border-color: rgba(148, 163, 184, 0.55);
  box-shadow: 0 22px 52px rgba(2, 6, 23, 0.6);
}

.cw-empty-state {
  position: absolute;
  inset: auto 1rem 1rem 1rem;
  border-radius: 1rem;
  border: 1px dashed color-mix(in srgb, var(--fg, #0f172a) 24%, transparent 76%);
  background: color-mix(in oklab, var(--bg, #fff) 92%, transparent 8%);
  padding: 1rem 1.1rem;
  font-size: 0.9rem;
  line-height: 1.45;
  color: color-mix(in srgb, var(--fg, #0f172a) 78%, transparent 22%);
  z-index: 2;
}

.cw-empty-state p {
  margin: 0;
}

.cw-empty-state p + p {
  margin-top: 0.28rem;
}

.cw-empty-query {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

body.dark .cw-empty-state,
html[data-theme="dark"] .cw-empty-state {
  border-color: rgba(148, 163, 184, 0.42);
  background: rgba(15, 23, 42, 0.58);
  color: rgba(226, 232, 240, 0.82);
}

@media (max-width: 980px) {
  .cw-layout {
    grid-template-columns: 1fr;
  }

  .cw-details {
    position: static;
  }

  .cw-toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .cw-year-chips {
    order: 2;
  }

  .cw-stats {
    order: 3;
  }
}

@media (max-width: 720px) {
  #cw-viz.cw {
    margin: clamp(0.9rem, 5.5vw, 1.6rem) auto;
    gap: 1.25rem;
  }

  .cw-caption {
    flex-direction: column;
    align-items: flex-start;
  }

  .cw .viz-canvas {
    border-radius: 1.35rem;
    min-height: clamp(320px, 78vw, 560px);
  }

  .cw-legend-btn,
  .cw-year-chip {
    min-height: 2.5rem;
  }
}
