:root {
  color-scheme: dark;
  --ink: #f8f3e8;
  --muted: #c9bdac;
  --gold: #f4c95d;
  --green: #3e8e55;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: #17120e;
}

main {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.hero-image {
  display: block;
  width: 100%;
  height: auto;
}

h1 {
  margin: 34px 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.5rem, 10vw, 7rem);
  letter-spacing: -0.055em;
  line-height: 0.9;
  text-align: center;
}

.patcher-section {
  margin: 32px 0 0;
  padding: 30px 0 0;
  border-top: 1px solid rgba(244, 201, 93, 0.32);
}

.patcher-section > h2,
.controls-diagram figcaption {
  margin: 0 0 18px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  line-height: 1.1;
}

.rom-section {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.rom-requirements {
  margin: -8px 0 22px;
  color: var(--muted);
}

.rom-requirements strong {
  color: var(--ink);
}

.rom-inputs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 28px;
}

.rom-input,
.colour-option {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 0;
  cursor: pointer;
}

.rom-input {
  align-items: flex-start;
}

.rom-input:hover .file-name,
.rom-input:focus-within .file-name,
.colour-option:has(input[type="radio"]:checked) strong {
  color: var(--gold);
}

.rom-input input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.rom-input > span:last-of-type,
.colour-option > span:last-of-type {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

small {
  color: var(--muted);
}

.rom-number {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  color: #17120e;
  font-weight: 900;
  border-radius: 50%;
  background: var(--gold);
}

.file-name {
  overflow: hidden;
  margin-top: 8px;
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-option {
  align-items: flex-start;
}

.mode-option:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.45;
}

.game-mode,
.mario-colour {
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
}

.colour-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 24px;
}

.colour-choice {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 14px;
}

.colour-swatch,
.custom-palette input[type="color"] {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
}

.green-swatch {
  background: rgb(30, 105, 27);
}

.red-swatch {
  background: #f00;
}

.custom-swatch {
  background: conic-gradient(#853825, #1e691b, #ffffec, #47332a, #f8bf99, #dea445, #853825);
}

.custom-palette input[type="color"] {
  overflow: hidden;
  cursor: pointer;
  background: none;
}

.custom-palette input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.custom-palette input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 50%;
}

.palette-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  padding-left: 44px;
}

.palette-list > span,
.custom-palette label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.palette-list i {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
}

.green-palette span:nth-child(1) i { background: #853825; }
.green-palette span:nth-child(2) i { background: #1e691b; }
.green-palette span:nth-child(3) i { background: #ffffec; }
.green-palette span:nth-child(4) i { background: #47332a; }
.green-palette span:nth-child(5) i { background: #f8bf99; }
.green-palette span:nth-child(6) i { background: #dea445; }
.red-palette span:nth-child(1) i { background: #0000ff; }
.red-palette span:nth-child(2) i { background: #ff0000; }
.red-palette span:nth-child(3) i { background: #ffffff; }
.red-palette span:nth-child(4) i { background: #721c0e; }
.red-palette span:nth-child(5) i { background: #fec179; }
.red-palette span:nth-child(6) i { background: #730600; }

.custom-palette label {
  justify-content: space-between;
}

.custom-palette input[type="color"] {
  width: 28px;
  height: 28px;
}

.canonical-note {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 22px 0 0;
  padding: 12px 14px;
  color: var(--ink);
  border-left: 4px solid var(--gold);
  background: rgba(244, 201, 93, 0.1);
}

.canonical-note strong {
  flex: 0 0 auto;
  color: var(--gold);
}

.controls-diagram {
  margin-right: 0;
  margin-left: 0;
}

.controller-layouts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 36px;
}

.controller-layout h2 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.controller-art {
  position: relative;
}

.controller-art img {
  display: block;
  width: 100%;
  height: auto;
}

.control-marker,
.control-key b {
  display: grid;
  width: 23px;
  height: 23px;
  place-items: center;
  color: #17120e;
  font-size: 0.76rem;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
  border: 2px solid #17120e;
  border-radius: 50%;
  background: var(--gold);
}

.control-marker {
  position: absolute;
  transform: translate(-50%, -50%);
}

.marker-move { left: 50%; top: 55%; }
.marker-camera { left: 19.35%; top: 31.22%; }
.marker-enhanced { left: 82.6576%; top: 22.9543%; }
.marker-items { left: 82.6576%; top: 34.5159%; }
.marker-jump { left: 75%; top: 42%; }
.marker-action { left: 68.56%; top: 35.18%; }
.marker-start { left: 50%; top: 36%; }
.marker-z { left: 50%; top: 83%; }
.marker-r { left: 81.09%; top: 12.56%; }

.control-key {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
  margin: 2px 0 0;
}

.control-key div {
  min-width: 0;
}

.control-key dt {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.9rem;
  font-weight: 800;
}

.control-key b {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  font-size: 0.68rem;
  border-width: 1px;
}

.control-key dd {
  margin: 3px 0 0 26px;
  color: var(--muted);
  font-size: 0.82rem;
}

.song-controls {
  margin-top: 30px;
  padding-top: 26px;
  border-top: 1px solid rgba(244, 201, 93, 0.2);
}

.song-controls h3 {
  margin: 0 0 10px;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: left;
}

.song-intro {
  margin: 0;
  color: var(--muted);
}

.song-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 30px;
  margin-top: 20px;
}

.song-grid h4 {
  margin: 0 0 7px;
  font-size: 1rem;
}

.song-grid article > p:not(.song-input) {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.song-input {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin: 14px 0 0;
}

.song-input kbd {
  padding: 5px 7px;
  color: #17120e;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 900;
  border-radius: 6px;
  background: var(--gold);
}

.song-input span {
  color: var(--muted);
  font-size: 0.76rem;
}

.soundtrack-matrix {
  width: 100%;
  margin-top: 30px;
  border-spacing: 0;
  border-collapse: collapse;
}

.soundtrack-matrix th,
.soundtrack-matrix td {
  padding: 12px 14px;
  text-align: left;
  border: 1px solid rgba(244, 201, 93, 0.25);
}

.soundtrack-matrix thead th,
.soundtrack-matrix tbody th {
  color: var(--gold);
  font-size: 0.82rem;
}

.soundtrack-matrix td strong,
.soundtrack-matrix td span {
  display: block;
}

.soundtrack-matrix td span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.build-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 0;
}

dialog {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  color: var(--ink);
  border: 1px solid rgba(244, 201, 93, 0.62);
  border-radius: 12px;
  background: #211a15;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

dialog form {
  padding: 24px;
}

dialog h2 {
  margin: 0 0 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
}

dialog p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.dialog-actions button {
  padding: 10px 13px;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  border: 1px solid var(--gold);
  border-radius: 8px;
  background: transparent;
}

#confirm-palette {
  color: #17120e;
  background: var(--gold);
}

.build-actions:has(.download-button[hidden]) {
  grid-template-columns: 1fr;
}

.build-button,
.download-button {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: center;
  padding: 18px 24px;
  color: var(--ink);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 850;
  cursor: pointer;
  text-decoration: none;
  border-radius: 12px;
}

.build-button {
  border: 0;
  background: var(--green);
}

.build-button:disabled {
  cursor: wait;
  opacity: 0.5;
}

.speedrun-link {
  margin: 18px 0 0;
  text-align: center;
}

.speedrun-link a,
.back-link a {
  color: var(--gold);
  font-weight: 750;
}

.leaderboard-page {
  width: min(760px, calc(100% - 32px));
  padding-top: 54px;
}

.leaderboard-page h1 {
  margin-bottom: 36px;
}

.back-link {
  margin: 0 0 28px;
}

.speedrun-rule {
  margin: -18px 0 28px;
  color: var(--muted);
}

.speedrun-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.speedrun-table th,
.speedrun-table td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.speedrun-table th {
  color: var(--gold);
}

.speedrun-empty,
.speedrun-status {
  color: var(--muted);
}

.download-button {
  border: 1px solid var(--gold);
}

.patcher-status {
  grid-column: 1 / -1;
  margin: 2px 0 0;
  color: var(--muted);
  text-align: center;
}

.patcher-status.error {
  color: #ffaaa4;
}

@media (max-width: 700px) {
  main {
    padding-top: 16px;
  }

  h1 {
    margin: 28px 0;
  }

  .rom-inputs,
  .build-actions {
    grid-template-columns: 1fr;
  }

  .colour-choice {
    gap: 12px;
  }

  .colour-options {
    grid-template-columns: 1fr;
  }

  .controller-layouts {
    grid-template-columns: 1fr;
  }

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

  .soundtrack-matrix th,
  .soundtrack-matrix td {
    padding: 9px 8px;
  }

  .canonical-note,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .patcher-status {
    grid-column: 1;
  }
}
