:root {
  color-scheme: light dark;
  --paper: #f7f5f0;
  --surface: #ece8df;
  --surface-hover: #e0dbd0;
  --ink: #1a1a1a;
  --muted: #56534e;
  --grid: #dcd7cc;
  --tone-b: #8a857e;
  --on-tone-b: var(--ink);
  --accent: #9b2c2c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161514;
    --surface: #23211f;
    --surface-hover: #2f2c29;
    --ink: #ece8e1;
    --muted: #b3aea5;
    --grid: #34312d;
    --tone-b: #8a857d;
    --on-tone-b: var(--paper);
    --accent: #f0998e;
  }
}

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

[hidden] {
  display: none !important;
}

html {
  scroll-padding-bottom: calc(var(--detail-height, 0px) + 32px + env(safe-area-inset-bottom, 0px));
}

html:not([data-js]) .filters,
html:not([data-js]) [data-role-block="both"],
html[data-js]:not([data-office]) [data-role-block]:not([data-role-block="state"]),
html[data-office="state"] [data-role-block]:not([data-role-block="state"]),
html[data-office="government"] [data-role-block]:not([data-role-block="government"]),
html[data-office="both"] [data-role-block]:not([data-role-block="both"]) {
  display: none;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  font-size: 1rem;
  line-height: 1.6;
}

:lang(ja) {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Hiragino Mincho ProN", "Yu Mincho", YuMincho,
    "Noto Serif JP", serif;
}

:lang(ja) :is(.page-header p, .chart .axis text, .chart .no-post, .lane-label, .sources dt) {
  font-style: normal;
}

.page-header,
main,
.page-footer {
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: 16px;
}

.page-header {
  padding-block: 48px 8px;
}

h1 {
  margin: 0;
  font-size: 2.4rem;
  font-weight: 400;
  line-height: 1.15;
}

.page-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  min-width: 44px;
  min-height: 44px;
  padding-inline: 4px;
}

.page-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-style: italic;
}

h2 {
  margin: 40px 0 12px;
  font-size: 1.15rem;
  font-weight: 400;
  font-variant: small-caps;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

a:hover {
  text-decoration-thickness: 3px;
}

:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

button {
  min-width: 44px;
  white-space: nowrap;
  min-height: 44px;
  padding: 8px 20px;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--paper);
}

button.secondary {
  background: transparent;
  color: var(--ink);
}

button.secondary:hover {
  border-color: var(--ink);
  background: var(--surface-hover);
}

button:disabled,
button:disabled:hover {
  border-color: var(--tone-b);
  background: transparent;
  color: var(--muted);
  cursor: not-allowed;
}

.filters {
  margin-top: 32px;
  border-radius: 8px;
  background: var(--surface);
}

.filters summary {
  min-height: 48px;
  padding: 12px 20px;
  border-radius: 8px;
  font-variant: small-caps;
  list-style: none;
  cursor: pointer;
}

.filters summary:hover {
  background: var(--surface-hover);
}

.filters summary::-webkit-details-marker {
  display: none;
}

.filters summary::after {
  float: inline-end;
  content: "+";
  font-size: 1.2rem;
  line-height: 1.3;
}

.filters[open] summary::after {
  content: "−";
}

.filters-form {
  display: grid;
  gap: 24px;
  padding: 8px 20px 20px;
}

fieldset {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 24px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.year-range label {
  margin-bottom: 4px;
  padding: 0;
  color: var(--muted);
  font-variant: small-caps;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}

.choice:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.choice input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--ink);
}

.years {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px 40px;
}

.year-range {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px 16px;
}

.year-range label {
  grid-column: 1 / -1;
}

.year-range input {
  width: 100%;
  min-width: 0;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
}

.year-range input::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--muted);
}

.year-range input::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--muted);
}

.year-range input::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border: 3px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
  appearance: none;
}

.year-range input::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 3px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}

.year-range input:hover::-webkit-slider-thumb {
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.year-range input:hover::-moz-range-thumb {
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.year-range output {
  min-width: 3em;
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
  text-align: end;
}

.filters-actions {
  display: flex;
  justify-content: flex-end;
}

.chart-frame {
  display: flex;
  align-items: flex-start;
}

.chart-scroll {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.chart,
.chart-labels {
  display: block;
  flex: none;
  max-width: none;
  font-size: 15px;
}

.chart-labels.chart-end,
.name-short {
  display: none;
}

@media (min-width: 1464px) {
  .chart-frame {
    margin-inline: -140px;
  }

  .chart-labels.chart-end {
    display: block;
  }
}

:is(.chart, .chart-labels) text {
  fill: var(--ink);
}

.chart .axis text,
.chart .no-post,
.lane-label {
  fill: var(--muted);
  font-size: 14px;
  font-style: italic;
}

.chart .grid {
  stroke: var(--grid);
  stroke-width: 1;
}

.row-label.is-active {
  fill: var(--accent);
  font-weight: 700;
}

.founded {
  stroke: var(--ink);
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

.bar {
  cursor: pointer;
}

.bar-label {
  font-size: 13px;
  pointer-events: none;
}

.chart .label-a,
.chart .bar[aria-current="true"] + .bar-label {
  fill: var(--paper);
}

.chart .label-b {
  fill: var(--on-tone-b);
}

.bar-tooltip {
  position: fixed;
  z-index: 2;
  max-width: 280px;
  padding: 6px 10px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9rem;
  line-height: 1.4;
}

.tone-a {
  fill: var(--ink);
  background: var(--ink);
}

.tone-b {
  fill: var(--tone-b);
  background: var(--tone-b);
}

.tone-acting {
  fill: var(--paper);
  stroke: var(--ink);
  stroke-width: 1.5;
  border: 1.5px solid var(--ink);
}

.bar:hover {
  stroke: var(--accent);
  stroke-width: 4;
}

.bar[aria-current="true"] {
  fill: var(--accent);
  stroke: var(--ink);
  stroke-width: 3;
}

.bar:focus {
  outline: none;
}

.bar:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  stroke: var(--paper);
  stroke-width: 2;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  margin: 16px 0 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.95rem;
  list-style: none;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  display: inline-block;
  width: 24px;
  height: 12px;
  border-radius: 2px;
}

.swatch.founded {
  width: 0;
  height: 16px;
  margin-inline: 8px;
  border-left: 2px dashed var(--ink);
  border-radius: 0;
}

.swatch.selected {
  border: 2px solid var(--ink);
  background: var(--accent);
}

.detail {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
  margin-top: 32px;
  border-radius: 8px;
  background: var(--surface);
}

.detail:not(:empty) {
  position: sticky;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 1;
  max-height: 50vh;
  padding: 24px;
  overflow-y: auto;
  border: 2px solid var(--ink);
  border-radius: 8px;
}

.detail-body {
  flex: 1;
  min-width: 0;
}

.portrait {
  flex: none;
  width: 120px;
  height: 150px;
  margin: 0;
  overflow: hidden;
  border-radius: 4px;
  background: var(--surface-hover);
}

.portrait img {
  display: block;
  width: 120px;
  height: 150px;
  border-radius: 4px;
  object-fit: cover;
  object-position: top;
}

.detail-name {
  margin: 0 0 12px;
  font-size: 1.6rem;
  line-height: 1.2;
}

.detail dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 24px;
  margin: 0 0 12px;
}

.detail dt {
  color: var(--muted);
  font-variant: small-caps;
}

.detail dd,
.detail p {
  margin: 0;
}

.detail a {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
}

.detail-nav {
  display: flex;
  flex-basis: 100%;
  justify-content: space-between;
  gap: 12px;
}

.sources ul {
  margin: 0;
  padding-left: 1.25em;
}

.sources li a {
  display: inline-block;
  min-height: 24px;
}

.sources dl {
  margin: 0;
}

.sources dt {
  margin-top: 12px;
  color: var(--muted);
  font-style: italic;
}

.sources dd {
  margin: 4px 0 0;
}

.page-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 64px;
  padding-block: 24px 40px;
  color: var(--muted);
  font-size: 0.95rem;
}

.page-footer p {
  margin: 0;
}

.page-footer .data-note {
  flex-basis: 100%;
}

.social {
  display: flex;
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.social a {
  display: inline-flex;
  align-items: center;
  min-width: 24px;
  min-height: 24px;
}

@media (max-width: 600px) {
  h1 {
    font-size: 2rem;
  }

  .chart-names {
    width: 100px;
  }

  .chart-lanes {
    width: 44px;
  }

  .name-long {
    display: none;
  }

  .name-short {
    display: inline;
  }

  .detail {
    gap: 16px;
  }

  .detail:not(:empty) {
    padding: 16px;
  }

  .portrait,
  .portrait img {
    width: 72px;
    height: 90px;
  }

  .detail-name {
    margin-bottom: 8px;
    font-size: 1.25rem;
  }

  .detail dl {
    gap: 0 12px;
    font-size: 0.9rem;
  }

  .detail dt {
    font-size: 0.8rem;
  }
}

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