:root {
  --night: #100a20;
  --night-2: #1a1136;
  --night-3: #261a4a;
  --lav: #cdbcf2;
  --lav-soft: #e9e0fa;
  --mauve: #b78fd0;
  --mauve-deep: #7d5a9c;
  --violet: #9a7cf0;
  --off: #f7f3fb;
  --line: rgba(205, 188, 242, .22);
  --glass: rgba(26, 17, 54, .72);
  --composer-h: 150px;
  --ease: cubic-bezier(.22, .8, .25, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--night) 0%, var(--night-2) 55%, #21143f 100%) fixed;
  color: var(--off);
  font-family: 'Tajawal', 'Segoe UI', Tahoma, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  overflow-x: hidden;
}
body.is-closed, body.is-opening { overflow: hidden; height: 100dvh; }
button, textarea, input { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

#sky, #fx, .nebula { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#sky { z-index: 0; }
.nebula {
  z-index: 0;
  background:
    radial-gradient(60% 45% at 82% 12%, rgba(154, 124, 240, .20), transparent 70%),
    radial-gradient(55% 40% at 10% 38%, rgba(183, 143, 208, .15), transparent 70%),
    radial-gradient(70% 45% at 55% 100%, rgba(205, 188, 242, .10), transparent 70%);
}
#fx { z-index: 30; }

/* ───────── المقدمة ───────── */
#app { position: relative; z-index: 1; padding-bottom: calc(var(--composer-h) + 12px); }
.top { text-align: center; padding: 22px 16px 6px; max-width: 760px; margin: 0 auto; }
.teacher {
  margin: 0;
  font-family: 'El Messiri', 'Tajawal', sans-serif;
  font-weight: 600;
  font-size: clamp(1.35rem, 4.6vw, 1.9rem);
  line-height: 1.4;
  color: var(--off);
  text-shadow: 0 0 26px rgba(205, 188, 242, .35);
}
.meta { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 8px; }
.meta li {
  font-size: .82rem;
  padding: 2px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--lav-soft);
  background: rgba(205, 188, 242, .06);
}
.meta li[lang="en"] { font-family: 'Segoe UI', system-ui, sans-serif; letter-spacing: .01em; }
.welcome { margin: 14px auto 0; max-width: 30em; color: var(--lav); font-size: .98rem; }
.count { margin: 4px 0 0; font-size: .85rem; color: rgba(233, 224, 250, .7); }
.count strong { color: var(--off); font-weight: 700; font-size: 1rem; margin-inline-start: 4px; }
.empty { text-align: center; color: rgba(233, 224, 250, .55); margin: -40vh 0 0; position: relative; pointer-events: none; }

/* ───────── النجوم ───────── */
#stage { position: relative; width: 100%; max-width: 1100px; margin: 0 auto; min-height: 300px; }
.star {
  position: absolute;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: left .6s var(--ease), top .6s var(--ease), opacity .5s;
  --c: #fff;
  --g: 205, 188, 242;
}
.star.tone-1 { --c: #dccbff; --g: 160, 130, 255; }
.star.tone-2 { --c: #f1c6f3; --g: 214, 140, 222; }
.star::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(var(--g), .55) 0%, rgba(var(--g), .16) 38%, transparent 68%);
  animation: breathe 4.2s ease-in-out var(--d, 0s) infinite;
}
.star svg {
  position: relative;
  width: calc(22px * var(--s, 1));
  height: calc(22px * var(--s, 1));
  fill: var(--c);
  filter: drop-shadow(0 0 4px rgba(var(--g), .95));
  animation: twinkle 4.2s ease-in-out var(--d, 0s) infinite;
  transition: transform .25s var(--ease);
}
.star:hover svg, .star:focus-visible svg { transform: scale(1.3) rotate(12deg); }
.star:focus-visible { outline: 2px solid var(--lav); outline-offset: 0; }
.star.mine::after {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 1px dashed rgba(var(--g), .55);
  animation: spin 18s linear infinite;
}
.star.unborn { opacity: 0; pointer-events: none; }
.star.landing svg { animation: land 1s var(--ease) both; }
.star.landing::before { animation: halo 1.4s ease-out both; }
.star.fade-in { animation: fadein 1.2s ease both; }

@keyframes twinkle { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .62; transform: scale(.86); } }
@keyframes breathe { 0%, 100% { opacity: .9; transform: scale(1); } 50% { opacity: .45; transform: scale(.8); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes land { 0% { transform: scale(.2) rotate(-90deg); opacity: 0; } 55% { transform: scale(1.7) rotate(8deg); opacity: 1; } 100% { transform: scale(1) rotate(0); } }
@keyframes halo { 0% { transform: scale(.3); opacity: 0; } 35% { transform: scale(2.4); opacity: 1; } 100% { transform: scale(1); opacity: .9; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ───────── الكتابة ───────── */
#composer {
  position: fixed;
  z-index: 20;
  inset-inline: 0;
  bottom: 0;
  margin: 0 auto;
  width: min(100% - 20px, 620px);
  padding: 12px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--glass);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 -10px 40px rgba(8, 4, 20, .5);
}
#composer textarea {
  display: block;
  width: 100%;
  resize: none;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(247, 243, 251, .07);
  color: var(--off);
  font-size: 16px;
  line-height: 1.6;
  outline: none;
  transition: border-color .2s, background .2s;
}
#composer textarea::placeholder { color: rgba(233, 224, 250, .5); }
#composer textarea:focus { border-color: var(--lav); background: rgba(247, 243, 251, .11); }
.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.tones { border: 0; margin: 0; padding: 0; display: flex; align-items: center; gap: 8px; min-width: 0; }
.tones legend { float: inline-start; padding: 0; margin-inline-end: 6px; font-size: .8rem; color: rgba(233, 224, 250, .7); }
.tones label { cursor: pointer; display: grid; place-items: center; width: 32px; height: 32px; position: relative; }
.tones input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.sw { width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 0 0 2px transparent; transition: box-shadow .2s, transform .2s; }
.sw.t0 { background: #fff; }
.sw.t1 { background: #b9a2ff; }
.sw.t2 { background: #dc9be3; }
.tones input:checked + .sw { box-shadow: 0 0 0 2px var(--night-2), 0 0 0 4px var(--lav), 0 0 14px rgba(205, 188, 242, .8); transform: scale(1.1); }
.tones input:focus-visible + .sw { outline: 2px solid #fff; outline-offset: 5px; }
.left { margin-inline-start: auto; font-size: .78rem; color: rgba(233, 224, 250, .5); font-variant-numeric: tabular-nums; }
#send, #open, .ghost {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
  transition: transform .2s var(--ease), box-shadow .2s, opacity .2s;
}
#send, #open {
  padding: 9px 22px;
  color: #1c1238;
  background: linear-gradient(135deg, #f3ecff, var(--lav) 55%, #c3a0dd);
  box-shadow: 0 6px 22px rgba(154, 124, 240, .4);
  white-space: nowrap;
}
#send:hover, #open:hover { transform: translateY(-1px); box-shadow: 0 8px 28px rgba(154, 124, 240, .6); }
#send:active, #open:active { transform: scale(.97); }
#send:disabled { opacity: .55; cursor: default; transform: none; }
#send:focus-visible, #open:focus-visible, .ghost:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.status { margin: 6px 2px 0; min-height: 1.5em; font-size: .86rem; color: var(--lav-soft); }
.status.err { color: #ffc9d6; }

/* ───────── بطاقة التعليق ───────── */
.card-wrap {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 6, 22, .62);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  animation: fadein .25s ease both;
}
.card {
  position: relative;
  width: min(100%, 440px);
  max-height: 80dvh;
  overflow: auto;
  padding: 34px 24px 20px;
  text-align: center;
  background: linear-gradient(160deg, #fbf8ff, #efe6fb);
  color: #2a1c4d;
  border-radius: 22px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .5), 0 24px 70px rgba(8, 4, 20, .6), 0 0 60px rgba(154, 124, 240, .35);
  animation: rise .4s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
.card-star {
  display: block;
  width: 26px;
  height: 26px;
  margin: 0 auto 12px;
  background: var(--mauve-deep);
  clip-path: polygon(50% 0, 58% 42%, 100% 50%, 58% 58%, 50% 100%, 42% 58%, 0 50%, 42% 42%);
}
.card-text { margin: 0; font-size: 1.08rem; line-height: 1.95; white-space: pre-wrap; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.card-note { margin: 14px 0 0; font-size: .84rem; color: var(--mauve-deep); background: rgba(183, 143, 208, .16); border-radius: 10px; padding: 6px 10px; }
.card-date { margin: 14px 0 0; font-size: .8rem; color: #7a6a99; }
.ghost { margin-top: 14px; padding: 7px 26px; background: transparent; color: var(--mauve-deep); box-shadow: inset 0 0 0 1px rgba(125, 90, 156, .4); }
.ghost:hover { background: rgba(125, 90, 156, .08); }

/* ───────── الستارة ───────── */
#curtain { position: fixed; inset: 0; z-index: 50; overflow: hidden; }
.drape {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50.5%;
  background:
    linear-gradient(180deg, rgba(16, 10, 32, .0) 0%, rgba(16, 10, 32, .12) 70%, rgba(16, 10, 32, .5) 100%),
    repeating-linear-gradient(90deg,
      #57397a 0, #8a64ad 16px, #b996d6 30px, #cdb4e6 36px, #9a74bd 48px, #6a4790 64px, #57397a 76px);
  box-shadow: inset 0 -40px 60px rgba(16, 10, 32, .35);
  transition: transform 2.3s cubic-bezier(.7, 0, .18, 1);
  will-change: transform;
}
.drape.left { left: 0; transform-origin: left center; box-shadow: inset -22px 0 40px rgba(16, 10, 32, .45), inset 0 -40px 60px rgba(16, 10, 32, .35); }
.drape.right { right: 0; transform-origin: right center; box-shadow: inset 22px 0 40px rgba(16, 10, 32, .45), inset 0 -40px 60px rgba(16, 10, 32, .35); }
.valance {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 74px;
  background:
    radial-gradient(circle at 50% 0, #6f4c96 0 62%, transparent 63%) 0 28px / 92px 92px repeat-x,
    linear-gradient(180deg, #4a2f6b, #6f4c96 60%, #7d5aa5);
  filter: drop-shadow(0 10px 14px rgba(10, 6, 22, .55));
  transition: transform 1.6s cubic-bezier(.6, 0, .3, 1) .9s;
}
.valance::after { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 6px; background: linear-gradient(90deg, #cdbcf2, #f3ecff, #cdbcf2); opacity: .7; }
.intro {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -46%);
  width: min(100% - 32px, 430px);
  padding: 26px 24px 24px;
  text-align: center;
  background: rgba(22, 14, 46, .84);
  border: 1px solid rgba(205, 188, 242, .35);
  border-radius: 24px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 30px 80px rgba(8, 4, 20, .6), 0 0 0 6px rgba(205, 188, 242, .06);
  transition: opacity .5s ease, transform .6s var(--ease);
}
.intro-kicker { margin: 0 0 14px; font-family: 'El Messiri', 'Tajawal', sans-serif; font-size: 1.3rem; font-weight: 600; color: var(--off); }
.lesson { margin: 0 0 20px; text-align: start; }
.lesson > div { display: flex; gap: 12px; align-items: baseline; padding: 8px 2px; border-bottom: 1px solid rgba(205, 188, 242, .14); }
.lesson > div:last-child { border-bottom: 0; }
.lesson dt { flex: 0 0 4.2em; font-size: .82rem; color: var(--mauve); }
.lesson dd { margin: 0; flex: 1; color: var(--off); font-weight: 500; text-align: start; }
.lesson dd[lang="en"] { font-family: 'Segoe UI', system-ui, sans-serif; text-align: right; }
#open { padding: 11px 34px; font-size: 1.02rem; }

.is-opening .intro, .is-open .intro { opacity: 0; transform: translate(-50%, -40%) scale(.96); pointer-events: none; }
.is-opening .drape.left, .is-open .drape.left { transform: translateX(-12%) scaleX(.04); }
.is-opening .drape.right, .is-open .drape.right { transform: translateX(12%) scaleX(.04); }
.is-opening .valance, .is-open .valance { transform: translateY(-110%); }
.is-opening #curtain { pointer-events: none; }
.is-open #curtain { display: none; }

.is-closed #composer { transform: translateY(110%); }
#composer { transition: transform .9s var(--ease) 1.2s; }
.is-closed .top, .is-closed #stage { opacity: 0; }
.top, #stage { transition: opacity 1.4s ease .7s; }

@media (max-width: 420px) {
  .tones legend { display: none; }
  #send { padding: 9px 18px; }
  .top { padding-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; animation-iteration-count: 1 !important; }
  .drape, .valance { transition: opacity .5s ease !important; }
  .is-opening .drape, .is-opening .valance { transform: none !important; opacity: 0; }
  .star { transition: opacity .5s; }
  #composer, .top, #stage { transition-delay: 0s; }
}
