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

:root {
  --bg: #121212;
  --surface: #1e1e1e;
  --surface-raised: #2a2a2a;
  --border: #333;
  --text: #e8e8e8;
  --text-muted: #888;
  --accent: #4fc3f7;
  --accent-dim: rgba(79, 195, 247, 0.15);
  --increase: #66bb6a;
  --increase-dim: rgba(102, 187, 106, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
}

html { font-size: 16px; }

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

#app {
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 100px;
}

/* ---- Top bar ---- */

.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.top-bar h1 {
  font-size: 1.4rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.edit-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  margin: -8px;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, background 0.15s;
}

.edit-toggle.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.btn-delete {
  background: rgba(239, 83, 80, 0.15);
  color: #ef5350;
  border: 1px solid rgba(239, 83, 80, 0.4);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-delete:active { opacity: 0.7; }

.btn-delete-group {
  width: 22px;
  height: 22px;
  font-size: 1rem;
}

.group-name-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
  margin: -8px;
  line-height: 1;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Exercise list ---- */

#exercise-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 16px;
}

.exercise-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 14px 8px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 64px;
  -webkit-tap-highlight-color: transparent;
}

.exercise-card:active { background: var(--surface-raised); }
.exercise-card.dragging { opacity: 0.3; }

.card-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.card-name {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-detail {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.card-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.badge-done {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--increase);
  background: var(--increase-dim);
  flex-shrink: 0;
}

/* A completed exercise reads as muted but stays legible. */
.exercise-card.card-done {
  opacity: 0.55;
}

.exercise-card.card-done .card-name {
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}

/* ---- Done-today divider ---- */

.done-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.done-divider::before,
.done-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.badge-increase {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--increase);
  background: var(--increase-dim);
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

/* ---- Drag handle ---- */

.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-height: 44px;
  cursor: grab;
  touch-action: none;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
}

.drag-handle::before {
  content: '';
  display: block;
  width: 14px;
  height: 2px;
  background: var(--text-muted);
  box-shadow: 0 5px 0 var(--text-muted), 0 10px 0 var(--text-muted);
  border-radius: 1px;
}

.drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: 0.9;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  transform: scale(1.03);
}

/* ---- Groups in list ---- */

.group-section {
  margin-bottom: 12px;
  padding: 6px;
  margin-left: -6px;
  margin-right: -6px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.group-section:last-child {
  margin-bottom: 0;
}

.group-section.drag-over {
  background: var(--accent-dim);
  border-color: var(--accent);
}

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

.group-name {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 4px;
  transition: background 0.15s;
}

.group-name:active {
  background: var(--surface-raised);
}

.group-name-input {
  font-size: 0.8rem !important;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text) !important;
  background: var(--surface-raised) !important;
  border: 1px solid var(--accent) !important;
  border-radius: 4px !important;
  padding: 2px 6px !important;
  outline: none;
  width: 140px !important;
}

.btn-log-group {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(79, 195, 247, 0.3);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 32px;
  -webkit-tap-highlight-color: transparent;
}

.btn-log-group:active { opacity: 0.7; }

.group-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 16px;
  line-height: 1.6;
}

.empty-state .empty-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

/* ---- FAB & menu ---- */

.fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  font-size: 2rem;
  font-weight: 300;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
  z-index: 22;
}

.fab.open { transform: rotate(45deg); }
.fab:active { opacity: 0.85; }

.fab-overlay {
  position: fixed;
  inset: 0;
  z-index: 18;
}

.fab-menu {
  position: fixed;
  bottom: 100px;
  right: 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  z-index: 21;
}

.fab-menu-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  -webkit-tap-highlight-color: transparent;
}

.fab-menu-item:active { background: var(--surface-raised); }

/* ---- Modal ---- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-content h2 {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-content label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

@media (min-width: 500px) {
  .modal { align-items: center; }
}

/* ---- Inputs ---- */

input[type="text"],
input[type="number"],
select {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.1rem;
  padding: 12px 14px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

select option {
  background: var(--surface);
  color: var(--text);
}

input:focus,
select:focus {
  border-color: var(--accent);
}

/* ---- Buttons ---- */

.btn-primary {
  background: var(--accent);
  color: #000;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px 24px;
  cursor: pointer;
  min-height: 48px;
  transition: opacity 0.15s;
}

.btn-primary:active { opacity: 0.8; }

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 24px;
  cursor: pointer;
  min-height: 48px;
}

.btn-full { width: 100%; }

/* ---- Log view ---- */

.log-body {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.info-card.suggestion {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.info-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.info-value {
  font-size: 1.3rem;
  font-weight: 700;
}

.info-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.info-reason {
  font-size: 0.8rem;
  color: var(--accent);
  margin-top: 4px;
}

/* Inline "[sets] × [reps] @ [weight] lbs" entry row. */
.formula-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.formula-input {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: 12px 6px;
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Drop the spinner arrows so the centered values read as a clean formula. */
.formula-input::-webkit-outer-spin-button,
.formula-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Weight tends to be the widest value (e.g. 137.5) — give it a little more. */
.formula-input:last-of-type {
  flex: 1.3;
}

.formula-op {
  color: var(--text-muted);
  font-size: 1.1rem;
  font-weight: 600;
  flex-shrink: 0;
}

.formula-unit {
  color: var(--text-muted);
  font-size: 0.9rem;
  flex-shrink: 0;
}

/* ---- Notes ---- */

.notes-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notes-field label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.notes-field textarea {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.4;
  padding: 12px 14px;
  width: 100%;
  outline: none;
  resize: vertical;
  transition: border-color 0.15s;
}

.notes-field textarea:focus {
  border-color: var(--accent);
}

/* ---- Toggle ---- */

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 56px;
}

.toggle-label {
  font-size: 0.95rem;
  font-weight: 500;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle input:checked + .toggle-track {
  background: var(--increase-dim);
  border-color: var(--increase);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(22px);
  background: var(--increase);
}

/* ---- Group log view ---- */

.grp-ex-block {
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.grp-ex-block:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.grp-ex-name {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.grp-ex-info {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.grp-ex-sug {
  font-size: 0.85rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

/* ---- History ---- */

#log-history h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

#log-history-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.95rem;
}

.hist-detail { font-weight: 600; }
.hist-date { font-size: 0.8rem; color: var(--text-muted); }

/* ---- Utilities ---- */

.hidden { display: none !important; }
