:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #475569;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --text: #f8fafc;
  --text-secondary: #94a3b8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  padding: 16px;
  /* Clear the device status bar / notch in the Android (Capacitor) shell.
     env(safe-area-inset-top) is 0 in a normal browser, so this is a no-op there. */
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-bottom: 80px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

/* Tab bar — matches the 480px content column; on phones (viewport ≤ 480px)
   width:100% takes effect first so the bar still goes edge-to-edge. */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

.tab-bar.hidden { display: none; }

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  transition: color 0.2s;
}

.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--primary); }

/* Typography */
h1 { font-size: 24px; font-weight: 700; margin-bottom: 16px; }
h2 { font-size: 18px; font-weight: 600; margin-bottom: 12px; }
h3 { font-size: 15px; font-weight: 600; margin-bottom: 8px; color: var(--text-secondary); }

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  width: 100%;
  color: #fff;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-danger { background: var(--danger); }
.btn-success { background: var(--success); }
.btn-surface { background: var(--surface-2); }
.btn-sm { padding: 8px 14px; font-size: 13px; width: auto; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover:not(:disabled) { background: var(--surface); }

/* Pill toggle (used for Inverted option) */
.pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  align-self: flex-start;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.pill-toggle .pill-dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}
.pill-toggle.active {
  background: rgba(99, 102, 241, 0.12);
  border-color: var(--primary);
  color: var(--text);
}
.pill-toggle.active .pill-dot {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: inset 0 0 0 3px var(--surface);
}
.pill-toggle:hover:not(:disabled) { border-color: var(--primary); }

/* Forms */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
}

.form-group input::placeholder { color: var(--text-secondary); }

/* The training-days picker rows put a label and a day-of-week select on
   one flex line. .form-group select otherwise stretches to width:100%,
   which steals horizontal space from labels like "Upper Body A" and
   forces a 3-line wrap. Cap the day-select so the label gets the room. */
.lift-order-row .lift-day-select {
  width: auto;
  min-width: 96px;
  flex: 0 0 auto;
}

/* Inline input (for logging sets) */
.input-inline {
  width: 70px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  text-align: center;
  outline: none;
}

.input-inline:focus { border-color: var(--primary); }

/* Hide the native spinner arrows on number inputs everywhere — they look
   noisy at our compact input sizes, and on touch the text input plus the
   numeric keypad is enough. Standard cross-browser pattern. */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Error & info */
.error-msg {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
}

.info-msg {
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
  padding: 32px 16px;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-primary { background: rgba(59, 130, 246, 0.2); color: var(--primary); }
.badge-success { background: rgba(34, 197, 94, 0.2); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.2); color: var(--warning); }

/* Sets table */
.sets-table { width: 100%; border-collapse: collapse; }

.sets-table th {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  text-align: left;
  padding: 8px 4px;
  border-bottom: 1px solid var(--surface-2);
}

.sets-table td {
  padding: 10px 4px;
  font-size: 14px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  vertical-align: middle;
}

.sets-table .amrap { color: var(--warning); font-weight: 600; }

/* Workout card */
.workout-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
  color: var(--text);
}

.workout-card:hover { background: var(--surface-2); }

.workout-card-locked {
  opacity: 0.5;
  cursor: not-allowed;
}
.workout-card-locked:hover { background: var(--surface); }

.workout-card .lift-name { font-weight: 600; font-size: 15px; }
.workout-card .week-label { font-size: 13px; color: var(--text-secondary); }

/* Lift card */
.lift-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.lift-card .lift-info { flex: 1; }
.lift-card .lift-name { font-weight: 600; font-size: 15px; }
.lift-card .lift-tm { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.lift-card .lift-actions { display: flex; gap: 8px; }

/* Auth page */
.auth-page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 80vh;
}

.auth-logo {
  display: block;
  margin: 0 auto 12px;
  width: 96px;
  height: 96px;
}

.auth-page h1 {
  text-align: center;
  font-size: 32px;
  margin-bottom: 8px;
}

.auth-page .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 15px;
}

.auth-page .switch-link {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

.auth-page .switch-link a {
  color: var(--primary);
  text-decoration: none;
}

/* Setup wizard progress dots */
.setup-progress {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 32px;
}

.progress-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-2);
  transition: background 0.3s;
}

.progress-dot.done { background: var(--success); }
.progress-dot.active { background: var(--primary); }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Modal overlay — scroll lives on the overlay itself so the scrollbar
   sits at the viewport's right edge (visually identical to the browser
   scrollbar) instead of as a mid-window strip inside the modal. The
   overlay is centred horizontally and starts from the top with padding,
   so a short modal still appears near the top of the viewport with a
   little breathing room and a tall modal scrolls with the page. */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 0;
  overflow-y: auto;
  z-index: 200;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 16px;
  width: 100%;
  max-width: 480px;
}

.modal h2 { margin-bottom: 16px; }

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions .btn { flex: 1; }

/* Start-block wizard */
.wizard-progress {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.wizard-progress .wizard-dot {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.wizard-progress .wizard-dot.active { background: var(--primary); }
.wizard-step-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}
.wizard-step { display: none; }
.wizard-step.active { display: block; }

/* Section spacing */
.section { margin-bottom: 24px; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

/* Divider */
.divider {
  height: 1px;
  background: var(--surface-2);
  margin: 16px 0;
}

/* Flex utils */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-secondary { color: var(--text-secondary); }
.text-sm { font-size: 13px; }

/* Settings tabs */
.settings-tabs {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 16px;
  gap: 3px;
}

.settings-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}

.settings-tab.active {
  background: var(--primary);
  color: #fff;
}

/* Help icon */
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  margin-left: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}

.help-icon:hover { background: var(--primary); color: #fff; }

/* Help page content */
.help-content p { margin-bottom: 12px; line-height: 1.6; font-size: 15px; }
.help-content h3 { margin-top: 20px; margin-bottom: 8px; }
.help-content ul { margin-bottom: 12px; padding-left: 20px; }
.help-content li { margin-bottom: 6px; line-height: 1.5; font-size: 15px; }
.help-content a { color: var(--primary); }
.help-content table { margin-bottom: 16px; }

/* Rest timer overlay */
.rest-timer-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 300;
  pointer-events: auto;
}
.rest-timer-next {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 14px 22px;
  max-width: 320px;
}
.rest-timer-next-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.rest-timer-next-detail {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.rest-timer-ring {
  position: relative;
  width: 240px;
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 24px rgba(0, 0, 0, 0.4));
}
.rest-timer-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.rest-timer-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1.5;
}
.rest-timer-progress {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
}
.rest-timer-ring.red    .rest-timer-progress { stroke: #ef4444; }
.rest-timer-ring.orange .rest-timer-progress { stroke: #f97316; }
.rest-timer-ring.yellow .rest-timer-progress { stroke: #eab308; }
.rest-timer-ring.green  .rest-timer-progress { stroke: #22c55e; }
.rest-timer-ring.red    .rest-timer-text { color: #ef4444; }
.rest-timer-ring.orange .rest-timer-text { color: #f97316; }
.rest-timer-ring.yellow .rest-timer-text { color: #eab308; }
.rest-timer-ring.green  .rest-timer-text { color: #22c55e; }
.rest-timer-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.rest-timer-stage {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  min-height: 16px;
  color: inherit;
  opacity: 0.85;
}
.rest-timer-text {
  position: relative;
  font-size: 56px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
  transition: color 0.3s;
  line-height: 1;
}
.rest-timer-dismiss {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Minimized state — small ring at bottom-right, lets the page beneath stay interactive */
.rest-timer-overlay.minimized {
  inset: auto;
  bottom: 16px;
  right: 16px;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
  padding: 0;
  gap: 0;
}
.rest-timer-overlay.minimized .rest-timer-ring {
  width: 76px;
  height: 76px;
  pointer-events: auto;
  cursor: pointer;
  background: var(--surface);
  border-radius: 50%;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.35));
}
.rest-timer-overlay.minimized .rest-timer-text { font-size: 18px; }
.rest-timer-overlay.minimized .rest-timer-stage,
.rest-timer-overlay.minimized .rest-timer-next,
.rest-timer-overlay.minimized .rest-timer-dismiss { display: none; }
