:root {
  --bg: #f4f5f7;
  --bg-elevated: #ffffff;
  --text: #14161a;
  --text-muted: #6b7280;
  --border: #e2e4e9;
  --accent: #1b6ef3;
  --accent-text: #ffffff;
  --success: #1f9d55;
  --danger: #e0433d;
  --warn: #b8860b;
  --chip-bg: #eef1f6;
  --chip-active-bg: #1b6ef3;
  --chip-active-text: #ffffff;
  --shadow: 0 1px 3px rgba(20, 22, 26, 0.08), 0 1px 2px rgba(20, 22, 26, 0.06);
  --radius: 16px;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --bg-elevated: #1a1d23;
    --text: #f2f3f5;
    --text-muted: #9aa0ab;
    --border: #2a2e37;
    --accent: #4d94ff;
    --accent-text: #06101f;
    --success: #37c76c;
    --danger: #ff6b64;
    --warn: #e0b23e;
    --chip-bg: #23262e;
    --chip-active-bg: #4d94ff;
    --chip-active-text: #06101f;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elevated: #1a1d23;
  --text: #f2f3f5;
  --text-muted: #9aa0ab;
  --border: #2a2e37;
  --accent: #4d94ff;
  --accent-text: #06101f;
  --success: #37c76c;
  --danger: #ff6b64;
  --warn: #e0b23e;
  --chip-bg: #23262e;
  --chip-active-bg: #4d94ff;
  --chip-active-text: #06101f;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, "Cairo", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  padding-bottom: 88px;
}

button, input, textarea {
  font-family: inherit;
  color: inherit;
}

a { color: var(--accent); }

.hidden { display: none !important; }

body.overlay-open .app-header {
  visibility: hidden;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.05rem;
  margin: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  border: none;
  background: var(--chip-bg);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.hero-card {
  background: linear-gradient(135deg, var(--accent), #6a3bd0);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.hero-card .week-label { font-size: 0.85rem; opacity: 0.85; }
.hero-card .week-value { font-size: 2rem; font-weight: 700; margin: 2px 0 6px; }
.hero-card .hero-sub { font-size: 0.9rem; opacity: 0.9; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--chip-bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; width: auto; border-radius: 10px; }

.day-list { display: flex; flex-direction: column; gap: 10px; }
.day-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}
.day-row.is-next { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.day-row .day-name { font-weight: 600; }
.day-row .day-meta { font-size: 0.8rem; color: var(--text-muted); }

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 22px 0 10px;
  color: var(--text-muted);
}

.exercise-card { margin-bottom: 12px; }
.exercise-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.exercise-title-link {
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.exercise-title-link .play-badge {
  color: var(--accent);
  font-size: 0.85rem;
}
.exercise-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.exercise-meta span {
  background: var(--chip-bg);
  padding: 4px 8px;
  border-radius: 8px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--border);
  background: var(--chip-bg);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.82rem;
  cursor: pointer;
}
.chip.active { background: var(--chip-active-bg); color: var(--chip-active-text); border-color: transparent; font-weight: 700; }

.notes-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--chip-bg);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  line-height: 1.6;
}

.set-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.set-row .set-label {
  width: 54px;
  flex-shrink: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.set-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
  font-size: 1rem;
  text-align: center;
}
.set-row .set-x { color: var(--text-muted); }
.last-time-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: -4px 0 10px;
}

.rest-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.rest-timer-display {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 54px;
  direction: ltr;
  unicode-bidi: isolate;
}

.exercise-notes-toggle {
  font-size: 0.78rem;
  color: var(--accent);
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
}
textarea.user-note {
  width: 100%;
  min-height: 60px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  margin-top: 6px;
  font-size: 0.9rem;
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 20;
}
.bottom-bar-inner { max-width: 560px; margin: 0 auto; }

.history-item {
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 10px;
  overflow: hidden;
}
.history-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  cursor: pointer;
}
.history-detail { padding: 0 14px 14px; font-size: 0.85rem; }
.history-detail table { width: 100%; border-collapse: collapse; }
.history-detail td { padding: 4px 2px; border-bottom: 1px solid var(--border); }
.history-detail td:first-child { color: var(--text-muted); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.9rem;
}

.instructions-block {
  white-space: pre-wrap;
  line-height: 1.9;
  font-size: 0.92rem;
}

.field-row { margin-bottom: 14px; }
.field-row label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; }
.field-row input[type="date"] {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
}

.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

.link-list { display: flex; flex-direction: column; gap: 10px; }
.link-list a {
  display: block;
  background: var(--chip-bg);
  padding: 12px 14px;
  border-radius: 12px;
  text-decoration: none;
  font-size: 0.9rem;
}

.warmup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.warmup-row:last-child { border-bottom: none; }

.finish-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  transform: translateZ(0);
  isolation: isolate;
}
.finish-panel {
  background: var(--bg-elevated);
  width: 100%;
  max-width: 560px;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}

.photo-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.photo-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--border);
}
.photo-thumb-lg {
  width: 96px;
  height: 96px;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transform: translateZ(0);
  isolation: isolate;
}
.lightbox-img {
  max-width: 92%;
  max-height: 85%;
  border-radius: 8px;
  object-fit: contain;
}
.lightbox-close {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  left: 16px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}
