:root {
  color-scheme: dark;
  --bg: #0c0e0b;
  --panel: #151811;
  --panel-2: #1b1f17;
  --line: rgba(239, 244, 225, 0.12);
  --line-strong: rgba(239, 244, 225, 0.22);
  --ink: #f1f4e8;
  --muted: #929988;
  --acid: #c8f85b;
  --heart: #ff6f78;
  --danger: #ff7b6b;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(200, 248, 91, 0.07), transparent 28rem),
    var(--bg);
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--acid);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.shell {
  width: min(1080px, calc(100% - 28px));
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  min-height: 52px;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 9px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
}

.brand-mark svg {
  width: 22px;
  fill: none;
  stroke: var(--acid);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 14px; letter-spacing: 0.18em; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 9px; }

.connect-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.connect-button {
  display: inline-flex;
  min-height: 38px;
  gap: 7px;
  align-items: center;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
  font-size: 12px;
}

.connect-button:disabled { cursor: wait; opacity: 0.55; }
.connect-button.is-connected { border-color: rgba(200, 248, 91, 0.48); }
.heart-connect.is-connected { border-color: rgba(255, 111, 120, 0.55); }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6e7467;
}

.is-connected .status-dot { background: var(--acid); box-shadow: 0 0 12px rgba(200, 248, 91, 0.55); }
.heart-icon { color: #777d71; font-size: 14px; line-height: 1; }
.heart-connect.is-connected .heart-icon { color: var(--heart); text-shadow: 0 0 12px rgba(255, 111, 120, 0.5); }

.notice {
  margin-top: 10px;
  padding: 10px 13px;
  border: 1px solid rgba(255, 123, 107, 0.3);
  border-radius: 10px;
  color: #d7b8b3;
  background: rgba(101, 31, 25, 0.16);
  font-size: 12px;
  line-height: 1.5;
}

.notice strong { color: var(--ink); }

.device-strip {
  display: flex;
  min-height: 46px;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin: 8px 0;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(21, 24, 17, 0.76);
}

.device-status { display: flex; gap: 9px; align-items: center; }

.pill {
  display: inline-flex;
  min-height: 23px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  color: #15170f;
  background: var(--acid);
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.pill.offline { color: #bdc2b5; background: #30352c; }

.protocol-label {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  white-space: nowrap;
}

.device-strip p {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(21, 24, 17, 0.9);
}

.metric-live {
  position: relative;
  min-height: 220px;
  padding: 18px;
  overflow: hidden;
}

.metric-heart {
  background:
    linear-gradient(140deg, rgba(255, 111, 120, 0.11), transparent 60%),
    var(--panel);
}

.metric-rpm {
  background:
    linear-gradient(140deg, rgba(200, 248, 91, 0.1), transparent 60%),
    var(--panel);
}

.metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #c9cebf;
  font-size: 12px;
}

.metric-head span:last-child {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
}

.live-value {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 9px;
  align-items: flex-end;
  margin-top: 28px;
}

.live-value strong {
  font-size: clamp(72px, 11vw, 126px);
  font-weight: 520;
  letter-spacing: -0.065em;
  line-height: 0.72;
  font-variant-numeric: tabular-nums;
}

.live-value small, .compact small {
  padding-bottom: 3px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
}

.metric-heart.has-heart .live-value strong { color: #fff1f1; }
.metric-heart.has-heart { border-color: rgba(255, 111, 120, 0.3); }

.heart-zone {
  display: flex;
  justify-content: space-between;
  margin-top: 27px;
  color: #d6dacf;
  font-size: 11px;
}

.heart-zone-track {
  height: 4px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #33372f;
}

.heart-zone-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--heart);
  transition: width 260ms ease, background 260ms ease;
}

.heart-stats {
  display: flex;
  gap: 18px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 10px;
}

.heart-stats strong { color: var(--ink); font-size: 11px; font-variant-numeric: tabular-nums; }

.metric-wave {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 34%;
}

.wave-line { fill: none; stroke: var(--acid); stroke-width: 1.7; vector-effect: non-scaling-stroke; }
.wave-fill { fill: rgba(200, 248, 91, 0.05); }

.compact-metrics {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.compact {
  min-height: 86px;
  padding: 13px;
}

.compact > span { display: block; color: var(--muted); font-size: 10px; }
.compact > strong, .compact div { display: flex; gap: 5px; align-items: flex-end; margin-top: 13px; }
.compact strong { font-size: clamp(25px, 4.7vw, 42px); font-weight: 520; letter-spacing: -0.045em; line-height: 0.9; font-variant-numeric: tabular-nums; }

.training-controls {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(260px, 0.75fr);
  gap: 8px;
  margin-top: 8px;
}

.resistance-control, .session-actions {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.resistance-control { padding: 14px 16px 12px; }

.resistance-title {
  display: flex;
  align-items: baseline;
  color: var(--muted);
  font-size: 11px;
}

.resistance-title strong { margin-left: auto; color: var(--acid); font-size: 28px; font-weight: 550; line-height: 0.9; }
.resistance-title small { margin-left: 4px; color: var(--muted); font-size: 10px; }

input[type="range"] {
  width: 100%;
  height: 22px;
  margin: 7px 0 1px;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--acid) 0 var(--range-progress, 0%), #3a3f33 var(--range-progress, 0%) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  margin-top: -10px;
  appearance: none;
  border: 5px solid var(--panel);
  border-radius: 50%;
  background: var(--acid);
  box-shadow: 0 0 0 1px var(--acid);
}

input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: #3a3f33; }
input[type="range"]::-moz-range-progress { height: 3px; background: var(--acid); }
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border: 5px solid var(--panel); border-radius: 50%; background: var(--acid); }
input[type="range"]:disabled { cursor: not-allowed; opacity: 0.38; }

.quick-levels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.quick-levels button {
  height: 27px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: #c7cbbc;
  background: rgba(255, 255, 255, 0.02);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  cursor: pointer;
}

.quick-levels button.active { border-color: var(--acid); color: var(--bg); background: var(--acid); }
.quick-levels button:disabled { cursor: not-allowed; opacity: 0.35; }

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

.session-button, .finish-button {
  min-height: 47px;
  border-radius: 11px;
  cursor: pointer;
}

.session-button {
  display: flex;
  gap: 9px;
  align-items: center;
  justify-content: center;
  border: 0;
  color: #11140c;
  background: var(--acid);
  font-weight: 760;
}

.finish-button { border: 1px solid var(--line-strong); background: rgba(255, 255, 255, 0.025); font-size: 12px; }
.session-button:disabled, .finish-button:disabled { cursor: not-allowed; filter: grayscale(0.65); opacity: 0.38; }

.play-icon {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 9px solid #11140c;
}

.session-button.is-paused .play-icon {
  width: 10px;
  height: 13px;
  border: 0;
  background: linear-gradient(90deg, #11140c 0 35%, transparent 35% 65%, #11140c 65%);
}

.secondary { margin-top: 8px; }

.panel {
  margin-top: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
}

.panel summary {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  list-style: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

.panel summary::-webkit-details-marker { display: none; }
.summary-action { color: var(--muted); font-size: 10px; font-weight: 400; }
.panel[open] .summary-action { color: var(--acid); }
.summary-tools { display: inline-flex; gap: 10px; align-items: center; }

.text-button {
  padding: 6px;
  border: 0;
  color: var(--acid);
  background: transparent;
  font-size: 11px;
  cursor: pointer;
}

.text-button.muted { color: var(--muted); }
.text-button.danger { color: var(--danger); }

.history-list { padding: 0 15px 12px; border-top: 1px solid var(--line); }

.history-item {
  display: grid;
  grid-template-columns: 1.1fr repeat(4, 0.8fr) auto;
  gap: 9px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.history-item:first-child { border-top: 0; }
.history-item strong, .history-item small { display: block; }
.history-item strong { font-size: 12px; font-variant-numeric: tabular-nums; }
.history-item small { margin-top: 3px; color: var(--muted); font-size: 8px; }
.history-item time { color: #ced2c4; font-size: 10px; }
.history-delete {
  min-width: 34px;
  height: 28px;
  padding: 0 7px;
  border: 1px solid rgba(255, 123, 107, 0.24);
  border-radius: 7px;
  color: #d99b94;
  background: rgba(255, 123, 107, 0.06);
  font-size: 9px;
  cursor: pointer;
}
.history-delete:hover { border-color: var(--danger); color: #fff; background: rgba(255, 123, 107, 0.14); }
.empty-state { padding: 16px 0 5px; color: var(--muted); font-size: 11px; }

.settings-body { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); }

.setting-row {
  display: flex;
  min-height: 68px;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 15px;
  border-right: 1px solid var(--line);
}

.setting-row:last-child { border-right: 0; }
.setting-row strong, .setting-row small { display: block; }
.setting-row strong { font-size: 12px; }
.setting-row small { margin-top: 3px; color: var(--muted); font-size: 9px; }

.input-unit { display: flex; align-items: center; border-bottom: 1px solid var(--line-strong); }
.input-unit input { width: 48px; padding: 5px 0; border: 0; color: var(--ink); background: transparent; font-size: 17px; text-align: right; }
.input-unit em { margin-left: 5px; color: var(--muted); font-size: 8px; font-style: normal; }

.toggle-row input {
  position: relative;
  width: 39px;
  height: 22px;
  flex: 0 0 auto;
  appearance: none;
  border-radius: 999px;
  background: #3a3e34;
  cursor: pointer;
}

.toggle-row input::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #b5baaa;
  content: "";
  transition: left 150ms ease;
}

.toggle-row input:checked { background: var(--acid); }
.toggle-row input:checked::after { left: 20px; background: #15170f; }

.debug-body { padding: 0 15px 15px; border-top: 1px solid var(--line); }
.debug-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.debug-toolbar p { margin: 0; color: var(--muted); font-size: 10px; }
.debug-toolbar > div { display: flex; gap: 8px; }

#debugLog {
  max-height: 300px;
  margin: 0;
  padding: 13px;
  overflow: auto;
  border-radius: 9px;
  color: #c8d3b3;
  background: #080a07;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
}

.toast {
  position: fixed;
  z-index: 10;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 14px;
  width: fit-content;
  max-width: min(440px, calc(100% - 28px));
  margin: auto;
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: rgba(28, 32, 24, 0.98);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: 180ms ease;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: rgba(255, 123, 107, 0.4); }

@media (max-width: 680px) {
  .shell { width: min(100% - 16px, 520px); padding-top: max(7px, env(safe-area-inset-top)); }
  .topbar { gap: 7px; }
  .brand-mark { width: 31px; height: 31px; }
  .brand small { display: none; }
  .connect-actions { gap: 5px; }
  .connect-button { min-height: 35px; padding: 0 9px; font-size: 10px; }
  .device-strip { min-height: 39px; margin: 5px 0; padding: 5px 8px; }
  .device-strip p { display: none; }
  .protocol-label { margin-left: auto; }
  .live-dashboard { gap: 5px; }
  .metric-live { min-height: 157px; padding: 12px; border-radius: 13px; }
  .live-value { margin-top: 24px; }
  .live-value strong { font-size: clamp(57px, 18vw, 82px); }
  .live-value small { font-size: 8px; }
  .heart-zone { margin-top: 21px; font-size: 9px; }
  .heart-stats { gap: 11px; margin-top: 7px; font-size: 8px; }
  .heart-stats strong { font-size: 9px; }
  .compact-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .compact { min-height: 69px; padding: 9px; border-radius: 11px; }
  .compact > strong, .compact div { margin-top: 10px; }
  .compact strong { font-size: clamp(20px, 6.8vw, 29px); }
  .compact small { font-size: 6px; }
  .training-controls { grid-template-columns: 1fr; gap: 5px; margin-top: 5px; }
  .resistance-control { padding: 9px 11px 8px; border-radius: 12px; }
  input[type="range"] { margin: 3px 0 0; }
  .quick-levels button { height: 24px; }
  .session-actions { grid-template-columns: 1.7fr 1fr; padding: 5px; border-radius: 12px; }
  .session-button, .finish-button { min-height: 42px; }
  .secondary { margin-top: 5px; }
  .panel { margin-top: 5px; }
  .panel summary { min-height: 43px; }
  .settings-body { grid-template-columns: 1fr; }
  .setting-row { min-height: 58px; border-right: 0; border-bottom: 1px solid var(--line); }
  .setting-row:last-child { border-bottom: 0; }
  .history-item { grid-template-columns: 1.05fr repeat(4, 0.8fr) auto; gap: 5px; }
  .history-delete { min-width: 28px; padding: 0 5px; }
}

@media (max-width: 370px) {
  .brand span:last-child { display: none; }
  .metric-live { min-height: 151px; }
  .connect-button { padding: 0 7px; }
  .history-item small { font-size: 7px; }
}
