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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--face);
  color: var(--tick);
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 1.125rem;
  line-height: 1.45;
  padding: 1.5rem 1.75rem 2.75rem;
}

.page {
  width: 100%;
  max-width: none;
}

.top {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  max-width: 100%;
}

#preset-controls,
#shape-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  appearance: none;
  margin: 0;
  padding: 0.28rem 0.7rem;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--chip);
  color: var(--tick);
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.2;
  cursor: pointer;
}

.chip:hover,
.chip:focus-visible {
  background: var(--chip-on);
  outline: none;
}

.chip[aria-pressed="true"],
.chip.is-active {
  background: var(--chip-on);
  border-color: var(--tick);
}

.title-block {
  text-align: left;
}

h1 {
  margin: 0;
  color: var(--title);
  font-size: clamp(1.45rem, 2.4vw, 2.05rem);
  font-weight: 700;
  line-height: 1.15;
}

.subtitle {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1.35;
}

.cat-filter {
  appearance: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  line-height: inherit;
  color: inherit;
  cursor: pointer;
}

.cat-filter:hover,
.cat-filter:focus-visible {
  border-bottom-color: currentColor;
  outline: none;
}

.cat-filter.is-selected {
  border-bottom-color: currentColor;
}

.cat-filter[data-cat="ARABLE"] {
  color: var(--petal-arable);
}

.cat-filter[data-cat="FOREST"] {
  color: var(--petal-forest);
}

.cat-filter[data-cat="MEAD"] {
  color: var(--petal-mead);
}

.cat-filter[data-cat="OTHER"] {
  color: var(--petal-other);
}

#error {
  margin: 0 0 0.75rem;
  color: var(--error);
}

.chart-scroll {
  width: 100%;
  overflow: visible;
}

.petal-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.55rem 0.65rem;
  width: 100%;
}

.country-cell {
  position: relative;
  min-width: 0;
  padding: 0.15rem 0.1rem 0.35rem;
  border-radius: 0.25rem;
  cursor: default;
}

.country-cell:hover,
.country-cell:focus-within,
.country-cell.is-hover {
  background: var(--cell-hover);
}

.country-cell.is-dim .petal {
  opacity: 0.18;
}

.country-cell.is-dim .petal.is-active {
  opacity: 1;
}

.country-head {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  margin-bottom: 0.15rem;
  min-height: 2.5rem;
}

.country-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--title);
}

.country-max {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
  color: var(--muted);
}

.country-svg {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  overflow: visible;
}

.grid-ring {
  fill: none;
  stroke: var(--grid);
  stroke-width: 0.04;
}

.grid-ring.r50 {
  opacity: 0.5;
}

.grid-ring.r25 {
  opacity: 0.3;
}

.grid-ring.r10 {
  opacity: 0.2;
}

.grid-axis {
  stroke: var(--grid);
  stroke-width: 0.035;
  stroke-dasharray: 0.12 0.1;
  opacity: 0.2;
}

.grid-label {
  fill: var(--tick);
  font-family: "Segoe UI", system-ui, sans-serif;
}

.grid-label.l50 {
  opacity: 0.5;
}

.grid-label.l25 {
  opacity: 0.3;
}

.grid-label.l10 {
  opacity: 0.2;
}

.petal {
  fill-opacity: var(--petal-alpha);
  stroke: none;
  transition: opacity 120ms ease;
}

.petal[data-cat="ARABLE"] {
  fill: var(--petal-arable);
}

.petal[data-cat="FOREST"] {
  fill: var(--petal-forest);
}

.petal[data-cat="MEAD"] {
  fill: var(--petal-mead);
}

.petal[data-cat="OTHER"] {
  fill: var(--petal-other);
}

.petal-grid.is-filtered .petal {
  opacity: 0.16;
}

.petal-grid.is-filtered .petal.is-active {
  opacity: 1;
}

#readout {
  min-height: 1.35em;
  margin: 0.65rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.caption {
  margin-top: 1.35rem;
  color: var(--caption);
  font-size: 1rem;
}

.caption a {
  color: inherit;
}

.sources {
  margin-bottom: 0.15rem;
}

#tooltip {
  position: fixed;
  z-index: 40;
  max-width: min(20rem, calc(100vw - 1.5rem));
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--tip-border);
  background: var(--tip-bg);
  color: var(--tick);
  font-size: 0.85rem;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}

#tooltip[hidden] {
  display: none;
}

.tip-row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin-top: 0.2rem;
}

.tip-swatch {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 999px;
  flex-shrink: 0;
  opacity: var(--petal-alpha);
}

.tip-swatch[data-cat="ARABLE"] {
  background: var(--petal-arable);
}

.tip-swatch[data-cat="FOREST"] {
  background: var(--petal-forest);
}

.tip-swatch[data-cat="MEAD"] {
  background: var(--petal-mead);
}

.tip-swatch[data-cat="OTHER"] {
  background: var(--petal-other);
}

#tooltip strong + div {
  margin-top: 0.2rem;
}

@media (max-width: 900px) {
  body {
    padding: 1rem 1rem 2rem;
  }

  .petal-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
  }
}

@media (max-width: 560px) {
  .petal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
