:root {
  color-scheme: dark;
  --bg: #10151f;
  --panel: #182231;
  --panel-2: #202b3a;
  --line: #334155;
  --text: #f4f7fb;
  --muted: #a7b2c3;
  --accent: #50c878;
  --accent-2: #4fb3ff;
  --danger: #ff6b6b;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 2px 14px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(2rem, 10vw, 3.1rem);
  line-height: 0.98;
}

h2 {
  font-size: 1.05rem;
}

.session-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.session-panel,
.exercise-card,
.summary-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.session-panel {
  display: grid;
  gap: 12px;
  padding: 12px;
}

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

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 750;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d131d;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  padding: 10px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(79, 179, 255, 0.18);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.tab,
.stats-link,
.primary-action,
.secondary-action,
.danger-button,
.small-button,
.set-button {
  min-height: 44px;
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 850;
}

.stats-link {
  display: grid;
  place-items: center;
  text-decoration: none;
}

.tab.is-active,
.primary-action {
  background: var(--accent);
  color: #07110b;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.exercise-list {
  display: grid;
  gap: 12px;
}

.exercise-card {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.exercise-head,
.summary-head,
.action-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
}

.action-row > button {
  flex: 1;
}

.exercise-head label {
  flex: 1;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 1.3rem;
  font-weight: 900;
}

.remove-exercise,
.remove-set {
  color: var(--danger);
}

.target-line {
  min-height: 26px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(80, 200, 120, 0.12);
  color: #c9f7d8;
  font-size: 0.86rem;
  line-height: 1.35;
}

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

.set-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 0.78fr 0.95fr 42px;
  align-items: end;
  gap: 7px;
}

.set-index {
  display: grid;
  place-items: center;
  height: 42px;
  color: var(--muted);
  font-weight: 900;
}

.set-button,
.secondary-action {
  width: 100%;
  color: var(--accent-2);
}

.secondary-action {
  margin-top: 12px;
}

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

.summary-box {
  padding: 12px;
}

.summary-head {
  align-items: center;
  margin-bottom: 10px;
}

.small-button {
  min-height: 38px;
  padding: 0 12px;
  color: var(--accent-2);
}

#summaryText {
  min-height: 420px;
  line-height: 1.45;
}

.action-row {
  margin-top: 12px;
  justify-content: stretch;
}

.danger-button {
  padding: 0 14px;
  color: var(--danger);
}

.primary-action {
  padding: 0 18px;
}

.action-row .primary-action {
  width: 100%;
}

.rest-timer {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 25;
  display: grid;
  justify-items: end;
  gap: 10px;
}

.timer-fab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 92px;
  height: 54px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #07110b;
  box-shadow: var(--shadow);
  font-weight: 900;
}

.timer-fab span:first-child {
  font-size: 1.2rem;
}

.timer-fab-text {
  min-width: 48px;
  text-align: center;
}

.rest-timer.is-running .timer-fab {
  background: var(--accent-2);
  color: #07111c;
}

.timer-panel {
  width: min(calc(100vw - 28px), 330px);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121b28;
  box-shadow: var(--shadow);
}

.timer-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.timer-display {
  display: block;
  margin-top: 2px;
  font-size: 2.25rem;
  font-weight: 950;
  line-height: 1;
}

.timer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 0.78fr;
  gap: 8px;
  margin-top: 12px;
}

.timer-preset,
.timer-stop {
  min-height: 44px;
  border-radius: 8px;
  background: var(--panel-2);
  font-weight: 900;
}

.timer-preset {
  color: var(--accent-2);
}

.timer-stop {
  color: var(--danger);
}

.timer-stop:disabled {
  color: var(--muted);
  opacity: 0.55;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 86px;
  z-index: 30;
  width: min(calc(100% - 28px), 520px);
  padding: 12px 14px;
  border: 1px solid rgba(80, 200, 120, 0.45);
  border-radius: 8px;
  background: #12251a;
  color: #dfffea;
  font-size: 0.92rem;
  font-weight: 750;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 560px) {
  .app-shell {
    padding-inline: 10px;
  }

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

  .session-grid label:first-child {
    grid-column: 1 / -1;
  }

  .set-row {
    grid-template-columns: 24px repeat(4, minmax(0, 1fr)) 38px;
    gap: 5px;
  }

  .set-row label {
    font-size: 0.62rem;
  }

  .set-row input,
  .set-row select,
  .set-row .icon-button {
    height: 38px;
    padding-inline: 6px;
  }

  .set-row .icon-button {
    width: 38px;
    flex-basis: 38px;
  }

  .timer-fab {
    min-width: 86px;
    height: 52px;
    padding-inline: 14px;
  }

  .timer-panel {
    width: min(calc(100vw - 20px), 320px);
  }

}

.stats-shell {
  width: min(100%, 980px);
}

.stats-topbar {
  align-items: start;
}

.stats-nav {
  display: flex;
  gap: 8px;
}

.stats-grid,
.metric-grid,
.chart-grid {
  display: grid;
  gap: 12px;
}

.metric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 14px 0;
}

.metric-card,
.chart-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 12px;
}

.metric-label,
.chart-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.metric-value {
  margin: 8px 0 0;
  font-size: 1.6rem;
  font-weight: 900;
}

.chart-grid {
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.85fr);
}

.chart-panel,
.table-panel {
  padding: 12px;
}

.chart-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.chart-title {
  margin: 3px 0 0;
  font-size: 1.05rem;
}

.chart {
  width: 100%;
  min-height: 240px;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart text {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.chart .axis {
  stroke: var(--line);
  stroke-width: 1;
}

.chart .bar {
  fill: var(--accent);
}

.chart .line {
  fill: none;
  stroke: var(--accent-2);
  stroke-width: 3;
}

.chart .dot {
  fill: var(--accent-2);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.stats-table th,
.stats-table td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.stats-table th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.empty-state {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 760px) {
  .metric-grid,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .stats-topbar {
    display: grid;
  }
}
