:root {
  color-scheme: dark;
  --bg: #11131a;
  --surface: #1d2029;
  --surface-2: #242835;
  --surface-3: #161922;
  --text: #f4f6fb;
  --muted: #9aa3b4;
  --line: #3b4252;
  --accent: #78d99a;
  --accent-2: #c8f5d5;
  --good: #5de2a3;
  --warn: #ffd166;
  --danger: #ff7a7a;
  --shadow: 0 20px 58px rgba(0, 0, 0, .24);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef7f1;
  --surface-3: #f9fbff;
  --text: #141722;
  --muted: #616b80;
  --line: #d9deea;
  --accent: #087d48;
  --accent-2: #d9f7e5;
  --good: #007f50;
  --warn: #9b6400;
  --danger: #b42318;
  --shadow: 0 18px 46px rgba(40, 50, 80, .12);
}

* { box-sizing: border-box; }

html,
body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--accent) 15%, transparent), transparent 28rem),
    var(--bg);
  color: var(--text);
}

button,
input,
select { font: inherit; }
button { cursor: pointer; }

.app {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 18px 14px 36px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
}

.brand { min-width: 0; }

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .04em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 5px;
  font-size: clamp(24px, 4.8vw, 42px);
  line-height: 1.02;
  letter-spacing: -0.05em;
}

h3 {
  margin-bottom: 2px;
  font-size: 17px;
  letter-spacing: -0.03em;
}

.lead {
  max-width: 620px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
}

.muted {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.small { font-size: 12px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.theme-toggle,
.button,
.segment,
.chip {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface-2);
  border-radius: 999px;
  min-height: 42px;
  transition: transform .15s ease, border-color .15s ease, background .15s ease, color .15s ease;
}

.theme-toggle {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 0 14px;
  white-space: nowrap;
}

.theme-toggle:active,
.button:active,
.segment:active,
.chip:active { transform: scale(.98); }

.card {
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.calculator { padding: 14px; }

.calc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(315px, 380px);
  grid-template-areas:
    "settings result"
    "fill result"
    "trip result";
  gap: 12px;
  align-items: start;
}

.settings-card { grid-area: settings; }
.fill-card { grid-area: fill; }
.result-panel { grid-area: result; }
.trip-card { grid-area: trip; }

.settings-card,
.fill-card,
.trip-card,
.result-panel {
  border: 1px solid color-mix(in srgb, var(--line) 76%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-2) 54%, transparent);
}

.settings-card,
.fill-card { padding: 13px; }

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

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

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

.label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  padding: 0 12px;
  font-size: 16px;
}

input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.preset-line {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.preset-line__label { margin-right: 1px; }

.mini-chip {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.mini-chip:hover { border-color: var(--accent); }

.section-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 11px;
}

.segmented {
  flex: 0 0 auto;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
}

.segment {
  min-width: 48px;
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment.is-active {
  background: var(--accent);
  color: #07130c;
}

html[data-theme="light"] .segment.is-active { color: #ffffff; }

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

.fill-input-wrap input {
  font-size: 20px;
  font-weight: 800;
}

.chips {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  margin-top: 10px;
}

.chip {
  min-height: 36px;
  padding: 0 7px;
  color: var(--text);
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  font-size: 13px;
  font-weight: 750;
}

.chip:hover { border-color: var(--accent); }

.result-panel {
  position: sticky;
  top: 12px;
  display: grid;
  gap: 10px;
  padding: 13px;
}

.result-kicker {
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.main-result {
  font-size: clamp(26px, 4vw, 36px);
  line-height: 1.04;
  letter-spacing: -0.05em;
  font-weight: 850;
}

.result-text {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.38;
}

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

.stat {
  min-height: 62px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg) 60%, transparent);
}

.stat__label {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.15;
}

.stat strong {
  font-size: 16px;
  line-height: 1.12;
}

.notice {
  padding: 10px 11px;
  border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button {
  padding: 0 13px;
  font-weight: 750;
}

.button-secondary {
  background: var(--accent);
  border-color: var(--accent);
  color: #07130c;
}

html[data-theme="light"] .button-secondary { color: #ffffff; }

.button-ghost { background: transparent; }

.button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.trip-card { overflow: hidden; }

.trip-card summary,
.notes summary {
  cursor: pointer;
  padding: 13px 14px;
  font-weight: 800;
}

.trip-card__body {
  display: grid;
  gap: 10px;
  padding: 0 13px 13px;
}

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

.trip-hint { margin-top: -2px; }

.trip-result {
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.trip-result.is-ok { color: var(--good); }
.trip-result.is-warn { color: var(--warn); }

.trip-breakdown {
  display: grid;
  gap: 8px;
}

.trip-breakdown__main {
  color: var(--text);
  font-size: 17px;
  line-height: 1.18;
  font-weight: 850;
  letter-spacing: -0.02em;
}

.trip-breakdown__text {
  color: var(--muted);
  line-height: 1.38;
}

.trip-breakdown__rows {
  display: grid;
  gap: 5px;
  margin-top: 1px;
}

.trip-breakdown__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 6px;
  border-top: 1px solid color-mix(in srgb, var(--line) 58%, transparent);
}

.trip-breakdown__row span:first-child { color: var(--muted); }

.trip-breakdown__row strong {
  text-align: right;
  color: var(--text);
}

.notes {
  margin-top: 12px;
  padding: 0;
  overflow: hidden;
}

.notes__body {
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.notes__body p:last-child { margin-bottom: 0; }

@media (max-width: 820px) {
  .app {
    padding: max(10px, env(safe-area-inset-top)) 10px 26px;
  }

  .app-header {
    gap: 10px;
    margin-bottom: 9px;
    align-items: flex-start;
  }

  .eyebrow { display: none; }

  h1 {
    margin-bottom: 3px;
    font-size: clamp(22px, 6.2vw, 28px);
  }

  .lead {
    font-size: 13px;
    line-height: 1.25;
  }

  .theme-toggle {
    width: 42px;
    min-width: 42px;
    min-height: 42px;
    justify-content: center;
    padding: 0;
  }

  .theme-toggle__text { display: none; }

  .calculator { padding: 10px; }

  .calc-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "settings"
      "fill"
      "result"
      "trip";
    gap: 10px;
  }

  .settings-card,
  .fill-card,
  .result-panel { padding: 11px; }

  .result-panel {
    position: static;
    gap: 9px;
  }

  input,
  .button { min-height: 44px; }
}

@media (max-width: 560px) {
  .grid-trip { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .settings-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .settings-card,
  .fill-card,
  .result-panel { border-radius: 14px; }

  .label { font-size: 11px; }

  input {
    min-height: 42px;
    padding: 0 9px;
  }

  .section-top {
    margin-bottom: 9px;
  }

  h3 { font-size: 16px; }

  .section-top .small { display: none; }

  .segment { min-width: 44px; min-height: 32px; }

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

  .chips { gap: 6px; }

  .chip {
    min-height: 34px;
    padding: 0 4px;
    font-size: 12px;
  }

  .main-result { font-size: 25px; }

  .result-text { font-size: 13px; }

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

  .stat {
    min-height: 54px;
    padding: 8px;
  }

  .stat strong { font-size: 15px; }

  .actions { grid-template-columns: 1fr; }
}

@media (max-width: 350px) {
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid .field:last-child { grid-column: 1 / -1; }
  .chips { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
