:root {
  color-scheme: dark;
  --navy: #081523;
  --ink: #0d2033;
  --ink-2: #102a42;
  --ivory: #f3e9d2;
  --muted: #b9b09d;
  --gold: #c99b42;
  --gold-light: #e6bd65;
  --green: #276047;
  --red: #9e3436;
  --yellow: #d4a63e;
  --border: rgba(201, 155, 66, 0.38);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
  font-family: "Noto Kufi Arabic", "Noto Sans Arabic", Tahoma, Arial, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--navy);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ivory);
  background:
    radial-gradient(circle at 12% 12%, rgba(39, 96, 71, 0.16), transparent 27rem),
    radial-gradient(circle at 88% 88%, rgba(158, 52, 54, 0.11), transparent 30rem),
    var(--navy);
}

.page-texture {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.18;
  pointer-events: none;
  background-image:
    linear-gradient(45deg, transparent 46%, rgba(201, 155, 66, 0.17) 47%, transparent 49%),
    linear-gradient(-45deg, transparent 46%, rgba(201, 155, 66, 0.12) 47%, transparent 49%);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, transparent, black 12%, black 88%, transparent);
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--ivory);
  outline-offset: 4px;
}

.masthead {
  width: min(1540px, calc(100% - 32px));
  min-height: 82px;
  margin: 14px auto 0;
  padding: 12px clamp(16px, 2vw, 28px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border: 1px solid var(--border);
  background: rgba(8, 21, 35, 0.87);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.18);
}

.brand-lockup,
.header-meta,
.admin-pill,
.live-pill,
.rail-heading-row,
.section-title-row,
.official-note {
  display: flex;
  align-items: center;
}

.brand-lockup {
  gap: 16px;
}

.sun-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  color: var(--gold-light);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--gold-light);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.brand-lockup h1 {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.75rem);
  line-height: 1.35;
}

.header-meta {
  gap: 12px;
}

.admin-pill,
.live-pill {
  min-height: 38px;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid rgba(201, 155, 66, 0.3);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  background: rgba(13, 32, 51, 0.75);
}

.admin-pill svg {
  width: 19px;
  fill: var(--gold-light);
}

.live-pill i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(212, 166, 62, 0.12);
}

.live-pill.is-open i {
  background: #54a56f;
  box-shadow: 0 0 0 4px rgba(84, 165, 111, 0.13);
}

.live-pill.is-error i {
  background: #c85d5d;
  box-shadow: 0 0 0 4px rgba(200, 93, 93, 0.13);
}

main {
  width: min(1540px, calc(100% - 32px));
  margin: 12px auto 24px;
}

.gate-card {
  width: min(520px, 100%);
  min-height: 420px;
  margin: clamp(42px, 9vh, 110px) auto;
  padding: 44px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1px solid var(--border);
  background: rgba(13, 32, 51, 0.84);
  box-shadow: var(--shadow);
}

.gate-card h2 {
  margin-bottom: 12px;
  font-size: 1.55rem;
}

.gate-card > p:last-child {
  max-width: 36ch;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.9;
}

.gate-medallion {
  width: 150px;
  height: 150px;
  margin-bottom: 24px;
  overflow: hidden;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--gold), 0 0 0 8px rgba(201, 155, 66, 0.12);
}

.gate-medallion img,
.hub-medallion img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.loader {
  width: 46px;
  height: 46px;
  margin-bottom: 24px;
  border: 3px solid rgba(201, 155, 66, 0.18);
  border-top-color: var(--gold-light);
  border-radius: 50%;
  animation: loader-spin 0.9s linear infinite;
}

@keyframes loader-spin {
  to { transform: rotate(360deg); }
}

.workspace {
  height: calc(100dvh - 126px);
  min-height: 600px;
  max-height: 980px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(330px, 27vw, 410px);
  grid-template-areas: "wheel rail";
  direction: ltr;
  gap: 14px;
}

.wheel-stage,
.raffle-rail {
  direction: rtl;
}

.wheel-stage {
  grid-area: wheel;
  position: relative;
  min-width: 0;
  padding: clamp(14px, 2vw, 28px) clamp(10px, 2vw, 26px) 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(201, 155, 66, 0.18);
  background: rgba(5, 16, 28, 0.42);
  overflow: hidden;
}

.wheel-frame {
  position: relative;
  width: min(68vw, calc(100dvh - 286px), 850px);
  aspect-ratio: 1;
  flex: 0 1 auto;
  filter: drop-shadow(0 24px 32px rgba(0, 0, 0, 0.36));
}

#wheel-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.pointer {
  position: absolute;
  z-index: 5;
  top: -1.5%;
  left: 50%;
  width: 9%;
  height: 14%;
  transform: translateX(-50%);
  pointer-events: none;
}

.pointer::before {
  content: "";
  position: absolute;
  inset: 0 15% 22%;
  clip-path: polygon(50% 100%, 0 0, 100% 0);
  background: linear-gradient(90deg, #a66b19, #f2c969 48%, #b77a20);
  border-radius: 50% 50% 18% 18%;
  box-shadow: 0 0 0 2px #5e3a0b, 0 7px 10px rgba(0, 0, 0, 0.4);
}

.pointer i {
  position: absolute;
  left: 50%;
  bottom: 14%;
  width: 18%;
  aspect-ratio: 1;
  transform: translateX(-50%);
  border: 2px solid #68420f;
  border-radius: 50%;
  background: var(--gold-light);
}

.hub-medallion {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 50%;
  width: 28%;
  aspect-ratio: 1;
  overflow: hidden;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--navy);
  box-shadow:
    0 0 0 2px #5d3b0b,
    0 0 0 7px var(--gold),
    0 0 0 10px #6d4510,
    0 8px 22px rgba(0, 0, 0, 0.42);
}

.wheel-actions {
  width: min(620px, 88%);
  margin-top: 14px;
  text-align: center;
}

.spin-button {
  position: relative;
  width: 100%;
  min-height: 70px;
  padding: 13px 72px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border: 2px solid #7d5013;
  border-radius: 4px;
  color: #17202a;
  background: linear-gradient(180deg, #e3b64f, #bd8625);
  box-shadow:
    inset 0 0 0 3px rgba(255, 237, 173, 0.22),
    0 10px 24px rgba(0, 0, 0, 0.26);
  cursor: pointer;
  font-size: clamp(1.25rem, 2.4vw, 1.8rem);
  font-weight: 900;
  transition: transform 160ms ease, filter 160ms ease;
}

.spin-button:not(:disabled):hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

.spin-button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.55) brightness(0.68);
}

.button-sun {
  position: absolute;
  right: 24px;
}

.button-spinner {
  position: absolute;
  left: 24px;
  width: 24px;
  height: 24px;
  border: 3px solid rgba(23, 32, 42, 0.25);
  border-top-color: #17202a;
  border-radius: 50%;
  opacity: 0;
}

.spin-button.is-spinning .button-spinner {
  opacity: 1;
  animation: loader-spin 0.85s linear infinite;
}

.official-note {
  justify-content: center;
  gap: 8px;
  margin: 12px auto 0;
  color: var(--muted);
  font-size: 0.77rem;
  line-height: 1.7;
}

.official-note svg {
  width: 18px;
  flex: 0 0 auto;
  fill: var(--gold-light);
}

.winner-card {
  position: absolute;
  z-index: 7;
  top: 47%;
  right: clamp(12px, 2vw, 34px);
  width: min(290px, 30%);
  padding: 22px 18px;
  text-align: center;
  color: #182333;
  border: 4px double #8b5b19;
  background: var(--ivory);
  box-shadow: 0 24px 44px rgba(0, 0, 0, 0.38);
  animation: winner-in 480ms cubic-bezier(0.2, 0.85, 0.25, 1.15) both;
}

@keyframes winner-in {
  from { opacity: 0; transform: translateY(16px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.winner-sun {
  display: block;
  color: var(--gold);
  font-size: 2rem;
}

.winner-card p {
  margin: 4px 0 5px;
  color: var(--green);
  font-size: 0.8rem;
  font-weight: 900;
}

.winner-card h2 {
  margin-bottom: 12px;
  font-size: clamp(1.05rem, 1.7vw, 1.45rem);
}

.winner-prize {
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid rgba(139, 91, 25, 0.38);
}

.winner-prize span {
  color: #6f6553;
  font-size: 0.7rem;
}

.raffle-rail {
  grid-area: rail;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(210px, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--border);
  background: rgba(8, 27, 44, 0.93);
  box-shadow: var(--shadow);
}

.raffle-heading,
.stat-grid,
.participant-section,
.prize-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.prize-section {
  border-bottom: 0;
}

.rail-heading-row,
.section-title-row {
  justify-content: space-between;
  gap: 16px;
}

.raffle-heading h2 {
  margin: 10px 0 6px;
  font-size: clamp(1.15rem, 1.5vw, 1.45rem);
  line-height: 1.6;
}

.raffle-description {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.75;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 8px;
  border: 1px solid var(--border);
  color: var(--gold-light);
  background: transparent;
  cursor: pointer;
}

.icon-button svg {
  width: 100%;
  fill: currentColor;
}

.icon-button.is-loading svg {
  animation: loader-spin 0.8s linear infinite;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-item {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-item + .stat-item {
  padding-right: 12px;
  border-right: 1px solid rgba(201, 155, 66, 0.24);
}

.stat-item svg {
  width: 26px;
  flex: 0 0 auto;
  fill: var(--gold-light);
}

.stat-item span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
}

.stat-item strong {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
  direction: ltr;
  text-align: right;
}

.participant-section {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-title-row h3 {
  margin: 0;
  color: var(--gold-light);
  font-size: 0.88rem;
}

.section-title-row > span {
  color: var(--muted);
  font-size: 0.7rem;
}

.participant-list {
  flex: 1 1 auto;
  min-height: 120px;
  margin: 14px 0 0;
  padding: 0 0 0 5px;
  overflow-y: auto;
  list-style: none;
  scrollbar-color: var(--gold) rgba(255, 255, 255, 0.05);
  scrollbar-width: thin;
}

.participant-list li {
  min-height: 43px;
  padding: 8px 2px;
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 9px;
  border-bottom: 1px solid rgba(243, 233, 210, 0.08);
  font-size: 0.79rem;
}

.participant-list .ticket-number {
  direction: ltr;
  color: var(--gold-light);
  font-variant-numeric: tabular-nums;
}

.participant-avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(201, 155, 66, 0.45);
  border-radius: 50%;
  color: var(--gold-light);
  font-size: 0.72rem;
  font-weight: 800;
}

.participant-list li.is-winner {
  padding-inline: 8px;
  color: var(--ivory);
  background: rgba(39, 96, 71, 0.34);
  border: 1px solid rgba(201, 155, 66, 0.38);
}

.participant-list li.empty-row {
  display: flex;
  justify-content: center;
  color: var(--muted);
}

.prize-list {
  margin-top: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prize-chip,
.empty-chip {
  padding: 8px 10px;
  border: 1px solid rgba(201, 155, 66, 0.36);
  color: var(--ivory);
  background: rgba(13, 32, 51, 0.8);
  font-size: 0.72rem;
}

.prize-chip:first-child {
  color: #182333;
  background: var(--gold-light);
}

.result-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(201, 155, 66, 0.26);
}

.result-block h3 {
  margin: 0 0 8px;
  color: var(--gold-light);
  font-size: 0.82rem;
}

.result-list {
  max-height: 126px;
  margin: 0;
  padding: 0 22px 0 3px;
  overflow-y: auto;
  color: var(--ivory);
  scrollbar-color: var(--gold) rgba(255, 255, 255, 0.05);
  scrollbar-width: thin;
}

.result-list li {
  padding: 5px 0;
  font-size: 0.74rem;
  line-height: 1.6;
}

.result-list strong {
  color: var(--gold-light);
}

.confirm-dialog {
  width: min(470px, calc(100% - 30px));
  padding: 0;
  border: 1px solid var(--gold);
  color: var(--ivory);
  background: var(--ink);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
}

.confirm-dialog::backdrop {
  background: rgba(2, 9, 16, 0.78);
  backdrop-filter: blur(4px);
}

.confirm-dialog form {
  padding: 30px;
  text-align: center;
}

.dialog-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border: 2px solid var(--gold);
  border-radius: 50%;
  color: var(--gold-light);
  font-size: 1.5rem;
  font-weight: 900;
}

.confirm-dialog h2 {
  margin-bottom: 10px;
}

.confirm-dialog p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.85;
}

.dialog-actions {
  margin-top: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.secondary-button,
.confirm-button {
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  color: var(--ivory);
  background: transparent;
  cursor: pointer;
  font-weight: 800;
}

.confirm-button {
  border-color: #8a5c17;
  color: #162130;
  background: var(--gold-light);
}

.toast {
  position: fixed;
  z-index: 20;
  right: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  max-width: min(520px, calc(100% - 30px));
  padding: 12px 18px;
  transform: translateX(50%);
  border: 1px solid var(--border);
  color: var(--ivory);
  background: #102a42;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.45);
  font-size: 0.8rem;
  line-height: 1.7;
}

.toast.is-error {
  border-color: rgba(200, 93, 93, 0.7);
  background: #401d25;
}

@media (max-width: 1100px) {
  .wheel-frame {
    width: min(62vw, calc(100dvh - 286px), 720px);
  }

  .winner-card {
    top: auto;
    right: 22px;
    bottom: 125px;
    width: min(250px, 34%);
  }
}

@media (max-width: 900px) {
  .masthead,
  main {
    width: min(100% - 20px, 720px);
  }

  .workspace {
    height: auto;
    min-height: auto;
    max-height: none;
    grid-template-columns: 1fr;
    grid-template-areas: "wheel" "rail";
  }

  .wheel-stage {
    min-height: auto;
    padding-top: 24px;
  }

  .wheel-frame {
    width: min(88vw, 660px);
  }

  .raffle-rail {
    min-height: 680px;
    overflow: hidden;
  }
}

@media (max-width: 600px) {
  .masthead {
    min-height: 70px;
    margin-top: 8px;
    padding: 10px 12px;
  }

  .brand-lockup {
    gap: 9px;
  }

  .sun-mark {
    width: 34px;
    height: 34px;
  }

  .brand-lockup .eyebrow,
  .admin-pill {
    display: none;
  }

  .brand-lockup h1 {
    font-size: 0.98rem;
  }

  .live-pill {
    padding: 6px 9px;
    font-size: 0.68rem;
  }

  main {
    margin-top: 8px;
  }

  .wheel-stage {
    padding: 18px 4px 14px;
  }

  .wheel-frame {
    width: min(94vw, 520px);
  }

  .wheel-actions {
    width: calc(100% - 20px);
    margin-top: 8px;
  }

  .spin-button {
    min-height: 60px;
    padding: 10px 58px;
    font-size: 1.25rem;
  }

  .button-sun {
    right: 18px;
  }

  .button-spinner {
    left: 18px;
  }

  .winner-card {
    top: 45%;
    right: 50%;
    bottom: auto;
    width: min(270px, 75%);
    transform: translate(50%, -50%);
    animation-name: winner-in-mobile;
  }

  @keyframes winner-in-mobile {
    from { opacity: 0; transform: translate(50%, calc(-50% + 18px)) scale(0.94); }
    to { opacity: 1; transform: translate(50%, -50%) scale(1); }
  }

  .raffle-heading,
  .stat-grid,
  .participant-section,
  .prize-section {
    padding-inline: 15px;
  }

  .raffle-rail {
    min-height: 640px;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
