:root {
  color-scheme: light;
  --ink: #f7ead7;
  --muted: #bcaea1;
  --paper: #0c0b0d;
  --line: #5a2d35;
  --accent: #b92e3f;
  --accent-strong: #d9a84e;
  --blood: #7f1628;
  --ember: #e45a2d;
  --panel: #151114;
  --wood: #4a2428;
  --white-key: #fff8e8;
  --white-key-active: #f2d5a1;
  --black-key: #101014;
  --black-key-active: #8b263a;
  --heading-font: "Didact Gothic", "Trebuchet MS", Inter, ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -16%, rgba(228, 90, 45, 0.24), transparent 28%),
    radial-gradient(circle at 12% 18%, rgba(127, 22, 40, 0.36), transparent 30%),
    linear-gradient(180deg, rgba(23, 13, 16, 0.72), rgba(5, 5, 7, 0.94)),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 11px),
    var(--paper);
  color: var(--ink);
  font-family: "Trebuchet MS", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 0 7%, rgba(0, 0, 0, 0.22) 7% 7.4%, transparent 7.4% 92.6%, rgba(0, 0, 0, 0.22) 92.6% 93%, transparent 93%),
    radial-gradient(circle at 50% 105%, rgba(217, 168, 78, 0.1), transparent 38%);
  mix-blend-mode: screen;
  opacity: 0.72;
}

.app {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto;
  gap: 18px;
}

.panel {
  min-height: 170px;
  padding: 24px;
  border: 1px solid rgba(217, 168, 78, 0.36);
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(217, 168, 78, 0.09), transparent 30%),
    linear-gradient(180deg, rgba(32, 21, 24, 0.96), rgba(12, 10, 12, 0.95));
  box-shadow:
    inset 0 0 0 1px rgba(127, 22, 40, 0.7),
    inset 0 -10px 30px rgba(0, 0, 0, 0.38),
    0 20px 70px rgba(0, 0, 0, 0.38);
  display: grid;
  grid-template-columns: minmax(240px, 0.68fr) minmax(560px, 1fr);
  gap: 24px;
  align-items: center;
  position: relative;
}

.panel::before,
.panel::after {
  content: "";
  position: absolute;
  width: 34px;
  height: 34px;
  border-color: var(--accent-strong);
  opacity: 0.72;
}

.panel::before {
  top: 9px;
  left: 9px;
  border-top: 2px solid;
  border-left: 2px solid;
}

.panel::after {
  right: 9px;
  bottom: 9px;
  border-right: 2px solid;
  border-bottom: 2px solid;
}

h1 {
  margin: 0;
  font-family: var(--heading-font);
  font-size: clamp(3rem, 5.4vw, 5.1rem);
  line-height: 0.95;
  letter-spacing: 0;
  color: #fff3df;
  text-shadow:
    0 2px 0 #5a1623,
    0 0 24px rgba(228, 90, 45, 0.18);
}

.brand {
  min-width: 0;
}

.controls {
  display: grid;
  grid-template-columns: minmax(96px, 0.82fr) minmax(118px, 1fr) minmax(72px, 0.56fr) minmax(112px, 0.9fr) minmax(96px, 0.74fr);
  gap: 12px;
  align-items: end;
  justify-self: end;
  width: min(100%, 610px);
}

.start-button {
  height: 48px;
  min-width: 0;
  border: 1px solid #f0c466;
  border-radius: 3px;
  background:
    linear-gradient(180deg, #f0c466, #a86f23 56%, #6f351f);
  color: #160d0b;
  cursor: pointer;
  font: inherit;
  font-weight: 850;
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 232, 0.45),
    0 0 18px rgba(217, 168, 78, 0.22);
}

.controls label:nth-of-type(4) {
  grid-column: 1 / 3;
}

.controls label:nth-of-type(5) {
  grid-column: 3 / 5;
}

.toggle {
  grid-column: 5;
}

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

label {
  font-family: var(--heading-font);
  color: var(--muted);
  display: grid;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input,
select {
  width: 100%;
  height: 42px;
  border: 1px solid rgba(217, 168, 78, 0.32);
  border-radius: 3px;
  background:
    linear-gradient(180deg, #24191c, #100d0f);
  color: var(--ink);
  font: inherit;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55);
}

select {
  color-scheme: dark;
}

option {
  background: #120e11;
  color: var(--ink);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  box-shadow: none;
}

input[type="number"],
select {
  padding: 0 10px;
}

input[type="number"] {
  width: 100%;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-strong);
}

.toggle {
  height: 42px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(217, 168, 78, 0.32);
  border-radius: 3px;
  background: linear-gradient(180deg, #24191c, #100d0f);
}

.game {
  min-height: 300px;
  border: 1px solid rgba(217, 168, 78, 0.28);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(20, 12, 15, 0.22), rgba(5, 5, 8, 0.92)),
    radial-gradient(circle at 50% 0%, rgba(217, 168, 78, 0.14), transparent 30%),
    repeating-linear-gradient(90deg, rgba(217, 168, 78, 0.045) 0 1px, transparent 1px 12.5%),
    #08080d;
  box-shadow:
    inset 0 0 0 1px rgba(127, 22, 40, 0.6),
    inset 0 0 90px rgba(0, 0, 0, 0.72),
    0 24px 70px rgba(0, 0, 0, 0.42);
  overflow: hidden;
  position: relative;
}

.stage {
  height: 100%;
  min-height: 258px;
  position: relative;
  overflow: hidden;
  perspective: 560px;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 12.4%, rgba(217, 168, 78, 0.13) 12.4% 12.6%, transparent 12.6% 24.9%, rgba(217, 168, 78, 0.13) 24.9% 25.1%, transparent 25.1% 37.4%, rgba(217, 168, 78, 0.13) 37.4% 37.6%, transparent 37.6% 49.9%, rgba(217, 168, 78, 0.13) 49.9% 50.1%, transparent 50.1% 62.4%, rgba(217, 168, 78, 0.13) 62.4% 62.6%, transparent 62.6% 74.9%, rgba(217, 168, 78, 0.13) 74.9% 75.1%, transparent 75.1% 87.4%, rgba(217, 168, 78, 0.13) 87.4% 87.6%, transparent 87.6%),
    linear-gradient(180deg, rgba(217, 168, 78, 0.05), transparent 26%, rgba(127, 22, 40, 0.11) 100%),
    radial-gradient(circle at 50% 8%, rgba(217, 168, 78, 0.18), transparent 24%);
  pointer-events: none;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 18px 28px auto;
  height: 94px;
  pointer-events: none;
  background:
    linear-gradient(135deg, transparent 0 18px, rgba(217, 168, 78, 0.18) 18px 20px, transparent 20px),
    linear-gradient(225deg, transparent 0 18px, rgba(217, 168, 78, 0.18) 18px 20px, transparent 20px);
  opacity: 0.42;
}

.moon {
  position: absolute;
  top: 24px;
  left: calc(50% - 28px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #ead69f;
  box-shadow: 0 0 70px rgba(234, 214, 159, 0.36), 0 0 140px rgba(127, 22, 40, 0.24);
  opacity: 0.34;
}

.hit-zone {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  height: 58px;
  border-top: 2px solid rgba(217, 168, 78, 0.8);
  background:
    linear-gradient(180deg, rgba(217, 168, 78, 0.12), transparent),
    linear-gradient(90deg, transparent, rgba(185, 46, 63, 0.22), transparent);
  box-shadow: 0 -10px 36px rgba(217, 168, 78, 0.1);
}

.enemy {
  --x: 50%;
  --y: 0%;
  --scale: 0.35;
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 96px;
  height: 76px;
  transform: translate(-50%, -50%) scale(var(--scale));
  display: grid;
  place-items: center;
  color: #fff8e8;
  font-size: 0.9rem;
  font-weight: 950;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.8);
  z-index: 3;
}

.enemy-sprite {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter:
    drop-shadow(1px 0 0 rgba(255, 248, 232, 0.62))
    drop-shadow(-1px 0 0 rgba(255, 248, 232, 0.48))
    drop-shadow(0 1px 0 rgba(255, 248, 232, 0.48))
    drop-shadow(0 -1px 0 rgba(255, 248, 232, 0.34))
    drop-shadow(0 8px 0 rgba(0, 0, 0, 0.42))
    drop-shadow(0 0 12px rgba(217, 168, 78, 0.24));
  image-rendering: pixelated;
  shape-rendering: crispEdges;
  overflow: visible;
}

.bat-sprite {
  animation: bat-flap 420ms steps(2) infinite;
}

.bat-shadow {
  fill: rgba(0, 0, 0, 0.36);
}

.bat-wing,
.bat-body {
  fill: #17131d;
  stroke: #07070b;
  stroke-width: 4px;
}

.bat-wing {
  fill: #21182b;
}

.bat-face {
  fill: #d0a85f;
}

.bat-red-eyes {
  fill: #ff304c;
  filter: drop-shadow(0 0 5px rgba(255, 48, 76, 0.78));
}

.bat-fangs {
  fill: #fff8e8;
}

.enemy .enemy-note {
  position: relative;
  z-index: 2;
  min-width: 28px;
  margin-top: 22px;
  padding: 2px 5px;
  border: 1px solid rgba(255, 248, 232, 0.32);
  background: rgba(0, 0, 0, 0.68);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.42);
  text-align: center;
}

.enemy.bat .enemy-note {
  margin-top: 30px;
}

.enemy.defeated {
  animation: defeat 180ms steps(3) forwards;
}

.stage.flash {
  animation: stage-flash 150ms ease;
}

@keyframes defeat {
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.4) rotate(18deg);
  }
}

@keyframes bat-flap {
  50% {
    transform: translateY(3px) scaleY(0.88);
  }
}

@keyframes stage-flash {
  50% {
    box-shadow: inset 0 0 90px rgba(208, 168, 95, 0.32);
  }
}

.keyboard {
  --keyboard-pad: 18px;
  align-self: end;
  min-height: 360px;
  padding: var(--keyboard-pad) var(--keyboard-pad) 24px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.1), transparent 25%, rgba(0, 0, 0, 0.08)),
    var(--wood);
  box-shadow: inset 0 8px 0 rgba(255, 255, 255, 0.1), 0 26px 80px rgba(0, 0, 0, 0.38);
  display: flex;
  gap: 5px;
  position: relative;
}

.key {
  border: 0;
  border-radius: 0 0 7px 7px;
  cursor: pointer;
  color: inherit;
  font: inherit;
  touch-action: manipulation;
  position: relative;
  transition: transform 90ms ease, background 90ms ease, box-shadow 90ms ease;
}

.key.white {
  flex: 1 1 0;
  min-height: 318px;
  padding: 0 6px 18px;
  background: linear-gradient(#fffefb 0%, var(--white-key) 76%, #e9e1d5 100%);
  box-shadow: inset 0 -12px 18px rgba(91, 70, 48, 0.12), 0 6px 0 #cfc4b6;
  display: flex;
  align-items: end;
  justify-content: center;
}

.key.black {
  position: absolute;
  top: var(--keyboard-pad);
  width: min(58px, 7vw);
  height: 58%;
  min-height: 190px;
  transform: translateX(-50%);
  z-index: 2;
  background: linear-gradient(90deg, #111418, var(--black-key) 44%, #30343a 100%);
  color: #fffdf7;
  box-shadow: inset 0 -18px 18px rgba(0, 0, 0, 0.45), 0 8px 14px rgba(0, 0, 0, 0.25);
}

.key.black[data-note-name="C#"] { left: calc(var(--keyboard-pad) + (100% - (var(--keyboard-pad) * 2)) * 0.125); }
.key.black[data-note-name="D#"] { left: calc(var(--keyboard-pad) + (100% - (var(--keyboard-pad) * 2)) * 0.25); }
.key.black[data-note-name="F#"] { left: calc(var(--keyboard-pad) + (100% - (var(--keyboard-pad) * 2)) * 0.5); }
.key.black[data-note-name="G#"] { left: calc(var(--keyboard-pad) + (100% - (var(--keyboard-pad) * 2)) * 0.625); }
.key.black[data-note-name="A#"] { left: calc(var(--keyboard-pad) + (100% - (var(--keyboard-pad) * 2)) * 0.75); }

.key.white.active {
  background: linear-gradient(var(--white-key-active), #ecfffb 72%, #b8dcd2);
  transform: translateY(5px);
  box-shadow: inset 0 -8px 12px rgba(47, 125, 110, 0.15), 0 1px 0 #a6c5bd;
}

.key.black.active {
  background: linear-gradient(90deg, #14483f, var(--black-key-active), #4ea593);
  transform: translateX(-50%) translateY(5px);
}

.key-label {
  display: grid;
  gap: 5px;
  justify-items: center;
  pointer-events: none;
}

.note {
  font-size: 0.78rem;
  font-weight: 850;
}

.computer-key {
  min-width: 28px;
  min-height: 28px;
  padding: 4px 7px;
  border: 1px solid rgba(24, 32, 29, 0.16);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.black .key-label {
  height: 100%;
  padding-bottom: 18px;
  align-content: end;
}

.black .computer-key {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  color: #fffdf7;
}

@media (max-width: 760px) {
  .app {
    width: min(100vw - 18px, 720px);
    padding: 12px 0;
    gap: 10px;
  }

  .panel {
    min-height: 0;
    padding: 18px;
    grid-template-columns: 1fr;
    gap: 18px;
    align-items: stretch;
  }

  h1 {
    font-size: clamp(3rem, 13vw, 4.2rem);
  }

  .controls {
    width: 100%;
    grid-template-columns: 1fr 1fr;
    justify-self: stretch;
  }

  .start-button {
    grid-column: 1 / -1;
  }

  .controls label:nth-of-type(4),
  .controls label:nth-of-type(5),
  .toggle {
    grid-column: auto;
  }

  .keyboard {
    --keyboard-pad: 10px;
    min-height: 330px;
    padding: var(--keyboard-pad) var(--keyboard-pad) 18px;
    gap: 3px;
  }

  .key.white {
    min-height: 292px;
  }

  .note {
    display: none;
  }
}
