/* Mobile first, dark theme. Touch targets ≥ 44px. Inputs ≥ 16px so iOS doesn't zoom. */
:root {
  --bg: #111418;
  --surface: #1b2027;
  --surface-2: #252b34;
  --border: #323a45;
  --text: #e8ecf1;
  --muted: #9aa4b2;
  --accent: #4fb3ff;
  --accent-text: #06213a;
  --ok: #3ecf8e;
  --warn: #f5b041;
  --danger: #ff6b6b;
  --radius: 12px;
  --tap: 44px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 640px; margin: 0 auto; }

button, input, textarea { font: inherit; color: inherit; }
button {
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
  touch-action: manipulation;  /* no double-tap zoom on − / + */
}
button:active { filter: brightness(1.25); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.text-btn { background: none; border: none; color: var(--accent); padding: 0 8px; }
input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  font-size: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
a { color: var(--accent); }

/* ---------- header ---------- */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  background: rgba(17, 20, 24, 0.94);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.bar h1 { flex: 1; margin: 0; font-size: 1.15rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .icon { width: var(--tap); padding: 0; font-size: 2rem; line-height: 1; background: none; border: none; color: var(--accent); }
.icon-space { width: 8px; }

/* sync dot */
.sync {
  position: relative;
  width: var(--tap); padding: 0;
  background: none; border: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.s-ok .dot { background: var(--ok); }
.s-syncing .dot, .s-idle .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.s-offline .dot, .s-unconfigured .dot { background: transparent; border: 2px solid var(--muted); }
.s-signed-out .dot, .s-error .dot { background: var(--warn); }
.sync .count {
  position: absolute; top: 4px; right: 0;
  min-width: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--surface-2); color: var(--text);
  font-size: 11px; line-height: 18px; text-align: center;
}
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .dot { animation: none !important; } }

/* ---------- layout ---------- */
main { padding: 12px 12px 32px; }
.empty { color: var(--muted); text-align: center; padding: 24px 16px; }
.meta { color: var(--muted); font-size: 0.9rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: 8px 14px;
  cursor: pointer;
}
.row.editing { flex-wrap: wrap; cursor: default; padding: 10px; }
.row .title { flex: 1; font-weight: 550; overflow-wrap: anywhere; }
.row .meta.all-done { color: var(--ok); }
.add-row { display: flex; gap: 8px; margin: 12px 0; }
.add-row input { flex: 1; }
.footer-link { text-align: center; margin-top: 24px; }
.footer-link a { display: inline-block; padding: 12px; }

.name-edit { flex: 1 1 180px; }
.edit-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.edit-controls button { min-width: var(--tap); padding: 0 12px; }

/* ---------- day (gym view) ---------- */
.day-tools {
  position: sticky; top: calc(env(safe-area-inset-top) + 57px); z-index: 5;
  margin: -12px -12px 12px; padding: 8px 12px 10px;
  background: var(--bg);
}
.progress-row { display: flex; align-items: center; justify-content: space-between; min-height: var(--tap); }
.progress-text { font-weight: 600; }
.progress-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--ok); transition: width 0.2s; }

.exercises { display: flex; flex-direction: column; gap: 10px; }
.exercise { padding: 10px 12px 12px; }
.exercise.done { border-color: color-mix(in srgb, var(--ok) 55%, var(--border)); }
.exercise.done h2 { color: var(--muted); text-decoration: line-through; }
.ex-head { display: flex; align-items: center; gap: 8px; min-height: var(--tap); }
.ex-head h2 { flex: 1; margin: 0; font-size: 1.05rem; font-weight: 600; overflow-wrap: anywhere; }
.ex-head .name-edit { flex: 1; min-width: 0; }

.tick-wrap { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); margin-left: -6px; cursor: pointer; flex: none; }
.tick {
  appearance: none; -webkit-appearance: none;
  width: 28px; height: 28px; margin: 0;
  border: 2px solid var(--muted); border-radius: 8px;
  display: grid; place-content: center; cursor: pointer;
}
.tick::after { content: ""; width: 14px; height: 8px; border: solid var(--accent-text); border-width: 0 0 3px 3px; transform: rotate(-45deg) translate(1px, -1px); opacity: 0; }
.tick:checked { background: var(--ok); border-color: var(--ok); }
.tick:checked::after { opacity: 1; }

.notes-btn { flex: none; padding: 0 12px; font-size: 0.9rem; background: none; color: var(--muted); }
.notes-btn.has-notes { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 60%, var(--border)); }

.ex-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.stepper .label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
.stepper .controls { display: flex; align-items: stretch; }
.stepper .step { width: var(--tap); flex: none; padding: 0; font-size: 1.4rem; line-height: 1; }
.stepper .step:first-child { border-radius: 10px 0 0 10px; }
.stepper .step:last-child { border-radius: 0 10px 10px 0; }
.stepper input {
  flex: 1; min-width: 0; padding: 4px 2px;
  text-align: center; font-size: 1.15rem; font-weight: 600;
  border-radius: 0; border-left: none; border-right: none;
}

.notes-wrap { margin-top: 10px; }
.notes { resize: vertical; min-height: 80px; }
.exercise .edit-controls { margin-top: 10px; }

/* ---------- settings ---------- */
.settings { display: flex; flex-direction: column; gap: 12px; }
.settings section { padding: 14px; }
.settings h2 { margin: 0; font-size: 1rem; }
.settings p { margin: 0; }
.sync-line { display: flex; align-items: center; gap: 10px; }
.inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
input.small { width: 96px; text-align: center; }
.msg { color: var(--warn); margin: 0; }
.msg:empty { display: none; }
.msg.note { padding: 12px 14px; border: 1px solid color-mix(in srgb, var(--warn) 50%, var(--border)); border-radius: var(--radius); background: var(--surface); }
.msg[hidden] { display: none; }

/* ---------- update banner ---------- */
.update-banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 12px); z-index: 20;
  max-width: 616px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px 10px 16px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

/* Very narrow phones: stack weight and reps. */
@media (max-width: 340px) {
  .ex-fields { grid-template-columns: 1fr; }
}

/* ---------- category picker (program edit mode) ---------- */
.cat-pick { display: flex; align-items: center; gap: 8px; flex: 1 1 100%; color: var(--muted); font-size: 0.9rem; }
.cat-select {
  flex: 1; min-height: var(--tap); padding: 0 10px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
.title.muted { color: var(--muted); font-style: italic; }
