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

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
}

a {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f0f0f8;
  color: #1a1a2e;
  min-height: 100vh;
  padding: 2rem 1rem;
}

.container {
  max-width: 700px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 2.5rem;
}

h1 {
  font-size: 2.2rem;
  font-weight: 800;
  color: #000000;
  font-family: 'Arial Narrow', Arial, sans-serif;
  margin-bottom: 0.4rem;
}

.subtitle {
  color: #7777aa;
  font-size: 1rem;
}

.form-section {
  background: #ffffff;
  border: 1px solid #e4e4f4;
  border-radius: 16px;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 2px 16px rgba(100, 80, 200, 0.07);
}

.form-group {
  margin-bottom: 1.6rem;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.6rem;
  color: #333355;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.label-hint {
  font-weight: 400;
  font-size: 0.8rem;
  text-transform: none;
  letter-spacing: 0;
  color: #aaaacc;
}

input[type="number"] {
  width: 100%;
  padding: 0.75rem 1rem;
  background: #f4f4fb;
  border: 1px solid #d8d8ee;
  border-radius: 10px;
  color: #1a1a2e;
  font-size: 1.1rem;
  transition: border-color 0.2s;
  outline: none;
}

input[type="number"]:focus {
  border-color: #7c3aed;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.count-hint {
  font-size: 0.78rem;
  color: #9999bb;
  margin-top: 0.35rem;
  min-height: 16px;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 1rem 0.5rem;
  background: #f8f8fd;
  border: 1px solid #ddddf0;
  border-radius: 12px;
  color: #7777aa;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}

.type-btn:hover {
  border-color: #7c3aed;
  color: #333355;
  background: #f3f0ff;
}

.type-btn.active {
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.28);
}

.type-icon {
  font-size: 1.6rem;
}

.duration-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
}

.duration-btn {
  padding: 0.75rem 0.5rem;
  background: #f8f8fd;
  border: 1px solid #ddddf0;
  border-radius: 10px;
  color: #7777aa;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s;
}

.duration-btn:hover {
  border-color: #2563eb;
  color: #1a1a2e;
  background: #eff6ff;
}

.duration-btn.active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28);
}

.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.5rem 0;
  color: #bbbbdd;
  font-size: 0.85rem;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e8e8f4;
}

.generate-btn {
  width: 100%;
  padding: 1rem;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  border: none;
  border-radius: 12px;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 4px 18px rgba(124, 58, 237, 0.28);
}

.generate-btn:hover { opacity: 0.92; }
.generate-btn:active { transform: scale(0.98); }

.results-section {
  background: #ffffff;
  border: 1px solid #e4e4f4;
  border-radius: 16px;
  padding: 2rem;
  animation: fadeIn 0.4s ease;
  box-shadow: 0 2px 16px rgba(100, 80, 200, 0.07);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.results-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #333355;
}

.regenerate-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid #d8d8ee;
  border-radius: 8px;
  color: #7777aa;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.regenerate-btn:hover {
  border-color: #7c3aed;
  color: #7c3aed;
}

.exercise-list {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.exercise-type-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #7c3aed;
  padding: 0.6rem 0 0.1rem;
  margin-top: 0.3rem;
  border-top: 1px solid #ede9fe;
}
.exercise-type-header:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.exercise-card {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  background: #f8f8fd;
  border: 1px solid #e4e4f4;
  border-radius: 12px;
  padding: 1.1rem 1.2rem;
  animation: slideIn 0.3s ease both;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

.exercise-number {
  min-width: 28px;
  height: 28px;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
}

.exercise-info {
  flex: 1;
}

.exercise-name-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.exercise-name {
  font-size: 1rem;
  font-weight: 700;
  color: #1a1a2e;
  line-height: 1.3;
  flex: 1;
}

.card-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
  padding-top: 0.1rem;
}
.card-actions > * + * { margin-left: 0.3rem; }

.card-action-btn {
  padding: 0.15rem 0.45rem;
  background: transparent;
  border: 1px solid #d8d8ee;
  border-radius: 5px;
  color: #aaaacc;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.card-replace:hover     { border-color: #2563eb; color: #2563eb; background: #eff6ff; }
.card-replace-del:hover { border-color: #dc2626; color: #dc2626; background: #fef2f2; }

.exercise-tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  margin-left: 0.4rem;
  vertical-align: middle;
  position: relative;
  top: -1px;
}

.tag-vikter    { background: #ede9fe; color: #6d28d9; }
.tag-kropp     { background: #dbeafe; color: #1d4ed8; }
.tag-kondition { background: #d1fae5; color: #065f46; }
.tag-rorlighet { background: #fef3c7; color: #92400e; }
.tag-core      { background: #fee2e2; color: #991b1b; }
.tag-tennis    { background: #cffafe; color: #0e7490; }

.exercise-how {
  font-size: 0.9rem;
  color: #444466;
  line-height: 1.55;
  margin-bottom: 0.5rem;
}

.exercise-meta {
  font-size: 0.82rem;
  color: #888899;
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.meta-sets   { color: #555577; font-weight: 600; }
.meta-sep    { color: #ccccdd; }
.meta-muscle { color: #9999aa; font-style: italic; }

.summary {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #ebebf8;
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
}

.summary-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.summary-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9999bb;
}

.summary-value {
  font-size: 1rem;
  font-weight: 600;
  color: #7c3aed;
}

.focus-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.focus-sep {
  height: 1px;
  background: #e8e8f4;
  margin: 0.6rem 0;
}

.focus-btn {
  padding: 0.6rem 0.4rem;
  background: #f8f8fd;
  border: 1px solid #ddddf0;
  border-radius: 10px;
  color: #7777aa;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
  text-align: center;
}

.focus-btn:hover {
  border-color: #10b981;
  color: #1a1a2e;
  background: #f0fdf8;
}

.focus-btn.active {
  background: #ecfdf5;
  border-color: #10b981;
  color: #065f46;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.15);
}

.error-msg {
  color: #dc2626;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* ── Profile bar ── */
.profile-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: #7777aa;
  min-height: 22px;
}

.profile-greeting strong { color: #7c3aed; }

.profile-link-btn {
  background: transparent;
  border: none;
  color: #aaaacc;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  transition: color 0.2s;
}
.profile-link-btn:hover { color: #7c3aed; }

/* ── Modal overlay ── */
.modal-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(40, 30, 80, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: #ffffff;
  border: 1px solid #e4e4f4;
  border-radius: 16px;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 12px 48px rgba(80, 60, 200, 0.14);
}

.modal h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 0.4rem;
  background: none;
  -webkit-text-fill-color: #1a1a2e;
}

.modal p {
  color: #7777aa;
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
  line-height: 1.5;
}

.modal input[type="text"] {
  width: 100%;
  padding: 0.75rem 1rem;
  background: #f4f4fb;
  border: 1px solid #d8d8ee;
  border-radius: 10px;
  color: #1a1a2e;
  font-size: 1rem;
  outline: none;
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}
.modal input[type="text"]:focus { border-color: #7c3aed; }

.modal-actions { display: flex; gap: 0.75rem; }
.modal-actions > * + * { margin-left: 0.75rem; }

.modal-submit-btn {
  flex: 1;
  padding: 0.75rem;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}
.modal-submit-btn:hover { opacity: 0.9; }

.modal-skip-btn {
  padding: 0.75rem 1rem;
  background: transparent;
  border: 1px solid #e0e0ee;
  border-radius: 10px;
  color: #9999bb;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
}
.modal-skip-btn:hover { border-color: #9999bb; color: #555577; }

.modal-footer-row { margin-top: 0.75rem; }

.modal-action-btn {
  width: 100%;
  padding: 0.65rem;
  background: transparent;
  border: 1px dashed #d8d8ee;
  border-radius: 10px;
  color: #aaaacc;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 0.5rem;
}
.modal-action-btn:hover { border-color: #7c3aed; color: #7c3aed; }

/* ── Profile list ── */
.profile-list-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  max-height: 280px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.profile-list-container > * + * { margin-top: 0.5rem; }

.profile-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: #f8f8fd;
  border: 1px solid #e4e4f4;
  border-radius: 10px;
  transition: border-color 0.2s;
}
.profile-card.active { border-color: #7c3aed; background: #faf5ff; }

.profile-card-name {
  flex: 1;
  text-align: left;
  background: transparent;
  border: none;
  color: #333355;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.profile-card.active .profile-card-name { color: #1a1a2e; }

.profile-card-email {
  display: block;
  font-size: 0.72rem;
  color: #9999bb;
  font-weight: 400;
  margin-top: 0.1rem;
}

.profile-create-error {
  color: #dc2626;
  font-size: 0.82rem;
  min-height: 1rem;
  margin-bottom: 0.5rem;
}

.modal input[type="email"] {
  width: 100%;
  padding: 0.75rem 1rem;
  background: #f4f4fb;
  border: 1px solid #d8d8ee;
  border-radius: 10px;
  color: #1a1a2e;
  font-size: 1rem;
  outline: none;
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}
.modal input[type="email"]:focus { border-color: #7c3aed; }

.profile-create-error.profile-create-ok { color: #059669; }

.profile-retry-row {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.75rem;
}
.profile-retry-row > button { flex: 1; }

#profile-alias-row input { margin-top: 0; }

.profile-card-active-badge {
  font-size: 0.68rem;
  background: #ede9fe;
  color: #6d28d9;
  padding: 0.1rem 0.45rem;
  border-radius: 5px;
  font-weight: 600;
  flex-shrink: 0;
}

.profile-card-delete {
  background: transparent;
  border: none;
  color: #d0d0e4;
  cursor: pointer;
  font-size: 0.78rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: color 0.2s;
  flex-shrink: 0;
  line-height: 1;
}
.profile-card-delete:hover { color: #dc2626; }

.profile-empty {
  color: #aaaacc;
  font-size: 0.88rem;
  text-align: center;
  padding: 1.25rem;
}

/* ── Stats modal ── */
.modal-wide { max-width: 560px; }

.modal-close-btn {
  background: transparent;
  border: 1px solid #e0e0ee;
  border-radius: 8px;
  color: #aaaacc;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.modal-close-btn:hover { border-color: #9999bb; color: #555577; }

.stats-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.stats-content {
  max-height: 62vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 0.2rem;
}

.stats-overview {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stats-kpi {
  flex: 1;
  background: #f4f4fb;
  border: 1px solid #e4e4f4;
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stats-kpi-value {
  font-size: 2rem;
  font-weight: 800;
  color: #7c3aed;
  line-height: 1;
}

.stats-kpi-label {
  font-size: 0.72rem;
  color: #9999bb;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stats-section { margin-bottom: 1.5rem; }

.stats-section h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: #9999bb;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.7rem;
}

.stat-bar-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.4rem;
}

.stat-bar-label {
  min-width: 78px;
  font-size: 0.82rem;
  color: #555577;
  text-align: right;
  flex-shrink: 0;
}

.stat-bar-track {
  flex: 1;
  background: #ededf8;
  border-radius: 4px;
  height: 7px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 4px;
  min-width: 4px;
}

.stat-bar-count {
  font-size: 0.75rem;
  color: #aaaacc;
  min-width: 22px;
  text-align: right;
  flex-shrink: 0;
}

.stats-top-list {
  list-style: none;
  counter-reset: stats-c;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.stats-top-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  counter-increment: stats-c;
  font-size: 0.87rem;
}

.stats-top-list li::before {
  content: counter(stats-c);
  min-width: 20px;
  height: 20px;
  background: #f4f4fb;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #9999bb;
  font-weight: 700;
  flex-shrink: 0;
}

.stats-ex-name  { flex: 1; color: #333355; }
.stats-ex-count { color: #7c3aed; font-weight: 600; }

.stats-recent-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.stats-recent-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid #f0f0f8;
}

.stats-recent-date { color: #9999bb; min-width: 90px; flex-shrink: 0; }
.stats-recent-info { color: #555577; flex: 1; }

.history-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
  margin-left: 0.5rem;
}

.history-action-btn {
  background: transparent;
  border: 1px solid #e0e0ee;
  border-radius: 5px;
  color: #c0c0d8;
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0.15rem 0.4rem;
  transition: all 0.18s;
  line-height: 1.5;
}
.history-edit-btn:hover   { border-color: #2563eb; color: #2563eb; background: #eff6ff; }
.history-delete-btn:hover { border-color: #dc2626; color: #dc2626; background: #fef2f2; }

.edit-exercise-row {
  padding: 0.6rem 0;
  border-bottom: 1px solid #f0f0f8;
}
.edit-exercise-row:last-child { border-bottom: none; }

.edit-exercise-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #333355;
  margin-bottom: 0.3rem;
}

.edit-workout-content {
  max-height: 55vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 0.2rem;
}

.stats-empty {
  color: #aaaacc;
  font-size: 0.9rem;
  text-align: center;
  padding: 2rem 1rem;
  line-height: 1.6;
}

/* ── Last result & log inputs ── */
.last-result {
  font-size: 0.78rem;
  color: #059669;
  margin-top: 0.35rem;
  font-weight: 500;
}

.log-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.log-label {
  font-size: 0.72rem;
  color: #bbbbdd;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  flex-shrink: 0;
}

.log-input {
  width: 68px;
  padding: 0.28rem 0.45rem;
  background: #f4f4fb;
  border: 1px solid #d8d8ee;
  border-radius: 6px;
  color: #1a1a2e;
  font-size: 0.85rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}
.log-input:focus { border-color: #7c3aed; }

.log-sep  { color: #d0d0e8; font-size: 0.85rem; }
.log-unit { font-size: 0.78rem; color: #bbbbdd; }

.log-check-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: #9999bb;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

/* ── Save button ── */
.results-footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #ebebf8;
}

.save-btn {
  padding: 0.65rem 1.5rem;
  background: transparent;
  border: 1px solid #10b981;
  border-radius: 10px;
  color: #059669;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.save-btn:hover { background: #ecfdf5; }
.save-btn:disabled { opacity: 0.55; cursor: default; }

/* ── Background image ── */
body.has-bg-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

body.has-bg-image .form-section,
body.has-bg-image .results-section {
  background: rgba(255, 255, 255, 0.93);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

body.has-bg-image .modal {
  background: rgba(255, 255, 255, 0.97);
}


@media (max-width: 480px) {
  h1 { font-size: 1.7rem; }
  .type-grid { grid-template-columns: repeat(3, 1fr); }
  .duration-grid { grid-template-columns: repeat(3, 1fr); }
  .form-section, .results-section { padding: 1.25rem; }
  .results-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
}
