:root {
  --night: #182a52;
  --violet: #60518d;
  --paper: #fffbea;
  --mint: #8ed8b2;
  --rose: #ee88ad;
  --gold: #f4d36b;
  --ink: #17213f;
}
html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--night);
}
.moth-night {
  color: var(--ink);
  background: linear-gradient(#17264c 0 48%, #315846 48%);
  touch-action: manipulation;
}
.moth-night .game-shell {
  height: 100dvh;
  min-height: 0;
  padding: max(7px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  display: grid;
  grid-template-rows: 50px auto minmax(160px, 1fr) auto;
  gap: 6px;
  max-width: 760px;
  background: transparent;
}
.moth-night header {
  padding: 0;
  min-height: 50px;
}
.moth-night .brand {
  color: white;
}
.moth-night .brand small {
  color: #c9f7dd;
}
.moth-night .round-button {
  width: 46px;
  height: 46px;
  min-height: 46px;
  background: #fffdf0;
  color: var(--night);
  border-color: white;
}
.moth-night .mission-card {
  margin: 0;
  min-height: 70px;
  padding: 7px 12px;
  background: #fffdf2f7;
  border: 2px solid #6d5a97;
  color: var(--ink);
}
.moth-night .mission-card > div:first-child {
  display: flex;
  justify-content: space-between;
}
.moth-night .mission-card p {
  margin: 4px 0;
  font-size: 13px;
  line-height: 1.15;
}
.moth-night .progress-track {
  height: 7px;
  margin: 4px 0 0;
}
.moth-night .progress-track i {
  background: linear-gradient(90deg, var(--mint), var(--rose));
}
#stage {
  position: relative;
  min-height: 0;
  height: auto;
  overflow: hidden;
  border: 2px solid #d9f9ec;
  border-radius: 22px;
  background: radial-gradient(circle at 50% 25%, #6278a8, #182a52 72%);
  box-shadow: 0 8px 20px #091329aa;
  isolation: isolate;
}
#stage canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none;
}
.scene-caption {
  position: absolute;
  z-index: 4;
  top: 7px;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 9px;
  border-radius: 999px;
  background: #17264cdd;
  color: white;
  white-space: nowrap;
  font-size: 9px;
  letter-spacing: 0.12em;
}
#loading {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: var(--night);
  color: white;
  font-weight: 900;
}
#habitat-status {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
}
.habitat-badge {
  position: absolute;
  bottom: 7px;
  padding: 3px 7px;
  border-radius: 8px;
  background: #fffbeadd;
  border: 1px solid #b9a45d;
  font-size: 9px;
  font-weight: 900;
}
.habitat-badge:nth-child(odd) {
  left: 7%;
}
.habitat-badge:nth-child(even) {
  right: 7%;
}
.divider-board {
  margin: 0;
  padding: 6px 8px;
  border: 2px solid #6d5a97;
  border-radius: 17px;
  background: #fffdf2f7;
  color: var(--ink);
  display: grid;
  gap: 5px;
}
#targets {
  position: static;
  display: flex;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
}
.target-chip {
  padding: 2px 6px;
  border-radius: 8px;
  background: #ede6f5;
  border: 1px solid #9a87bd;
  font-size: 9px;
  font-weight: 900;
}
#controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}
.divider {
  min-height: 44px;
  padding: 3px;
  border: 2px solid #65518c;
  border-radius: 11px;
  background: #dceee4;
  color: var(--ink);
  font-size: 9px;
  font-weight: 900;
  box-shadow: 0 3px 0 #443766;
  line-height: 1.05;
}
.divider span {
  display: block;
  font-size: 15px;
  line-height: 17px;
}
.divider.raised {
  background: #fff0a8;
}
.divider.hinted {
  animation: signal 0.7s ease-in-out infinite alternate;
}
.board-actions {
  display: flex;
  justify-content: center;
  gap: 5px;
}
.moth-night #hint,
.moth-night #undo,
.moth-night #test-habitats,
.moth-night #restart {
  min-height: 44px;
  padding: 5px 7px;
}
.moth-night #hint,
.moth-night #undo {
  min-width: 58px;
}
.moth-night #test-habitats {
  flex: 1;
  max-width: 200px;
  margin: 0;
  background: linear-gradient(135deg, #8c4f88, #5d3f7b);
  color: white;
}
.moth-night #restart {
  min-width: 44px;
}
.moth-night .intro-card {
  border-color: #6d5a97;
  background: #fffdf2;
}
.moth-night .primary {
  background: linear-gradient(135deg, #75589c, #3f396e);
  color: white;
}
.moth-night .eyebrow {
  color: #7b4f82;
}
.moth-night button:focus-visible,
.moth-night a:focus-visible {
  outline: 4px solid #ffe36e;
  outline-offset: 2px;
}
body.stage-complete #stage {
  box-shadow:
    0 0 0 4px #bfffe4,
    0 0 30px #eea7dd;
}
@keyframes signal {
  to {
    box-shadow:
      0 3px 0 #443766,
      0 0 17px 6px #ffe36e;
    filter: brightness(1.08);
  }
}
@media (prefers-reduced-motion: reduce) {
  .divider {
    animation: none !important;
    transition: none !important;
  }
}
@media (max-width: 360px) {
  .moth-night .brand small {
    display: none;
  }
  .moth-night .mission-card p {
    font-size: 11px;
  }
  .target-chip {
    font-size: 8px;
    padding: 2px 4px;
  }
  .moth-night #hint,
  .moth-night #undo {
    min-width: 50px;
    font-size: 9px;
  }
  .moth-night #test-habitats {
    font-size: 9px;
  }
  .divider-board {
    padding: 4px;
    gap: 4px;
  }
  .divider {
    font-size: 8px;
  }
}
@media (max-height: 620px) and (orientation: portrait) {
  .moth-night .game-shell {
    grid-template-rows: 46px 66px minmax(150px, 1fr) auto;
    gap: 4px;
  }
  .moth-night header {
    min-height: 46px;
  }
  .moth-night .round-button {
    width: 44px;
    height: 44px;
    min-height: 44px;
  }
  .moth-night .mission-card {
    min-height: 0;
    padding: 4px 10px;
  }
  .divider-board {
    padding: 4px 6px;
  }
  .divider {
    min-height: 44px;
  }
}
@media (orientation: landscape) and (max-height: 500px) {
  .moth-night .game-shell {
    max-width: 1000px;
    grid-template-columns: 175px minmax(0, 1fr) 320px;
    grid-template-rows: 48px minmax(240px, 1fr);
    gap: 6px;
  }
  .moth-night header {
    grid-column: 1/4;
  }
  .moth-night .mission-card {
    grid-column: 1;
    grid-row: 2;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: auto;
  }
  .moth-night .mission-card > div:first-child {
    display: block;
  }
  .moth-night .mission-card p {
    font-size: 11px;
    margin: 8px 0;
  }
  .moth-night #stage {
    grid-column: 2;
    grid-row: 2;
    margin: 0;
    width: auto;
  }
  .moth-night .divider-board {
    grid-column: 3;
    grid-row: 2;
    width: auto;
    align-content: center;
  }
  .moth-night #controls {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .divider {
    min-height: 44px;
  }
  .board-actions {
    flex-wrap: wrap;
  }
  .moth-night #test-habitats {
    order: -1;
    flex-basis: 100%;
    max-width: none;
  }
}
