:root {
  color-scheme: dark;
  --ink: #172449;
  --cave: #10183c;
  --wall: #283d72;
  --paper: #fff9df;
  --amber: #d77b28;
  --amber-soft: #ffe3a3;
  --teal: #43c6b0;
  --dark-pebble: #b8c5ce;
}
* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 15% 2%, #344a82 0, transparent 33%), var(--cave);
  color: var(--paper);
  font-family: ui-rounded, "Trebuchet MS", system-ui, sans-serif;
}
button,
a {
  font: inherit;
}
button {
  cursor: pointer;
}
.skip-link {
  position: fixed;
  z-index: 10;
  top: -60px;
  left: 10px;
  padding: 8px;
  background: #fff;
  color: var(--ink);
}
.skip-link:focus {
  top: 10px;
}
.game-bar {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px clamp(10px, 3vw, 26px);
  border-bottom: 2px solid #7189bf;
}
.game-bar a,
.auxiliary {
  min-height: 44px;
  padding: 9px 12px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  color: var(--ink);
  background: #fffdf5;
  font-weight: 900;
  text-decoration: none;
}
.game-bar [data-player-profile-slot] {
  max-width: 44vw;
  overflow-wrap: anywhere;
}
.primary {
  min-height: 48px;
  padding: 10px 16px;
  border: 3px solid #f8e6b9;
  border-radius: 14px;
  color: #1a274b;
  background: #ffbf4f;
  font-weight: 900;
  box-shadow: 0 3px 0 #9f5316;
}
.primary:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #9f5316;
}
:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 3px;
  box-shadow: 0 0 0 7px var(--teal);
}
main {
  width: min(1050px, 100%);
  margin: auto;
  padding: clamp(10px, 3vw, 28px);
}
h1,
h2,
h3,
p {
  margin-top: 0;
}
.card {
  border: 3px solid #07112f;
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 6px 0 rgba(2, 9, 29, 0.65);
}
.welcome {
  width: min(660px, 100%);
  margin: clamp(18px, 8vh, 90px) auto;
  padding: clamp(20px, 5vw, 45px);
  text-align: center;
}
.welcome h1 {
  margin-bottom: 9px;
  font-size: clamp(2.3rem, 8vw, 4.2rem);
  line-height: 1;
}
.welcome .auxiliary {
  display: block;
  margin: 12px auto 0;
}
.opening-cave {
  display: grid;
  grid-template-columns: repeat(3, 42px);
  gap: 6px;
  justify-content: center;
  width: 176px;
  margin: 0 auto 15px;
  padding: 13px;
  border: 4px solid #07112f;
  border-radius: 18px;
  background: var(--wall);
}
.opening-cave span {
  width: 42px;
  height: 42px;
  border: 4px solid #f8ce75;
  border-radius: 48% 52% 44% 56%;
  background: radial-gradient(
    circle at 35% 30%,
    #fff9d4 0 16%,
    #f3ae40 17% 50%,
    #bd6425 51%
  );
  box-shadow: 0 0 10px #ffb543;
}
.opening-cave span:nth-child(2),
.opening-cave span:nth-child(4),
.opening-cave span:nth-child(8) {
  background:
    radial-gradient(circle at 64% 35%, #10183c 0 18%, transparent 19%), #b8c5ce;
  border-color: #71849b;
  box-shadow: none;
}
.eyebrow {
  margin-bottom: 7px;
  color: #725529;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}
.round-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}
.round-head h1 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 4vw, 2.5rem);
}
.player-note {
  max-width: 280px;
  margin: 0;
  padding: 8px;
  border: 2px solid #e0bd66;
  border-radius: 10px;
  background: #fff7d8;
  font-weight: 800;
  overflow-wrap: anywhere;
}
.summary {
  margin: 10px 0;
  padding: 10px;
  border-left: 5px solid var(--teal);
  border-radius: 8px;
  background: #1c2b58;
  color: #fff9df;
  font-weight: 800;
  line-height: 1.4;
}
.layout {
  display: grid;
  grid-template-columns: minmax(272px, 1fr) minmax(285px, 0.72fr);
  align-items: start;
  gap: 14px;
}
.cave {
  padding: clamp(8px, 2vw, 16px);
  background:
    radial-gradient(circle at 50% 35%, #405a8e 0, transparent 45%), #172652;
  color: var(--paper);
}
.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(64px, 1fr));
  gap: clamp(7px, 1.5vw, 12px);
}
.lamp {
  position: relative;
  display: grid;
  min-width: 64px;
  min-height: 76px;
  place-items: center;
  padding: 2px;
  border: 0;
  border-radius: 17px;
  background: transparent;
}
.lamp-art {
  width: min(88%, 82px);
  height: min(88%, 82px);
  overflow: visible;
}
.lamp-art .pebble {
  fill: var(--dark-pebble);
  stroke: #dce5e8;
  stroke-width: 5;
}
.lamp-art .moon-notch {
  fill: #172652;
}
.lamp-art .rays {
  display: none;
  fill: none;
  stroke: #f7bb4c;
  stroke-width: 7;
  stroke-linecap: round;
}
.lamp.lit .pebble {
  fill: #ffecac;
  stroke: #fff9df;
}
.lamp.lit .moon-notch {
  fill: #f1a335;
}
.lamp.lit .rays {
  display: block;
}
.lamp.lit {
  filter: drop-shadow(0 0 8px #ffb33e);
}
.lamp.selected {
  background: rgba(67, 198, 176, 0.3);
  outline: 4px solid var(--teal);
  outline-offset: 2px;
}
.lamp.affected .lamp-art {
  outline: 4px dotted #fff9df;
  outline-offset: 1px;
  border-radius: 50%;
}
.lamp span {
  position: absolute;
  right: 8px;
  bottom: 7px;
  display: grid;
  width: 21px;
  height: 21px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #172449;
  font-size: 0.72rem;
  font-weight: 900;
}
.result {
  min-height: 24px;
  margin: 8px 0 0;
  text-align: center;
  font-weight: 900;
}
.controls {
  padding: 14px;
}
.controls > .primary,
.controls > #next {
  width: 100%;
}
.feedback {
  min-height: 48px;
  margin: 10px 0;
  padding: 8px;
  border-left: 5px solid var(--amber);
  border-radius: 8px;
  background: #fff1cd;
  font-weight: 800;
  line-height: 1.35;
}
.actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}
.actions .auxiliary {
  width: 100%;
}
.hint-output {
  min-height: 42px;
  margin: 10px 0;
  padding: 8px;
  border: 2px solid #896232;
  border-radius: 8px;
  background: #fff9df;
  color: #3d2b15;
  font-weight: 900;
}
.ending {
  display: grid;
  grid-template-columns: minmax(210px, 0.7fr) 1fr;
  gap: 14px;
  align-items: center;
  margin-top: 12px;
  padding: 14px;
}
.ending h2 {
  margin-bottom: 7px;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
}
.seals {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 15px;
  border: 3px solid #07112f;
  border-radius: 14px;
  background: #243967;
}
.seals i {
  display: block;
  width: 46px;
  height: 46px;
  border: 5px solid #f5c35d;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    #fff2b7 0 16%,
    #cd742b 17% 45%,
    #7b3d21 46%
  );
}
.ending-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ending-actions button {
  flex: 1 1 150px;
}
dialog {
  width: min(760px, calc(100% - 24px));
  border: 4px solid #07112f;
  border-radius: 18px;
  background: #fff9df;
  color: var(--ink);
}
dialog::backdrop {
  background: rgba(2, 9, 29, 0.68);
}
dialog a {
  display: inline-block;
  margin-top: 12px;
  color: #172449;
  font-weight: 900;
}
.examples {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.examples article {
  padding: 10px;
  border: 3px solid #172449;
  border-radius: 12px;
  background: #e4f1ed;
}
.examples h3 {
  margin-bottom: 6px;
}
.examples p {
  margin: 8px 0 0;
  font-size: 0.88rem;
}
.demo-grid {
  display: grid;
  grid-template-columns: repeat(3, 24px);
  gap: 3px;
  align-items: center;
  justify-content: center;
}
.demo-arrow {
  display: block;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 900;
}
.demo-lamp {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
}
.demo-lamp .lamp-art {
  width: 24px;
  height: 24px;
}
.demo-lamp .lamp-art .pebble {
  stroke-width: 8;
}
.demo-lamp .lamp-art .rays {
  stroke-width: 11;
}
.demo-lamp.marked {
  outline: 2px dotted #172449;
  border-radius: 50%;
}
.demo-lamp.changed {
  background: #b8e1d8;
  border-radius: 50%;
}
@media (max-width: 620px) {
  .game-bar strong {
    display: none;
  }
  .layout {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .board {
    gap: 7px;
  }
  .round-head {
    align-items: start;
  }
  .player-note {
    font-size: 0.78rem;
  }
  .controls {
    padding: 9px;
  }
  .feedback {
    min-height: 38px;
    margin: 7px 0;
  }
  .ending {
    grid-template-columns: 1fr;
  }
  .seals {
    padding: 7px;
  }
  .examples {
    grid-template-columns: 1fr;
  }
  .welcome {
    margin: 28px auto;
  }
}
@media (max-height: 430px) and (orientation: landscape) {
  .game-bar {
    min-height: 42px;
    padding-block: 2px;
  }
  .game-bar a {
    min-height: 36px;
    padding: 5px 9px;
  }
  main {
    padding: 4px 10px;
  }
  .round-head,
  .summary {
    display: none;
  }
  .layout {
    grid-template-columns: 320px minmax(300px, 1fr);
    gap: 8px;
  }
  .cave {
    padding: 5px;
  }
  .board {
    gap: 4px;
  }
  .lamp {
    min-height: 64px;
  }
  .lamp-art {
    width: 58px;
    height: 58px;
  }
  .controls {
    padding: 5px;
  }
  .feedback {
    min-height: 24px;
    margin: 3px 0;
    padding: 3px;
    font-size: 0.74rem;
  }
  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }
  .actions .auxiliary {
    min-height: 44px;
    padding: 4px;
    font-size: 0.68rem;
  }
  .hint-output {
    min-height: 0;
    margin: 3px 0;
    padding: 3px;
    font-size: 0.72rem;
  }
  .ending {
    grid-template-columns: 180px 1fr;
    margin-top: 5px;
    padding: 5px;
  }
  .ending p {
    margin-bottom: 4px;
  }
  .seals {
    padding: 5px;
  }
  .seals i {
    width: 33px;
    height: 33px;
  }
  .ending-actions button {
    min-height: 44px;
    padding: 5px;
    font-size: 0.78rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
body[data-phase="finished"] #controls {
  display: none;
}
@media (max-width: 620px) {
  body[data-phase="finished"] .ending {
    margin-top: 8px;
    padding: 9px;
  }
  body[data-phase="finished"] .ending h2 {
    margin-bottom: 5px;
    font-size: 1.45rem;
  }
  body[data-phase="finished"] .ending p {
    margin-bottom: 6px;
  }
}
@media (max-height: 430px) and (orientation: landscape) {
  body[data-phase="finished"] #play-area {
    position: relative;
  }
  body[data-phase="finished"] .layout {
    display: block;
    width: 320px;
  }
  body[data-phase="finished"] .ending {
    position: absolute;
    top: 0;
    right: 0;
    left: 328px;
    display: block;
    margin: 0;
    min-height: 210px;
  }
  body[data-phase="finished"] .ending .seals {
    display: none;
  }
  body[data-phase="finished"] .ending h2 {
    font-size: 1.2rem;
  }
  body[data-phase="finished"] .ending p {
    font-size: 0.76rem;
  }
  .ending-actions {
    display: block;
  }
  .ending-actions button {
    width: 100%;
    margin-top: 4px;
  }
}
@media (max-width: 620px) {
  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }
  .actions .auxiliary {
    min-height: 44px;
    padding: 4px;
    font-size: 0.67rem;
  }
  .hint-output {
    min-height: 30px;
    margin: 5px 0;
    padding: 5px;
    font-size: 0.78rem;
  }
}

/* The standalone Help examples use the same SVG state classes as the board. */
.lamp-art-lit .pebble {
  fill: #ffecac;
  stroke: #fff9df;
}
.lamp-art-lit .moon-notch {
  fill: #f1a335;
}
.lamp-art-lit .rays {
  display: block;
}
.help-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.help-actions .auxiliary,
.help-actions a {
  display: inline-flex;
  flex: 1 1 140px;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin: 0;
  padding: 9px 12px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  color: var(--ink);
  background: #fffdf5;
  font-weight: 900;
  text-decoration: none;
}
.examples article {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
}
.examples h3,
.examples p {
  grid-column: 1 / -1;
}

@media (max-width: 620px) {
  main {
    padding: 8px;
  }
  .cave {
    padding: 6px;
  }
  .board {
    gap: 4px;
  }
  .lamp {
    min-height: 64px;
  }
  .lamp-art {
    width: 62px;
    height: 62px;
  }
  .round-head .eyebrow {
    display: none;
  }
  .round-head h1 {
    font-size: 1.35rem;
  }
  .summary {
    margin: 6px 0;
    padding: 6px;
    font-size: 0.78rem;
    line-height: 1.25;
  }
  .controls {
    padding: 7px;
  }
  .feedback {
    min-height: 34px;
    margin: 6px 0;
    padding: 5px;
    font-size: 0.78rem;
    line-height: 1.25;
  }
  .actions .auxiliary {
    font-size: 0.72rem;
  }
  .hint-output {
    min-height: 26px;
    margin: 5px 0;
    padding: 4px;
    font-size: 0.76rem;
  }
  .examples {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .examples article {
    padding: 6px;
  }
  .examples h3 {
    margin-bottom: 3px;
    font-size: 0.9rem;
  }
  .examples p {
    margin: 5px 0 0;
    font-size: 0.73rem;
    line-height: 1.18;
  }
  .demo-grid {
    grid-template-columns: repeat(3, 19px);
    gap: 2px;
  }
  .demo-lamp,
  .demo-lamp .lamp-art {
    width: 19px;
    height: 19px;
  }
  .demo-arrow {
    font-size: 1.1rem;
  }
}

/* Keep compact controls at their authored touch target minima. */
@media (max-height: 430px) and (orientation: landscape) {
  .game-bar a {
    min-height: 44px;
  }
  .actions button.primary,
  .ending-actions button.primary,
  #play-again.primary {
    min-height: 48px;
  }

  dialog {
    width: calc(100% - 12px);
    max-height: calc(100dvh - 12px);
    margin: 6px auto;
    padding: 8px;
    overflow-y: auto;
  }
  dialog .eyebrow {
    margin-bottom: 2px;
    font-size: 0.66rem;
  }
  dialog h2 {
    margin-bottom: 4px;
    font-size: 1.1rem;
  }
  .examples {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }
  .examples article {
    padding: 4px;
  }
  .examples h3 {
    margin-bottom: 2px;
    font-size: 0.8rem;
  }
  .examples p {
    margin-top: 3px;
    font-size: 0.66rem;
    line-height: 1.12;
  }
  .demo-grid {
    grid-template-columns: repeat(3, 19px);
    gap: 2px;
  }
  .demo-lamp,
  .demo-lamp .lamp-art {
    width: 19px;
    height: 19px;
  }
  .demo-arrow {
    font-size: 1rem;
  }
  .help-actions {
    margin-top: 4px;
  }
}

.actions button.primary,
.ending-actions button.primary,
#play-again.primary {
  min-height: 48px;
}

/* A solved intermediate grotto keeps the proof of success and Next together. */
body[data-round-state="done"]:not([data-phase="finished"]) #flip,
body[data-round-state="done"]:not([data-phase="finished"])
  #actions
  > :not(#help),
body[data-round-state="done"]:not([data-phase="finished"]) #hint-output {
  display: none;
}
body[data-round-state="done"]:not([data-phase="finished"]) .feedback {
  min-height: 0;
  margin: 6px 0;
}

@media (max-width: 620px) {
  body[data-phase="finished"] .ending {
    gap: 6px;
    margin-top: 7px;
    padding: 6px;
  }
  body[data-phase="finished"] .seals {
    gap: 4px;
    padding: 4px;
  }
  body[data-phase="finished"] .seals i {
    width: 30px;
    height: 30px;
    border-width: 3px;
  }
  body[data-phase="finished"] .ending h2 {
    margin: 0 0 4px;
    font-size: 1.15rem;
  }
  body[data-phase="finished"] .ending p {
    display: none;
  }
  body[data-phase="finished"] .ending-actions {
    flex-wrap: nowrap;
    gap: 4px;
  }
  body[data-phase="finished"] .ending-actions button {
    min-width: 0;
    flex: 1 1 0;
    min-height: 48px;
    padding: 5px;
    font-size: 0.75rem;
  }
}
@media (max-height: 430px) and (orientation: landscape) {
  #play-area {
    position: relative;
  }
  .round-head {
    display: block;
    position: absolute;
    z-index: 2;
    top: 0;
    left: 328px;
    width: calc(100% - 332px);
    margin: 0;
  }
  .round-head .eyebrow,
  .player-note {
    display: none;
  }
  .round-head h1 {
    font-size: 1rem;
  }
  .controls {
    padding-top: 35px;
  }
}

/* A short landscape welcome gives the cave preview its own column, keeping
   the first primary action inside the first phone viewport. */
@media (max-height: 390px) and (min-width: 600px) and (orientation: landscape) {
  main {
    padding: 4px 10px;
  }
  #welcome {
    display: grid;
    grid-template-columns: 185px minmax(0, 1fr);
    column-gap: 14px;
    align-items: center;
    width: min(760px, 100%);
    margin: 4px auto;
    padding: 10px 14px;
    text-align: left;
  }
  .opening-cave {
    grid-row: 1 / span 5;
    margin: 0 auto;
  }
  #welcome > :not(.opening-cave) {
    grid-column: 2;
  }
  #welcome .eyebrow {
    margin-bottom: 3px;
    font-size: 0.66rem;
  }
  #welcome h1 {
    margin-bottom: 5px;
    font-size: 2rem;
  }
  #welcome > p:not(.eyebrow) {
    margin-bottom: 7px;
    font-size: 0.82rem;
    line-height: 1.25;
  }
  #welcome .primary,
  #welcome .auxiliary {
    justify-self: start;
  }
  #welcome .primary {
    min-width: 230px;
  }
  #welcome .auxiliary {
    margin: 4px 0 0;
  }
}
