/* === Theme Tokens === */
:root {
  --bg: #fef9f0;
  --surface: #ffffff;
  --surface-alt: #f7f3ee;
  --border: #e8ddd0;
  --text: #2d3748;
  --text-muted: #718096;
  --text-faint: #a0aec0;
  --accent: #b7791f;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 20px;

  --aqi-good: #48bb78;
  --aqi-moderate: #ecc94b;
  --aqi-usg: #ed8936;
  --aqi-unhealthy: #f56565;
  --aqi-very-unhealthy: #9f7aea;
  --aqi-hazardous: #822727;
}

/* === Reset === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* === Base === */
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* === Screen-reader only === */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* === Header === */
.header {
  text-align: center;
  padding: 40px 20px 24px;
}

.header__title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

.header__subtitle {
  font-size: 14px;
  color: var(--text-faint);
  margin-top: 4px;
}

/* === Main Layout === */
.main {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 20px;
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

/* === Card === */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card__label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 14px;
}

/* === Chips (Pollutant Selector) === */
.chips {
  border: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.chip {
  background: var(--surface-alt);
  color: var(--text-muted);
  border: none;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  font-family: inherit;
}

.chip:hover {
  background: #ede5d8;
}

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

.chip--active {
  background: var(--text);
  color: #fff;
}

.chip--active:hover {
  background: #1a202c;
}

/* === Concentration Input === */
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.concentration-input {
  flex: 1;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.2s;
  -moz-appearance: textfield;
}

.concentration-input::-webkit-inner-spin-button,
.concentration-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.concentration-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(183, 121, 31, 0.15);
}

.unit-badge {
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

/* === Result === */
.result {
  text-align: center;
  padding: 8px 0 16px;
}

.result__number {
  display: block;
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
  transition: color 0.3s;
}

.result__category {
  display: inline-block;
  padding: 4px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 700;
  margin-top: 6px;
  transition: background 0.3s, color 0.3s;
}

.result__scale {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 6px;
}

/* === Color Bar === */
.color-bar {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  height: 8px;
  margin-bottom: 16px;
  position: relative;
}

.color-bar__segment {
  flex: 1;
}

.color-bar__segment--good { background: var(--aqi-good); }
.color-bar__segment--moderate { background: var(--aqi-moderate); }
.color-bar__segment--usg { background: var(--aqi-usg); }
.color-bar__segment--unhealthy { background: var(--aqi-unhealthy); }
.color-bar__segment--very-unhealthy { background: var(--aqi-very-unhealthy); }
.color-bar__segment--hazardous { background: var(--aqi-hazardous); }

.color-bar__indicator {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 16px;
  background: var(--text);
  border-radius: 2px;
  transition: left 0.3s ease;
  display: none;
}

.color-bar__indicator--visible {
  display: block;
}

/* === Health Advisory === */
.health-advisory {
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  display: none;
}

.health-advisory--visible {
  display: block;
}

.health-advisory__title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.health-advisory__text {
  font-size: 13px;
  color: #744210;
  line-height: 1.5;
}

.health-advisory__groups {
  font-size: 12px;
  color: var(--accent);
  margin-top: 8px;
  font-weight: 600;
}

/* === Scale Rows === */
.scales-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scale-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--text-faint);
  transition: background 0.3s, border-color 0.3s, transform 0.15s;
  background: var(--surface-alt);
}

.scale-row:hover {
  transform: translateX(2px);
}

.scale-row__info {
  display: flex;
  flex-direction: column;
}

.scale-row__name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.scale-row__subtitle {
  font-size: 11px;
  color: var(--text-faint);
}

.scale-row__value {
  font-size: 22px;
  font-weight: 800;
  transition: color 0.3s;
}

.scale-row__na {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-faint);
  cursor: help;
  position: relative;
}

.scale-row__na::after {
  content: ' ⓘ';
}

.tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--text);
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 400;
  width: 220px;
  z-index: 10;
  line-height: 1.4;
}

.scale-row__na:hover .tooltip,
.scale-row__na:focus .tooltip {
  display: block;
}

/* === Accordion === */
.accordion-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.accordion-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.accordion-toggle__icon {
  font-size: 18px;
  color: var(--text-faint);
  transition: transform 0.3s;
}

.accordion-toggle[aria-expanded="false"] .accordion-toggle__icon {
  transform: rotate(-90deg);
}

.accordion-body {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  max-height: 600px;
  opacity: 1;
  margin-top: 12px;
}

.accordion-body--collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

/* === Breakpoint Table === */
.bp-row {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 12px;
}

.bp-row__swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 8px;
  flex-shrink: 0;
}

.bp-row__name {
  flex: 1;
  font-weight: 600;
  color: var(--text);
}

.bp-row__range {
  color: var(--text-muted);
  margin-left: 8px;
}

.bp-row__conc {
  color: var(--text-faint);
  margin-left: 8px;
}

/* === Footer === */
.footer {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: var(--text-faint);
}

/* === Responsive === */
@media (max-width: 768px) {
  .main {
    grid-template-columns: 1fr;
  }

  .header {
    padding: 28px 16px 16px;
  }

  .header__title {
    font-size: 24px;
  }

  .result__number {
    font-size: 44px;
  }

  .scale-row__value {
    font-size: 18px;
  }
}

@media (max-width: 480px) {
  .chip {
    padding: 6px 10px;
    font-size: 12px;
  }

  .concentration-input {
    font-size: 18px;
    padding: 10px 12px;
  }
}

/* === Print styles === */
@media print {
  body { background: white; }
  .card { box-shadow: none; border: 1px solid #eee; }
}
