:root {
  --ink: #173f39;
  --sun: #ef745f;
  --moon: #5653a8;
  --cream: #fff3d3;
  --sea: #2c6653;
  --stone: #195544;
}
* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 90% 2%, #ffdd91 0 8%, transparent 9%),
    var(--cream);
  color: var(--ink);
  font:
    17px/1.35 system-ui,
    sans-serif;
}
.game-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 8px clamp(10px, 3vw, 26px);
  border-bottom: 3px solid #d3a363;
  background: #fff8e6;
}
.game-bar strong {
  margin-right: auto;
}
button,
a {
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 13px;
  background: #fffdf5;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}
button.primary {
  min-height: 48px;
  background: var(--sun);
  color: #342220;
}
button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}
:focus-visible {
  outline: 4px solid #2948b3;
  outline-offset: 3px;
}
main {
  width: min(980px, 100%);
  margin: auto;
  padding: 16px;
}
.welcome {
  max-width: 620px;
  margin: 7vh auto;
  padding: clamp(20px, 5vw, 44px);
  text-align: center;
}
.card {
  border: 3px solid var(--ink);
  border-radius: 28px;
  background: #fff8e6;
  box-shadow: 0 10px 0 #d4a466;
}
.eyebrow {
  margin: 0.1rem 0;
  color: #7a3b28;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
h1 {
  margin: 0.2rem 0;
  font-size: clamp(2.4rem, 10vw, 4.8rem);
  line-height: 1;
}
.opening-art {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 24px 0;
}
.opening-art span {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  border: 4px solid var(--ink);
  border-radius: 50%;
  font-size: 0.78rem;
  font-weight: 900;
}
.opening-sun {
  background: radial-gradient(circle, #ffd460 0 38%, var(--sun) 40%);
}
.opening-moon {
  background: radial-gradient(
    circle at 35% 40%,
    #fff3d3 0 28%,
    var(--moon) 30%
  );
}
.opening-beacon {
  border-radius: 20px !important;
  background: repeating-radial-gradient(
    circle,
    #fff8e6 0 8px,
    #4eaa89 9px 14px
  );
}
#play-area {
  display: grid;
  grid-template-columns: minmax(250px, 330px) auto minmax(230px, 1fr);
  gap: 18px;
  align-items: start;
}
.round-copy {
  grid-column: 1/-1;
  padding: 10px 14px;
  border: 2px solid #d3a363;
  border-radius: 18px;
  background: #fff8e6;
}
.round-copy p {
  margin: 0.35rem 0;
}
#feedback {
  min-height: 1.5em;
  font-weight: 750;
}
#grid {
  display: grid;
  grid-template-columns: repeat(4, 56px);
  gap: 4px;
  width: max-content;
  padding: 9px;
  border: 5px solid var(--sea);
  border-radius: 23px;
  background: linear-gradient(140deg, #458f77, #1f5d4c);
  box-shadow: inset 0 0 0 4px #c3ddad;
}
.tile {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 56px;
  border: 2px solid #d3b36a;
  border-radius: 14px;
  background: #fff8e6;
  overflow: hidden;
}
.tile-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.tile.stone {
  background: linear-gradient(135deg, #1f5947, #123f35);
  color: #e6efcf;
}
.beacon {
  position: absolute;
  inset: 5px;
  display: grid;
  place-items: end center;
  border: 3px solid;
  border-radius: 50%;
  font-size: 0;
}
.sun-beacon {
  border-color: var(--sun);
  background: repeating-radial-gradient(circle, #fff7d7 0 4px, #ffd460 5px 8px);
}
.moon-beacon {
  border-color: var(--moon);
  background: repeating-radial-gradient(circle, #fff8e6 0 4px, #afa9eb 5px 8px);
}
.buddy {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  font-size: 0;
}
.sun {
  border: 0;
  background:
    radial-gradient(circle, var(--sun) 0 50%, transparent 52%),
    repeating-conic-gradient(#ffd460 0 10deg, transparent 11deg 28deg);
}
.moon {
  border: 0;
  background:
    radial-gradient(circle at 34% 33%, #fff8e6 0 31%, transparent 33%),
    var(--moon);
  color: #fff8e6;
}
.sun-beacon::before,
.moon-beacon::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 43%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
}
.sun-beacon::before {
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--sun) 0 46%, transparent 49%),
    repeating-conic-gradient(var(--sun) 0 9deg, transparent 10deg 30deg);
}
.moon-beacon::before {
  border-radius: 50%;
  background:
    radial-gradient(circle at 33% 32%, #fff8e6 0 31%, transparent 34%),
    var(--moon);
}
.controls {
  display: grid;
  gap: 10px;
}
#pad {
  display: grid;
  grid-template-columns: repeat(2, minmax(114px, 1fr));
  gap: 8px;
}
#pad button {
  min-height: 48px;
  background: #eaf4da;
}
#actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
#actions button {
  min-width: 0;
}
#next,
#play-again {
  grid-column: 1/-1;
}
#finish-stamps {
  grid-column: 1/-1;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
#finish-stamps span {
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 20px;
  background: #ffd460;
  font-weight: 900;
}
#play-area:has(#next:not([hidden])) #pad,
#play-area:has(#play-again:not([hidden])) #pad,
#play-area:has(#next:not([hidden])) #actions button:not(#next),
#play-area:has(#play-again:not([hidden])) #actions button:not(#play-again) {
  display: none;
}
dialog {
  width: min(700px, calc(100vw - 24px));
  max-width: min(700px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-x: hidden;
  overflow-y: auto;
  border: 4px solid var(--ink);
  border-radius: 22px;
  background: #fff8e6;
  color: var(--ink);
}
dialog::backdrop {
  background: #173f3990;
}
.frames {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.frames figure {
  min-width: 0;
  margin: 0;
}
.frame-action {
  min-height: 1.4em;
  margin: 0 0 6px;
  color: #7a3b28;
  font-weight: 900;
}
.frames figcaption {
  font-weight: 700;
}
.mini-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-height: 104px;
  border: 4px solid var(--sea);
  border-radius: 16px;
  background: #d8f1ce;
  overflow: hidden;
}
.mini-cell {
  position: relative;
  min-width: 0;
  border-right: 2px solid #8dbb8e;
}
.mini-cell:last-child {
  border-right: 0;
}
.mini-cell.blocked {
  box-shadow: inset 7px 0 0 var(--stone);
}
.mini-board i {
  position: absolute;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.mini-sun {
  z-index: 1;
  background: repeating-conic-gradient(var(--sun) 0 10deg, #ffd460 11deg 22deg);
}
.mini-sun::after {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--sun);
  content: "";
}
.mini-moon {
  z-index: 1;
  background: var(--moon);
}
.mini-moon::after {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff8e6;
  box-shadow: -6px 0 0 var(--moon);
  content: "";
}
.mini-sun-beacon {
  width: 40px !important;
  height: 40px !important;
  border: 3px solid #b77a28 !important;
  background: #ffd460;
}
.mini-sun-beacon::after {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--sun);
  content: "";
}
#close-help {
  position: sticky;
  z-index: 1;
  top: 0;
  display: block;
  margin-left: auto;
  background: #fffdf5;
  box-shadow: 0 3px 0 #d3a363;
}
@media (max-width: 650px) {
  main {
    padding: 10px;
  }
  .game-bar strong {
    display: none;
  }
  #play-area {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 10px;
  }
  #play-area:has(#play-again:not([hidden])) {
    gap: 4px;
  }
  .round-copy,
  #finish-stamps {
    width: 100%;
  }
  .controls {
    width: min(100%, 450px);
  }
  #grid {
    grid-row: 2;
  }
  .round-copy {
    grid-row: 1;
  }
  .controls {
    grid-row: 3;
  }
  .welcome {
    margin: 3vh auto;
  }
  .opening-art span {
    width: 75px;
    height: 75px;
  }
  dialog {
    padding: 12px;
  }
  .frames {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }
  .help-frame {
    width: min(100%, 320px);
    margin-inline: auto !important;
  }
}
@media (max-height: 360px) and (min-width: 700px) {
  .game-bar {
    position: absolute;
    z-index: 3;
    left: 0;
    right: 0;
    min-height: 45px;
    padding: 2px 10px;
  }
  .game-bar button,
  .game-bar a {
    min-height: 44px;
    padding: 4px 9px;
  }
  main {
    width: 100%;
    padding: 48px 8px 4px;
  }
  #play-area {
    grid-template-columns: 250px 230px 1fr;
    grid-template-rows: auto auto;
    gap: 8px;
  }
  .round-copy {
    grid-column: 2/-1;
    grid-row: 1;
    min-height: 48px;
    display: flex;
    flex-wrap: wrap;
    align-content: start;
    gap: 10px;
    padding: 4px 8px;
    font-size: 0.78rem;
  }
  .round-copy p {
    margin: 0;
  }
  #grid {
    grid-column: 1;
    grid-row: 1 / span 2;
    grid-template-columns: repeat(4, 48px);
    padding: 5px;
  }
  .tile {
    min-height: 48px;
  }
  .controls {
    grid-column: 2/-1;
    grid-row: 2;
    align-self: start;
    padding-top: 0;
  }
  #pad {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  #pad button {
    min-height: 48px;
  }
  .controls button {
    min-height: 44px;
    padding: 5px 8px;
    font-size: 0.82rem;
  }
  #actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  #finish-stamps {
    position: fixed;
    right: 7px;
    bottom: 3px;
    z-index: 4;
    gap: 3px;
  }
  #finish-stamps span {
    padding: 3px 6px;
    font-size: 0.68rem;
  }
  .welcome {
    margin: 0 auto;
    padding: 12px;
  }
  .opening-art {
    margin: 8px 0;
  }
  h1 {
    font-size: 2rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *:before,
  *:after {
    animation: none !important;
    transition: none !important;
  }
}
