:root {
  --violet-900: #3b1a78;
  --violet-700: #5b21b6;
  --violet-600: #7c3aed;
  --violet-500: #8b5cf6;
  --lilac-400: #b69cf7;
  --lilac-300: #d4c4fb;
  --lilac-200: #e7dcff;
  --lilac-100: #f3edff;
  --lilac-50: #faf7ff;
  --white: #ffffff;
  --ink: #2a1d47;
  --muted: #6f6290;
  --line: #e6dcfa;
  --taken-bg: #f1eef6;
  --taken-ink: #a49cb6;
  --ok: #16a34a;
  --ok-bg: #e9f9ef;
  --warn: #b45309;
  --warn-bg: #fff6e6;
  --danger: #dc2626;
  --danger-bg: #fdecec;
  --shadow: 0 10px 30px -12px rgba(91, 33, 182, 0.28);
  --radius: 20px;
  font-family: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--lilac-100) 0%, var(--lilac-50) 40%, var(--white) 100%);
  line-height: 1.6;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ── الترويسة ── */
.hero {
  position: relative;
  overflow: hidden;
  padding: 36px 20px 64px;
  text-align: center;
  color: var(--white);
  background: linear-gradient(135deg, var(--violet-700) 0%, var(--violet-600) 45%, var(--lilac-400) 100%);
  border-radius: 0 0 36px 36px;
}
.hero::before, .hero::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}
.hero::before { width: 220px; height: 220px; top: -90px; left: -60px; }
.hero::after { width: 140px; height: 140px; bottom: -50px; right: -30px; background: rgba(255, 255, 255, 0.16); }
.hero .sparkle { position: absolute; color: rgba(255, 255, 255, 0.7); font-size: 18px; }
.hero .s1 { top: 22px; right: 12%; }
.hero .s2 { top: 60%; left: 10%; font-size: 13px; }
.hero .s3 { bottom: 28px; right: 30%; font-size: 11px; }
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 14px;
  font-weight: 500;
}
.hero h1 { position: relative; margin: 12px 0 6px; font-size: clamp(26px, 7vw, 38px); font-weight: 700; line-height: 1.3; }
.hero p { position: relative; margin: 0; opacity: 0.92; font-size: 16px; }

/* ── الحاوية والبطاقات ── */
.wrap { width: 100%; max-width: 640px; margin: -40px auto 0; padding: 0 16px 140px; position: relative; }
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
}
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.step-head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.step-num {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--lilac-200);
  color: var(--violet-700);
  font-weight: 700;
}
.step.done .step-num { background: var(--violet-600); color: var(--white); }

.field {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--lilac-50);
  font-size: 17px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.field:focus { border-color: var(--violet-500); background: var(--white); }
.hint { margin: 8px 2px 0; font-size: 13.5px; color: var(--muted); }

.notice { margin-top: 12px; padding: 12px 14px; border-radius: 14px; font-size: 15px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.error { background: var(--danger-bg); color: var(--danger); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }

/* ── الأسابيع ── */
.weeks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 5px; background: var(--lilac-100); border-radius: 16px; margin-bottom: 14px; }
.week-btn {
  border: 0;
  border-radius: 12px;
  padding: 8px 4px;
  background: transparent;
  color: var(--violet-700);
  line-height: 1.35;
}
.week-btn b { display: block; font-size: 14.5px; }
.week-btn small { font-size: 12px; opacity: 0.8; }
.week-btn[aria-selected='true'] { background: var(--white); box-shadow: 0 4px 12px -6px rgba(91, 33, 182, 0.45); color: var(--violet-900); }

/* ── الأيام ── */
.days { display: grid; grid-template-columns: 1fr; gap: 8px; }
.day-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--white);
  text-align: right;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.day-btn:active { transform: scale(0.99); }
.day-date {
  flex: none;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 14px;
  background: var(--lilac-100);
  color: var(--violet-700);
  line-height: 1.1;
}
.day-date b { font-size: 20px; }
.day-date small { font-size: 11px; }
.day-info { flex: 1; }
.day-info b { display: block; font-size: 16px; }
.day-info small { color: var(--muted); font-size: 13px; }
.day-free { flex: none; font-size: 13px; font-weight: 600; color: var(--violet-600); background: var(--lilac-100); padding: 4px 10px; border-radius: 999px; }
.day-btn[aria-pressed='true'] { border-color: var(--violet-600); background: var(--lilac-50); }
.day-btn[aria-pressed='true'] .day-date { background: var(--violet-600); color: var(--white); }
.day-btn.full { background: var(--taken-bg); }
.day-btn.full .day-free { color: var(--taken-ink); background: var(--white); }

/* ── الحصص ── */
.periods { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.period-btn {
  position: relative;
  min-height: 62px;
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--white);
  line-height: 1.3;
  transition: border-color 0.15s, background 0.15s;
}
.period-btn b { display: block; font-size: 16px; }
.period-btn small { font-size: 12.5px; color: var(--ok); font-weight: 600; }
.period-btn[aria-pressed='true'] { border-color: var(--violet-600); background: var(--violet-600); color: var(--white); }
.period-btn[aria-pressed='true'] small { color: var(--lilac-200); }
.period-btn:disabled {
  cursor: not-allowed;
  color: var(--taken-ink);
  border-style: dashed;
  background: repeating-linear-gradient(-45deg, var(--taken-bg), var(--taken-bg) 8px, #ebe7f1 8px, #ebe7f1 16px);
}
.period-btn:disabled small { color: var(--taken-ink); }
.empty { padding: 18px; text-align: center; color: var(--muted); background: var(--lilac-50); border-radius: 14px; font-size: 15px; }
.legend { display: flex; gap: 16px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 14px; border-radius: 4px; border: 2px solid var(--line); display: inline-block; }
.legend .l-taken { border-style: dashed; background: var(--taken-bg); }
.legend .l-sel { background: var(--violet-600); border-color: var(--violet-600); }

/* ── شريط التأكيد السفلي ── */
.submit-bar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -10px 30px -18px rgba(91, 33, 182, 0.4);
}
.submit-inner { max-width: 640px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.summary { flex: 1; font-size: 13.5px; color: var(--muted); line-height: 1.45; min-width: 0; }
.summary b { color: var(--ink); }
.btn {
  border: 0;
  border-radius: 14px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--violet-600), var(--violet-500));
  color: var(--white);
  box-shadow: 0 8px 20px -8px rgba(124, 58, 237, 0.7);
  white-space: nowrap;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; box-shadow: none; cursor: not-allowed; }
.btn.secondary { background: var(--lilac-100); color: var(--violet-700); box-shadow: none; }
.btn.danger { background: var(--danger-bg); color: var(--danger); box-shadow: none; }
.btn.small { padding: 8px 14px; font-size: 14px; border-radius: 12px; }
.btn.block { width: 100%; }

/* ── بطاقة النتيجة ── */
.result { text-align: center; padding: 28px 20px; }
.result-icon {
  width: 76px;
  height: 76px;
  margin: 0 auto 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--violet-600), var(--lilac-400));
  color: var(--white);
  box-shadow: 0 12px 26px -10px rgba(124, 58, 237, 0.8);
}
.result-icon.warn { background: linear-gradient(135deg, #f59e0b, #fbbf24); box-shadow: 0 12px 26px -10px rgba(245, 158, 11, 0.7); }
.result h2 { margin: 0 0 4px; font-size: 22px; }
.result > p { margin: 0 0 18px; color: var(--muted); }
.details { list-style: none; margin: 0 0 18px; padding: 0; border-radius: 16px; background: var(--lilac-50); border: 1px solid var(--line); text-align: right; }
.details li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.details li:last-child { border-bottom: 0; }
.details span { color: var(--muted); }
.details b { text-align: left; }
.result .link-btn { border: 0; background: none; color: var(--violet-600); font-weight: 600; text-decoration: underline; padding: 8px; }

.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.spinner { width: 34px; height: 34px; margin: 0 auto 10px; border-radius: 50%; border: 4px solid var(--lilac-200); border-top-color: var(--violet-600); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: 30;
  transform: translate(-50%, -20px);
  opacity: 0;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--white);
  font-size: 15px;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

footer { text-align: center; font-size: 12.5px; color: var(--muted); padding: 8px 16px 24px; }

@media (min-width: 560px) {
  .days { grid-template-columns: repeat(1, 1fr); }
  .periods { grid-template-columns: repeat(4, 1fr); }
  .card { padding: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; }
}
