/* Three Stars Before Bed — night-sky shell (spec §5.1 visual identity) */

@font-face {
  font-family: 'Fredoka';
  src: url('fonts/fredoka-latin.woff2') format('woff2');
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --sky-deep: #0e1030;
  --sky-high: #232a5c;
  --moon: #f7e8b0;
  --star-gold: #ffd76e;
  --lavender: #b9b3e8;
  --mint: #9fe6c3;
  --text: #f3f1ff;
  --card-bg: rgba(255, 255, 255, 0.08);
  --card-edge: rgba(185, 179, 232, 0.28);
}

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

html, body { min-height: 100%; }

body {
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, var(--sky-deep) 0%, var(--sky-high) 100%) fixed;
  color: var(--text);
  text-align: center;
  padding: 20px 16px 48px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
  transition: background 2s ease;
}

body.night-deep {
  background: linear-gradient(180deg, #070818 0%, #131740 100%) fixed;
}

/* ---------- ambient starfield ---------- */

#starfield {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.bg-star {
  position: absolute;
  background: #fff;
  border-radius: 50%;
  opacity: 0.7;
  animation: twinkle var(--tw, 4s) ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 0.85; }
}

/* ---------- header / emblem ---------- */

.top { max-width: 560px; margin: 0 auto; }

.emblem {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
}

.emblem .moon { width: 64px; height: 64px; filter: drop-shadow(0 0 14px rgba(247, 232, 176, 0.35)); }

.star-socket { width: 34px; height: 34px; }

.star-socket path {
  fill: rgba(255, 255, 255, 0.07);
  stroke: rgba(185, 179, 232, 0.45);
  stroke-width: 1.4;
  transition: fill 0.4s ease;
}

.star-socket.lit path {
  fill: var(--star-gold);
  stroke: none;
}

.star-socket.lit {
  filter: drop-shadow(0 0 10px rgba(255, 215, 110, 0.8));
  animation: star-pop 0.6s ease;
}

@keyframes star-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.45) rotate(12deg); }
  100% { transform: scale(1); }
}

.app-title {
  font-size: clamp(1.35rem, 5.5vw, 1.9rem);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.date-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
  color: var(--lavender);
  font-weight: 400;
  font-size: 1.05rem;
}

.picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card-bg);
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  padding: 6px 14px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}

.picker-btn:focus-visible { outline: 2px solid var(--star-gold); outline-offset: 2px; }

/* ---------- calendar popover ---------- */

.calendar {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 8, 24, 0.65);
}

.cal-panel {
  background: #1a1e48;
  border: 2px solid var(--card-edge);
  border-radius: 22px;
  padding: 16px;
  width: min(340px, 92vw);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  animation: fade-in 0.2s ease;
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.cal-title { font-weight: 600; color: var(--moon); font-size: 1.1rem; }

.cal-nav {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--card-edge);
  background: var(--card-bg);
  color: var(--text);
  font: inherit;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.cal-nav:disabled { opacity: 0.25; cursor: default; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-wd {
  color: var(--lavender);
  font-size: 0.8rem;
  text-align: center;
  padding: 4px 0;
}

.cal-day {
  aspect-ratio: 1;
  min-height: 38px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--card-bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}

.cal-day:not(:disabled):hover { border-color: var(--lavender); }

.cal-day:focus-visible { outline: 2px solid var(--star-gold); outline-offset: 1px; }

.cal-day:disabled {
  background: transparent;
  opacity: 0.25;
  cursor: default;
}

.cal-day.active {
  border-color: var(--star-gold);
  color: var(--star-gold);
  font-weight: 600;
  box-shadow: 0 0 8px rgba(255, 215, 110, 0.35);
}

.cal-close {
  margin-top: 12px;
  width: 100%;
  padding: 10px;
}

.greeting {
  margin-top: 10px;
  font-size: 1.15rem;
  font-weight: 400;
  color: var(--moon);
  min-height: 1.4em;
}

.notice {
  margin: 10px auto 0;
  max-width: 420px;
  background: rgba(255, 215, 110, 0.12);
  border: 1px solid rgba(255, 215, 110, 0.4);
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 0.95rem;
  color: var(--moon);
}

/* ---------- stage ---------- */

#stage { max-width: 560px; margin: 18px auto 0; }

#game-title {
  font-size: clamp(1.2rem, 4.5vw, 1.5rem);
  font-weight: 500;
  margin-bottom: 16px;
  min-height: 1.4em;
}

/* big rounded tap targets shared by all engines */
.tile, .card {
  min-width: 72px;
  min-height: 72px;
  border-radius: 22px;
  border: 2px solid var(--card-edge);
  background: var(--card-bg);
  color: var(--text);
  font-size: 2.3rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.3s ease, background 0.3s ease;
}

.tile:active, .card:active { transform: scale(0.93); }

.tile:focus-visible, .card:focus-visible, .soft-btn:focus-visible {
  outline: 3px solid var(--star-gold);
  outline-offset: 3px;
}

.round-dots { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(185, 179, 232, 0.3);
  transition: background 0.3s ease, transform 0.3s ease;
}

.dot.done { background: var(--star-gold); transform: scale(1.25); }

/* memory match */

.memory-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  gap: 12px;
  max-width: 420px;
  margin: 0 auto;
}

.card { aspect-ratio: 1; perspective: 600px; padding: 0; background: transparent; border: none; }

.card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
}

.card.open .card-inner, .card.matched .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  border-radius: 22px;
  border: 2px solid var(--card-edge);
  font-size: 2.3rem;
}

.face.front {
  background: var(--card-bg);
  color: rgba(185, 179, 232, 0.6);
  font-size: 1.6rem;
}

.face.back {
  background: rgba(255, 255, 255, 0.12);
  transform: rotateY(180deg);
}

.card.matched .face.back {
  border-color: var(--mint);
  box-shadow: 0 0 12px rgba(159, 230, 195, 0.35);
}

/* odd one out */

.odd-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
  gap: 12px;
  max-width: 420px;
  margin: 0 auto;
}

.tile.correct {
  border-color: var(--mint);
  background: rgba(159, 230, 195, 0.18);
}

/* pattern next */

.pattern-seq {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
}

.seq-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border-radius: 16px;
  background: var(--card-bg);
  border: 2px solid var(--card-edge);
  font-size: 1.8rem;
}

.seq-tile.slot {
  border-style: dashed;
  border-color: var(--star-gold);
  color: var(--star-gold);
  font-weight: 600;
}

.seq-tile.slot.filled {
  border-style: solid;
  border-color: var(--mint);
  animation: star-pop 0.5s ease;
}

.pattern-options {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

/* shared feedback */

.wiggle { animation: wiggle 0.45s ease; }

@keyframes wiggle {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px) rotate(-3deg); }
  75% { transform: translateX(7px) rotate(3deg); }
}

.fail-open { font-size: 1.2rem; color: var(--moon); }

/* confetti */

.confetti {
  position: fixed;
  top: -12px;
  left: var(--x);
  width: var(--s);
  height: var(--s);
  background: var(--c);
  border-radius: 3px;
  pointer-events: none;
  z-index: 50;
  animation: confetti-fall var(--t) ease-in forwards;
}

@keyframes confetti-fall {
  to { transform: translateY(105vh) rotate(var(--r)); opacity: 0.6; }
}

/* ---------- goodnight scene ---------- */

.goodnight {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(180deg, rgba(7, 8, 24, 0.96), rgba(19, 23, 64, 0.96));
  z-index: 40;
  animation: fade-in 1.2s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.gn-moon { width: 130px; height: 130px; filter: drop-shadow(0 0 24px rgba(247, 232, 176, 0.4)); }

.gn-zzz span {
  display: inline-block;
  color: var(--lavender);
  font-size: 1.3rem;
  animation: zzz 3s ease-in-out infinite;
}

.gn-zzz span:nth-child(2) { animation-delay: 0.5s; font-size: 1.6rem; }
.gn-zzz span:nth-child(3) { animation-delay: 1s; font-size: 1.9rem; }

@keyframes zzz {
  0%, 100% { transform: translateY(0); opacity: 0.35; }
  50% { transform: translateY(-10px); opacity: 1; }
}

.gn-text { font-size: clamp(1.5rem, 6vw, 2.1rem); font-weight: 600; }

.gn-sub { color: var(--lavender); font-size: 1.05rem; }

.soft-btn {
  margin-top: 14px;
  font: inherit;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--card-bg);
  border: 2px solid var(--card-edge);
  border-radius: 999px;
  padding: 12px 26px;
  cursor: pointer;
}

.soft-btn:active { transform: scale(0.95); }

/* hidden always wins, even over display:flex components */
[hidden] { display: none !important; }

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
  .bg-star { animation: none; opacity: 0.5; }
  .confetti { display: none; }
}
