:root {
  color-scheme: dark;
  --bg: #15231c;
  --surface: rgba(26, 42, 34, 0.64);
  --surface-strong: rgba(23, 37, 30, 0.82);
  --text: #eef5e7;
  --muted: #91a799;
  --line: rgba(185, 202, 189, 0.14);
  --line-highlight: rgba(255, 255, 255, 0.09);
  --primary: #a9d864;
  --primary-strong: #bde779;
  --accent: #d9b456;
  --success: #a9d864;
  --danger: #ef8177;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.3);
  --glass-shadow: inset 0 1px 0 var(--line-highlight), 0 16px 44px rgba(0, 0, 0, 0.18);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  position: relative;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  transition: background-color 220ms ease, color 220ms ease;
}

body::before,
body::after {
  position: fixed;
  z-index: -1;
  width: min(64vw, 920px);
  aspect-ratio: 1;
  border-radius: 50%;
  content: "";
  filter: blur(96px);
  opacity: 0.76;
  pointer-events: none;
}

body::before {
  top: -28vw;
  right: -20vw;
  background: rgba(169, 216, 100, 0.22);
}

body::after {
  bottom: -34vw;
  left: -22vw;
  background: rgba(47, 125, 77, 0.24);
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

svg {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 44px 18px;
}

.calculator {
  width: min(100%, 1120px);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, color-mix(in srgb, var(--surface) 94%, transparent), color-mix(in srgb, var(--surface) 72%, transparent));
  box-shadow: var(--shadow);
  animation: enter 520ms ease both;
  backdrop-filter: blur(28px) saturate(135%);
  -webkit-backdrop-filter: blur(28px) saturate(135%);
}

.calculator__header,
.results__top,
.section-heading,
.actions,
.switch-row {
  display: flex;
  align-items: center;
}

.calculator__header,
.results__top,
.section-heading {
  justify-content: space-between;
  gap: 20px;
}

.title-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.title-icon,
.result-card__icon,
.switch-row__icon {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--primary) 13%, var(--surface));
  color: var(--primary);
  box-shadow: inset 0 1px 0 var(--line-highlight);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.7rem, 3vw, 2.6rem);
  line-height: 1.05;
  letter-spacing: -0.045em;
}

h2 {
  font-size: 1.2rem;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-row__toggle {
  position: relative;
  width: 52px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  box-shadow: inset 0 1px 0 var(--line-highlight);
  transition: background-color 180ms ease, border-color 180ms ease;
}

.switch-row__toggle::after {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.16);
  content: "";
  transition: transform 180ms ease, background-color 180ms ease;
}

.switch-row input:checked + .switch-row__toggle::after {
  transform: translateX(22px);
}

.switch-row input:checked + .switch-row__toggle {
  border-color: color-mix(in srgb, var(--primary) 60%, var(--line));
  background: color-mix(in srgb, var(--primary) 18%, var(--surface));
}

.calculator__form {
  margin-top: 28px;
}

.form-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.form-section:not(:first-child),
.results {
  border-top-color: color-mix(in srgb, var(--line) 82%, transparent);
}

.form-section:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

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

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

.field__label,
.switch-row__title,
.result-card__label {
  font-size: 0.92rem;
  font-weight: 700;
}

.field__control {
  display: flex;
  align-items: center;
  min-height: 54px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-strong);
  box-shadow: inset 0 1px 0 var(--line-highlight);
  backdrop-filter: blur(16px);
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.field__control:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 20%, transparent);
  transform: translateY(-1px);
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 15px 6px 15px 16px;
}

.field select {
  cursor: pointer;
  padding-right: 16px;
}

.field__control--select {
  padding-right: 6px;
}

.field__unit {
  flex: 0 0 auto;
  padding: 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.field__error {
  min-height: 18px;
  color: var(--danger);
  font-size: 0.8rem;
}

.field.is-invalid .field__control,
.route-row.is-invalid .segment-distance-control {
  border-color: var(--danger);
}

.route-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.route-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(150px, 0.7fr) 46px;
  gap: 12px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, var(--surface-strong), color-mix(in srgb, var(--surface) 84%, transparent));
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(18px);
  animation: rowEnter 220ms ease both;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, color 160ms ease;
}

.icon-button:hover {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--line));
  color: var(--danger);
  transform: translateY(-1px);
}

.route-error {
  margin: 10px 0 0;
}

.switch-row {
  position: relative;
  gap: 14px;
  margin-top: 22px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, var(--surface-strong), color-mix(in srgb, var(--surface) 82%, transparent));
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(18px);
  cursor: pointer;
}

.switch-row__hint {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.86rem;
}

.switch-row__toggle {
  margin-left: auto;
}

.actions {
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.button {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 0 22px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button--compact {
  min-height: 40px;
  padding: 0 16px;
}

.button--primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 28px rgba(47, 125, 77, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.button--primary { color: #14231b; }

.button--primary:hover {
  background: var(--primary-strong);
}

.button--ghost {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--line-highlight);
}

.button.is-success {
  border-color: color-mix(in srgb, var(--success) 45%, var(--line));
  color: var(--success);
}

.button--primary.is-success {
  background: var(--success);
  color: #ffffff;
}

.button--primary.is-success { color: #14231b; }

.results {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.result-badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--success) 16%, var(--surface));
  color: var(--success);
  font-weight: 800;
  padding: 0 14px;
  white-space: nowrap;
}

.route-summary {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-strong);
  color: var(--muted);
  line-height: 1.55;
  padding: 14px 16px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.result-card {
  display: grid;
  min-height: 150px;
  align-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: linear-gradient(145deg, var(--surface-strong), color-mix(in srgb, var(--surface) 80%, transparent));
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(18px);
  padding: 16px;
  transition: transform 180ms ease, border-color 180ms ease;
}

.result-card:hover {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--line));
  transform: translateY(-2px);
}

.result-card strong {
  overflow-wrap: anywhere;
  font-size: clamp(1.1rem, 2vw, 1.45rem);
}

.result-card--total {
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 76%, var(--accent)));
  color: #ffffff;
}

.result-card--total .result-card__label {
  color: rgba(255, 255, 255, 0.84);
}

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

.detail-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  border-bottom: 1px solid var(--line);
}

.detail-list dt {
  color: var(--muted);
  font-weight: 700;
}

.detail-list dd {
  margin: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
  text-align: right;
}

.per-person-row.is-hidden {
  display: none;
}

.status-message {
  min-height: 22px;
  margin: 16px 0 0;
  color: var(--muted);
}

.status-message.is-error {
  color: var(--danger);
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rowEnter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 920px) {
  .calculator {
    padding: 22px;
  }

  .calculator__header,
  .results__top,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .route-row,
  .input-grid,
  .result-grid,
  .detail-list {
    grid-template-columns: 1fr;
  }

  .route-row {
    position: relative;
    padding-right: 68px;
  }

  .route-row .icon-button {
    position: absolute;
    top: 14px;
    right: 14px;
  }

  .result-card {
    min-height: 118px;
  }
}

@media (max-width: 560px) {
  .page {
    padding: 16px 10px;
  }

  .calculator {
    padding: 18px;
  }

  .title-group {
    align-items: flex-start;
  }

  .switch-row {
    align-items: flex-start;
    display: grid;
    grid-template-columns: 44px 1fr auto;
  }

  .actions .button,
  .section-heading .button {
    width: 100%;
  }

  .route-row {
    padding: 14px;
  }

  .route-row .icon-button {
    position: static;
    width: 100%;
  }
}
