:root {
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  color: #e9eddf;
  background: #112521;
  font-synthesis: none;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 40%, #24433a 0, transparent 65%);
  min-height: 100svh;
}
main {
  max-width: 820px;
  margin: auto;
  padding: 32px 28px;
}
header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 10px;
  letter-spacing: 2px;
  color: #829c8e;
}
header a {
  color: #b3c4af;
  text-decoration: none;
}
header span {
  font-size: 9px;
}
.intro {
  text-align: center;
  margin: 55px 0 32px;
}
.eyebrow {
  color: #c5cf7e;
  font-size: 10px;
  letter-spacing: 3px;
}
h1 {
  font:
    normal clamp(32px, 6vw, 52px) Georgia,
    serif;
  letter-spacing: -1.5px;
  margin: 16px 0 12px;
}
.subtitle {
  font-size: 13px;
  color: #9eb4a7;
}
.play {
  max-width: 420px;
  margin: auto;
}
.board-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 9px;
  letter-spacing: 1px;
  color: #b3c4ad;
  margin: 0 2px 15px;
}
.board-meta i {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #e5c978;
  margin-right: 7px;
}
#board {
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  gap: 5px;
  padding: 8px;
  border: 1px solid #40564a;
  border-radius: 20px;
  background: #0e211c;
  box-shadow: 0 20px 60px #0003;
}
.tile {
  aspect-ratio: 1;
  min-width: 0;
  display: block;
  padding: 0;
  background: #213a31;
  border: 1px solid #2b4439;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
  touch-action: manipulation;
}
.tile:hover {
  background: #2d493b;
}
.tile svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.pipes {
  stroke: #668275;
  stroke-width: 7;
  stroke-linecap: round;
}
.tile circle {
  fill: #738e7c;
}
.tile text {
  fill: #172b22;
  font: 24px Georgia;
  text-anchor: middle;
}
.tile.lit {
  background: #304938;
}
.tile.lit .pipes {
  stroke: #e5d386;
  filter: drop-shadow(0 0 4px #dbc36a55);
}
.tile.lit circle {
  fill: #ecdc98;
}
.tile:disabled {
  cursor: default;
  opacity: 1;
}
button {
  font: inherit;
}
button:focus-visible,
a:focus-visible {
  outline: 3px solid #f2d88d;
  outline-offset: 3px;
}
#message {
  text-align: center;
  color: #c3d1be;
  font-size: 12px;
  min-height: 32px;
  margin: 24px 0 8px;
  line-height: 1.6;
}
.tools {
  display: flex;
  justify-content: center;
  gap: 30px;
}
.tools button {
  background: none;
  border: 0;
  color: #a4b9a8;
  font-size: 11px;
  cursor: pointer;
  padding: 12px;
}
.primary {
  display: block;
  margin: 8px auto 14px;
  border: 0;
  border-radius: 24px;
  background: #e6d28a;
  color: #233529;
  padding: 12px 24px;
  cursor: pointer;
  font-size: 12px;
}
.primary[hidden] {
  display: none;
}
footer {
  text-align: center;
  margin-top: 30px;
}
#levels {
  display: flex;
  gap: 8px;
  justify-content: center;
}
#levels button {
  width: 29px;
  height: 29px;
  border: 1px solid #48604b;
  border-radius: 50%;
  background: transparent;
  color: #a5bba7;
  font-size: 10px;
  cursor: pointer;
}
#levels button.selected {
  background: #c8d49c;
  color: #263c2c;
  border-color: #c8d49c;
}
#levels button:disabled {
  opacity: 0.25;
  cursor: default;
}
footer p {
  font:
    italic 14px Georgia,
    serif;
  color: #a7b6a1;
  margin: 23px 0 14px;
}
footer small {
  font-size: 9px;
  color: #799080;
}
.hint {
  animation: pulse 1s 3;
}
@keyframes pulse {
  50% {
    box-shadow: inset 0 0 0 3px #f7de93;
    background: #58613c;
  }
}
@media (max-width: 500px) {
  main {
    padding: 24px 20px;
  }
  header span {
    display: none;
  }
  .intro {
    margin: 35px 0 26px;
  }
  .play {
    max-width: 360px;
  }
  footer {
    margin-top: 22px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
  .hint {
    outline: 3px solid #f7de93;
  }
}
/* A viewport-sized play surface: decoration yields space before game controls do. */
main {
  height: 100svh;
  min-height: 480px;
  display: grid;
  grid-template-rows: 16px 88px minmax(0, 1fr) 84px;
  gap: 8px;
  padding: 16px 20px;
}
header {
  align-items: center;
}
.intro {
  margin: 0;
  align-self: center;
}
.eyebrow {
  margin: 0;
}
h1 {
  font-size: clamp(28px, 4vw, 40px);
  margin: 8px 0;
}
.subtitle {
  margin: 0;
  font-size: 12px;
}
.play {
  width: 100%;
  max-width: 420px;
  min-height: 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.board-meta {
  width: 100%;
  flex: none;
  margin: 0;
  height: 18px;
}
#board {
  flex: 1;
  min-height: 0;
  max-height: 420px;
  width: auto;
  max-width: 100%;
  aspect-ratio: 1;
  align-self: center;
  box-sizing: border-box;
}
#message {
  flex: none;
  min-height: 24px;
  line-height: 24px;
  margin: 0;
  font-size: 11px;
  white-space: nowrap;
}
.tools {
  flex: none;
  gap: 20px;
  height: 44px;
}
.tools button {
  min-height: 44px;
  font-size: 12px;
  padding: 10px;
}
.primary {
  flex: none;
  min-height: 44px;
  margin: 0;
  padding: 10px 24px;
}
.primary[hidden] {
  display: none;
}
footer {
  margin: 0;
  align-self: start;
}
#levels {
  gap: 7px;
}
#levels button {
  width: 40px;
  height: 40px;
  min-width: 40px;
  font-size: 12px;
}
footer p {
  margin: 8px 0;
  font-size: 12px;
}
footer small {
  font-size: 9px;
  display: block;
}
@media (max-height: 650px) and (max-width: 599px) {
  main {
    padding: 8px 12px;
    grid-template-rows: 0 60px minmax(0, 1fr) 50px;
    gap: 6px;
  }
  header {
    visibility: hidden;
    overflow: hidden;
  }
  .subtitle {
    display: none;
  }
  .eyebrow {
    font-size: 9px;
  }
  h1 {
    font-size: 28px;
    margin: 6px 0;
  }
  footer p {
    display: none;
  }
  footer small {
    font-size: 8px;
    margin-top: 4px;
  }
  #board {
    padding: 5px;
    gap: 4px;
    border-radius: 14px;
  }
  #message {
    font-size: 10px;
  }
  .tools {
    height: 40px;
  }
  .tools button {
    min-height: 40px;
  }
  #levels button {
    width: 40px;
    height: 40px;
  }
}
@media (min-width: 600px) and (max-height: 560px) {
  main {
    min-height: 320px;
    max-width: 1000px;
    grid-template-columns: minmax(220px, 1fr) minmax(320px, 1.4fr);
    grid-template-rows: 20px minmax(0, 1fr) 100px;
    padding: 12px 20px;
    gap: 8px 24px;
  }
  header {
    grid-column: 1/-1;
  }
  .intro {
    grid-column: 1;
    grid-row: 2;
    align-self: center;
  }
  footer {
    grid-column: 1;
    grid-row: 3;
    align-self: start;
  }
  .play {
    grid-column: 2;
    grid-row: 2/4;
  }
  .intro h1 {
    font-size: 32px;
  }
  header span {
    display: none;
  }
  #board {
    max-height: calc(100svh - 158px);
  }
  #message {
    font-size: 10px;
  }
  footer small {
    line-height: 1.4;
  }
  .play:has(.primary:not([hidden])) #board {
    max-height: calc(100svh - 208px);
  }
}
@media (min-width: 600px) and (max-height: 560px) {
  #board {
    padding: 5px;
    gap: 4px;
    max-height: calc(100svh - 140px);
  }
}

/* Optional feedback is a separate dialog; it does not displace puzzle controls. */
#feedback-open {
  min-height: 40px;
  padding: 4px 10px;
  font: inherit;
  font-size: 11px;
  color: inherit;
  border: 1px solid #668c77;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
}
#feedback-dialog {
  box-sizing: border-box;
  width: min(460px, 94vw);
  max-height: 90svh;
  overflow: auto;
  padding: 20px;
  border: 1px solid #668c77;
  border-radius: 14px;
  background: #142c25;
  color: #edf1de;
}
#feedback-dialog::backdrop {
  background: #0009;
}
#feedback-dialog h2 {
  font: 600 22px system-ui;
  margin: 0 0 12px;
}
#feedback-dialog p {
  font: 14px/1.5 system-ui;
}
#feedback-dialog label {
  display: block;
  margin: 12px 0 6px;
  font: 14px system-ui;
}
#feedback-dialog select,
#feedback-dialog textarea {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  background: #fff9ef;
  color: #263d35;
  font: 16px system-ui;
  border-radius: 6px;
  padding: 8px;
}
.feedback-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.feedback-actions button {
  min-height: 44px;
  padding: 10px;
  background: #d5e29d;
  color: #142c25;
  border: 0;
  border-radius: 6px;
  font: 14px system-ui;
}

.tools {
  width: 100%;
  gap: 4px;
}
.tools button {
  flex: 1;
  min-width: 0;
  padding: 6px;
  font-size: 11px;
}
