/* ============================================================
   رسالتنا الأسبوعية — Stylesheet
   Palette: warm ivory base, deep emerald, saffron gold,
   terracotta, indigo. Full dark mode via [data-theme="dark"].
   ============================================================ */

:root {
  --bg: #FBF6EC;
  --bg-soft: #F3ECDD;
  --surface: #FFFFFF;
  --ink: #23312D;
  --ink-soft: #5C6A64;
  --emerald: #0E6B5C;
  --emerald-deep: #0A5246;
  --gold: #C9952F;
  --gold-soft: #E8C77E;
  --terracotta: #B65336;
  --indigo: #41618F;
  --ring: rgba(201, 149, 47, 0.45);
  --shadow: 0 18px 45px rgba(35, 49, 45, 0.16);
  --shadow-soft: 0 6px 18px rgba(35, 49, 45, 0.10);
  --overlay: rgba(20, 28, 26, 0.55);
}

[data-theme="dark"] {
  --bg: #0F1D1A;
  --bg-soft: #14241F;
  --surface: #1A2C27;
  --ink: #EDE7D8;
  --ink-soft: #A7B3AC;
  --emerald: #2FA08B;
  --emerald-deep: #1C7A68;
  --gold: #D9AC4E;
  --gold-soft: #B68A33;
  --terracotta: #D0744F;
  --indigo: #7693C2;
  --ring: rgba(217, 172, 78, 0.5);
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.35);
  --overlay: rgba(4, 10, 8, 0.7);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: "IBM Plex Sans Arabic", "Tajawal", system-ui, sans-serif;
  background:
    radial-gradient(1100px 500px at 50% -10%, var(--bg-soft), transparent 70%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.4s ease, color 0.4s ease;
}

.skip-link {
  position: absolute;
  inset-inline-start: 0;
  top: -48px;
  background: var(--emerald);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 10px 10px;
  z-index: 50;
  transition: top 0.2s ease;
}
.skip-link:focus { top: 0; }

/* ---------- Header ---------- */
.site-header {
  text-align: center;
  padding: 2.2rem 1rem 0.8rem;
  position: relative;
}

.header-controls {
  position: absolute;
  top: 1rem;
  inset-inline-end: 1rem;
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1.5px solid var(--gold);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.15rem;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.18s ease, background 0.3s ease;
}
.icon-btn:hover { transform: translateY(-2px); }
.icon-btn:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

.icon-moon, .icon-sound-off { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: inline; }
body.muted .icon-sound-on { display: none; }
body.muted .icon-sound-off { display: inline; }

.title {
  font-family: "Aref Ruqaa", serif;
  font-weight: 700;
  font-size: clamp(2.3rem, 6vw, 3.6rem);
  color: var(--emerald);
  line-height: 1.4;
}

.title::after {
  content: "";
  display: block;
  width: 120px;
  height: 3px;
  margin: 0.5rem auto 0;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.subtitle {
  margin-top: 0.6rem;
  color: var(--ink-soft);
  font-size: clamp(0.95rem, 2.5vw, 1.1rem);
}

/* ---------- Wheel ---------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem 1rem 2rem;
}

.wheel-stage {
  position: relative;
  margin-top: 1.6rem;
  display: flex;
  justify-content: center;
}

.pointer {
  position: absolute;
  top: -26px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.25));
}
.pointer-body { fill: var(--gold); }
.pointer-jewel { fill: var(--terracotta); stroke: var(--bg); stroke-width: 2.5; }

.wheel-wrap {
  position: relative;
  width: min(82vw, 460px);
  aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: var(--shadow), inset 0 0 0 6px var(--gold);
  background: var(--surface);
}

#wheel {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  transition: transform 4.6s cubic-bezier(0.12, 0.82, 0.16, 1);
  will-change: transform;
}

#wheel.no-anim { transition: none; }

#wheel .segment {
  cursor: pointer;
  stroke: var(--bg);
  stroke-width: 2;
  transition: filter 0.25s ease, opacity 0.25s ease;
}
#wheel .segment:hover { filter: brightness(1.12); }
#wheel .segment.selected {
  stroke: var(--gold);
  stroke-width: 6;
  filter: brightness(1.18) drop-shadow(0 0 10px var(--ring));
}
#wheel .segment.dimmed { opacity: 0.45; }

#wheel .seg-label {
  font-family: "IBM Plex Sans Arabic", sans-serif;
  font-weight: 700;
  font-size: 24px;
  pointer-events: none;
  user-select: none;
}

.hub {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 27%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid var(--gold);
  background: radial-gradient(circle at 35% 30%, var(--emerald), var(--emerald-deep));
  color: #FFF8E8;
  cursor: pointer;
  z-index: 4;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
  transition: transform 0.18s ease;
}
.hub:hover { transform: translate(-50%, -50%) scale(1.06); }
.hub:active { transform: translate(-50%, -50%) scale(0.96); }
.hub:focus-visible { outline: 3px solid var(--ring); outline-offset: 3px; }

.hub-text {
  font-family: "Aref Ruqaa", serif;
  font-size: clamp(0.95rem, 3.4vw, 1.35rem);
  line-height: 1.5;
  display: block;
}

/* ---------- Result banner & actions ---------- */
.result-banner {
  min-height: 2.4rem;
  margin-top: 1.4rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--terracotta);
  text-align: center;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
  margin-top: 0.6rem;
}

.btn {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0.75rem 1.6rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.3s ease;
}
.btn:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--emerald), var(--emerald-deep));
  color: #FFF8E8;
  box-shadow: var(--shadow-soft);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-ghost {
  background: transparent;
  color: var(--emerald);
  border: 2px solid var(--emerald);
}
[data-theme="dark"] .btn-ghost { color: var(--gold); border-color: var(--gold); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-ghost:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- History ---------- */
.history {
  width: min(92vw, 560px);
  margin-top: 2.2rem;
  background: var(--surface);
  border-radius: 18px;
  padding: 1.1rem 1.3rem 1.3rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--bg-soft);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}
.history-head h2 {
  font-size: 1.05rem;
  color: var(--ink);
  font-weight: 700;
}

.link-btn {
  background: none;
  border: none;
  color: var(--terracotta);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: underline;
}
.link-btn:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

.history-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.history-list li {
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--gold-soft);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.92rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.history-list li time { color: var(--ink-soft); font-size: 0.78rem; }

.history-empty { color: var(--ink-soft); font-size: 0.92rem; }
.history-empty.hidden { display: none; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 1rem;
  animation: fadeIn 0.25s ease;
}
.modal-overlay[hidden] { display: none; }

.modal {
  position: relative;
  background: var(--surface);
  width: min(94vw, 480px);
  max-height: 85vh;
  overflow-y: auto;
  border-radius: 22px;
  border-top: 6px solid var(--gold);
  padding: 2.4rem 1.8rem 1.8rem;
  text-align: center;
  box-shadow: var(--shadow);
  animation: popIn 0.35s cubic-bezier(0.2, 1.2, 0.3, 1);
}

.modal-close {
  position: absolute;
  top: 0.8rem;
  inset-inline-start: 0.8rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}
.modal-close:hover { background: var(--gold-soft); }
.modal-close:focus-visible { outline: 3px solid var(--ring); }

.modal-ornament {
  color: var(--gold);
  font-size: 1.4rem;
  margin-bottom: 0.4rem;
}

.modal-name {
  font-family: "Aref Ruqaa", serif;
  font-size: clamp(1.9rem, 6vw, 2.6rem);
  color: var(--emerald);
  margin-bottom: 0.9rem;
}

.modal-message {
  color: var(--ink);
  font-size: 1.08rem;
  line-height: 1.95;
  margin-bottom: 1.5rem;
}
.modal-message p + p { margin-top: 0.85rem; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: translateY(24px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Confetti ---------- */
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

/* ---------- Footer ---------- */
.site-footer {
  text-align: center;
  padding: 1.4rem 1rem 1.8rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* ---------- Loading / error ---------- */
.load-error {
  margin-top: 2rem;
  background: var(--surface);
  border: 2px solid var(--terracotta);
  border-radius: 14px;
  padding: 1.2rem 1.5rem;
  color: var(--ink);
  max-width: 460px;
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .pointer { top: -20px; }
  .pointer svg { width: 34px; height: 46px; }
  #wheel .seg-label { font-size: 28px; }
  .actions { width: 100%; }
  .btn { flex: 1 1 auto; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  #wheel { transition-duration: 0.5s; }
  .modal, .modal-overlay { animation: none; }
}
