:root {
  --bg: #282a36;
  --card: #343746;
  --card-2: #44475a;
  --text: #f8f8f2;
  --muted: #8a93bd;
  --purple: #bd93f9;
  --pink: #ff79c6;
  --cyan: #8be9fd;
  --green: #50fa7b;
  --red: #ff5555;
  --orange: #ffb86c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 16px);
  min-height: 100dvh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

h1 { font-size: 1.2rem; margin: 0; }
h2 { font-size: 1rem; color: var(--muted); margin: 20px 0 8px; text-transform: uppercase; letter-spacing: .05em; }

.view { display: flex; flex-direction: column; gap: 12px; }

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 44px;
}
.topbar > :last-child { justify-self: end; }
.topbar > :first-child { justify-self: start; }

.back, .icon-btn {
  background: none;
  border: none;
  color: var(--cyan);
  font: inherit;
  font-size: 1rem;
  padding: 8px 4px;
  text-decoration: none;
  cursor: pointer;
}
.icon-btn { font-size: 1.4rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--card-2);
  border-radius: 12px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  min-height: 48px;
  user-select: none;
}
.btn:active { background: var(--card-2); }
.btn.primary { background: var(--purple); border-color: var(--purple); color: #1e1f29; }
.btn.primary:active { background: var(--pink); }
.btn.danger { color: var(--red); }
.btn.wide { width: 100%; }
.btn.huge { font-size: 1.4rem; min-height: 72px; margin-top: auto; }

.row { display: flex; gap: 10px; }
.row.center { justify-content: center; }

.list { display: flex; flex-direction: column; gap: 10px; }

.plan {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.plan-info { flex: 1; min-width: 0; }
.plan-name { font-weight: 700; }
.plan-meta { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan .btn { flex: 0 0 auto; min-height: 42px; padding: 8px 14px; }

.banner {
  background: var(--card-2);
  border-left: 4px solid var(--green);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.banner > div { flex: 1; }
.banner .btn { flex: 0 0 auto; }

textarea {
  width: 100%;
  min-height: 260px;
  background: #1e1f29;
  color: var(--text);
  border: 1px solid var(--card-2);
  border-radius: 12px;
  padding: 12px;
  font: 0.95rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

.preview { font-size: .9rem; display: flex; flex-direction: column; gap: 4px; }
.preview .ok { color: var(--green); }
.preview .err { color: var(--red); }

.help summary { color: var(--cyan); cursor: pointer; }
.help pre {
  background: #1e1f29;
  padding: 12px;
  border-radius: 12px;
  overflow-x: auto;
  font-size: .8rem;
  line-height: 1.5;
}

/* Workout */
.workout { min-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }

.progress { height: 6px; background: var(--card); border-radius: 3px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--green); transition: width .3s; }

.set-head { text-align: center; padding: 12px 0 4px; }
.set-label { font-size: 1.1rem; font-weight: 800; color: var(--pink); letter-spacing: .08em; }
.set-target { font-size: 3rem; font-weight: 800; line-height: 1.1; margin-top: 4px; }
.set-exercise { font-size: 1.5rem; font-weight: 600; margin: 4px 0; }

.picker { background: var(--card); border-radius: 16px; padding: 10px 12px 12px; }
.picker-label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; text-align: center; margin-bottom: 6px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper input {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 2.4rem;
  font-weight: 800;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 4px 0;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: 2px solid var(--purple); border-radius: 8px; }
.step {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--card-2);
  color: var(--text);
  font-size: 2rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.step:active { background: var(--purple); color: #1e1f29; }

/* Rest */
.ring-wrap { position: relative; width: min(78vw, 320px); aspect-ratio: 1; margin: 16px auto; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--card); stroke-width: 12; }
.ring-fg {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 552.92;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset .25s linear, stroke .3s;
}
.ring-fg.warn { stroke: var(--orange); }
.rest-time {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4.2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.next-up { text-align: center; background: var(--card); border-radius: 12px; padding: 12px; }
.next-label { font-size: 1.15rem; font-weight: 600; margin-top: 2px; }

/* Summary / History */
.session { background: var(--card); border-radius: 12px; padding: 14px; }
.session-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.session-title { font-weight: 700; }
.ex-line { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-top: 1px solid var(--card-2); font-size: .92rem; }
.ex-line .sets { color: var(--muted); text-align: right; }
.ex-line .miss { color: var(--orange); }
.session .del { background: none; border: none; color: var(--red); font: inherit; font-size: .85rem; cursor: pointer; padding: 6px 0 0; }

.setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
}
.setting input[type=number] {
  width: 90px;
  background: #1e1f29;
  color: var(--text);
  border: 1px solid var(--card-2);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  text-align: center;
}
.setting input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--purple); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  background: var(--card-2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  z-index: 10;
}

/* Today / plan tags */
.plan.today { border: 2px solid var(--green); }
.today-label { color: var(--green); font-size: .75rem; font-weight: 800; letter-spacing: .1em; }
.plan-days { color: var(--cyan); font-size: .8rem; }
.tag { font-size: .7rem; font-weight: 600; color: var(--orange); border: 1px solid var(--orange); border-radius: 6px; padding: 1px 5px; vertical-align: middle; }
