:root {
  color-scheme: dark;
  --night: #05090e;
  --night-2: #07121a;
  --ink: #fff4d2;
  --muted: rgba(255, 232, 184, 0.68);
  --line: rgba(255, 218, 142, 0.3);
  --line-bright: rgba(255, 218, 142, 0.58);
  --gold: #ffd66f;
  --gold-2: #ffb642;
  --blue: #8adfff;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.54);
  --serif: Charter, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--night);
  color: var(--ink);
  font-family: var(--sans);
}

button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(10, 12, 13, 0.42);
  color: var(--ink);
  font: 760 12px/1 var(--sans);
  min-height: 36px;
  padding: 0 14px;
  cursor: pointer;
  box-shadow: inset 0 0 18px rgba(255, 214, 111, 0.05);
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

button:hover,
button:focus-visible {
  border-color: var(--line-bright);
  background: rgba(255, 214, 111, 0.13);
  outline: none;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  transform: none;
}

.game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 28% 55%, rgba(255, 182, 66, 0.2), transparent 18%),
    radial-gradient(circle at 74% 18%, rgba(138, 223, 255, 0.18), transparent 24%),
    var(--night);
  touch-action: none;
  user-select: none;
}

.game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 46%, transparent 0 38%, rgba(0, 0, 0, 0.36) 76%),
    linear-gradient(180deg, rgba(4, 7, 10, 0.22), transparent 18%, rgba(2, 4, 6, 0.28));
}

.game-shell.help-open::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: auto;
  background:
    radial-gradient(circle at 44% 44%, rgba(255, 214, 111, 0.08), transparent 32%),
    rgba(0, 0, 0, 0.56);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: none;
}

.hud {
  position: absolute;
  z-index: 3;
  top: 14px;
  left: 16px;
  right: 16px;
  height: 48px;
  display: grid;
  grid-template-columns: minmax(112px, 1fr) minmax(0, auto) minmax(196px, 1fr);
  align-items: center;
  gap: 18px;
  pointer-events: none;
}

.brand,
.meters,
.hud-actions,
.result-stats,
.result-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 11px;
  color: var(--ink);
  font: 500 18px/1 var(--serif);
  text-shadow: 0 0 22px rgba(255, 214, 111, 0.24);
}

.brand-mark {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow:
    0 0 11px rgba(255, 214, 111, 0.95),
    0 0 28px rgba(255, 182, 66, 0.6);
}

.meters {
  justify-content: center;
  gap: clamp(12px, 2.4vw, 26px);
  width: min(450px, calc(100vw - 380px));
  min-width: 320px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 218, 142, 0.16);
  border-radius: 999px;
  background: rgba(4, 8, 12, 0.24);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.meter,
.dawn-meter {
  display: grid;
  gap: 5px;
}

.meter {
  grid-template-columns: auto auto;
  align-items: baseline;
  column-gap: 9px;
}

.meter span,
.dawn-meter span,
.result-panel p {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.meter strong {
  color: var(--gold);
  font-size: 17px;
  line-height: 1;
  text-shadow: 0 0 18px rgba(255, 214, 111, 0.58);
}

.dawn-meter {
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 8px;
  width: clamp(118px, 16vw, 148px);
}

.dawn-meter span {
  display: block;
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  text-align: right;
  width: auto;
}

.dawn-track {
  grid-column: 1;
  grid-row: 1;
  height: 5px;
  border-radius: 999px;
  background: rgba(138, 223, 255, 0.16);
  overflow: hidden;
}

.dawn-track i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), #fff4b4, var(--gold));
  box-shadow: 0 0 20px rgba(255, 214, 111, 0.48);
}

.hud-actions {
  justify-content: flex-end;
  gap: 9px;
  pointer-events: auto;
}

.music-toggle[aria-pressed="true"] {
  color: rgba(255, 244, 210, 0.58);
}

.result-panel,
.level-panel {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 32px;
  width: min(560px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 25px 28px 24px;
  border: 1px solid rgba(255, 218, 142, 0.42);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255, 214, 111, 0.11), rgba(138, 223, 255, 0.06)),
    rgba(4, 8, 12, 0.68);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  text-align: center;
}

.level-panel {
  bottom: 50%;
  width: min(500px, calc(100vw - 32px));
  transform: translate(-50%, 50%);
}

.result-panel[hidden],
.level-panel[hidden] {
  display: none;
}

.result-panel p,
.result-panel h1,
.level-panel p,
.level-panel h1 {
  margin: 0;
}

.result-panel h1,
.level-panel h1 {
  margin-top: 8px;
  color: #fff5cf;
  font: 520 clamp(30px, 5vw, 54px)/1.02 var(--serif);
  text-shadow:
    0 0 22px rgba(255, 214, 111, 0.38),
    0 0 70px rgba(138, 223, 255, 0.18);
}

.level-panel h1 {
  font-size: clamp(34px, 5.4vw, 58px);
}

.result-stats,
.level-stats {
  justify-content: center;
  gap: 18px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.level-stats {
  display: flex;
  align-items: center;
}

.result-stats strong,
.level-stats strong {
  color: var(--gold);
}

.best-line {
  margin-top: 10px !important;
  color: rgba(255, 244, 210, 0.7) !important;
  letter-spacing: 0.08em !important;
}

.result-actions {
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.score-entry,
.high-score-row {
  display: grid;
  align-items: center;
}

.score-entry {
  grid-template-columns: auto auto;
  justify-content: center;
  gap: 9px;
  margin-top: 16px;
}

.score-entry input {
  width: 4.4ch;
  height: 36px;
  border: 1px solid rgba(255, 218, 142, 0.34);
  border-radius: 7px;
  background: rgba(5, 9, 14, 0.58);
  color: var(--ink);
  font: 900 17px/1 var(--sans);
  letter-spacing: 0.04em;
  text-align: center;
  text-transform: uppercase;
  outline: none;
}

.score-entry input:focus-visible {
  border-color: rgba(255, 214, 111, 0.82);
  box-shadow: 0 0 0 2px rgba(255, 214, 111, 0.14);
}

.score-entry button {
  min-height: 36px;
  padding-inline: 15px;
}

.score-entry button:disabled,
.score-entry input:disabled {
  opacity: 0.58;
  cursor: default;
}

.high-score-list {
  display: grid;
  gap: 5px;
  width: min(344px, 100%);
  margin: 16px auto 0;
  padding: 12px 0 0;
  border-top: 1px solid rgba(255, 218, 142, 0.18);
  list-style: none;
  list-style-type: none;
}

.high-score-row {
  grid-template-columns: 32px 52px 1fr 76px;
  column-gap: 12px;
  min-height: 27px;
  padding: 4px 10px;
  border: 1px solid rgba(255, 218, 142, 0.18);
  border-radius: 7px;
  background: rgba(5, 9, 14, 0.42);
  color: rgba(255, 244, 210, 0.66);
  font: 800 12px/1 var(--sans);
  letter-spacing: 0.06em;
}

.high-score-row:first-child {
  border-color: rgba(255, 214, 111, 0.24);
  background: rgba(255, 214, 111, 0.06);
  color: rgba(255, 244, 210, 0.9);
}

.high-score-list b {
  color: rgba(138, 223, 255, 0.74);
  font-weight: 900;
  text-align: right;
}

.high-score-list span {
  color: var(--gold);
  font-weight: 950;
  text-align: center;
}

.high-score-list strong {
  color: var(--ink);
  font-weight: 950;
  text-align: right;
}

.high-score-list em {
  color: var(--muted);
  font-style: normal;
  text-align: left;
}

.result-actions button:first-child,
.help-dialog button,
.level-panel button {
  border-color: rgba(255, 214, 111, 0.78);
  background: var(--gold);
  color: #151007;
}

.level-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.level-panel button {
  min-height: 42px;
  min-width: 196px;
}

.level-panel button:first-child {
  border-color: rgba(255, 218, 142, 0.26);
  background: rgba(5, 9, 14, 0.46);
  color: var(--ink);
}

.help-dialog {
  position: fixed;
  z-index: 6;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(390px, calc(100vw - 28px));
  margin: 0;
  border: 1px solid rgba(255, 218, 142, 0.5);
  border-radius: 18px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 214, 111, 0.18), transparent 46%),
    rgba(5, 9, 14, 0.9);
  color: var(--ink);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.help-dialog form {
  margin: 0;
  display: grid;
  gap: 16px;
  padding: 8px 4px 2px;
}

.help-dialog h2 {
  margin: 0;
  text-align: center;
  font: 520 42px/1 var(--serif);
}

.help-kicker {
  margin: -4px auto 0;
  width: min(280px, 100%);
  color: rgba(255, 214, 111, 0.86);
  font: 850 11px/1.35 var(--sans);
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}

.help-dialog ol {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 9px;
  color: rgba(255, 244, 210, 0.84);
  font-size: 15px;
  line-height: 1.35;
  text-align: center;
}

.help-credit {
  margin: -2px 0 0;
  color: rgba(255, 244, 210, 0.58);
  font: 800 11px/1.25 var(--sans);
  letter-spacing: 0.1em;
  text-align: center;
  text-transform: uppercase;
}

.help-credit a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(255, 214, 111, 0.46);
  text-underline-offset: 3px;
}

.help-credit a:focus-visible {
  outline: 2px solid rgba(255, 214, 111, 0.9);
  outline-offset: 3px;
}

.help-dialog button {
  min-height: 42px;
  justify-self: center;
  min-width: 134px;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  background: var(--night);
}

.noscript h1,
.noscript p {
  margin: 0;
}

@media (max-width: 600px) {
  .hud {
    top: 10px;
    left: 10px;
    right: 10px;
    height: auto;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .brand {
    font-size: 17px;
  }

  .meters {
    grid-column: 1 / -1;
    grid-row: 2;
    order: 3;
    width: 100%;
    min-width: 0;
    gap: 16px;
    justify-content: space-between;
    padding: 8px 12px;
  }

  .dawn-meter {
    width: min(46vw, 180px);
  }

  .hud-actions {
    gap: 7px;
  }

  button {
    min-height: 34px;
    padding: 0 12px;
  }

  .result-panel {
    bottom: 18px;
    padding: 22px 18px;
  }

  .result-stats,
  .result-actions {
    flex-wrap: wrap;
  }

  .level-actions {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  button {
    transition: none;
  }
}

body.build-page {
  min-height: 100%;
  height: auto;
  overflow: auto;
  background:
    linear-gradient(rgba(5, 9, 14, 0.72), rgba(5, 9, 14, 0.92)),
    url("assets/lightmoth-bg.png") center / cover fixed,
    var(--night);
}

.build-nav {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 62px;
  padding: 0 clamp(16px, 4vw, 52px);
  border-bottom: 1px solid rgba(255, 218, 142, 0.2);
  background: rgba(5, 9, 14, 0.76);
  backdrop-filter: blur(18px);
}

.build-nav,
.build-nav nav {
  display: flex;
  align-items: center;
}

.build-nav nav {
  gap: 14px;
}

.build-nav a,
.build-card a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
}

.build-nav > a {
  font: 520 22px/1 var(--serif);
}

.build-nav nav a,
.build-card a {
  color: var(--muted);
  font-size: 12px;
}

.build-main {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(48px, 9vh, 96px) 0 72px;
}

.build-hero {
  max-width: 760px;
}

.build-hero p,
.build-card p,
.build-grid small {
  margin: 0;
  color: var(--gold);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.build-hero h1 {
  margin: 12px 0 18px;
  color: #fff5cf;
  font: 520 clamp(44px, 8vw, 86px)/0.95 var(--serif);
  text-shadow: 0 0 44px rgba(255, 214, 111, 0.18);
}

.build-hero span,
.build-card span,
.build-grid p {
  color: rgba(255, 244, 210, 0.78);
  font-size: 17px;
  line-height: 1.6;
}

.build-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 44px;
}

.build-grid article,
.build-card {
  border: 1px solid rgba(255, 218, 142, 0.22);
  border-radius: 16px;
  background: rgba(5, 9, 14, 0.62);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(18px);
}

.build-grid article {
  padding: 18px;
}

.build-grid p {
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.55;
}

.build-card {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 24px;
}

.build-card h2 {
  margin: 8px 0 8px;
  font: 520 32px/1.05 var(--serif);
}

.build-card a {
  flex: 0 0 auto;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 214, 111, 0.74);
  border-radius: 999px;
  padding: 0 18px;
  background: var(--gold);
  color: #151007;
}

@media (max-width: 860px) {
  .build-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .build-card {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .build-nav {
    align-items: flex-start;
    flex-direction: column;
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .build-grid {
    grid-template-columns: 1fr;
  }
}
