:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  --night: #181b39;
  --paper: #fff6dc;
  --sun: #ffdf75;
  --mint: #a9efdd;
  --fog: #e3e3f5;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  padding: 0 0 2rem;
  color: var(--paper);
  background: radial-gradient(ellipse at 75% 5%, #363865, transparent 55%), var(--night);
}
body.has-expanded-game { overflow: hidden; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 4px; }
button, select { font: inherit; }
button, .back-link, select { touch-action: manipulation; }
.shell { width: min(100% - 2rem, 1080px); margin-inline: auto; }
.skip-link {
  position: absolute;
  z-index: 5;
  top: .75rem;
  left: 1rem;
  padding: .65rem 1rem;
  transform: translateY(-200%);
  color: var(--night);
  background: var(--sun);
}
.skip-link:focus { transform: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: .7rem;
}
.site-header > a:first-child { padding: .2rem .5rem; border-radius: 12px; background: var(--paper); }
.site-header img { display: block; width: clamp(86px, 11vw, 111px); height: auto; }
.back-link { padding: .65rem 0; color: var(--mint); font-weight: 750; text-underline-offset: .24em; }
.back-link span { margin-right: .2rem; }
.intro {
  display: grid;
  grid-template-columns: 1fr minmax(0, .86fr);
  align-items: center;
  gap: clamp(1.4rem, 4vw, 4rem);
  margin: .25rem 0 1.15rem;
}
.intro h1 {
  max-width: 12ch;
  margin: 0;
  font: 750 clamp(2.45rem, 5.8vw, 4.4rem)/.99 Georgia, serif;
  letter-spacing: -.055em;
  text-wrap: balance;
}
.intro em { color: var(--sun); font-style: normal; }
.intro p { max-width: 38ch; margin: .75rem 0 0; color: var(--fog); line-height: 1.5; }
.cover {
  display: block;
  width: 100%;
  height: clamp(145px, 19vw, 208px);
  object-fit: cover;
  object-position: 50% 48%;
  border: 1px solid #626490;
  border-radius: 22px;
}
.game {
  padding: clamp(.7rem, 2.9vw, 1.6rem);
  border: 1px solid #51547c;
  border-radius: 26px;
  background: #252848;
  box-shadow: 0 16px 42px #10112870;
}
.game.is-expanded, .game:fullscreen {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: clamp(.7rem, 2.9vw, 1.6rem);
  border: 0;
  border-radius: 0;
  background: var(--night);
  overscroll-behavior: contain;
}
.game.is-expanded { position: fixed; z-index: 10; inset: 0; }
.game-header, .game-content { width: min(100%, 1030px); margin-inline: auto; }
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1rem;
}
.level-picker select, .button {
  min-height: 44px;
  padding: .52rem .72rem;
  border: 1px solid #787ca5;
  border-radius: 11px;
  color: var(--paper);
  background: #30355d;
  font-weight: 700;
  cursor: pointer;
}
.level-picker select { max-width: 100%; }
.button:hover:not(:disabled) { background: #444a7a; }
.button:disabled { opacity: .57; cursor: default; }
.fullscreen { display: inline-flex; align-items: center; justify-content: center; gap: .42rem; border-color: var(--mint); color: var(--mint); }
.expand-icon { font-size: 1.15em; line-height: 1; }
.game-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(14rem, .43fr);
  align-items: start;
  gap: clamp(1rem, 3vw, 2rem);
}
.level-heading { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.level-heading h2 { margin: 0; font: 700 clamp(1.24rem, 3vw, 1.72rem)/1.08 Georgia, serif; }
.star-count {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: .33rem;
  margin: 0;
  color: var(--sun);
  font-weight: 760;
  font-size: .89rem;
  font-variant-numeric: tabular-nums;
}
.star-count > span:first-child { font-size: 1.2rem; }
.board {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(var(--columns, 7), minmax(0, 1fr));
  gap: clamp(3px, .8vw, 8px);
  padding: clamp(7px, 1.4vw, 15px);
  border: 1px solid #505280;
  border-radius: 18px;
  background: radial-gradient(circle at center, #7776a866 0 1px, transparent 1.6px) 0 0 / 21px 23px, linear-gradient(145deg, #161a37, #22264b);
  user-select: none;
}
.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1.22;
  border: 2px solid transparent;
  border-radius: clamp(4px, 1.2vw, 11px);
}
.roof {
  background: repeating-linear-gradient(0deg, #783a4e55 0 1px, transparent 2px 7px), linear-gradient(160deg, #cd796c, #a4505d);
  box-shadow: inset 0 2px #ffb48e85, inset 0 -4px #693b4a90, 0 2px 2px #0b102450;
}
.roof:nth-child(3n) { background-color: #d79374; filter: saturate(.85); }
.reachable { border-color: var(--mint); cursor: pointer; touch-action: manipulation; }
.reachable:hover { box-shadow: inset 0 0 0 2px var(--mint); }
.suggested { border-color: var(--sun); outline: 2px dashed var(--sun); outline-offset: 1px; }
.has-cat { border-color: #fff0b5; }
.mark { display: grid; place-items: center; pointer-events: none; }
.star .mark { color: #ffdf75; font-size: clamp(1rem, 5.9cqi, 2.5rem); line-height: 1; text-shadow: 0 2px #67314b; }
.chimney .mark {
  width: 41%;
  height: 55%;
  border-top: 4px solid #af8184;
  border-radius: 3px 3px 6px 6px;
  background: repeating-linear-gradient(0deg, #aa787b 0 1px, #633f56 1px 6px);
  box-shadow: 2px 3px #582b4866;
}
.fragile .mark {
  width: 60%;
  height: 56%;
  background: #58314d;
  clip-path: polygon(54% 0, 66% 0, 49% 38%, 73% 63%, 35% 100%, 21% 100%, 57% 62%, 37% 38%);
}
.home .mark {
  width: 57%;
  height: 64%;
  border: 3px solid #59354d;
  border-radius: 50% 50% 18% 18% / 55% 55% 12% 12%;
  background: linear-gradient(90deg, transparent 44%, #724b59 44% 56%, transparent 56%), linear-gradient(transparent 44%, #724b59 44% 56%, #dfac60 56%), var(--sun);
  box-shadow: 0 0 10px #ffdf7590;
}
.home-open .mark { outline: 2px solid var(--sun); outline-offset: 2px; }
.cat {
  position: absolute;
  z-index: 1;
  bottom: 1%;
  left: 50%;
  width: 91%;
  height: 115%;
  object-fit: contain;
  object-position: bottom;
  pointer-events: none;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 1px #321b31b0);
}
.cat.hop { animation: hop .21s ease-out; }
@keyframes hop {
  48% { transform: translate(-50%, -19%); }
}
.status { min-height: 2.75em; margin: .55rem 0 0; color: var(--fog); font-size: .89rem; line-height: 1.4; }
.status:empty { min-height: 0; margin: 0; }
.game-tools {
  display: grid;
  gap: .75rem;
  padding: .92rem;
  border: 1px solid #51547c;
  border-radius: 17px;
  background: #202341;
}
.tools-copy p { margin: 0; color: var(--fog); font-size: .88rem; line-height: 1.45; }
.tools-copy .clue { margin-bottom: .38rem; color: var(--paper); font-weight: 720; }
.directions {
  display: grid;
  grid-template-areas: '. up .' 'left down right';
  grid-template-columns: repeat(3, minmax(44px, 1fr));
  gap: .35rem;
  width: min(100%, 13rem);
  margin-inline: auto;
}
.direction { display: grid; place-items: center; padding: 0; font-size: 1.45rem; line-height: 1; }
[data-key="ArrowUp"] { grid-area: up; }
[data-key="ArrowLeft"] { grid-area: left; }
[data-key="ArrowDown"] { grid-area: down; }
[data-key="ArrowRight"] { grid-area: right; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem; }
.actions .button { font-size: .82rem; }
.win { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .6rem; border: 1px solid #777049; border-radius: 12px; background: #413952; }
.win p { margin: 0; font-weight: 700; }
.button-sun { border-color: var(--sun); background: var(--sun); color: #272344; }
.button-sun:hover:not(:disabled) { background: #ffed9f; }

@media (max-width: 680px) {
  body { padding-bottom: 1rem; }
  .shell { width: min(100% - 1.25rem, 33rem); }
  .intro { grid-template-columns: minmax(0, 1fr) minmax(0, .61fr); gap: .6rem; margin-bottom: .8rem; }
  .intro h1 { font-size: clamp(1.88rem, 7vw, 2.65rem); }
  .intro p { margin-top: .4rem; font-size: .86rem; }
  .cover { height: clamp(104px, 30vw, 149px); border-radius: 15px; }
  .game-content { grid-template-columns: minmax(0, 1fr); gap: .42rem; }
  .game-header { margin-bottom: .7rem; }
  .game-tools { gap: .5rem; padding: .6rem; }
  .directions { grid-row: 1; }
  .tools-copy { grid-row: 3; }
  .actions .button { padding-inline: .55rem; }
  .status { min-height: 1.4em; }
}
@media (max-width: 390px) {
  .fullscreen { gap: .25rem; }
}
@media (min-width: 551px) and (max-height: 580px) and (orientation: landscape) {
  .game:fullscreen, .game.is-expanded { padding: clamp(.7rem, 2vw, 1rem); }
  .game:fullscreen .game-content, .game.is-expanded .game-content {
    grid-template-columns: minmax(0, 1fr) minmax(11rem, .58fr);
    align-items: start;
  }
  .game:fullscreen .play-area, .game.is-expanded .play-area { width: min(100%, 126vh - 114px); margin-inline: auto; }
  .game:fullscreen .directions, .game.is-expanded .directions { grid-row: 1; }
  .game:fullscreen .tools-copy, .game.is-expanded .tools-copy { grid-row: 3; }
}
@media (prefers-reduced-motion: reduce) {
  .cat.hop { animation: none; }
}
