:root {
  --ink: #171717;
  --paper: #f6f3ec;
  --gold: #f2cd49;
  --green: #24834a;
  --red: #bd3434;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family:
    system-ui,
    -apple-system,
    sans-serif;
}
.menu-wrap {
  width: min(900px, 92vw);
  margin: 5rem auto 3rem;
}
.menu-wrap h1 {
  text-align: center;
  font-size: clamp(2.3rem, 6vw, 4rem);
  margin: 0.5rem;
}
.intro {
  text-align: center;
  color: #666;
}
.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 30px;
}
.menu-card,
.level-card {
  background: #fff;
  border: 1px solid #d2cec5;
  border-radius: 18px;
  text-decoration: none;
  color: inherit;
  box-shadow: 0 7px 20px #0000000b;
}
.menu-card {
  min-height: 120px;
  padding: 25px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.menu-card span {
  font-size: 1.5rem;
  font-weight: 800;
}
.menu-card small,
.level-card span {
  color: #666;
  margin-top: 5px;
}
.level-list {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}
.level-card {
  padding: 17px 21px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
}
.nav-button {
  display: inline-block;
  background: #fff;
  color: #111;
  text-decoration: none;
  border: 1px solid #bbb;
  border-radius: 10px;
  padding: 8px 12px;
}
.game {
  width: min(1120px, 97vw);
  margin: auto;
  padding: 12px;
}
.game-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}
.game-head h1 {
  text-align: center;
  font-size: clamp(1.2rem, 3vw, 2rem);
  margin: 4px;
}
.head-actions {
  justify-self: end;
  display: flex;
  gap: 7px;
}
.btn {
  font: inherit;
  font-weight: 750;
  padding: 8px 13px;
  border: 1px solid #999;
  border-radius: 10px;
  background: #fff;
  color: #111;
  cursor: pointer;
  text-decoration: none;
}
.hud {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  margin: 8px auto;
}
.timer {
  height: 12px;
  background: #ddd;
  border-radius: 99px;
  overflow: hidden;
}
.timer > i {
  display: block;
  height: 100%;
  background: #222;
  width: 100%;
  transform-origin: left;
}
.score,
.lives {
  font-weight: 850;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 10px;
  padding: 7px 10px;
}
.lives {
  display: flex;
  gap: 7px;
  align-items: center;
}
.life {
  width: 27px;
  height: 35px;
  position: relative;
  display: inline-block;
}
.life svg {
  width: 27px;
  height: 35px;
  display: block;
}
.life.dead {
  opacity: 0.4;
}
.life.dead::before,
.life.dead::after {
  content: "";
  position: absolute;
  left: 0;
  top: 16px;
  width: 28px;
  height: 4px;
  background: #d71920;
  border-radius: 3px;
}
.life.dead::before {
  transform: rotate(45deg);
}
.life.dead::after {
  transform: rotate(-45deg);
}
.game-over-card {
  text-align: center;
}
.game-over-card .deadrow {
  color: #b90000;
  font-size: 2.5rem;
  letter-spacing: 0.15em;
}
.stage {
  background: #fff;
  border: 1px solid #d4d0c7;
  border-radius: 18px;
  box-shadow: 0 9px 28px #0000000d;
  padding: 12px;
}
.notation {
  width: 100%;
  height: min(42vh, 360px);
  display: block;
}
.prompt {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 760;
  margin: 9px;
}
.answers {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.answers button {
  min-width: 145px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 850;
  padding: 14px;
  border: 2px solid #333;
  border-radius: 13px;
  background: white;
}
.answers button.answer-correct {
  background: #54aa68;
  color: #fff;
}
.answers button.answer-wrong {
  background: #cf5555;
  color: #fff;
}
.keyboard-wrap {
  overflow-x: auto;
  background: #d8d4cc;
  border-radius: 13px;
  padding: 8px;
}
.keyboard {
  position: relative;
  height: 190px;
  min-width: 1220px;
}
.white-key,
.black-key {
  position: absolute;
  top: 0;
  cursor: pointer;
}
.white-key {
  height: 100%;
  background: #fff;
  border: 1px solid #222;
  border-radius: 0 0 5px 5px;
}
.black-key {
  height: 62%;
  background: #111;
  border: 1px solid #000;
  border-radius: 0 0 4px 4px;
  z-index: 2;
}
.white-key.middle-c {
  background: var(--gold);
}
.white-key.key-answer,
.black-key.key-answer {
  background: #e8952f !important;
}
.feedback {
  text-align: center;
  min-height: 29px;
  font-weight: 850;
  padding: 6px;
}
.feedback.good {
  color: var(--green);
}
.feedback.bad {
  color: var(--red);
}
dialog {
  border: 0;
  border-radius: 20px;
  padding: 0;
  max-width: min(620px, 92vw);
  box-shadow: 0 20px 80px #0008;
}
dialog::backdrop {
  background: #000a;
}
.hint {
  padding: 28px;
}
.hint .eyebrow {
  font-weight: 900;
  letter-spacing: 0.18em;
  color: #806900;
}
.hint h2 {
  font-size: 1.8rem;
  margin: 0.25rem 0 1rem;
}
.hint p {
  font-size: 1.12rem;
  line-height: 1.55;
}
.hint .btn {
  display: block;
  margin: 20px auto 0;
  background: #111;
  color: #fff;
}
.badge {
  text-align: center;
}
.badge .medal {
  font-size: 4rem;
}
@media (max-width: 700px) {
  .game-head {
    grid-template-columns: auto 1fr;
  }
  .game-head h1 {
    grid-column: 1/-1;
    grid-row: 2;
  }
  .head-actions {
    grid-column: 2;
  }
  .notation {
    height: 270px;
  }
  .level-card {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }
  .keyboard {
    height: 145px;
  }
  .hud {
    grid-template-columns: 1fr auto;
  }
  .lives {
    grid-column: 1/-1;
    text-align: center;
  }
}


/* Alpha 30 keyboard sizing:
   desktop/tablet always fits the available screen width;
   phones may scroll horizontally so keys do not become unusably narrow. */
.keyboard-wrap{
  width:100%;
  max-width:100vw;
  overflow-x:hidden;
}
#keyboard.keyboard{
  width:100%;
  max-width:100%;
  min-width:0; /* override legacy 1220px minimum: desktop must fit its wrapper */
  margin-left:auto;
  margin-right:auto;
}
@media (max-width: 600px){
  .keyboard-wrap{
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
    overscroll-behavior-x:contain;
  }
  #keyboard.keyboard{
    width:max(100%, calc(var(--pitch-white-keys, 15) * 42px));
    max-width:none;
    min-width:max(100%, calc(var(--pitch-white-keys, 15) * 42px));
    margin-left:0;
    margin-right:0;
  }
}

/* Alpha 32: keep the keyboard surround symmetrical and contained. */
.keyboard-wrap{box-sizing:border-box;}
#keyboard.keyboard{box-sizing:border-box;}

/* Catalogue-driven level cards: retain the syllabus description under each title. */
.level-details{display:flex;flex-direction:column;min-width:0;gap:4px}
.level-description{font-size:.9rem;color:#666;line-height:1.4}
.level-target{flex-shrink:0;text-align:right}
@media(max-width:520px){.level-card{align-items:flex-start}.level-target{max-width:38%;font-size:.82rem}}
