:root {
  --bg: #121212;
  --surface: #1E1E1E;
  --surface-hover: #252525;
  --border: #2C2C2E;
  --accent: #00E5FF;
  --accent-dim: rgba(0, 229, 255, 0.15);
  --danger: #FF453A;
  --danger-dim: rgba(255, 69, 58, 0.15);
  --success: #32D74B;
  --success-dim: rgba(50, 215, 75, 0.15);
  --text: #FFFFFF;
  --text-dim: #98989D;
  --radius: 16px;
  --radius-sm: 8px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
}

* {
  box-sizing: border-box;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', 'Inter', sans-serif;
  direction: rtl;
  min-height: 100vh;
}

.mono {
  font-family: 'JetBrains Mono', 'Vazirmatn', monospace;
  font-variant-numeric: tabular-nums;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- shared ---------- */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
}

.btn-primary {
  background: var(--danger);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  padding: 16px;
  border-radius: 999px;
  width: 100%;
  box-shadow: 0 4px 20px rgba(255, 69, 58, 0.3);
  transition: transform 120ms ease, opacity 120ms ease;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.4; }

.btn-ghost {
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  padding: 10px;
}

.input {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 15px;
  width: 100%;
  font-family: inherit;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.input::placeholder { color: var(--text-dim); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-2); }
.field label { font-size: 13px; color: var(--text-dim); }

.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- auth screen ---------- */
.auth-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-4) var(--space-3);
}
.auth-brand {
  text-align: center;
  margin-bottom: var(--space-4);
}
.auth-brand .logo {
  width: 64px; height: 64px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), #0891A8);
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  margin: 0 auto var(--space-2);
}
.auth-brand .brand-logo-img {
  max-width: 300px; width: 88%; height: auto;
  margin: 0 auto var(--space-2);
  display: block;
}
.auth-brand h1 { font-size: 22px; margin: 0; }
.auth-brand p { color: var(--text-dim); font-size: 14px; margin-top: 4px; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
}
.auth-toggle {
  display: flex;
  justify-content: center;
  gap: var(--space-1);
  margin-top: var(--space-3);
  font-size: 14px;
  color: var(--text-dim);
}

/* ---------- header ---------- */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3);
}
.header .greeting h2 { margin: 0; font-size: 18px; }
.header .greeting p { margin: 2px 0 0; color: var(--text-dim); font-size: 13px; }
.header .greeting .program-label { color: var(--accent); font-size: 12px; font-weight: 600; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--danger);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  object-fit: cover;
  flex-shrink: 0;
}
.avatar.avatar-sm {
  width: 34px; height: 34px; font-size: 13px; cursor: pointer;
}
.streak {
  display: flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px; font-size: 13px;
}

/* ---------- today card ---------- */
.today-card {
  margin: 0 var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
}
.today-card .eyebrow { color: var(--text-dim); font-size: 13px; margin: 0 0 4px; }
.today-card .row-top {
  display: flex; justify-content: space-between; align-items: center;
  gap: var(--space-2);
}
.today-card h3 { font-size: 20px; margin: 0; }
.tags { display: flex; gap: 8px; margin-top: var(--space-2); flex-wrap: wrap; }
.tag {
  background: #2A2A2A; color: var(--text-dim);
  font-size: 12px; padding: 6px 10px; border-radius: var(--radius-sm);
}

.ring-wrap { position: relative; width: 76px; height: 76px; flex-shrink: 0; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-wrap .ring-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  flex-direction: column;
}
.ring-wrap .ring-label .pct { font-size: 15px; font-weight: 700; }
.ring-wrap .ring-label .sub { font-size: 10px; color: var(--text-dim); }

/* ---------- stat rings ---------- */
.stats-row {
  display: flex; justify-content: space-around;
  padding: var(--space-4) var(--space-3) var(--space-3);
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.stat .ring-wrap { width: 64px; height: 64px; }
.stat .ring-wrap .pct { font-size: 14px; }
.stat .label { font-size: 12px; color: var(--text-dim); }

/* ---------- exercise list ---------- */
.section-title {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 var(--space-3); margin-bottom: var(--space-2);
}
.section-title h4 { margin: 0; font-size: 15px; }

.exercise-list { padding: 0 var(--space-3) var(--space-4); display: flex; flex-direction: column; gap: 10px; }
.exercise-list.locked { opacity: 0.5; }
.exercise-list.locked .exercise-item { cursor: not-allowed; }

.exercise-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  border-right: 3px solid var(--border);
  transition: border-color 150ms ease, background 150ms ease;
}
.exercise-item.done { border-right-color: var(--success); background: var(--success-dim); }

.check {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: transparent; font-size: 14px;
}
.exercise-item.done .check { background: var(--success); border-color: var(--success); color: #0a0a0a; }

.ex-icon { font-size: 22px; width: 30px; text-align: center; }
.ex-info { flex: 1; }
.ex-info .name { font-size: 15px; }
.ex-info .meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.exercise-item.done .name { color: var(--text-dim); text-decoration: line-through; }

.group-item { border-right-color: var(--accent); align-items: flex-start; }
.group-item.done { border-right-color: var(--success); }
.group-label { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.group-item.done .group-label { color: var(--success); }
.group-sub { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-top: 1px dashed var(--border); }
.group-sub:first-of-type { border-top: none; }
.group-sub .name { font-size: 14px; }
.group-sub .meta { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.group-item.done .group-sub .name { color: var(--text-dim); text-decoration: line-through; }

/* ---------- empty / add-workout state ---------- */
.empty-state { padding: var(--space-4) var(--space-3); text-align: center; }
.empty-state p { color: var(--text-dim); margin-bottom: var(--space-2); }

.builder { padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.builder .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.ex-row {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto auto auto; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px; align-items: center;
  transition: border-color 150ms ease;
}
.ex-row.linked { border-color: var(--accent); }
.ex-row .input { padding: 8px 10px; font-size: 13px; }
.remove-btn { background: transparent; color: var(--danger); font-size: 18px; padding: 4px; }
.link-btn {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 14px; padding: 6px 8px;
}
.link-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.move-btns { display: flex; flex-direction: column; gap: 2px; }
.move-btn {
  background: transparent; border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-dim); font-size: 9px; line-height: 1; padding: 3px 5px;
}
.move-btn:active { background: var(--accent-dim); color: var(--accent); }

/* ---------- timer bar ---------- */
.timer-bar {
  position: sticky; bottom: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 12px var(--space-3);
  display: flex; justify-content: space-between; align-items: center;
}
.timer-bar .time { font-size: 20px; font-weight: 700; color: var(--accent); }
.timer-bar .finish-btn { background: var(--success); color: #0a0a0a; font-weight: 700; padding: 10px 20px; border-radius: 999px; }

.finished-banner {
  background: var(--success-dim); border: 1px solid var(--success);
  border-radius: var(--radius-sm); padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.finished-banner p { margin: 0; font-size: 13px; color: var(--success); }
.finished-banner .btn-ghost { padding: 4px 8px; font-size: 13px; }

.top-bar { display: flex; justify-content: space-between; align-items: center; padding: var(--space-2) var(--space-3); }
.top-bar-logo { height: 32px; width: auto; }
.icon-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); width: 36px; height: 36px; border-radius: 50%; font-size: 14px; }

/* ---------- profile sheet ---------- */
.overlay-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
}
.profile-sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 480px;
  padding: var(--space-2) var(--space-3) var(--space-4);
  animation: sheet-up 180ms ease;
}
@keyframes sheet-up { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 16px; }
.profile-header { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 8px; }
.avatar-lg {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--danger);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
}
img.avatar-lg { cursor: pointer; }

.avatar-viewer {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
  animation: fade-in 150ms ease;
}
.avatar-viewer img {
  width: 85vw; max-width: 420px; height: 85vw; max-height: 420px;
  border-radius: 50%; object-fit: cover;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.profile-row {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 4px; border-bottom: 1px solid var(--border);
  cursor: pointer; font-size: 15px;
}
.profile-row:last-child { border-bottom: none; }
.profile-row.danger { color: var(--danger); }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border);
  padding: 10px 18px; border-radius: 999px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
