:root {
  --bg: #0c1024;
  --bg2: #141a38;
  --tile: #1d2547;
  --tile-hover: #262f5a;
  --tile-sel: #e8e3d4;
  --tile-sel-text: #11132a;
  --ink: #eef1ff;
  --muted: #9aa3cc;
  --line: #2a3260;
  /* solved group colors, easy -> hard */
  --g0: #d8a24a; /* berries  */
  --g1: #7fa86b; /* -ly time */
  --g2: #5f8cd6; /* stars    */
  --g3: #9b6fc9; /* acheans  */
  /* fonts (themes may override these via JS) */
  --font-body: "Space Grotesk";
  --font-heading: "Cormorant";
  /* derived from --bg so every theme (light or dark) gets a matching
     page gradient instead of a hardcoded dark one */
  --bg-glow: color-mix(in srgb, var(--bg) 78%, white);
  --bg-deep: color-mix(in srgb, var(--bg) 72%, black);
  --shadow: color-mix(in srgb, var(--bg-deep) 60%, transparent);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  /* iOS Safari tints its toolbar from the page background colour rather than
     the theme-color meta, so set a solid colour here (it updates per theme
     via --bg). The gradient below paints over it visually. */
  background-color: var(--bg);
}

body {
  background:
    radial-gradient(125% 90% at 50% -10%, var(--bg-glow) 0%, var(--bg) 52%, var(--bg-deep) 100%);
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-body), system-ui, sans-serif;
  min-height: 100vh;
  transition: background-color .4s ease, color .4s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px 48px;
}

/* soft ambient glows tinted by the theme's accent colours — works on both
   light and dark backgrounds, unlike a white starfield */
body::before {
  content: "";
  position: fixed;
  inset: -20vmax;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(38vmax 38vmax at 18% 12%, color-mix(in srgb, var(--g2) 45%, transparent), transparent 60%),
    radial-gradient(34vmax 34vmax at 85% 22%, color-mix(in srgb, var(--g3) 40%, transparent), transparent 60%),
    radial-gradient(40vmax 40vmax at 70% 95%, color-mix(in srgb, var(--g1) 32%, transparent), transparent 62%);
  opacity: .5;
  filter: blur(8px);
  animation: drift 26s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(2%, 2%, 0) scale(1.08); }
}

/* ---- Per-puzzle decorations -------------------------------------------
   Optional background flourishes, opted into via a puzzle's theme.decor
   (a preset name or array of them). Each preset is a `.decor-<name>` class
   below; add a new flourish by adding a class and listing its name in
   DECOR_PRESETS in app.js. Layers sit above the ambient glow but behind the
   content (.wrap, z-index 1) and never capture clicks. */
.decor {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.decor-layer {
  position: absolute;
  inset: 0;
}

/* Twinkling star field — two tiled layers at different scales/speeds for a
   subtle parallax shimmer. Stars use --ink so they show on light themes too. */
.decor-stars {
  background-repeat: repeat;
  background-size: 260px 260px;
  background-image:
    radial-gradient(1.4px 1.4px at 30px 40px, var(--ink), transparent),
    radial-gradient(1px 1px at 120px 90px, var(--ink), transparent),
    radial-gradient(1.2px 1.2px at 200px 30px, var(--ink), transparent),
    radial-gradient(1px 1px at 80px 200px, var(--ink), transparent),
    radial-gradient(1.6px 1.6px at 230px 220px, var(--ink), transparent),
    radial-gradient(1px 1px at 160px 150px, var(--ink), transparent);
  opacity: .8;
  animation: twinkle 4.5s ease-in-out infinite alternate;
}

.decor-stars::before {
  content: "";
  position: absolute;
  inset: 0;
  background-repeat: repeat;
  background-size: 180px 180px;
  background-position: 50px 70px;
  background-image:
    radial-gradient(1px 1px at 20px 30px, var(--ink), transparent),
    radial-gradient(1.3px 1.3px at 130px 60px, var(--ink), transparent),
    radial-gradient(1px 1px at 90px 140px, var(--ink), transparent),
    radial-gradient(1px 1px at 160px 120px, var(--ink), transparent);
  opacity: .45;
  animation: twinkle 7s ease-in-out infinite alternate-reverse;
}

@keyframes twinkle {
  from { opacity: .35; }
  to   { opacity: .9; }
}

/* Soft, slowly drifting coloured clouds tinted by the theme's accents. */
.decor-nebula::before {
  content: "";
  position: absolute;
  inset: -30vmax;
  background:
    radial-gradient(30vmax 30vmax at 25% 28%, color-mix(in srgb, var(--g3) 60%, transparent), transparent 60%),
    radial-gradient(26vmax 26vmax at 78% 36%, color-mix(in srgb, var(--g2) 52%, transparent), transparent 60%),
    radial-gradient(34vmax 30vmax at 55% 82%, color-mix(in srgb, var(--g0) 42%, transparent), transparent 62%);
  filter: blur(20px);
  opacity: .55;
  animation: nebula-drift 44s ease-in-out infinite alternate;
}

@keyframes nebula-drift {
  from { transform: translate3d(-3%, -2%, 0) rotate(-3deg) scale(1); }
  to   { transform: translate3d(3%, 3%, 0) rotate(4deg) scale(1.12); }
}

/* Aurora-style wavy bands sweeping across the top of the page. */
.decor-aurora::before {
  content: "";
  position: absolute;
  left: -25%;
  right: -25%;
  top: -15%;
  height: 75%;
  background:
    radial-gradient(60% 40% at 30% 30%, color-mix(in srgb, var(--g1) 55%, transparent), transparent 70%),
    radial-gradient(55% 45% at 70% 20%, color-mix(in srgb, var(--g2) 50%, transparent), transparent 70%);
  filter: blur(26px);
  opacity: .5;
  animation: aurora-wave 18s ease-in-out infinite alternate;
}

@keyframes aurora-wave {
  from { transform: translateX(-4%) skewX(-6deg) scaleY(1); }
  to   { transform: translateX(4%) skewX(6deg) scaleY(1.15); }
}

/* A warm sun setting at the bottom horizon, with a soft radiant halo. The disc
   sits mostly below the viewport so only its outer glow shows — keeping the
   bright core away from the status text and buttons that live at the bottom of
   the page. Tinted by --g0/--g1, so it reads as a sunset on the warm palette
   but adapts to any theme. ::before is the disc, ::after the broad ambient halo. */
.decor-sun::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -46vmin;
  width: 64vmin;
  height: 64vmin;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%,
    var(--g0) 0%,
    color-mix(in srgb, var(--g0) 70%, var(--g1)) 34%,
    color-mix(in srgb, var(--g1) 55%, transparent) 62%,
    transparent 74%);
  filter: blur(3px);
  opacity: .8;
  animation: sun-glow 9s ease-in-out infinite alternate;
}

.decor-sun::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -82vmin;
  width: 130vmin;
  height: 130vmin;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle,
    color-mix(in srgb, var(--g1) 34%, transparent) 0%,
    color-mix(in srgb, var(--g3) 20%, transparent) 40%,
    transparent 62%);
  filter: blur(22px);
  opacity: .5;
}

@keyframes sun-glow {
  from { transform: translateX(-50%) scale(1);    opacity: .68; }
  to   { transform: translateX(-50%) scale(1.05); opacity: .9; }
}

.wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
}

header {
  text-align: center;
  margin-bottom: 22px;
}

/* Logo and title link back to the start page; keep them looking like the
   original heading (no underline / link colour) with a subtle interactive cue. */
.home-link {
  display: inline-block;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  border-radius: 12px;
  transition: opacity .15s;
}

.home-link:hover {
  opacity: .82;
}

.home-link:focus-visible {
  outline: 2px solid var(--g2);
  outline-offset: 4px;
}

.logo {
  display: block;
  width: 72px;
  height: 72px;
  margin: 0 auto 10px;
  filter: drop-shadow(0 4px 12px var(--shadow));
  animation: logo-in .5s cubic-bezier(.2, .8, .3, 1) both;
}

@keyframes logo-in {
  from { opacity: 0; transform: translateY(-8px) scale(.9); }
  to { opacity: 1; transform: none; }
}

.eyebrow {
  font-size: .72rem;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

h1 {
  font-family: var(--font-heading), serif;
  font-weight: 600;
  font-size: 3.4rem;
  line-height: 1;
  margin: .18em 0 .12em;
  letter-spacing: .01em;
}

.sub {
  color: var(--muted);
  font-size: .92rem;
}

.picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}

.date-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.date-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .82rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 600;
}

.all-btn {
  font-family: inherit;
  font-size: .78rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--tile);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, background .15s;
}

.all-btn:hover {
  border-color: var(--muted);
}

.all-btn:focus-visible {
  outline: 2px solid var(--g2);
  outline-offset: 2px;
}

.date-field input {
  font-family: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: var(--tile);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
}

.date-field input::-webkit-calendar-picker-indicator {
  filter: invert(.6);
  cursor: pointer;
}

.date-field input:focus-visible {
  outline: 2px solid var(--g2);
  outline-offset: 2px;
}

.puzzle-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  font-family: inherit;
  font-weight: 600;
  font-size: .86rem;
  color: var(--ink);
  background: var(--tile);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 7px 16px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  line-height: 1.25;
}

.chip .stars {
  font-size: .66rem;
  letter-spacing: .08em;
  color: var(--g0);
  opacity: .85;
}

.chip.active .stars {
  color: var(--tile-sel-text);
  opacity: .7;
}

.chip .chip-author {
  margin-left: 5px;
  font-size: .58rem;
  font-weight: 600;
  vertical-align: super;
  color: var(--muted);
}

.chip.active .chip-author {
  color: var(--tile-sel-text);
  opacity: .65;
}

.chip:hover {
  border-color: var(--muted);
}

.chip:focus-visible {
  outline: 2px solid var(--g2);
  outline-offset: 2px;
}

.chip.active {
  background: var(--tile-sel);
  color: var(--tile-sel-text);
  border-color: var(--tile-sel);
}

.chip .check {
  margin-left: 6px;
  font-weight: 700;
  color: var(--g1);
}

.chip.done {
  border-color: var(--g1);
}

.chip.active .check {
  color: var(--tile-sel-text);
}

.empty-day {
  color: var(--muted);
  font-size: .9rem;
  font-style: italic;
}

.board {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.grid {
  display: grid;
  /* minmax(0, 1fr) lets columns shrink below their content's intrinsic width;
     plain 1fr defaults to a min-content minimum, so a long word would force
     its column wider and push the whole board sideways. */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.tile {
  appearance: none;
  border: none;
  cursor: pointer;
  background: var(--tile);
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(.7rem, 3.1vw, 1rem);
  text-transform: uppercase;
  letter-spacing: .02em;
  aspect-ratio: 1.45 / 1;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px;
  /* keep long words contained instead of overflowing the tile */
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  box-shadow: 0 1px 2px var(--shadow);
  transition: background .15s, transform .12s cubic-bezier(.2, .8, .3, 1),
    color .15s, box-shadow .15s;
  user-select: none;
}

.tile:hover {
  background: var(--tile-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--shadow);
}

.tile:active {
  transform: translateY(0) scale(.97);
}

.tile:focus-visible {
  outline: 2px solid var(--g2);
  outline-offset: 2px;
}

.tile.sel {
  background: var(--tile-sel);
  color: var(--tile-sel-text);
  transform: translateY(-1px) scale(.95);
  box-shadow: 0 4px 14px var(--shadow);
}

.tile.pop {
  animation: pop .2s ease;
}

@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(.88); }
  100% { transform: translateY(-1px) scale(.95); }
}

/* staggered entrance when a fresh board is dealt */
.tile.deal {
  animation: deal .4s cubic-bezier(.2, .8, .3, 1) backwards;
}

@keyframes deal {
  from { opacity: 0; transform: translateY(10px) scale(.94); }
  to { opacity: 1; transform: none; }
}

.grid.shake {
  animation: shake .42s ease;
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

.solved {
  border-radius: 12px;
  padding: 11px 14px;
  color: #16110a;
  text-align: center;
  box-shadow: 0 6px 18px var(--shadow);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, .16), rgba(0, 0, 0, .06));
  animation: reveal .45s cubic-bezier(.2, .8, .3, 1) both;
}

@keyframes reveal {
  0% { opacity: 0; transform: translateY(-10px) scale(.96); }
  60% { transform: translateY(0) scale(1.015); }
  100% { opacity: 1; transform: none; }
}

.solved .cat {
  font-weight: 700;
  font-size: .84rem;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.solved .members {
  font-weight: 600;
  font-size: .96rem;
  margin-top: 1px;
  letter-spacing: .04em;
}

.lvl0 { background-color: var(--g0); }
.lvl1 { background-color: var(--g1); }
.lvl2 { background-color: var(--g2); }
.lvl3 { background-color: var(--g3); }

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 20px 0 14px;
  color: var(--muted);
  font-size: .9rem;
  min-height: 22px;
  /* keep the label legible over bright decorations (e.g. the sunset glow) */
  text-shadow: 0 1px 6px var(--bg), 0 0 2px var(--bg);
}

.dots {
  display: flex;
  gap: 7px;
}

.dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--g3);
  transition: transform .25s, opacity .25s;
}

.dot.gone {
  transform: scale(.4);
  opacity: .2;
  background: var(--line);
}

.toast {
  min-height: 20px;
  text-align: center;
  font-size: .9rem;
  color: var(--ink);
  margin-bottom: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  text-shadow: 0 1px 6px var(--bg), 0 0 2px var(--bg);
}

.toast.show {
  animation: toast-in .3s cubic-bezier(.2, .8, .3, 1);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: .92rem;
  /* faint backdrop in the theme background so the button reads over any
     decoration, while still feeling translucent on a plain background */
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 11px 22px;
  cursor: pointer;
  text-shadow: 0 1px 4px var(--bg);
  transition: border-color .15s, background .15s, opacity .15s,
    transform .12s cubic-bezier(.2, .8, .3, 1), box-shadow .15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--muted);
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  transform: translateY(-2px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn.primary {
  background: var(--tile-sel);
  color: var(--tile-sel-text);
  border-color: var(--tile-sel);
}

.btn.primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--tile-sel) 86%, white);
  box-shadow: 0 6px 18px var(--shadow);
}

.btn:disabled {
  opacity: .4;
  cursor: default;
}

/* ---- Footer / share ---- */
.footer {
  margin-top: 26px;
  display: flex;
  justify-content: center;
}

.share-btn {
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--muted);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 8px 20px;
  cursor: pointer;
  text-shadow: 0 1px 4px var(--bg);
  transition: border-color .15s, color .15s, background .15s;
}

.share-btn:hover {
  color: var(--ink);
  border-color: var(--muted);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.share-btn:focus-visible {
  outline: 2px solid var(--g2);
  outline-offset: 2px;
}

/* ---- All-puzzles modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 70%, black);
  backdrop-filter: blur(3px);
  animation: fade-in .15s ease;
}

.modal {
  width: 100%;
  max-width: 460px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border: 1.5px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 18px 50px var(--shadow);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1.5px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--ink);
}

.modal-close {
  font-family: inherit;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--ink);
}

.modal-close:focus-visible {
  outline: 2px solid var(--g2);
  outline-offset: 2px;
}

.modal-body {
  padding: 14px 20px 20px;
  overflow-y: auto;
}

.modal-day {
  margin-top: 16px;
}

.modal-day:first-child {
  margin-top: 0;
}

.modal-day-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .74rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 8px;
}

/* Today's section stands out so the current day's puzzles are easy to find. */
.modal-day.is-today .modal-day-label {
  color: var(--ink);
}

.today-badge {
  letter-spacing: .06em;
  color: var(--tile-sel-text);
  background: var(--tile-sel);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: .66rem;
}

.modal-day .puzzle-list {
  justify-content: flex-start;
}

/* the hidden attribute must win over the flex displays above */
[hidden] {
  display: none !important;
}

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

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
