:root {
  --night: #04071a;
  --lapis: #16245a;
  --ivory: #f6efdd;
  --brass: #d3b06b;
  --rose: #eaa9a0;
  --ink: #0a1030;
  --ar: 'Amiri', 'Geeza Pro', 'Noto Naskh Arabic', serif;
  --name: 'Aref Ruqaa', 'Amiri', serif;
  --en: 'IM Fell English', 'Iowan Old Style', Georgia, serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--ivory);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--ar);
  user-select: none;
  -webkit-user-select: none;
}

canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#sky { touch-action: none; cursor: grab; }
#sky.dragging { cursor: grabbing; }
#ink { pointer-events: none; }

#ui { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 2.4s ease 0.6s; }
body.open #ui { opacity: 1; }
#ui button { pointer-events: auto; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
button:focus-visible { outline: 1px solid var(--brass); outline-offset: 6px; border-radius: 4px; }

/* The count, set like a numeral engraved at the head of an atlas plate */
#count {
  position: absolute;
  top: calc(var(--safe-t) + clamp(14px, 3.2vh, 34px));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 0;
  padding: 6px 18px;
  color: var(--brass);
  transition: color 3s ease;
}
#countNum {
  font-family: var(--name);
  font-weight: 700;
  font-size: clamp(34px, 5.4vh, 58px);
  line-height: 1;
  letter-spacing: 0.02em;
  text-shadow: 0 0 22px rgba(211, 176, 107, 0.35);
  display: inline-block;
  transition: transform 0.5s cubic-bezier(.3, 1.6, .5, 1), opacity 0.5s ease;
}
#countCap { font-size: clamp(14px, 1.9vh, 18px); opacity: 0.72; margin-top: 2px; }
#count.wobble #countNum { animation: wobble 0.7s ease; }
#count.flip #countNum { transform: scale(0.2) rotate(-12deg); opacity: 0; }
@keyframes wobble {
  20% { transform: rotate(-7deg) scale(1.06); }
  45% { transform: rotate(6deg) scale(1.06); }
  70% { transform: rotate(-3deg); }
}

/* Name of the constellation she touched, pinned to it in the sky */
#label {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  justify-items: center;
  gap: 1px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.9s ease;
  will-change: transform;
  text-shadow: 0 1px 14px rgba(4, 7, 26, 0.95), 0 0 3px rgba(4, 7, 26, 0.9);
  white-space: nowrap;
}
#label.on { opacity: 1; }
#label .l-ar { font-size: clamp(19px, 2.6vh, 26px); color: var(--brass); }
#label .l-la { font-family: var(--en); font-style: italic; font-size: clamp(13px, 1.7vh, 16px); color: rgba(246, 239, 221, 0.78); }
#label .l-star { font-size: clamp(13px, 1.7vh, 16px); color: rgba(246, 239, 221, 0.9); margin-top: 3px; }
#label .l-star:empty { display: none; }

#verse {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + clamp(84px, 15vh, 150px));
  width: min(88vw, 760px);
  transform: translateX(-50%) translateY(10px);
  text-align: center;
  opacity: 0;
  transition: opacity 0.42s ease, transform 0.42s ease;
}
#verse.on { opacity: 1; transform: translateX(-50%) translateY(0); transition-duration: 1.1s; }
#verse p { margin: 0; }
.v-ar {
  font-size: clamp(21px, 1.5vw + 16px, 34px);
  line-height: 1.75;
  text-shadow: 0 1px 18px rgba(4, 7, 26, 0.95), 0 0 4px rgba(4, 7, 26, 0.85);
  text-wrap: balance;
}
.v-en {
  font-family: var(--en);
  font-style: italic;
  font-size: clamp(15px, 0.5vw + 13px, 20px);
  line-height: 1.5;
  margin-top: 6px !important;
  color: rgba(246, 239, 221, 0.8);
  text-shadow: 0 1px 14px rgba(4, 7, 26, 0.95), 0 0 3px rgba(4, 7, 26, 0.85);
  text-wrap: balance;
}
#verse::before {
  content: '';
  position: absolute;
  inset: -34px -8vw;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(34, 20, 64, 0.62), rgba(34, 20, 64, 0.34) 55%, rgba(34, 20, 64, 0));
  opacity: 0;
  transition: opacity 3s ease;
  pointer-events: none;
}
body.dawn #verse::before { opacity: 1; }
body.dawn .v-ar, body.dawn .v-en { text-shadow: 0 1px 14px rgba(30, 18, 60, 0.9), 0 0 4px rgba(30, 18, 60, 0.8); }
body.dawn .v-en { color: rgba(246, 239, 221, 0.92); }
body.dawn #tally, body.dawn #sound { color: rgba(246, 239, 221, 0.9); }

#hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + clamp(26px, 5vh, 46px));
  transform: translateX(-50%);
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 1px;
  opacity: 0;
  transition: opacity 1.2s ease;
  white-space: nowrap;
  text-shadow: 0 1px 12px rgba(4, 7, 26, 0.9);
}
#hint.on { opacity: 0.86; animation: breathe 3.4s ease-in-out infinite; }
#hint .h-ar { font-size: clamp(16px, 2.1vh, 19px); color: var(--brass); }
#hint .h-en { font-family: var(--en); font-style: italic; font-size: clamp(13px, 1.6vh, 15px); color: rgba(246, 239, 221, 0.7); }
@keyframes breathe { 50% { opacity: 0.45; } }

#tally {
  position: absolute;
  inset-inline-start: calc(18px + env(safe-area-inset-left, 0px));
  bottom: calc(var(--safe-b) + 18px);
  font-size: 15px;
  color: rgba(246, 239, 221, 0.6);
  opacity: 0;
  transition: opacity 1s ease;
}
#tally.on { opacity: 1; }

#sound, #phase {
  position: absolute;
  bottom: calc(var(--safe-b) + 12px);
  min-width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: rgba(246, 239, 221, 0.78);
  border-radius: 22px;
}
#sound { inset-inline-end: calc(12px + env(safe-area-inset-right, 0px)); }
#phase { inset-inline-end: calc(62px + env(safe-area-inset-right, 0px)); padding: 0 12px; font-size: 16px; color: var(--brass); }
#sound .off { opacity: 0; transition: opacity 0.3s; }
#sound.muted .off { opacity: 1; }
#sound.muted { color: rgba(246, 239, 221, 0.45); }
#sound.loading { animation: breathe 1.6s ease-in-out infinite; }
[hidden] { display: none !important; }

/* Threshold */
#gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 90% at 50% 110%, #101c4a 0%, #070c26 45%, #03050f 100%);
  transition: opacity 2.6s ease, visibility 0s linear 2.6s;
  z-index: 5;
}
body.open #gate { opacity: 0; visibility: hidden; pointer-events: none; }
.gate-in { width: min(86vw, 640px); text-align: center; display: grid; justify-items: center; }
.gate-in p { margin: 0; }
.g-ar { font-size: clamp(25px, 2vw + 18px, 42px); line-height: 1.7; text-wrap: balance; opacity: 0; animation: rise 2.2s ease 0.4s forwards; }
.g-en { font-family: var(--en); font-style: italic; font-size: clamp(16px, 0.6vw + 14px, 21px); color: rgba(246, 239, 221, 0.72); margin-top: 8px !important; opacity: 0; animation: rise 2.2s ease 1.1s forwards; }
#enter {
  margin-top: clamp(36px, 8vh, 72px);
  width: clamp(132px, 22vh, 168px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(211, 176, 107, 0.55);
  display: grid;
  place-content: center;
  gap: 2px;
  color: var(--brass);
  position: relative;
  opacity: 0;
  animation: rise 2s ease 2.2s forwards;
  transition: background 0.5s ease, transform 0.5s ease;
}
#enter::before, #enter::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1px solid rgba(211, 176, 107, 0.4);
  animation: ring 3.6s ease-out infinite;
}
#enter::after { animation-delay: 1.8s; }
#enter:hover { background: rgba(211, 176, 107, 0.08); }
#enter:active { transform: scale(0.96); }
.e-ar { font-size: clamp(20px, 2.9vh, 25px); }
.e-en { font-family: var(--en); font-style: italic; font-size: clamp(14px, 1.9vh, 16px); color: rgba(246, 239, 221, 0.7); }
.g-note { margin-top: 30px !important; display: grid; gap: 2px; opacity: 0; animation: rise 2s ease 3.2s forwards; min-height: 3em; }
.n-ar { font-size: 17px; color: rgba(246, 239, 221, 0.78); }
.n-en { font-family: var(--en); font-style: italic; font-size: 14px; color: rgba(246, 239, 221, 0.55); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes ring { from { transform: scale(1); opacity: 0.7; } to { transform: scale(1.55); opacity: 0; } }

/* The discovery record, set like a plate from an old star atlas */
#plate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 8, 34, 0.38);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  opacity: 0;
  transition: opacity 1.4s ease;
  z-index: 4;
  overflow-y: auto;
}
#plate.on { opacity: 1; }
.plate-in {
  width: min(92vw, 470px);
  padding: clamp(24px, 4.4vh, 40px) clamp(20px, 5vw, 38px);
  text-align: center;
  background: linear-gradient(180deg, rgba(14, 20, 62, 0.82), rgba(8, 11, 40, 0.88));
  border: 1px solid rgba(211, 176, 107, 0.6);
  outline: 1px solid rgba(211, 176, 107, 0.28);
  outline-offset: -7px;
  border-radius: 2px;
  box-shadow: 0 30px 80px rgba(2, 3, 14, 0.55);
}
#plateTitle { margin: 0; font-family: var(--name); font-weight: 700; font-size: clamp(38px, 7vh, 58px); line-height: 1.25; color: var(--brass); }
.plate-sub { margin: 0 0 18px; font-family: var(--en); font-style: italic; font-size: 19px; color: rgba(246, 239, 221, 0.8); }
#plateRows { margin: 0; display: grid; gap: 0; }
#plateRows .row { padding: 11px 0; border-top: 1px solid rgba(211, 176, 107, 0.22); display: grid; gap: 2px; }
#plateRows dt { font-size: 15px; color: rgba(211, 176, 107, 0.9); }
#plateRows dd { margin: 0; font-size: clamp(18px, 2.5vh, 21px); line-height: 1.55; }
#plateRows .en { font-family: var(--en); font-style: italic; font-size: 14.5px; color: rgba(246, 239, 221, 0.62); }
#plateClose { margin-top: 20px; padding: 10px 22px; min-height: 44px; border: 1px solid rgba(211, 176, 107, 0.55); border-radius: 22px; color: var(--brass); font-size: 17px; transition: background 0.4s; }
#plateClose:hover { background: rgba(211, 176, 107, 0.1); }

.nojs { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; z-index: 9; background: var(--night); }

@media (max-height: 520px) {
  #verse { bottom: calc(var(--safe-b) + 62px); }
  #enter { margin-top: 22px; width: 112px; }
  .g-note { margin-top: 12px !important; }
}

@media (prefers-reduced-motion: reduce) {
  #enter::before, #enter::after, #hint.on, #sound.loading { animation: none; }
  .g-ar, .g-en, #enter, .g-note { animation-duration: 0.01s; animation-delay: 0s; }
}
