/* Page shell: reset, header, settings, footer, responsive. */

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header. Same max width as the chart. */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: transparent;
}

.header-inner {
  max-width: var(--title-max);
  margin: 0 auto;
  background: var(--surface);
  padding: 1.1rem 1.5rem 1rem;
}

.title-block {
  min-width: 0;
  max-width: 56em;
  margin-inline: auto;
  text-align: center;
}

.title-block h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--type-title-size);
  font-weight: 600;
  letter-spacing: var(--type-title-tracking);
  line-height: 1.2;
  color: var(--text);
  font-optical-sizing: auto;
}

.subtitle {
  margin: 0.35rem auto 0;
  font-family: var(--font);
  font-size: var(--type-lead-size);
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: var(--type-body-tracking);
  color: var(--text-secondary);
  max-width: 52em;
}

.settings-control {
  position: relative;
  align-self: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Theme bar sits above the sticky header */
.theme-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0.55rem 1rem 0.2rem;
}

.dataset-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.theme-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0;
  margin: 0 0 0 auto;
  padding: 0.16rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
}

.dataset-switcher[hidden] {
  display: none;
}

.theme-btn {
  appearance: none;
  position: relative;
  margin: 0;
  padding: 0.28rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  line-height: 1.2;
  cursor: pointer;
}

.theme-btn:hover,
.theme-btn:focus-visible {
  outline: none;
  border-color: var(--border-light);
  color: var(--text);
}

.theme-btn:focus-visible {
  box-shadow: var(--focus-ring);
}

.theme-btn.is-active,
.theme-btn[aria-pressed="true"] {
  background: var(--surface-2);
  font-weight: 600;
}

.theme-switcher .theme-btn {
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 0.16rem 0.62rem;
}

.theme-switcher .theme-btn:hover:not(.is-active),
.theme-switcher .theme-btn:focus-visible:not(.is-active) {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.theme-switcher .theme-btn.is-active,
.theme-switcher .theme-btn[aria-pressed="true"] {
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--border);
  font-weight: 600;
}

.settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.32rem 0.4rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.settings-btn:hover {
  color: var(--text);
  background: transparent;
}

.settings-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.settings-btn.is-open {
  color: var(--text);
  background: transparent;
  box-shadow: inset 0 -1px 0 currentColor;
}

.settings-icon {
  display: block;
}

.settings-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  left: auto;
  z-index: 30;
  min-width: 14.5rem;
  padding: 0.7rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--tooltip-shadow);
}

.settings-panel[hidden] {
  display: none !important;
}

.settings-panel-inner {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.settings-heading {
  font-family: var(--font);
  font-size: var(--type-label-size);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--type-label-tracking);
  color: var(--text-muted);
  margin-bottom: 0.1rem;
}

.settings-heading:not(:first-child) {
  margin-top: 0.35rem;
}

.settings-panel .toggle {
  font-size: 1rem;
  white-space: nowrap;
}

/* Nested options that only apply when their parent toggle is on. */
.settings-nest {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-left: 0.55rem;
  padding-left: 0.65rem;
  border-left: 1px solid var(--border);
}

.settings-orient {
  width: 100%;
}

.settings-orient .chip-btn {
  flex: 1 1 0;
  text-align: center;
}

.settings-exp {
  display: inline-block;
  margin-left: 0.2rem;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  color: var(--text-muted);
  opacity: 0.75;
  cursor: help;
  vertical-align: super;
}

.toggle input {
  accent-color: var(--accent);
}

.toggle input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 1rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.toggle[hidden],
html:not([data-congress-settings="true"]) label:has(#show-congresses) {
  display: none !important;
}

/* Footer */
.footer {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0.85rem 1rem 2rem;
  font-family: var(--font);
  font-size: var(--type-lead-size);
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: var(--type-body-tracking);
  color: var(--text-muted);
}

.footer p {
  margin: 0;
}

.footer .footer-source {
  margin-top: 1.25rem;
}

.footer a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

@media (prefers-reduced-motion: reduce) {
  .bar,
  .chip-btn {
    transition: none;
  }
}

@media (max-width: 960px) {
  .subtitle {
    max-width: none;
  }
}

@media (max-width: 640px) {
  :root {
    --year-h: 24px;
    --seat-w: 24px;
    --label-h: 156px;
    --year-label-w: 64px;
    --state-gap: 3px;
    --seat-gap: 2px;
    --ruler-inset: 0;
    --ruler-width: 100%;
    --year-w: 20px;
    --seat-h: 24px;
    --label-w: 112px;
    --axis-h: 44px;
    --ruler-top: 0;
    --ruler-bar-h: 100%;
  }

  .header-inner,
  .theme-bar {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .header-inner {
    padding-top: 0.85rem;
    padding-bottom: 0.75rem;
  }

  .title-block h1 {
    font-size: 1.5rem;
    line-height: 1.18;
  }

  .subtitle {
    font-size: 1rem;
  }

  .filter-label input,
  .chip-btn,
  .sort-btn,
  .export-btn,
  .settings-btn {
    min-height: 2.125rem;
  }

  .theme-btn {
    padding: 0.22rem 0.56rem;
    font-size: 1rem;
  }

  .theme-switcher .theme-btn {
    padding: 0.12rem 0.48rem;
  }

  .export-btn {
    padding: 0.35rem;
  }

  .settings-panel {
    right: 0;
    left: auto;
    width: min(16.5rem, calc(100vw - 2rem));
    min-width: 0;
  }

  .chart-chrome-inner {
    padding-top: 0.3rem;
    padding-bottom: 0.15rem;
    max-width: 100%;
  }

  .footer {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
