:root {
  color-scheme: dark;
  --ink: #f5f0ff;
  --muted: #c9bddf;
  --night: #120d2c;
  --night-2: #201243;
  --panel: rgba(31, 21, 63, 0.84);
  --line: rgba(225, 210, 255, 0.2);
  --moon: #f8df93;
  --lilac: #a78bfa;
  --aqua: #78e7dd;
  --rose: #ff8fb6;
  --shadow: 0 26px 90px rgba(3, 1, 16, 0.48);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Gill Sans", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 78% 14%, rgba(248, 223, 147, .86) 0 54px, transparent 56px),
    radial-gradient(circle at 20% 12%, rgba(120, 231, 221, .18), transparent 28%),
    radial-gradient(circle at 8% 88%, rgba(167, 139, 250, .28), transparent 34%),
    linear-gradient(160deg, #09071a 0%, var(--night) 48%, #2d1450 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, rgba(255,255,255,.5) 0 1px, transparent 1.5px);
  background-size: 54px 54px;
  opacity: .2;
}

.shell {
  width: min(960px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

.top-links {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.top-links a {
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  background: rgba(255,255,255,.08);
  backdrop-filter: blur(10px);
  font-weight: 800;
}

.hero { text-align: center; margin-bottom: 22px; }
.eyebrow { color: var(--aqua); text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; font-weight: 900; margin: 0 0 6px; }
h1 { font-size: clamp(2.3rem, 8vw, 5rem); line-height: .9; margin: 0; letter-spacing: -0.06em; }
.lede { max-width: 670px; margin: 16px auto 0; color: var(--muted); font-size: 1.06rem; line-height: 1.55; }

.game-card {
  max-width: 760px;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 28px);
  background: linear-gradient(180deg, rgba(43,28,89,.9), var(--panel));
  border: 1px solid var(--line);
  border-radius: 30px;
  box-shadow: var(--shadow);
}

.level-bar { display: flex; justify-content: space-between; gap: 16px; align-items: start; }
.chapter { margin: 0 0 3px; color: var(--aqua); font-weight: 900; font-size: .82rem; text-transform: uppercase; letter-spacing: .12em; }
h2 { margin: 0; font-size: clamp(1.4rem, 5vw, 2.2rem); }
.scorebox { min-width: 92px; border: 1px solid var(--line); border-radius: 20px; padding: 10px; text-align: center; background: rgba(8, 6, 22, .34); }
.scorebox span { display: block; font-size: 1.9rem; font-weight: 1000; color: var(--moon); }
.scorebox small { color: var(--muted); font-weight: 800; }
.hint { color: var(--muted); line-height: 1.45; }

.board {
  width: min(100%, 470px);
  aspect-ratio: 1;
  margin: 18px auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 10px;
  border-radius: 28px;
  background: rgba(6, 5, 18, .48);
  border: 1px solid var(--line);
}

.cell {
  position: relative;
  border: 1px solid rgba(225,210,255,.16);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(255,255,255,.08), rgba(255,255,255,.02));
  color: var(--ink);
  font-size: clamp(1.35rem, 7vw, 2.2rem);
  cursor: pointer;
  min-width: 0;
  touch-action: manipulation;
}

.cell:disabled { cursor: default; }
.cell.rock { background: linear-gradient(145deg, #332b48, #171225); color: #7b718d; }
.cell.mail { box-shadow: inset 0 0 0 2px rgba(248,223,147,.55); }
.cell.moth { outline: 3px solid var(--aqua); outline-offset: -5px; }
.cell.trail { background: rgba(120,231,221,.18); }
.cell.bad { animation: shake .32s ease-in-out; }
.cell .breeze { position: absolute; right: 8px; bottom: 5px; color: var(--aqua); font-size: .74em; text-shadow: 0 2px 10px rgba(0,0,0,.55); }
.cell .lantern { color: var(--moon); filter: drop-shadow(0 0 8px rgba(248,223,147,.75)); }
.cell .mothmark { color: var(--rose); filter: drop-shadow(0 0 8px rgba(255,143,182,.8)); }
.cell .mailmark { color: var(--moon); }

.legend, .tools, .controls { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.legend { color: var(--muted); font-weight: 800; font-size: .93rem; }
.legend b { color: var(--moon); }
.moth-dot { color: var(--rose) !important; }
.toolbox { margin-top: 20px; padding: 16px; border: 1px solid var(--line); border-radius: 22px; background: rgba(255,255,255,.05); }
.tool-label { margin: 0 0 12px; text-align: center; color: var(--muted); font-weight: 800; }
button { font: inherit; }
.tools button, .controls button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 15px;
  background: rgba(255,255,255,.09);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}
.tools button.active { background: linear-gradient(135deg, var(--aqua), var(--lilac)); color: #120d2c; border-color: transparent; }
.tools button:disabled { opacity: .45; cursor: not-allowed; }
.controls { margin-top: 18px; }
.controls button.primary { background: linear-gradient(135deg, var(--rose), var(--lilac)); border-color: transparent; color: white; }
.controls button:disabled { opacity: .45; cursor: not-allowed; }
.message { min-height: 2.8em; text-align: center; color: var(--ink); font-weight: 850; line-height: 1.4; }

@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

@media (max-width: 560px) {
  .shell { width: min(100vw - 16px, 520px); padding-top: 14px; }
  .game-card { border-radius: 22px; }
  .board { gap: 5px; padding: 7px; border-radius: 20px; }
  .cell { border-radius: 13px; }
  .level-bar { align-items: stretch; }
}
