/* Components and layout. Borderless M3: tonal surfaces, spacing and radius, never outlines. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font: var(--body-l);
  background: var(--md-surface);
  color: var(--md-on-surface);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--md-primary); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.icon {
  font-family: 'Material Symbols Rounded';
  font-weight: normal; font-style: normal;
  font-size: 24px; line-height: 1;
  letter-spacing: normal; text-transform: none; white-space: nowrap; direction: ltr;
  display: inline-block; width: 1em; overflow: hidden;
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 0;
  flex: none;
}

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 8px 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  min-height: 64px;
  background: var(--md-surface);
  transition: background-color 200ms var(--ease);
}
.appbar.scrolled { background: var(--md-surface-container); }
.appbar-title { position: relative; flex: 1; min-width: 0; height: 32px; }
.appbar-name, .appbar-compact {
  position: absolute; inset: 0;
  display: flex; align-items: center;
  font: var(--title-l);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.appbar-compact { opacity: 0; transform: translateY(8px); color: var(--md-primary); }
.appbar.show-compact .appbar-name { opacity: 0; transform: translateY(-8px); }
.appbar.show-compact .appbar-compact { opacity: 1; transform: none; }

/* ---------- Layout ---------- */
.layout {
  display: flex; flex-direction: column; gap: 16px;
  max-width: 1200px; margin: 0 auto;
  padding: 0 16px 48px;
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}
.layout > * { min-width: 0; }

/* Expanded (≥ 840px): everything in the left column, the result card sticky on the right. */
@media (min-width: 840px) {
  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px; padding: 8px 24px 64px;
    align-items: start;
  }
  .layout > * { grid-column: 1; }
  .layout > .intro { grid-column: 1 / -1; padding-top: 8px; }
  .intro h1 { font: 500 32px/40px var(--font); }
  .layout > .card-result { grid-column: 2; grid-row: 2 / span 7; position: sticky; top: 80px; }
}

/* ---------- Intro (the page's h1, for people and search engines) ---------- */
.intro { display: flex; flex-direction: column; gap: 6px; padding: 4px 4px 4px; }
.intro h1 { font: 500 26px/34px var(--font); }
.intro p { font: var(--label-l); font-weight: 400; color: var(--md-on-surface-variant); max-width: 62ch; }

/* ---------- Cards ---------- */
.card {
  background: var(--md-surface-container-low);
  border-radius: var(--r-xl);
  padding: 24px 20px;
  display: flex; flex-direction: column; gap: 20px;
}
.card-title { font: var(--headline-s); }
.sub-title { font: var(--title-m); }
.hint { font: var(--label-l); font-weight: 400; color: var(--md-on-surface-variant); }
.optional { font-weight: 400; color: var(--md-on-surface-variant); }

/* ---------- Result card ---------- */
.card-result { background: var(--md-surface-container-high); gap: 0; }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -8px -8px 0 0; }
.result-label { font: var(--title-m); color: var(--md-on-surface-variant); }
.result-empty { padding: 12px 0 4px; color: var(--md-on-surface-variant); }
.result-number {
  font: var(--display-l); letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  color: var(--md-on-surface);
}
.result-number .unit { font: var(--title-l); color: var(--md-on-surface-variant); letter-spacing: 0; }
.result-range { color: var(--md-on-surface-variant); margin-bottom: 20px; }

.bar { display: flex; gap: 3px; height: 28px; border-radius: var(--r-full); overflow: hidden; }
.bar-seg {
  height: 100%; min-width: 4px;
  transition: flex-grow var(--dur) var(--ease);
}
.bar-seg:first-child { border-radius: var(--r-full) 4px 4px var(--r-full); }
.bar-seg:last-child { border-radius: 4px var(--r-full) var(--r-full) 4px; }
.bar-seg:not(:first-child):not(:last-child) { border-radius: 4px; }

.legend {
  list-style: none; padding: 0; margin: 16px 0 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 16px;
}
.legend li { display: flex; align-items: baseline; gap: 8px; font: var(--label-l); font-weight: 400; }
.legend .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; transform: translateY(1px); }
.legend .kcal { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }
.result-meta { margin-top: 16px; font: var(--label-l); font-weight: 400; color: var(--md-on-surface-variant); }

/* ---------- Fields: filled tonal, no indicator line ---------- */
.group { display: flex; flex-direction: column; gap: 10px; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.group-label, .field > label { font: var(--label-l); color: var(--md-on-surface-variant); }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr; gap: 16px; }
.field-input {
  display: flex; align-items: center; gap: 8px;
  background: var(--md-surface-container-highest);
  border-radius: var(--r-m);
  padding: 0 16px;
  min-height: 56px;
  transition: background-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
.field-input:focus-within { background: var(--md-secondary-container); }
.field:focus-within > label { color: var(--md-primary); }
.field-input input {
  flex: 1; min-width: 0; width: 100%;
  border: 0; outline: 0; background: transparent;
  font: 500 20px/28px var(--font);
  padding: 14px 0;
  font-variant-numeric: tabular-nums;
}
.field-input input + .suffix + input { margin-left: 8px; }
.field-input input::placeholder { color: var(--md-on-surface-variant); opacity: 0.7; }
.suffix { color: var(--md-on-surface-variant); font: var(--label-l); font-weight: 400; flex: none; }
.field.invalid .field-input { background: var(--md-error-container); }
.error { font: var(--label-l); font-weight: 400; color: var(--md-error); min-height: 0; }
.error:empty { display: none; }

/* ---------- Segmented buttons (tonal, borderless) ---------- */
.segmented {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--md-surface-container-highest);
  border-radius: var(--r-full);
  align-self: flex-start;
}
.segmented button {
  border: 0; cursor: pointer;
  min-height: 48px; padding: 0 22px;
  border-radius: var(--r-full);
  background: transparent;
  font: var(--label-l);
  color: var(--md-on-surface-variant);
  display: inline-flex; align-items: center; gap: 6px;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.segmented button[aria-checked='true'] { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.segmented button:hover:not([aria-checked='true']) { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.segmented.small button { min-height: 40px; padding: 0 16px; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 24px 0 20px;
  border-radius: var(--r-full);
  font: var(--label-l);
  transition: background-color 150ms var(--ease), box-shadow 150ms var(--ease);
  align-self: flex-start;
}
.btn.filled { background: var(--md-primary); color: var(--md-on-primary); padding: 0 28px; }
.btn.tonal { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }
.btn.text { background: transparent; color: var(--md-primary); padding: 0 16px; }
.btn.danger { color: var(--md-error); }
.btn:hover { box-shadow: inset 0 0 0 100px color-mix(in srgb, currentColor 8%, transparent); }

.icon-btn {
  border: 0; cursor: pointer; flex: none;
  width: 48px; height: 48px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: transparent; color: var(--md-on-surface-variant);
}
.icon-btn:hover { background: color-mix(in srgb, var(--md-on-surface) 8%, transparent); }
.icon-btn.tonal { background: var(--md-secondary-container); color: var(--md-on-secondary-container); }

:focus-visible { outline: 3px solid var(--md-primary); outline-offset: 2px; }
.field-input input:focus-visible { outline: none; }

/* ---------- Sliders ---------- */
.slider-row { display: flex; flex-direction: column; gap: 10px; }
.slider-label { font: var(--label-l); color: var(--md-on-surface-variant); display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.slider-label output { font-weight: 700; color: var(--md-on-surface); margin-left: auto; font-variant-numeric: tabular-nums; }
.slider-label output.long { margin-left: 0; flex-basis: 100%; font-weight: 600; }
.steps-control { display: flex; align-items: center; gap: 16px; }
.steps-control input[type='range'] { flex: 1; }
.steps-input { width: 120px; min-height: 52px; }
.steps-input input { text-align: right; }

input[type='range'] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 44px; background: transparent; cursor: pointer; margin: 0;
  --fill: 50%;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 16px; border-radius: var(--r-full);
  background: linear-gradient(to right, var(--md-primary) var(--fill), var(--md-secondary-container) var(--fill));
}
input[type='range']::-moz-range-track { height: 16px; border-radius: var(--r-full); background: var(--md-secondary-container); }
input[type='range']::-moz-range-progress { height: 16px; border-radius: var(--r-full); background: var(--md-primary); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 6px; height: 40px; margin-top: -12px;
  border-radius: 3px; background: var(--md-primary);
  box-shadow: 0 0 0 4px var(--md-surface-container-low);
}
input[type='range']::-moz-range-thumb {
  width: 6px; height: 40px; border: 0; border-radius: 3px; background: var(--md-primary);
  box-shadow: 0 0 0 4px var(--md-surface-container-low);
}
input[type='range']:focus-visible { outline: none; }
input[type='range']:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--md-surface-container-low), 0 0 0 7px var(--md-primary); }

.inline-select {
  border: 0; border-radius: var(--r-m);
  background: var(--md-surface-container-highest);
  padding: 0 14px; min-height: 48px; max-width: 100%; align-self: flex-start;
  font: var(--label-l); color: var(--md-on-surface);
}

.whatif-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.whatif-pick .inline-select { flex: 1 1 220px; min-width: 0; width: 100%; }
.delta { font: var(--title-m); font-weight: 500; }
.delta b { color: var(--md-primary); }
.goal-impact { font: var(--label-l); font-weight: 400; color: var(--md-on-surface-variant); margin-top: 6px; }
.goal-impact b { color: var(--md-on-surface); font-weight: 600; }

/* ---------- Workouts list ---------- */
.workouts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.workouts:empty { display: none; }
.workout {
  display: flex; align-items: center; gap: 4px;
  background: var(--md-surface-container-high);
  border-radius: var(--r-l);
  padding: 4px 4px 4px 0;
}
.workout-main {
  flex: 1; min-width: 0; text-align: left;
  border: 0; background: transparent; cursor: pointer;
  padding: 12px 8px 12px 18px; border-radius: var(--r-l);
  display: flex; flex-direction: column; gap: 2px;
}
.workout-main:hover { background: color-mix(in srgb, var(--md-on-surface) 6%, transparent); }
.workout-name { font: var(--title-m); font-weight: 500; overflow-wrap: anywhere; }
.workout-sub { font: var(--label-l); font-weight: 400; color: var(--md-on-surface-variant); }
.workout-sub b { color: var(--md-on-surface); font-weight: 600; }

/* ---------- Goal ---------- */
.goal-big { font: var(--headline-s); }
.goal-big b { font: 500 36px/44px var(--font); color: var(--md-primary); font-variant-numeric: tabular-nums; }
.goal-lines { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.notice {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--md-tertiary-container); color: var(--md-on-tertiary-container);
  border-radius: var(--r-m); padding: 14px 16px; margin-top: 12px;
  font: var(--label-l); font-weight: 400;
}
.notice .icon { font-size: 22px; }
.spark { width: 100%; height: auto; display: block; margin-top: 16px; overflow: visible; }
.spark-labels { display: flex; justify-content: space-between; gap: 12px; font: var(--label-l); font-weight: 400; color: var(--md-on-surface-variant); margin-top: 6px; }
.spark-labels span:last-child { text-align: right; }

/* ---------- Data card ---------- */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row .btn { align-self: auto; }

/* ---------- Snackbar ---------- */
.snackbar {
  position: fixed; z-index: 100; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  background: var(--md-inverse-surface); color: var(--md-inverse-on-surface);
  border-radius: var(--r-m); padding: 6px 8px 6px 20px; min-height: 56px;
  font: var(--label-l); font-weight: 400;
  transform: translateY(150%); opacity: 0;
  transition: transform 300ms var(--ease), opacity 200ms var(--ease);
}
.snackbar.show { transform: none; opacity: 1; }
.snackbar span { flex: 1; padding: 10px 0; }
.snackbar button {
  border: 0; background: transparent; cursor: pointer; flex: none;
  color: var(--md-inverse-primary, var(--md-primary-container)); font: var(--label-l);
  min-height: 44px; padding: 0 14px; border-radius: var(--r-full);
}

/* ---------- About ---------- */
.about { display: flex; flex-direction: column; gap: 10px; padding: 8px 4px; font: var(--label-l); font-weight: 400; color: var(--md-on-surface-variant); }

/* ---------- Sheet (dialog) ---------- */
.sheet {
  border: 0; padding: 0; margin: 0;
  color: var(--md-on-surface);
  background: var(--md-surface-container-low);
  position: fixed; inset: auto 0 0 0;
  width: 100%; max-width: 640px; margin-inline: auto;
  max-height: min(88vh, 88dvh); height: min(88vh, 88dvh);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  display: none; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet[open] { display: flex; animation: sheet-up 350ms var(--ease); }
.sheet::backdrop { background: var(--md-scrim); animation: fade 250ms var(--ease); }
@keyframes sheet-up { from { transform: translateY(40%); opacity: 0; } }
@keyframes sheet-side { from { transform: translateX(40%); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.sheet-handle { width: 32px; height: 4px; border-radius: 2px; background: var(--md-on-surface-variant); opacity: 0.4; margin: 12px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; gap: 4px; padding: 4px 8px 4px 20px; flex: none; }
.sheet-head .icon-btn:first-child { margin-left: -12px; }
.sheet-title { font: var(--headline-s); flex: 1; }
.sheet-step { display: flex; flex-direction: column; gap: 16px; padding: 4px 20px 20px; overflow-y: auto; flex: 1; min-height: 0; }
#step-pick { padding-bottom: 0; }

@media (min-width: 840px) {
  .sheet {
    inset: 0 0 0 auto; margin: 0;
    width: 440px; max-width: 100vw; height: 100vh; max-height: 100vh;
    border-radius: var(--r-xl) 0 0 var(--r-xl);
  }
  .sheet[open] { animation-name: sheet-side; }
  .sheet-handle { display: none; }
  .sheet-head { padding-top: 16px; }
}

.search {
  display: flex; align-items: center; gap: 12px;
  background: var(--md-surface-container-highest);
  border-radius: var(--r-full); padding: 0 20px; min-height: 56px; flex: none;
}
.search:focus-within { background: var(--md-secondary-container); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: var(--body-l); padding: 14px 0; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.speed-seg { flex: none; }

.results { display: flex; flex-direction: column; gap: 4px; padding-bottom: 20px; }
.results h3 { font: var(--label-l); color: var(--md-primary); padding: 16px 4px 6px; }
.results h3:first-child { padding-top: 0; }
.result-item {
  border: 0; cursor: pointer; text-align: left;
  background: transparent; border-radius: var(--r-m);
  padding: 12px; display: flex; align-items: center; gap: 12px;
}
.result-item:hover, .result-item:focus-visible { background: var(--md-surface-container-high); }
.result-item .name { flex: 1; min-width: 0; font: var(--body-l); }
.result-item .met { font: var(--label-l); font-weight: 400; color: var(--md-on-surface-variant); flex: none; }
.results .empty { color: var(--md-on-surface-variant); padding: 12px 4px; }

.detail-name { font: var(--title-l); }
.detail-meta { font: var(--label-l); font-weight: 400; color: var(--md-on-surface-variant); margin-top: -10px; }
.detail-note { font: var(--label-l); font-weight: 400; background: var(--md-tertiary-container); color: var(--md-on-tertiary-container); padding: 12px 16px; border-radius: var(--r-m); }
.stepper-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input {
  width: 72px; text-align: center; border: 0; outline: 0;
  background: var(--md-surface-container-highest); border-radius: var(--r-m);
  min-height: 48px; font: 500 20px/28px var(--font); font-variant-numeric: tabular-nums;
}
.stepper input:focus { background: var(--md-secondary-container); }
.detail-preview { font: var(--title-m); font-weight: 500; }
.detail-preview b { color: var(--md-primary); }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: auto; padding-top: 8px; }
.sheet-actions .btn { align-self: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
