/* Our Sky: the experience */
html, body.sky-page { height: 100%; overflow: hidden; overscroll-behavior: none; }
body.sky-page { position: fixed; inset: 0; touch-action: none; -webkit-user-select: none; user-select: none; }

.stage { position: fixed; inset: 0; overflow: hidden; background: var(--night); cursor: grab; }
.stage.dragging { cursor: grabbing; }
.sky-gl, .sky-ov { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.markers { position: absolute; inset: 0; pointer-events: none; z-index: 2; }

/* memory stars (real buttons, positioned over the canvas every frame) */
.mstar {
  position: absolute; left: 0; top: 0; width: 56px; height: 56px; margin: -28px 0 0 -28px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; pointer-events: auto; will-change: transform;
  -webkit-tap-highlight-color: transparent; transition: opacity 0.6s ease;
}
.mstar .em {
  position: absolute; left: 50%; top: 44px; transform: translateX(-50%);
  font-size: 15px; line-height: 1; padding: 4px 6px; border-radius: 999px;
  background: rgba(6, 10, 24, 0.55); border: 1px solid rgba(255, 255, 255, 0.12);
  white-space: nowrap; transition: transform 0.3s ease, opacity 0.3s ease;
}
.mstar .num { font-family: var(--mono); font-size: 11px; color: var(--ink-2); margin-left: 4px; vertical-align: 1px; }
.mstar.opened .em { opacity: 0.6; transform: translateX(-50%) scale(0.86); }
.mstar:focus-visible { outline: 2px solid var(--accent); outline-offset: -6px; }
body:not([data-state="explore"]) .mstar { opacity: 0; pointer-events: none; }

/* HUD */
.hud-top {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: calc(var(--sat) + 10px) calc(var(--sar) + 12px) 0 calc(var(--sal) + 16px); pointer-events: none;
  transition: opacity 0.8s ease;
}
.hud-top > * { pointer-events: auto; }
.hud-names { margin: 10px 0 0; font-family: var(--display); font-size: 17px; letter-spacing: 0.04em; color: var(--ink); text-shadow: 0 1px 12px rgba(0, 0, 0, 0.6); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-kicker { font-family: var(--mono); font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent); display: block; margin-bottom: 1px; }
.hud-btns { display: flex; gap: 6px; flex: none; }
.ibtn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass);
  display: grid; place-items: center; padding: 0; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  -webkit-tap-highlight-color: transparent; transition: background 0.2s ease, border-color 0.2s ease;
}
.ibtn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ibtn[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 22%, var(--glass)); }
#btn-sound .ic-on { display: none; }
#btn-sound[aria-pressed="true"] .ic-on { display: block; }
#btn-sound[aria-pressed="true"] .ic-off { display: none; }

.demo-ribbon {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%); top: calc(var(--sat) + 64px);
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em; color: var(--ink-2); text-decoration: none;
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; white-space: nowrap;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); transition: opacity 0.6s ease;
}
body[data-state="gate"] .demo-ribbon { top: calc(var(--sat) + 14px); }

.hud-bottom {
  position: fixed; z-index: 5; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 0 calc(var(--sar) + 16px) calc(var(--sab) + 14px) calc(var(--sal) + 16px); pointer-events: none; text-align: center;
  transition: opacity 0.8s ease;
}
.hud-bottom > * { pointer-events: auto; }
.hint { margin: 0; font-size: 15px; color: var(--ink); text-shadow: 0 1px 10px rgba(0, 0, 0, 0.8); min-height: 1.5em; transition: opacity 0.6s ease; max-width: 34ch; }
.hint:empty { opacity: 0; }
.progress {
  display: inline-flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 16px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--line); font-size: 14px; color: var(--ink-2);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); pointer-events: none;
}
.pdots { display: inline-flex; gap: 5px; }
.pdots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.22); transition: background 0.4s ease, box-shadow 0.4s ease; }
.pdots i.on { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.infoline { margin: 0; font-family: var(--mono); font-size: 11.5px; line-height: 1.55; letter-spacing: 0.02em; color: var(--ink-3); max-width: 60ch; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9); pointer-events: none; }
.infoline b { font-weight: 400; color: var(--ink-2); }
#btn-finale { animation: breathe 2.6s ease-in-out infinite; }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent), 0 8px 30px -6px color-mix(in srgb, var(--accent) 70%, transparent); } 50% { box-shadow: 0 0 0 12px transparent, 0 8px 40px -2px color-mix(in srgb, var(--accent) 80%, transparent); } }

body[data-state="gate"] .hud-top, body[data-state="intro"] .hud-top,
body[data-state="gate"] .hud-bottom, body[data-state="intro"] .hud-bottom,
body[data-state="finale"] .hud-bottom, body[data-state="end"] .hud-bottom,
body[data-state="finale"] .hud-top { opacity: 0; pointer-events: none; }
body[data-state="gate"] .hud-top *, body[data-state="intro"] .hud-top *, body[data-state="finale"] .hud-top *,
body[data-state="gate"] .hud-bottom *, body[data-state="intro"] .hud-bottom *, body[data-state="finale"] .hud-bottom *, body[data-state="end"] .hud-bottom * { pointer-events: none; }
body[data-state="intro"] .demo-ribbon, body[data-state="finale"] .demo-ribbon, body[data-state="end"] .demo-ribbon { opacity: 0; pointer-events: none; }

/* gate & intro */
.intro { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; pointer-events: none; }
.gate {
  pointer-events: auto; text-align: center; padding: 24px calc(var(--sar) + 24px) calc(var(--sab) + 24px) calc(var(--sal) + 24px);
  display: flex; flex-direction: column; align-items: center; transition: opacity 1.2s ease, transform 1.4s ease;
}
.gate-kicker { margin: 0 0 6px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.24em; text-transform: uppercase; color: var(--accent); }
.gate-name { margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(54px, min(19vw, 15svh), 120px); line-height: 1.02; letter-spacing: 0.02em; overflow-wrap: anywhere; max-width: 92vw; text-shadow: 0 0 40px color-mix(in srgb, var(--accent) 35%, transparent); }
.gate-from { margin: 14px 0 34px; font-size: 16px; color: var(--ink-2); }
.gate-note { margin: 20px 0 0; font-size: 13px; color: var(--ink-3); }
.btn-big { min-height: 56px; padding: 0 34px; font-size: 18px; }
body:not([data-state="gate"]) .gate { opacity: 0; transform: translateY(-20px) scale(0.98); pointer-events: none; }

.seq { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center; padding: 0 calc(var(--sar) + 24px) 0 calc(var(--sal) + 24px); pointer-events: none; }
.seq-line { margin: 0 auto; max-width: 22ch; opacity: 0; transform: translateY(10px); transition: opacity 1.4s ease, transform 1.8s ease; font-size: clamp(18px, 5vw, 26px); line-height: 1.35; color: var(--ink); text-shadow: 0 2px 20px rgba(0, 0, 0, 0.9); }
.seq-big { font-family: var(--display); font-size: clamp(30px, min(9vw, 7svh), 58px); line-height: 1.1; margin: 10px auto 12px; max-width: 16ch; color: #fff; }
.seq-line.show { opacity: 1; transform: none; }
.clock { margin: 26px 0 0; font-family: var(--mono); font-size: 14px; letter-spacing: 0.2em; color: var(--accent); opacity: 0; transition: opacity 1s ease; }
.clock.show { opacity: 0.9; }
.seq.out .seq-line, .seq.out .clock { opacity: 0; transform: translateY(-14px); transition-duration: 1.2s; }
.skip {
  position: absolute; right: calc(var(--sar) + 14px); bottom: calc(var(--sab) + 14px); pointer-events: auto; min-height: 44px; padding: 0 16px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--glass); color: var(--ink-2); font-size: 14px;
}

/* sheets (memory card, wish) */
.sheet {
  position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  padding: 0 calc(var(--sar) + 10px) calc(var(--sab) + 10px) calc(var(--sal) + 10px); pointer-events: none;
}
.sheet-inner {
  pointer-events: auto; width: 100%; max-width: 520px; max-height: min(62svh, 560px); overflow-y: auto; overscroll-behavior: contain;
  background: linear-gradient(180deg, rgba(20, 26, 52, 0.86), rgba(8, 11, 26, 0.92)); border: 1px solid var(--line);
  border-radius: 26px; padding: 22px 22px 18px; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  animation: sheet-in 0.55s cubic-bezier(0.2, 0.9, 0.2, 1) both; touch-action: pan-y; -webkit-user-select: text; user-select: text;
}
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.card-emoji { width: 48px; height: 48px; flex: none; display: grid; place-items: center; font-size: 26px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 16%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); box-shadow: 0 0 24px color-mix(in srgb, var(--accent) 30%, transparent); }
.card-count { margin: 0; font-family: var(--mono); font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
.card-title { margin: 0 0 4px; font-family: var(--display); font-weight: 400; font-size: clamp(24px, 6.4vw, 32px); line-height: 1.15; overflow-wrap: anywhere; }
.card-date { margin: 0 0 12px; font-family: var(--mono); font-size: 13px; color: var(--ink-2); }
.card-date:empty { display: none; }
.card-text { margin: 0 0 14px; font-size: 17px; line-height: 1.55; color: var(--ink); white-space: pre-line; overflow-wrap: anywhere; }
.card-star { margin: 0 0 16px; padding-top: 12px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.card-star:empty { display: none; }
.card-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.card-actions .btn { flex: 1 1 auto; }

@media (min-width: 900px) and (min-height: 520px) {
  .sheet { left: auto; top: 0; bottom: 0; right: 0; width: 460px; align-items: center; padding: calc(var(--sat) + 80px) calc(var(--sar) + 28px) calc(var(--sab) + 28px) 0; }
  .sheet-inner { max-height: 100%; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .sheet { left: auto; top: 0; right: 0; width: min(420px, 52vw); align-items: flex-end; padding-top: calc(var(--sat) + 8px); }
  .sheet-inner { max-height: calc(100svh - var(--sat) - var(--sab) - 20px); padding: 16px 18px 14px; }
  .card-text { font-size: 15px; }
}

/* the ending */
.final {
  position: fixed; inset: 0; z-index: 9; display: flex; align-items: flex-end; justify-content: center;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 14px) calc(var(--sab) + 14px) calc(var(--sal) + 14px); pointer-events: none;
}
.final-inner {
  position: relative; pointer-events: auto; width: 100%; max-width: 560px; max-height: 64vh; max-height: max(260px, min(54svh, calc(100svh - 320px))); overflow-y: auto; overscroll-behavior: contain; text-align: center;
  padding: 26px 22px 16px; border-radius: 28px;
  background: radial-gradient(120% 90% at 50% 0%, rgba(30, 36, 70, 0.7), rgba(6, 8, 20, 0.9)); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); touch-action: pan-y; -webkit-user-select: text; user-select: text;
  animation: sheet-in 1.2s cubic-bezier(0.2, 0.9, 0.2, 1) both;
}
.final-kicker { margin: 0 0 6px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--accent); }
.final-names { margin: 0 0 14px; font-family: var(--display); font-weight: 400; font-size: clamp(32px, 9vw, 52px); line-height: 1.05; overflow-wrap: anywhere; }
.final-msg p { margin: 0 0 12px; font-size: 17px; line-height: 1.6; opacity: 0; transform: translateY(8px); transition: opacity 1.6s ease, transform 1.6s ease; white-space: pre-line; overflow-wrap: anywhere; }
.final-msg p.show { opacity: 1; transform: none; }
.final-sign { margin: 4px 0 18px; font-family: var(--display); font-size: 22px; color: var(--accent); opacity: 0; transition: opacity 1.4s ease; }
.final-sign.show { opacity: 1; }
.final-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; opacity: 0; transition: opacity 1s ease; }
.final-actions.show { opacity: 1; }
.final-actions .btn { flex: 1 1 140px; }
.final-actions .btn-glow { flex-basis: 100%; }
.final-foot { margin: 16px 0 0; font-size: 13px; }
.final-foot a { color: var(--ink-3); text-decoration: none; display: inline-block; padding: 10px 4px; }
@media (orientation: landscape) and (max-height: 520px) {
  .final { justify-content: flex-end; align-items: center; }
  .final-inner { max-width: min(460px, 56vw); max-height: calc(100svh - var(--sat) - var(--sab) - 24px); padding: 18px 18px 10px; }
  .final-names { font-size: 30px; }
  .final-msg p { font-size: 15px; }
}
@media (min-width: 900px) and (min-height: 600px) {
  .final { align-items: flex-end; padding-bottom: calc(var(--sab) + 36px); }
}

/* modals */
.modal {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 12px) calc(var(--sab) + 12px) calc(var(--sal) + 12px);
  background: rgba(2, 3, 9, 0.72); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.modal-inner {
  width: 100%; max-width: 560px; max-height: 100%; display: flex; flex-direction: column; gap: 12px; overflow: hidden;
  background: linear-gradient(180deg, rgba(20, 26, 52, 0.96), rgba(8, 11, 26, 0.98)); border: 1px solid var(--line); border-radius: 24px; padding: 20px;
  touch-action: pan-y; -webkit-user-select: text; user-select: text;
}
.modal-scroll { overflow-y: auto; overscroll-behavior: contain; display: block; }
.modal-scroll > * + * { margin-top: 12px; }
.modal-title { margin: 0; font-family: var(--display); font-weight: 400; font-size: 26px; }
.modal-note { margin: 0; font-size: 13px; color: var(--ink-3); }
.poster-frame { position: relative; flex: 1 1 auto; min-height: 0; display: grid; place-items: center; }
.poster-frame img { display: block; max-width: 100%; max-height: min(62svh, 640px); border-radius: 10px; box-shadow: 0 20px 60px -10px rgba(0, 0, 0, 0.8); -webkit-touch-callout: default; user-select: auto; }
.poster-frame img:not([src]) { visibility: hidden; height: 300px; }
.poster-wait { position: absolute; margin: 0; font-family: var(--mono); font-size: 13px; color: var(--ink-2); }
.list-info { margin: 0; font-family: var(--mono); font-size: 13px; color: var(--ink-2); }
.list-mems { margin: 0; padding: 0 0 0 1.4em; }
.list-mems li { margin: 0 0 14px; }
.list-mems h3 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 20px; overflow-wrap: anywhere; }
.list-mems p, .list-p, #list-msg p { margin: 2px 0 0; white-space: pre-line; overflow-wrap: anywhere; }
.list-mems .d { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.list-h { margin: 18px 0 0; font-family: var(--mono); font-weight: 400; font-size: 12px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
#list-msg p + p { margin-top: 10px; }

.toast {
  position: fixed; z-index: 30; left: 50%; top: calc(var(--sat) + 70px); transform: translateX(-50%); margin: 0; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 14px; background: var(--glass-2); border: 1px solid var(--line); font-size: 14px; text-align: center;
}
.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; padding: 24px; text-align: center; }

@media (max-height: 560px) {
  .gate-from { margin: 8px 0 18px; }
  .gate-note { margin-top: 12px; }
  .hud-bottom { gap: 6px; }
  .infoline { font-size: 11px; }
}
@media (max-width: 380px) {
  .infoline { font-size: 11px; }
}

/* keep the main actions reachable when a card has to scroll */
.modal-scroll .card-actions {
  position: sticky; bottom: -20px; z-index: 1; padding: 12px 0 20px; margin-bottom: -20px;
  background: linear-gradient(180deg, rgba(8, 11, 26, 0), rgba(8, 11, 26, 0.96) 30%);
}
@media (max-height: 520px) { body:not([data-state="gate"]) .demo-ribbon { display: none; } }

/* wide screens: the ending sits to the right so the drawing gets the whole left side */
@media (min-width: 1100px) and (min-height: 600px) {
  .final { justify-content: flex-end; align-items: center; padding: calc(var(--sat) + 24px) calc(var(--sar) + 48px) calc(var(--sab) + 24px) 24px; }
  .final-inner { max-width: 480px; max-height: calc(100svh - 48px); }
}
