:root {
  color-scheme: light;
  --background: #f7f2fa;
  --surface: #fffbfe;
  --surface-container: #f3edf7;
  --surface-container-high: #ece6f0;
  --surface-container-highest: #e6e0e9;
  --surface-variant: #e7e0ec;
  --primary: #65558f;
  --primary-on: #ffffff;
  --primary-container: #eaddff;
  --primary-container-on: #21005d;
  --secondary: #625b71;
  --secondary-container: #e8def8;
  --tertiary: #7d5260;
  --tertiary-container: #ffd8e4;
  --danger: #b3261e;
  --danger-container: #f9dedc;
  --stop: #ba1a1a;
  --stop-on: #ffffff;
  --ink: #1d1b20;
  --muted: #49454f;
  --outline: #79747e;
  --outline-variant: #cac4d0;
  --slider-active: #65558f;
  --slider-inactive: #e8def8;
  --slider-stop: #4a4458;
  --slider-gap: #f7f2fa;
  --nav-background: rgba(255, 251, 255, 0.88);
  --shadow: 0 16px 40px rgba(31, 27, 32, 0.12);
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #141218;
  --surface: #211f26;
  --surface-container: #2b2930;
  --surface-container-high: #36343b;
  --surface-container-highest: #45424b;
  --surface-variant: #49454f;
  --primary: #d0bcff;
  --primary-on: #381e72;
  --primary-container: #4f378b;
  --primary-container-on: #eaddff;
  --secondary: #ccc2dc;
  --secondary-container: #4a4458;
  --tertiary: #efb8c8;
  --tertiary-container: #633b48;
  --danger: #f2b8b5;
  --danger-container: #8c1d18;
  --stop: #cf2a27;
  --stop-on: #ffffff;
  --ink: #e6e0e9;
  --muted: #cac4d0;
  --outline: #938f99;
  --outline-variant: #49454f;
  --slider-active: #d0bcff;
  --slider-inactive: #4a4458;
  --slider-stop: #e6e0e9;
  --slider-gap: #141218;
  --nav-background: rgba(33, 31, 38, 0.9);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --background: #141218;
    --surface: #211f26;
    --surface-container: #2b2930;
    --surface-container-high: #36343b;
    --surface-container-highest: #45424b;
    --surface-variant: #49454f;
    --primary: #d0bcff;
    --primary-on: #381e72;
    --primary-container: #4f378b;
    --primary-container-on: #eaddff;
    --secondary: #ccc2dc;
    --secondary-container: #4a4458;
    --tertiary: #efb8c8;
    --tertiary-container: #633b48;
    --danger: #f2b8b5;
    --danger-container: #8c1d18;
    --stop: #cf2a27;
    --stop-on: #ffffff;
    --ink: #e6e0e9;
    --muted: #cac4d0;
    --outline: #938f99;
    --outline-variant: #49454f;
    --slider-active: #d0bcff;
    --slider-inactive: #4a4458;
    --slider-stop: #e6e0e9;
    --slider-gap: #141218;
    --nav-background: rgba(33, 31, 38, 0.9);
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

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

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--ink);
  overscroll-behavior: none;
}

button,
input,
select {
  font: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  width: min(1120px, 100%);
  min-height: calc(100vh - 82px);
  margin: 0 auto;
  padding: 18px 18px 82px;
}

.top-bar {
  display: grid;
  grid-template-columns: minmax(112px, 1fr) auto minmax(112px, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 64px;
}

.menu-button {
  justify-self: start;
}

.connect-pill {
  justify-self: end;
}

.menu-button,
.connect-pill {
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  background: var(--primary-container);
  color: var(--primary-container-on);
  font-weight: 780;
}

.menu-button {
  display: grid;
  place-content: center;
  gap: 5px;
  width: 48px;
  padding: 0;
}

.menu-button span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.menu-button.active {
  background: var(--primary);
  color: var(--primary-on);
}

.header-menu {
  position: absolute;
  top: 76px;
  left: 18px;
  z-index: 20;
  display: grid;
  gap: 4px;
  min-width: 184px;
  padding: 8px;
  border: 1px solid var(--outline-variant);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.header-menu button {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  padding: 0 12px;
  text-align: left;
  font-weight: 760;
}

.header-menu button:hover,
.header-menu button.active {
  background: var(--primary-container);
  color: var(--primary-container-on);
}

.connect-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 112px;
  padding: 0 18px;
}

.connect-pill.connecting {
  color: var(--primary-container-on);
}

.connect-pill.connected {
  background: var(--primary);
  color: var(--primary-on);
}

.connect-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.48;
}

.connect-pill.connected .connect-dot {
  opacity: 1;
}

.connect-pill.connecting .connect-dot {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.9);
  }

  50% {
    opacity: 1;
    transform: scale(1.12);
  }
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  min-width: 0;
  text-align: center;
  font-size: 2rem;
  line-height: 1.05;
}

h2 {
  font-size: 1.25rem;
}

.screen {
  display: none;
}

[hidden] {
  display: none !important;
}

.screen.active {
  display: block;
}

.workout-grid {
  display: grid;
  grid-template-columns: minmax(76px, 120px) minmax(0, 1fr) minmax(76px, 120px);
  gap: 18px;
  align-items: stretch;
  min-height: calc(100vh - 216px);
}

.center-console,
.panel {
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.center-console {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  min-height: 590px;
  padding: clamp(18px, 4vw, 38px);
}

.center-console.workout-running {
  justify-content: center;
}

.workout-config {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}

.active-workout {
  display: grid;
  place-items: center;
  min-height: 100%;
}

.active-workout-inner {
  display: grid;
  place-items: center;
  gap: 16px;
  width: 100%;
}

.big-stop-button {
  width: min(440px, 86%);
  aspect-ratio: 1 / 1;
  border: 0;
  border-radius: 999px;
  background: var(--stop);
  color: var(--stop-on);
  box-shadow: 0 22px 60px color-mix(in srgb, var(--stop) 36%, transparent);
  font-size: clamp(3rem, 9vw, 6rem);
  font-weight: 900;
  letter-spacing: 0;
}

.voice-stop-status,
.voice-stop-heard {
  max-width: min(360px, 90%);
  border-radius: 999px;
  padding: 8px 14px;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 760;
}

.voice-stop-status {
  background: var(--surface-container-high);
  color: var(--muted);
}

.voice-stop-status.listening,
.voice-stop-status.starting {
  background: var(--primary-container);
  color: var(--primary-container-on);
}

.voice-stop-status.heard {
  background: var(--primary);
  color: var(--primary-on);
}

.voice-stop-status.error,
.voice-stop-status.unavailable {
  background: var(--danger-container);
  color: var(--danger);
}

.voice-stop-heard {
  overflow: hidden;
  background: var(--surface-container);
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weight-dial {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  align-items: center;
  gap: 14px;
}

.weight-dial.adaptive {
  grid-template-columns: minmax(0, 1fr);
}

.weight-readout {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 156px;
  border-radius: 24px;
  background: var(--surface-container);
  border: 1px solid var(--outline-variant);
}

#weightValue {
  width: 5.1ch;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: center;
  font-size: 7.25rem;
  font-weight: 780;
  line-height: 1;
}

#weightValue:focus {
  outline: 3px solid color-mix(in srgb, var(--primary) 32%, transparent);
  outline-offset: 4px;
}

#weightValue::-webkit-outer-spin-button,
#weightValue::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

#weightValue[type="number"] {
  appearance: textfield;
}

#autoLoadValue {
  color: var(--ink);
  font-size: 7.25rem;
  font-weight: 780;
  line-height: 1;
}

#weightUnit {
  color: var(--muted);
  font-size: 1.8rem;
  font-weight: 750;
}

.mode-readout {
  text-align: center;
  min-height: 34px;
  color: var(--primary);
  font-size: 1.3rem;
  font-weight: 760;
}

.mode-picker {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 16px;
  background: var(--surface-container-high);
  color: var(--muted);
  font-weight: 760;
}

.mode-picker select {
  min-height: 38px;
  border-radius: 12px;
  background: var(--surface);
  font-weight: 760;
}

.toggle-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 16px;
  background: var(--surface-container);
  color: var(--ink);
}

.toggle-row input {
  width: 24px;
  min-height: 24px;
  accent-color: var(--primary);
}

.workout-options {
  display: block;
  padding: 0 12px 12px;
  border-radius: 18px;
  background: var(--surface-container);
}

.workout-options summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 780;
  cursor: pointer;
  list-style: none;
}

.workout-options summary::-webkit-details-marker {
  display: none;
}

.workout-options summary::after {
  content: "+";
  color: var(--tertiary);
  font-size: 1.1rem;
  font-weight: 800;
}

.workout-options[open] summary::after {
  content: "-";
}

.workout-options .toggle-row {
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--outline-variant);
}

.control-grid,
.echo-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.control-grid.single {
  grid-template-columns: 1fr;
}

.echo-panel {
  margin-top: 12px;
}

.mini-stepper {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 32px;
  gap: 6px;
  min-width: 0;
}

.mini-stepper button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--secondary-container);
  color: var(--ink);
  font-weight: 900;
}

.mini-stepper input {
  min-width: 0;
  appearance: textfield;
  padding-left: 4px;
  padding-right: 4px;
  text-align: center;
  font-weight: 760;
}

.mini-stepper input::-webkit-outer-spin-button,
.mini-stepper input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

label,
.settings-row {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--outline);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
}

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

.rom-strip > div,
.info-grid > div {
  min-height: 70px;
  padding: 12px;
  border-radius: 18px;
  background: var(--surface-container);
}

.metric-label,
dt {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

dd {
  margin: 4px 0 0;
  font-size: 1.05rem;
  font-weight: 760;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.filled-button,
.tonal-button,
.danger-button,
.icon-button {
  min-height: 48px;
  border: 0;
  border-radius: 999px;
  padding: 0 18px;
  font-weight: 780;
}

.filled-button {
  background: var(--primary);
  color: var(--primary-on);
}

.tonal-button {
  background: var(--primary-container);
  color: var(--primary-container-on);
}

.danger-button {
  background: var(--danger-container);
  color: var(--danger);
}

.icon-button {
  width: 56px;
  padding: 0;
  background: var(--surface-variant);
  color: var(--ink);
  font-size: 1.8rem;
}

.load-meter {
  display: grid;
  grid-template-rows: 1fr auto auto;
  align-items: end;
  justify-items: center;
  gap: 10px;
  min-height: 590px;
  padding: 18px 10px;
}

.load-meter.editable {
  cursor: ns-resize;
  touch-action: none;
}

.load-meter:focus-visible {
  outline: none;
}

.load-meter:focus-visible .meter-track {
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--slider-active) 18%, transparent);
}

.load-meter.editable .meter-track {
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--slider-active) 10%, transparent);
}

.load-meter.editable .meter-fill {
  background: var(--slider-active);
}

.load-meter.editable .meter-fill.right {
  background: var(--slider-active);
}

.meter-track {
  position: relative;
  width: min(78px, 100%);
  height: 100%;
  min-height: 420px;
  overflow: visible;
  border-radius: 999px;
  background: var(--slider-inactive);
  border: 0;
  isolation: isolate;
}

.meter-track::before {
  content: "";
  position: absolute;
  top: 20px;
  left: 50%;
  z-index: 1;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--slider-stop);
  opacity: 0.86;
  transform: translateX(-50%);
}

.meter-fill {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0%;
  min-height: 0;
  background: var(--slider-active);
  border-radius: 0 0 999px 999px;
  z-index: 2;
  transition: height 160ms linear;
}

.meter-fill::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 3;
  width: calc(100% + 12px);
  height: 7px;
  border-radius: 999px;
  background: var(--slider-active);
  box-shadow: 0 0 0 5px var(--slider-gap);
  transform: translate(-50%, -50%);
}

.meter-fill.right {
  background: var(--slider-active);
}

.meter-value {
  min-height: 28px;
  font-size: 1.1rem;
  font-weight: 780;
}

.meter-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 760;
}

.panel {
  min-height: calc(100vh - 216px);
  padding: 24px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.muted {
  color: var(--muted);
}

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

.settings-panel {
  display: grid;
  align-content: start;
  gap: 16px;
}

.settings-row {
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 220px);
  align-items: center;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 4px;
  width: min(620px, calc(100% - 24px));
  min-height: 62px;
  padding: 6px;
  border: 1px solid var(--outline-variant);
  border-radius: 22px;
  background: var(--nav-background);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.bottom-nav button {
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: var(--muted);
  font-weight: 760;
}

.bottom-nav button.active {
  background: var(--primary-container);
  color: var(--primary-container-on);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%) translateY(16px);
  max-width: calc(100% - 32px);
  min-height: 44px;
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--surface);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: 8px 8px 64px;
  }

  .top-bar {
    grid-template-columns: minmax(100px, 1fr) auto minmax(100px, 1fr);
    gap: 6px;
    min-height: 44px;
  }

  h1 {
    font-size: 0.98rem;
  }

  .menu-button {
    width: 42px;
    min-height: 42px;
  }

  .connect-pill {
    min-width: 100px;
    min-height: 42px;
    padding: 0 12px;
    font-size: 0.86rem;
  }

  .header-menu {
    top: 58px;
    left: 8px;
  }

  .workout-grid {
    grid-template-columns: 56px minmax(0, 1fr) 56px;
    gap: 8px;
    height: calc(100dvh - 122px);
    min-height: 0;
  }

  .center-console {
    justify-content: space-between;
    gap: 7px;
    height: 100%;
    min-height: 0;
    padding: 9px;
    border-radius: 20px;
  }

  .workout-config {
    justify-content: space-between;
    gap: 7px;
    min-height: 100%;
  }

  .center-console.workout-running {
    justify-content: center;
  }

  .big-stop-button {
    width: min(210px, 86%);
    font-size: 3rem;
  }

  .active-workout-inner {
    gap: 10px;
  }

  .voice-stop-status,
  .voice-stop-heard {
    max-width: 94%;
    padding: 7px 11px;
    font-size: 0.72rem;
  }

  .load-meter {
    gap: 5px;
    height: 100%;
    min-height: 0;
    padding: 8px 0;
  }

  .meter-track {
    width: 44px;
    min-height: 0;
  }

  .meter-track::before {
    top: 15px;
    width: 5px;
    height: 5px;
  }

  .meter-fill::after {
    width: calc(100% + 9px);
    height: 5px;
    box-shadow: 0 0 0 4px var(--slider-gap);
  }

  .weight-dial {
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    gap: 4px;
  }

  .weight-dial.adaptive {
    grid-template-columns: minmax(0, 1fr);
  }

  .icon-button {
    width: 34px;
    min-height: 34px;
    font-size: 1.35rem;
  }

  .weight-readout {
    min-height: 78px;
    gap: 4px;
    border-radius: 20px;
  }

  #weightValue {
    width: 5.2ch;
    font-size: 2.55rem;
  }

  #weightUnit {
    font-size: 0.78rem;
  }

  .weight-dial.adaptive #weightValue {
    font-size: 2.85rem;
  }

  #autoLoadValue,
  .weight-dial.adaptive #autoLoadValue {
    font-size: 2.85rem;
  }

  .mode-readout {
    min-height: 24px;
    font-size: 1rem;
  }

  .mode-picker {
    grid-template-columns: 44px minmax(0, 1fr);
    min-height: 38px;
    padding: 0 8px;
    border-radius: 14px;
    font-size: 0.78rem;
  }

  .mode-picker select {
    min-height: 32px;
    padding: 0 8px;
    border-radius: 10px;
    font-size: 0.82rem;
  }

  .toggle-row {
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .workout-options {
    padding: 0 8px 8px;
    border-radius: 14px;
  }

  .workout-options summary {
    min-height: 34px;
    font-size: 0.78rem;
  }

  .workout-options .toggle-row {
    margin-bottom: 7px;
  }

  .control-grid,
  .echo-panel,
  .rom-strip,
  .action-row {
    gap: 7px;
  }

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

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

  .rom-strip > div {
    min-height: 50px;
    padding: 8px;
    border-radius: 14px;
  }

  input,
  select,
  .filled-button,
  .tonal-button,
  .danger-button {
    min-height: 38px;
    padding-left: 10px;
    padding-right: 10px;
    border-radius: 12px;
  }

  input,
  select {
    font-size: 1rem;
  }

  .filled-button,
  .tonal-button,
  .danger-button {
    font-size: 0.88rem;
  }

  .mini-stepper {
    grid-template-columns: 30px minmax(0, 1fr) 30px;
    gap: 4px;
  }

  .mini-stepper button {
    min-height: 38px;
    border-radius: 12px;
    font-size: 0.9rem;
  }

  .mini-stepper input {
    padding-left: 0;
    padding-right: 0;
    font-size: 0.9rem;
  }

  label,
  .settings-row,
  .meter-label {
    font-size: 0.76rem;
  }

  .metric-label,
  dt {
    font-size: 0.68rem;
  }

  .meter-value,
  dd {
    font-size: 0.86rem;
  }

  .panel {
    min-height: calc(100dvh - 116px);
    overflow: auto;
    padding: 16px;
  }

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

  .settings-row {
    grid-template-columns: 1fr;
  }

  .bottom-nav {
    bottom: 6px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: calc(100% - 16px);
    min-height: 50px;
    border-radius: 18px;
  }

  .bottom-nav button {
    border-radius: 13px;
    font-size: 0.76rem;
  }

  .toast {
    bottom: 64px;
  }
}

@media (max-width: 360px) {
  .top-bar {
    grid-template-columns: minmax(86px, 1fr) auto minmax(86px, 1fr);
    gap: 4px;
  }

  h1 {
    font-size: 0.86rem;
  }

  .menu-button {
    width: 38px;
    min-height: 38px;
  }

  .connect-pill {
    min-width: 86px;
    min-height: 38px;
    gap: 5px;
    padding: 0 8px;
    font-size: 0.74rem;
  }

  .connect-dot {
    width: 7px;
    height: 7px;
  }
}
