:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-strong: #f1f5f2;
  --text: #17211b;
  --muted: #657064;
  --line: #d9dfd8;
  --accent: #0c7b5b;
  --accent-strong: #075b45;
  --accent-soft: #dcefe7;
  --warn: #9b3d28;
  --shadow: 0 20px 60px rgba(21, 39, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(12, 123, 91, 0.12), rgba(238, 121, 52, 0.08)),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 32px 18px;
}

.calculator {
  display: grid;
  gap: 22px;
  padding: clamp(20px, 4vw, 40px);
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(217, 223, 216, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.footer {
  padding: 18px 2px 0;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.footer p {
  margin-bottom: 0;
}

.footer a {
  color: var(--accent-strong);
  font-weight: 720;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

.header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 420px);
  gap: 20px;
  align-items: end;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 7vw, 5.8rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.intro {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.mode-switch,
.split-controls {
  display: inline-grid;
  grid-auto-flow: column;
  justify-content: start;
  width: max-content;
  max-width: 100%;
  padding: 4px;
  gap: 4px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.mode-button,
.split-button {
  min-height: 42px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.mode-button.is-active,
.split-button.is-active {
  color: var(--surface);
  background: var(--accent);
}

.form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span,
.time-part label,
legend {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 680;
}

fieldset {
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
}

legend {
  padding: 0;
}

input,
select {
  width: 100%;
  min-height: 52px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

input {
  padding: 0 14px;
  font-variant-numeric: tabular-nums;
}

select {
  padding: 0 38px 0 12px;
}

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.inline-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
}

.time-field {
  grid-column: span 2;
}

.pace-field {
  grid-column: span 2;
}

.time-parts,
.pace-parts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.time-part {
  display: grid;
  gap: 6px;
}

.time-part label {
  font-size: 0.78rem;
}

.time-parts input,
.pace-parts input {
  min-width: 0;
  padding: 0 4px;
  text-align: center;
}

.pace-unit-field {
  display: grid;
  gap: 6px;
}

.pace-unit-field span {
  font-size: 0.78rem;
}

.time-stepper {
  display: grid;
  gap: 6px;
}

.time-step-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.time-stepper button {
  min-height: 42px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 820;
  line-height: 1;
  touch-action: manipulation;
}

.time-stepper button:active {
  color: var(--surface);
  background: var(--accent);
}

.is-hidden {
  display: none;
}

.message {
  min-height: 22px;
  margin-bottom: 0;
  color: var(--warn);
  font-weight: 650;
}

.results {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.result {
  display: grid;
  gap: 8px;
  min-height: 118px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.result span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 680;
}

.result strong {
  align-self: end;
  font-size: clamp(1.45rem, 4vw, 2.25rem);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.splits {
  display: grid;
  gap: 14px;
}

summary {
  width: max-content;
  max-width: 100%;
  padding: 11px 14px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 8px;
  font-weight: 760;
  cursor: pointer;
}

.splits[open] summary {
  margin-bottom: 14px;
}

.split-header {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

.split-table-wrap {
  max-height: 420px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 0.85rem;
  text-transform: uppercase;
}

td:last-child,
th:last-child {
  text-align: right;
}

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

@media (max-width: 780px) {
  .app {
    padding: 12px;
  }

  .calculator {
    gap: 18px;
    padding: 18px;
  }

  .header,
  .form,
  .results {
    grid-template-columns: 1fr;
  }

  .time-field,
  .pace-field {
    grid-column: auto;
  }

  .mode-switch {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-header {
    align-items: start;
    flex-direction: column;
  }

  .split-controls {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .result {
    min-height: 96px;
  }
}
