/* NOVA — design tokens
   bg deep space #060913 | panel #0E1526 | ink #D9E1F5 | muted #7C88A8
   star gold #FFD98E (glow #FFB84D) | conflict #FF6B7A
   display: Space Grotesk | body: system-ui */

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #060913;
  --panel: #0E1526;
  --ink: #D9E1F5;
  --muted: #7C88A8;
  --gold: #FFD98E;
  --gold-glow: #FFB84D;
  --bad: #FF6B7A;
  --line: rgba(6, 9, 19, 0.85);
  --r0: #4A3C8C; --r1: #71317E; --r2: #96385E;
  --r3: #9C4A3C; --r4: #9A742F; --r5: #4C8F3E;
  --r6: #2FBFA4; --r7: #3B7DAD; --r8: #4053C4;
  --r9: #6E7488;
}

html { -webkit-text-size-adjust: 100%; }

/* --- Light theme: "daybreak" — dawn glow into pale morning sky ------------ */
:root[data-theme="light"] {
  --bg: #E3EFF8;
  --panel: #FFFFFF;
  --ink: #232B4A;
  --muted: #6B7590;
  --gold: #E89B1C;
  --gold-glow: #F5B93F;
  --bad: #D8404F;
  --r0: #7C6FD9; --r1: #A855B8; --r2: #D25C86;
  --r3: #E06A50; --r4: #E0A63C; --r5: #62B44E;
  --r6: #35C9AC; --r7: #4D9BD6; --r8: #5A6AE0;
  --r9: #8B95AD;
}
[data-theme="light"] body {
  background: linear-gradient(180deg, #FBEFD9 0%, #E7F1F9 38%, #DDEAF5 100%);
}
[data-theme="light"] body::before {
  background-image:
    radial-gradient(46% 34% at 84% 2%, rgba(255, 202, 100, 0.6), transparent 70%),
    radial-gradient(30% 20% at 12% 14%, rgba(255, 255, 255, 0.9), transparent 70%),
    radial-gradient(26% 16% at 66% 26%, rgba(255, 255, 255, 0.65), transparent 70%),
    radial-gradient(36% 20% at 28% 74%, rgba(255, 255, 255, 0.55), transparent 72%);
}
[data-theme="light"] body::after { background-image: none; animation: none; }
[data-theme="light"] .cosmos { opacity: 0.85; }
[data-theme="light"] .mode, [data-theme="light"] .chip, [data-theme="light"] .btn,
[data-theme="light"] .howto, [data-theme="light"] .sheet, [data-theme="light"] .gear,
[data-theme="light"] .sync-row code, [data-theme="light"] .sync-row input {
  border-color: rgba(35, 43, 74, 0.14);
}
[data-theme="light"] .mode.active, [data-theme="light"] .chip.active,
[data-theme="light"] .btn.primary { color: #FFFFFF; background: var(--gold); border-color: var(--gold); }
[data-theme="light"] .board { }
[data-theme="light"] .cell { box-shadow: 0 2px 5px rgba(35, 43, 74, 0.2); }
[data-theme="light"] .cell.burned {
  background-color: #232B4A;
  box-shadow: inset 0 0 0 1px rgba(216, 64, 79, 0.35), 0 2px 5px rgba(35, 43, 74, 0.2);
}
[data-theme="light"] .card,
[data-theme="light"] .sheet { box-shadow: 0 12px 36px rgba(35, 43, 74, 0.18); }
[data-theme="light"] .hint-bar {
  background: rgba(232, 155, 28, 0.1);
  border-color: rgba(232, 155, 28, 0.4);
}
[data-theme="light"] .howto summary, [data-theme="light"] .sheet h2 { color: var(--ink); }
[data-theme="light"] .overlay { background: rgba(231, 241, 249, 0.75); }
[data-theme="light"] .modal { background: rgba(231, 241, 249, 0.8); }
[data-theme="light"] .card { border-color: rgba(232, 155, 28, 0.5); }
[data-theme="light"] .mk { text-shadow: 0 1px 2px rgba(35, 43, 74, 0.35); }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 7px calc(24px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* Deep-space backdrop: soft nebula clouds + two layers of stars, one drifting. */
body::before, body::after {
  content: "";
  position: fixed;
  inset: -10%;
  pointer-events: none;
  z-index: -1;
}
body::before {
  background-image:
    radial-gradient(52% 38% at 18% 12%, rgba(74, 60, 140, 0.22), transparent 70%),
    radial-gradient(45% 35% at 85% 20%, rgba(113, 49, 126, 0.16), transparent 70%),
    radial-gradient(55% 42% at 70% 85%, rgba(44, 122, 108, 0.13), transparent 70%),
    radial-gradient(40% 30% at 10% 78%, rgba(46, 110, 150, 0.14), transparent 70%),
    radial-gradient(1px 1px at 12% 22%, rgba(217,225,245,.7) 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 12%, rgba(217,225,245,.5) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 33% 68%, rgba(255,217,142,.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 62% 45%, rgba(217,225,245,.6) 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 78%, rgba(217,225,245,.45) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 8% 85%, rgba(217,225,245,.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 45% 8%, rgba(255,217,142,.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 25% 45%, rgba(217,225,245,.35) 50%, transparent 51%);
}
body::after {
  background-image:
    radial-gradient(1px 1px at 55% 30%, rgba(217,225,245,.5) 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 55%, rgba(217,225,245,.4) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 15% 60%, rgba(217,225,245,.35) 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 90%, rgba(255,217,142,.35) 50%, transparent 51%),
    radial-gradient(1px 1px at 38% 25%, rgba(217,225,245,.3) 50%, transparent 51%);
  animation: drift 90s linear infinite alternate;
}
@keyframes drift { from { transform: translateY(0); } to { transform: translateY(3%); } }
@media (prefers-reduced-motion: reduce) {
  body::after { animation: none; }
}

/* --- Header --- */

.top {
  text-align: center;
  margin-bottom: 14px;
  position: relative;
  width: 100%;
  max-width: 460px;
}
.cosmos {
  position: absolute;
  inset: -12px 0 -8px;
  pointer-events: none;
  z-index: -1;
}
.cosmos svg { width: 100%; height: 100%; }
.cosmos .tw1 { animation: twinkle 3.2s ease-in-out infinite; }
.cosmos .tw2 { animation: twinkle 4.1s ease-in-out 1.1s infinite; }
.cosmos .tw3 { animation: twinkle 5.3s ease-in-out 2.2s infinite; }
@keyframes twinkle {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
.cosmos .drift { animation: bob 14s ease-in-out infinite alternate; }
@keyframes bob {
  from { transform: translateY(0); }
  to { transform: translateY(5px); }
}
/* comet streaks toward lower-left, then rests invisible most of the cycle */
.cosmos .shoot {
  animation: shoot 13s ease-in 4s infinite;
  opacity: 0;
}
@keyframes shoot {
  0% { opacity: 0; transform: translate(0, 0); }
  4% { opacity: 0.8; }
  14% { opacity: 0; transform: translate(-130px, 52px); }
  100% { opacity: 0; transform: translate(-130px, 52px); }
}
@media (prefers-reduced-motion: reduce) {
  .cosmos .tw1, .cosmos .tw2, .cosmos .tw3, .cosmos .drift, .cosmos .shoot { animation: none; }
  .cosmos .shoot { opacity: 0.5; }
}

.brand {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-weight: 500;
  font-size: 1.7rem;
  letter-spacing: 0.35em;
  margin-left: 0.35em; /* optically recenter letterspaced text */
}
.brand-star {
  color: var(--gold);
  text-shadow: 0 0 12px var(--gold-glow);
  letter-spacing: 0;
}
.tagline {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

main {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Mode tabs + status --- */

.modes {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mode, .chip {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid rgba(217,225,245,0.08);
  border-radius: 999px;
  padding: 8px 13px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.mode.active, .chip.active {
  color: var(--bg);
  background: var(--gold);
  border-color: var(--gold);
  font-weight: 700;
}
.daily-check { font-weight: 700; }

.status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.count {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.9rem;
}
.count b { color: var(--gold); font-weight: 700; }
.hearts { display: flex; gap: 2px; font-size: 0.95rem; }
.heart {
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255,184,77,0.5);
  transition: transform 0.25s, opacity 0.25s;
}
.heart.lost {
  color: rgba(217,225,245,0.18);
  text-shadow: none;
  transform: scale(0.82);
}
.timer {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.95rem;
}

/* --- Sub-rows: free sizes / level strip --- */

.subrow {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.subrow::-webkit-scrollbar { display: none; }
.level-chip { min-width: 46px; text-align: center; }
.level-chip.done:not(.active) {
  color: var(--gold);
  border-color: rgba(255,217,142,0.35);
}
.level-chip.locked { opacity: 0.4; cursor: default; }

/* --- Board --- */

.board-wrap {
  position: relative;
  width: 100%;
}
/* Flat tile board, Meowdoku-style: every cell is an identical rounded tile
   with a uniform gap; regions are readable ONLY by color. No region borders —
   outlined region blobs telegraph the shapes and make the puzzle easier. */
.board {
  display: grid;
  width: 100%;
  gap: 3px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* drag paints ✕ notes; the board owns its gestures */
}
.board.locked { pointer-events: none; }

.cell {
  aspect-ratio: 1;
  border: 0;
  border-radius: 6px;
  position: relative;
  font: inherit; /* buttons don't inherit font-size — without this, em-based glyph sizing collapses to the UA button default */
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.15s;
  /* soft top-light for tile depth */
  background-image: radial-gradient(circle at 35% 28%, rgba(255,255,255,0.10), rgba(0,0,0,0.14) 78%);
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.cell:active { filter: brightness(1.25); }

.c0 { background-color: var(--r0); } .c1 { background-color: var(--r1); }
.c2 { background-color: var(--r2); } .c3 { background-color: var(--r3); }
.c4 { background-color: var(--r4); } .c5 { background-color: var(--r5); }
.c6 { background-color: var(--r6); } .c7 { background-color: var(--r7); }
.c8 { background-color: var(--r8); } .c9 { background-color: var(--r9); }

.cell .mk {
  color: rgba(240,244,252,0.9);
  font-size: 0.6em;
  font-weight: 800;
  text-shadow: 0 1px 3px rgba(0,0,0,0.45);
}
.cell .mk.auto { color: rgba(240,244,252,0.4); }

/* Burned cell: a wrong placement scorches the tile — it turns dark with a
   bold white ✕ so paid-for mistakes stay unmistakable among the nebulas. */
.cell { transition: filter 0.15s, background-color 0.35s; }
.cell.burned {
  background-color: #12141E;
  background-image: none;
  box-shadow: inset 0 0 0 1px rgba(255,107,122,0.25), 0 2px 6px rgba(0,0,0,0.35);
}
.cell.burned .mk { color: rgba(255,255,255,0.95); }
/* Placed icons overflow their tile like a sticker — stars are never adjacent
   by rule, so oversized icons can't collide with each other. The z-index sits
   on the icon span itself (not a :has() on the cell) so it works on older
   mobile browsers too; the win overlay (z 5) still covers it. */
.cell .star {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 1.22em;
  height: 1.22em;
  transform: translate(-50%, -50%);
  animation: pop 0.3s cubic-bezier(0.2, 1.6, 0.4, 1);
  pointer-events: none;
}
.cell .star svg { display: block; width: 100%; height: 100%; }
@keyframes pop {
  from { transform: translate(-50%, -50%) scale(0.2); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.cell .star.wrong {
  filter: drop-shadow(0 0 8px var(--bad)) saturate(0.6) brightness(0.9);
}
.cell.shake { animation: shake 0.45s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9%); }
  40% { transform: translateX(8%); }
  60% { transform: translateX(-6%); }
  80% { transform: translateX(4%); }
}

.cell.hinted {
  animation: hintpulse 1.2s ease-in-out infinite;
  box-shadow: inset 0 0 0 3px var(--gold), 0 2px 6px rgba(0,0,0,0.35);
}
@keyframes hintpulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.45); }
}

.cell.ignite { animation: ignite 0.6s ease-out; }
@keyframes ignite {
  0% { filter: brightness(1); }
  25% { filter: brightness(1.7); }
  100% { filter: brightness(1); }
}
@media (prefers-reduced-motion: reduce) {
  .cell.ignite, .cell.shake, .cell .star, .cell.hinted { animation: none; }
}

/* --- Settings gear + modal --- */

.gear {
  width: 34px;
  height: 34px;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid rgba(217,225,245,0.1);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 19, 0.78);
  padding: 20px;
  animation: fadein 0.25s ease-out;
}
.sheet {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid rgba(217,225,245,0.12);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sheet h2, .sheet h3 {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-weight: 500;
}
.sheet h2 { font-size: 1.1rem; }
.sheet h3 { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.opt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
}
.stats-list { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; }
.stats-list .stat-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}
.stats-list .stat-row b {
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.sheet-actions { display: flex; gap: 8px; margin-top: 6px; }

.sync-hint { font-size: 0.78rem; color: var(--muted); line-height: 1.45; }
.sync-row { display: flex; gap: 6px; align-items: center; }
.sync-row code {
  flex: 1;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  background: rgba(6, 9, 19, 0.6);
  border: 1px solid rgba(217,225,245,0.1);
  border-radius: 8px;
  padding: 8px;
  overflow-x: auto;
  white-space: nowrap;
}
.sync-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.8rem;
  color: var(--ink);
  background: rgba(6, 9, 19, 0.6);
  border: 1px solid rgba(217,225,245,0.1);
  border-radius: 8px;
  padding: 8px;
}
.sync-msg { font-size: 0.8rem; color: var(--gold); }
.sync-msg.error { color: var(--bad); }

/* --- How to play (visual rules dropdown) --- */

.howto {
  background: var(--panel);
  border: 1px solid rgba(217,225,245,0.08);
  border-radius: 12px;
  padding: 9px 12px;
}
.howto summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  list-style: none;
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 0.85rem;
  color: var(--ink);
}
.howto summary::-webkit-details-marker { display: none; }
.howto summary::after { content: "▾"; color: var(--muted); }
.howto[open] summary::after { content: "▴"; }
.rule-flash {
  margin-left: auto;
  color: var(--bad);
  font-size: 0.78rem;
  animation: pillflash 1.1s ease-out;
}
@keyframes pillflash {
  0%, 60% { opacity: 1; }
  100% { opacity: 0.4; }
}
.howto-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.howto-cards figure { margin: 0; text-align: center; }
.howto-cards svg { width: 100%; height: auto; display: block; }
.howto-cards figcaption {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.3;
}
.howto-extra {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(217,225,245,0.08);
}
.lang-chips { display: flex; gap: 6px; }

/* --- Hint message --- */

.hint-bar {
  color: var(--gold);
  background: rgba(255, 217, 142, 0.08);
  border: 1px solid rgba(255, 217, 142, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem;
}

/* --- Constellation lines (win) --- */

.constellation {
  position: absolute;
  inset: 0;
  z-index: 3; /* above overflowing star tiles (z 2) */
  pointer-events: none;
  opacity: 0;
}
.constellation.show { opacity: 1; }
.constellation polyline {
  fill: none;
  stroke: var(--gold);
  stroke-width: 0.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 2px var(--gold-glow));
}
.constellation.show polyline {
  stroke-dasharray: 500;
  stroke-dashoffset: 500;
  animation: draw 1.1s ease-out forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  .constellation.show polyline { animation: none; stroke-dashoffset: 0; }
}

/* --- End-of-game overlay --- */

.overlay[hidden] { display: none; }
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5; /* above star tiles and constellation lines */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 9, 19, 0.72);
  border-radius: 16px;
  animation: fadein 0.4s ease-out;
  padding: 16px;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.card {
  text-align: center;
  background: var(--panel);
  border: 1px solid rgba(255,217,142,0.35);
  border-radius: 16px;
  padding: 24px 28px;
  box-shadow: 0 0 40px rgba(255,184,77,0.15);
  max-width: 100%;
}
.card-star {
  color: var(--gold);
  text-shadow: 0 0 14px var(--gold-glow);
  font-size: 1.6rem;
  margin-bottom: 6px;
}
.card h2 {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-weight: 500;
  font-size: 1.1rem;
  margin-bottom: 8px;
}
.result {
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
}
.result:empty { display: none; }
.best { color: var(--muted); font-size: 0.85rem; margin: 6px 0 16px; }
.card-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* --- Buttons / toolbar --- */

.toolbar { display: flex; gap: 8px; }
.btn {
  flex: 1;
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid rgba(217,225,245,0.12);
  border-radius: 12px;
  padding: 12px 8px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: default; }
#hintCount { color: var(--muted); }
.btn:active { filter: brightness(1.3); }
.btn.primary {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--bg);
  font-weight: 700;
}
.card-actions .btn { flex: initial; }

button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* --- Rules + skins --- */

.rules {
  background: var(--panel);
  border: 1px solid rgba(217,225,245,0.08);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.88rem;
  color: var(--muted);
}
.rules summary {
  cursor: pointer;
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
}
.rules ul { margin: 10px 0 2px 18px; display: grid; gap: 6px; }
.rules strong { color: var(--ink); font-weight: 500; }
.rules-tips {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(217,225,245,0.08);
  line-height: 1.5;
}

.settings {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.toggle { flex-shrink: 0; }

.skins {
  display: flex;
  align-items: center;
  gap: 10px;
}
.skins-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-family: "Space Grotesk", system-ui, sans-serif;
}
.skin-row { display: flex; gap: 6px; flex-wrap: wrap; }
.skin {
  background: var(--panel);
  border: 1px solid rgba(217,225,245,0.1);
  border-radius: 12px;
  width: 48px;
  height: 48px;
  padding: 5px;
  cursor: pointer;
  touch-action: manipulation;
}
.skin svg { display: block; width: 100%; height: 100%; }
.skin.mix { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; padding: 6px; }
.skin.mix svg:first-child { grid-area: 1 / 1; }
.skin.mix svg:last-child { grid-area: 2 / 2; }
.skin.active {
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(255,184,77,0.35);
}
