:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #eef2f3;
  --border: #d9e0e3;
  --border-strong: #b9c5ca;
  --text: #1f2a30;
  --muted: #68777f;
  --accent: #176b87;
  --accent-strong: #0e5067;
  --accent-soft: #dff1f6;
  --good: #1b7f48;
  --warn: #986a00;
  --danger: #a93d3d;
  --shadow: 0 18px 45px rgba(31, 42, 48, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.site-header {
  width: 100%;
  background: #18313b;
  color: #ffffff;
  border-bottom: 4px solid #e2b84f;
}

.header-inner {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #b8d7df;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 18px;
  font-size: 1.25rem;
}

h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.intro {
  max-width: 650px;
  margin-bottom: 0;
  color: #d7e5e9;
  font-size: 1rem;
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
}

.unit-switch,
.tabs {
  display: inline-flex;
  width: fit-content;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.1);
}

.unit-button,
.tab-button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-weight: 700;
  padding: 8px 14px;
}

.unit-button.is-active {
  background: #ffffff;
  color: #18313b;
}

.language-control {
  display: grid;
  gap: 5px;
  width: 170px;
}

.language-control span {
  color: #d7e5e9;
  font-size: 0.78rem;
  font-weight: 800;
}

.language-select {
  min-height: 40px;
  border-color: rgba(255, 255, 255, 0.36);
  background: #ffffff;
}

.app-shell {
  width: min(1120px, calc(100% - 24px));
  margin: 22px auto 40px;
  min-width: 0;
}

.tabs {
  margin-bottom: 16px;
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 6px 18px rgba(31, 42, 48, 0.08);
}

.tab-button.is-active {
  background: var(--accent);
  color: #ffffff;
}

.panel {
  display: none;
}

.panel.is-active {
  display: block;
}

.tool-layout {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.calculator-panel,
.results-panel,
.table-block {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.calculator-panel {
  padding: 18px;
}

.results-panel {
  padding: 18px;
}

fieldset {
  margin: 0 0 18px;
  padding: 0;
  border: 0;
}

fieldset:last-child {
  margin-bottom: 0;
}

legend {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.tire-input-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px 10px;
}

.tire-input-row.single {
  flex-wrap: nowrap;
}

label {
  display: grid;
  gap: 6px;
  width: 82px;
}

.tire-input-row label:first-child {
  width: 92px;
}

.tire-input-row.single label {
  width: 82px;
}

label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  padding: 8px 10px;
}

.size-mark {
  padding-bottom: 9px;
  color: var(--muted);
  font-size: 1.3rem;
  font-weight: 800;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.summary-card {
  min-height: 86px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  padding: 13px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.summary-card strong {
  display: block;
  margin-top: 5px;
  font-size: 1.2rem;
  line-height: 1.2;
}

.candidate-grid {
  display: grid;
  gap: 10px;
}

.result-section + .result-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.candidate-card {
  display: grid;
  gap: 12px;
  width: 100%;
  border: 1px solid var(--border);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  background: #ffffff;
  color: inherit;
  padding: 14px;
  text-align: left;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.candidate-card.is-recommended {
  border-left-color: #d49b20;
  background: #fffdf7;
}

.candidate-card:hover,
.candidate-card:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 10px 24px rgba(31, 42, 48, 0.14);
  transform: translateY(-1px);
  outline: none;
}

.candidate-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.rank-label {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.candidate-size {
  font-size: 1.25rem;
  font-weight: 850;
}

.quality {
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: capitalize;
  white-space: nowrap;
}

.quality.excellent {
  background: #dcf3e8;
  color: var(--good);
}

.quality.good {
  background: #dff1f6;
  color: var(--accent-strong);
}

.quality.acceptable {
  background: #fff2cc;
  color: var(--warn);
}

.quality.warning {
  background: #f8dddd;
  color: var(--danger);
}

.candidate-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  color: var(--muted);
  font-size: 0.88rem;
}

.metric strong {
  display: block;
  color: var(--text);
  font-size: 1rem;
}

.table-block {
  margin-top: 18px;
  padding: 14px;
  box-shadow: none;
}

.table-scroll {
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.empty-state {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.site-footer {
  width: min(1120px, calc(100% - 32px));
  min-width: 0;
  margin: 0 auto 28px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

@media (min-width: 760px) {
  .header-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .tool-layout {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    align-items: start;
  }

  .candidate-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 430px) {
  .summary-grid,
  .candidate-metrics {
    grid-template-columns: 1fr;
  }

  .unit-switch,
  .tabs {
    width: 100%;
  }

  .header-controls,
  .language-control {
    width: 100%;
  }

  .unit-button,
  .tab-button {
    flex: 1;
  }
}

@media (max-width: 560px) {
  .header-inner {
    width: min(1120px, calc(100% - 24px));
  }

  .results-panel {
    padding: 14px;
  }

  .table-block {
    padding: 12px;
  }

  table {
    min-width: 0;
    table-layout: fixed;
  }

  th,
  td {
    padding: 9px 7px;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 0.92rem;
    line-height: 1.25;
  }

  th {
    font-size: 0.74rem;
  }

  #compare-table th:first-child,
  #compare-table td:first-child {
    width: 46%;
  }

  #speed-table th,
  #speed-table td {
    width: 33.33%;
  }
}
