:root {
  color-scheme: light;
  --ink: #17251d;
  --paper: #f2eee4;
  --surface: #fbf8f0;
  --muted: #687269;
  --line: #d9d4c8;
  --moss: #2e5942;
  --lime: #d7f46c;
  --danger: #b84336;
  --dusk: #27352e;
  --glow: #fff2a0;
  --shadow: 0 22px 70px rgba(35, 48, 39, 0.13);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8% 2%, rgba(215, 244, 108, .19), transparent 30rem),
    var(--paper);
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next", Avenir, system-ui, sans-serif;
}
button, a { font: inherit; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }

.game-shell {
  width: min(980px, calc(100% - 28px));
  margin: 0 auto;
  padding-bottom: 42px;
}
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
}
.brand, .text-button, .eyebrow {
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.brand { color: var(--moss); }
.header-actions { display: flex; align-items: center; gap: 18px; }
.text-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}
.game-intro {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  align-items: end;
  gap: 36px;
  padding: 14px 0 18px;
}
.eyebrow { margin: 0 0 8px; color: var(--moss); }
h1, h2 { margin: 0; letter-spacing: -.055em; }
h1 { font-family: Georgia, serif; font-size: clamp(2.8rem, 6vw, 4.8rem); font-weight: 400; line-height: .92; }
.game-intro > p { max-width: 360px; margin: 0 0 4px; color: #536158; font-size: 1rem; line-height: 1.55; }

.play-card {
  display: grid;
  justify-items: center;
  padding: clamp(18px, 4vw, 34px);
  border: 1px solid rgba(44, 72, 55, .18);
  border-radius: 28px;
  background: rgba(251, 248, 240, .92);
  box-shadow: var(--shadow);
}
.puzzle-meta, .controls {
  display: flex;
  width: min(560px, 100%);
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.puzzle-meta { margin-bottom: 18px; }
.puzzle-meta p { margin: 0 0 3px; font-size: 1.08rem; font-weight: 800; }
.puzzle-meta span { color: var(--muted); font-size: .78rem; }
.puzzle-meta strong { max-width: 390px; color: var(--moss); font-size: .72rem; line-height: 1.45; text-align: right; }

.rule-guide {
  width: min(560px, 100%);
  margin: -3px 0 15px;
  padding: 12px 14px;
  border: 1px solid #d8d7c5;
  border-radius: 14px;
  background: #f4f2e5;
  font-size: .76rem;
  line-height: 1.45;
}
.rule-guide strong, .rule-guide span { display: block; }
.rule-guide span { margin-top: 2px; color: var(--muted); }
.rule-guide p {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid #dcdbca;
  color: var(--moss);
  font-weight: 750;
}
.rule-guide p.is-error { color: var(--danger); }

.board {
  --grid-size: 5;
  --board-size: 350px;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), 1fr);
  width: min(var(--board-size), 100%);
  height: min(var(--board-size), calc(100vw - 56px));
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--dusk);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.06),
    0 16px 38px rgba(23,37,29,.18);
  touch-action: manipulation;
}
.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0 solid rgba(23, 37, 29, .85);
  background: color-mix(in srgb, var(--region-color) 43%, var(--dusk));
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cell::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: -26%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 241, 145, .72), rgba(255, 220, 91, .16) 38%, transparent 68%);
  opacity: 0;
  transform: scale(.42);
  pointer-events: none;
}
.cell::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0);
  transition: background .14s ease, transform .14s ease;
}
.cell:hover::after { background: rgba(255, 255, 255, .14); }
.cell:focus-visible { z-index: 3; outline: 4px solid white; outline-offset: -6px; }
.cell.edge-top { border-top-width: 2px; }
.cell.edge-right { border-right-width: 2px; }
.cell.edge-bottom { border-bottom-width: 2px; }
.cell.edge-left { border-left-width: 2px; }
.cell.is-conflict {
  background: #9f493f;
  animation: nudge .24s ease;
}
.cell.is-lantern::before {
  opacity: 1;
  transform: scale(1);
  transition: opacity .2s ease, transform .25s ease;
}
.cell.is-new-lantern::before { animation: light-spread .42s ease both; }
.mark {
  z-index: 1;
  color: rgba(255,255,255,.55);
  font-size: clamp(1rem, 4vw, 1.6rem);
  font-weight: 500;
}
.lantern {
  position: relative;
  z-index: 2;
  display: block;
  width: 42%;
  aspect-ratio: .78;
  border: 3px solid var(--ink);
  border-radius: 45% 45% 36% 36%;
  background: var(--lime);
  box-shadow:
    0 0 0 5px rgba(255,255,255,.28),
    0 0 28px rgba(255,235,120,.7),
    0 4px 0 rgba(23,37,29,.22);
  animation: bloom .22s ease both;
}
.lantern::before {
  content: "";
  position: absolute;
  left: 17%;
  right: 17%;
  top: -18%;
  height: 18%;
  border: 3px solid var(--ink);
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
}
.lantern i {
  position: absolute;
  inset: 28% 26%;
  border-radius: 50%;
  background: #fff6b5;
  box-shadow: 0 0 14px #fff2a0;
}

.controls { margin-top: 18px; }
.mode-switch, .edit-actions { display: flex; gap: 7px; }
.mode-switch {
  padding: 4px;
  border-radius: 14px;
  background: #e6e2d8;
}
.mode-button, .icon-button {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 760;
}
.mode-button { display: flex; align-items: center; gap: 7px; padding: 0 13px; }
.mode-button.is-active { background: var(--ink); color: white; box-shadow: 0 4px 12px rgba(23,37,29,.18); }
.mini-lantern { width: 12px; height: 15px; border-radius: 5px; background: var(--lime); border: 2px solid currentColor; }
.icon-button { padding: 0 11px; border: 1px solid var(--line); background: var(--surface); }
.icon-button:disabled { opacity: .35; cursor: default; }

.collection {
  display: grid;
  grid-template-columns: .55fr 1.45fr;
  gap: 34px;
  padding: 70px 0;
}
.collection h2 { font-family: Georgia, serif; font-size: clamp(2rem, 5vw, 4rem); font-weight: 400; }
.level-picker { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; }
.level-chip {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 800;
}
.level-chip.is-active { border-color: var(--ink); background: var(--ink); color: white; }
.level-chip.is-complete:not(.is-active) { border-color: var(--moss); background: #dcebdc; color: var(--moss); }
footer {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  padding: 26px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .82rem;
}
footer p { margin: 0; }
footer a { color: var(--moss); font-weight: 800; }

.dialog {
  width: min(440px, calc(100% - 28px));
  padding: 30px;
  border: 1px solid rgba(23,37,29,.15);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 30px 90px rgba(11, 25, 16, .28);
  color: var(--ink);
}
.dialog::backdrop { background: rgba(16, 27, 20, .58); backdrop-filter: blur(5px); }
.dialog h2 { font-family: Georgia, serif; font-size: 2.25rem; font-weight: 400; }
.dialog ol { padding-left: 22px; color: #4e5c53; line-height: 1.7; }
.dialog > p:not(.eyebrow) { color: #59665e; line-height: 1.55; }
.dialog-mark { margin-bottom: 14px; color: var(--moss); font-size: 1.6rem; }
.primary-button, .secondary-button {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 800;
}
.primary-button { border: 0; background: var(--ink); color: white; }
.secondary-button { border: 1px solid var(--line); background: transparent; }
.dialog-actions { display: flex; gap: 9px; margin-top: 22px; }
.dialog-actions { flex-wrap: wrap; }
.share-button {
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid var(--moss);
  border-radius: 12px;
  background: #e2eedf;
  color: var(--moss);
  cursor: pointer;
  font-weight: 800;
}
.achievement {
  display: inline-flex;
  margin: 3px 0 13px !important;
  padding: 7px 10px;
  border-radius: 999px;
  background: #e4efdd;
  color: var(--moss) !important;
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.share-status {
  min-height: 1.3em;
  margin: 12px 0 0 !important;
  font-size: .78rem;
}
.celebration { display: flex; gap: 18px; margin-bottom: 20px; color: #d49b24; font-size: 1.7rem; }
.celebration span:nth-child(2) { transform: translateY(-8px) scale(1.25); }

.board.is-progress {
  animation: board-breathe .42s ease;
}
.board.is-solved .cell.is-lantern::before {
  animation: solved-glow .7s ease both;
}
.board.is-solved .cell.is-lantern:nth-child(3n + 2)::before {
  animation-delay: .08s;
}
.board.is-solved .cell.is-lantern:nth-child(3n)::before {
  animation-delay: .16s;
}

@keyframes bloom {
  from { opacity: 0; transform: scale(.55) rotate(-9deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes nudge {
  40% { transform: translateX(-2px); }
  70% { transform: translateX(2px); }
}
@keyframes light-spread {
  from { opacity: 0; transform: scale(.2); }
  55% { opacity: 1; transform: scale(1.18); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes board-breathe {
  50% { box-shadow: inset 0 0 0 2px rgba(255,241,145,.35), 0 18px 44px rgba(23,37,29,.24); }
}
@keyframes solved-glow {
  from { opacity: .45; transform: scale(.75); }
  55% { opacity: 1; transform: scale(1.38); }
  to { opacity: 1; transform: scale(1); }
}

@media (max-width: 640px) {
  .game-shell { width: min(100% - 20px, 980px); }
  .game-header { min-height: 52px; }
  .header-actions { gap: 11px; }
  .game-intro {
    display: block;
    padding: 4px 4px 12px;
  }
  h1 { font-size: clamp(2.55rem, 13vw, 3.8rem); }
  .game-intro > p { margin-top: 10px; font-size: .86rem; }
  .play-card { padding: 14px 9px 16px; border-radius: 20px; }
  .puzzle-meta { width: calc(100% - 10px); margin-bottom: 11px; }
  .puzzle-meta strong { max-width: 210px; font-size: .62rem; }
  .rule-guide { margin-bottom: 10px; padding: 9px 11px; font-size: .68rem; }
  .board { border-radius: 14px; }
  .controls { width: calc(100% - 8px); margin-top: 12px; }
  .mode-button, .icon-button { min-height: 40px; }
  .edit-actions { gap: 4px; }
  .icon-button { padding: 0 8px; font-size: .74rem; }
  .collection { grid-template-columns: 1fr; gap: 18px; padding: 46px 4px; }
  .level-picker { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .level-chip { border-radius: 9px; font-size: .66rem; }
  footer { display: block; padding-inline: 4px; }
  footer a { display: inline-block; margin-top: 12px; }
}

@media (max-width: 370px) {
  .mode-button { padding: 0 9px; }
  .mode-button span:not(.mini-lantern) { display: none; }
  .level-picker { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; }
}
