.game-root {
  min-height: 36rem;
  display: flex;
  flex-direction: column;
}

/* Attribute [hidden] loses to .field/.stat/.piano-octave-row display rules */
#game-root [hidden] {
  display: none !important;
}

.game-root.is-filled {
  overflow: auto;
  min-height: 0;
}

.game-root.is-filled .piano-stage {
  flex: 1 1 auto;
  min-height: 0;
  justify-content: flex-start;
}

.piano-stage {
  width: min(100%, 52rem);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1 1 auto;
  min-height: 0;
}

.piano-chrome {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  flex-wrap: nowrap;
}

.piano-tabs {
  display: inline-flex;
  gap: 0;
  flex-wrap: nowrap;
  flex: 0 1 auto;
  min-width: 0;
  border: 1px solid rgba(244, 240, 232, 0.28);
  border-radius: var(--radius);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.18);
}

.piano-tab {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  min-height: var(--tap-min);
  padding: 0.4rem 0.85rem;
  border: 0;
  border-right: 1px solid rgba(244, 240, 232, 0.18);
  border-radius: 0;
  background: transparent;
  color: #f4f0e8;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.piano-tab:last-child {
  border-right: 0;
}

.piano-tab:hover {
  background: color-mix(in srgb, var(--gold) 14%, transparent);
}

.piano-tab.is-selected {
  background: color-mix(in srgb, var(--gold) 22%, transparent);
  box-shadow: inset 0 0 0 1px var(--gold, #e0b948);
  font-weight: 600;
}

.piano-options {
  position: relative;
  margin: 0 0 0 auto;
  flex: 0 0 auto;
}

.piano-options > summary {
  list-style: none;
  cursor: pointer;
  min-height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.85rem;
  border: 1px solid rgba(244, 240, 232, 0.28);
  border-radius: var(--radius);
  color: #f4f0e8;
  background: rgba(0, 0, 0, 0.18);
  user-select: none;
  white-space: nowrap;
}

.piano-options > summary::-webkit-details-marker {
  display: none;
}

.piano-options[open] > summary {
  border-color: var(--gold, #e0b948);
}

.piano-options-panel {
  position: absolute;
  right: 0;
  left: auto;
  top: calc(100% + 0.35rem);
  z-index: 40;
  width: min(18rem, calc(100vw - 2rem));
  min-width: 0;
  box-sizing: border-box;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  border: 1px solid rgba(244, 240, 232, 0.28);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--felt-dark, #14241e) 92%, #000);
  box-shadow: var(--shadow, 0 8px 24px rgba(0, 0, 0, 0.28));
  color: #f4f0e8;
}

.piano-options-panel .field,
.piano-options-panel .switch {
  color: #f4f0e8;
}

.piano-options-panel .field-label,
.piano-options-panel .switch-text {
  color: #d5ddd6;
}

.piano-opt-hint {
  margin: -0.25rem 0 0;
  font-size: 0.85rem;
  line-height: 1.35;
  color: #d5ddd6;
}

.piano-piece {
  text-align: center;
  min-height: 2.8rem;
}

.piano-piece-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.25;
  color: #f4f0e8;
}

.piano-piece-title.has-star::after {
  content: " ★";
  color: var(--gold, #e0b948);
  font-size: 0.95em;
}

.piano-piece-composer {
  margin: 0.1rem 0 0;
  color: #d5ddd6;
  font-size: 0.95rem;
}

.game-root[data-mode="free"] .piano-piece {
  display: none;
}

.piano-status {
  min-height: 2.8rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.08rem;
  text-align: center;
}

.piano-line,
.piano-note {
  margin: 0;
  line-height: 1.35;
  min-height: 1.35em;
}

.piano-line { color: #f4f0e8; }

.piano-note {
  color: #d5ddd6;
  font-size: 0.95rem;
}

.piano-staff-wrap {
  min-height: 5.5rem;
  /* Match .piano-keys-host horizontal inset */
  padding-inline: 0.65rem;
  box-sizing: border-box;
}

.piano-staff-host {
  width: 100%;
}

.piano-staff-wrap .music-staff-scroll {
  border-radius: 14px;
  overflow: hidden;
  overflow-x: auto;
}

.piano-keys-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.piano-octave-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
}

.piano-oct-btn {
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  color: #f4f0e8;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(244, 240, 232, 0.28);
}

.piano-oct-label {
  min-width: 5.5rem;
  text-align: center;
  color: #d5ddd6;
  font-size: 0.92rem;
}

.stat b.is-low {
  color: #e0b948;
}

.piano-keys-host {
  width: 100%;
  padding: 0.7rem 0.65rem 0.85rem;
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 42%),
    #14241e;
  box-shadow:
    inset 0 0 0 1px rgba(232, 217, 168, 0.35),
    inset 0 10px 20px rgba(0, 0, 0, 0.22);
}

@media (max-width: 640px) {
  .game-root {
    min-height: 30rem;
  }

  .game-root > .game-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .game-root > .game-toolbar .toolbar-stats {
    width: 100%;
  }

  .game-root > .game-toolbar .toolbar-controls {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.4rem;
    width: 100%;
  }

  .game-root > .game-toolbar .toolbar-controls .field {
    width: 100%;
  }

  .game-root > .game-toolbar .toolbar-controls .field .select {
    width: 100%;
  }

  .game-root > .game-toolbar .toolbar-controls > .btn,
  .game-root > .game-toolbar .toolbar-controls > a,
  .game-root > .game-toolbar .toolbar-controls > .btn-icon {
    justify-self: stretch;
  }

  .game-root > .game-toolbar .toolbar-controls {
    grid-template-columns: 1fr auto auto;
  }

  .game-root > .game-toolbar .toolbar-controls .field {
    grid-column: 1 / -1;
  }

  .piano-piece-title {
    font-size: 1.15rem;
  }

  .piano-tab {
    padding: 0.35rem 0.5rem;
    font-size: 0.92rem;
  }

  .piano-options > summary {
    padding: 0.35rem 0.65rem;
  }

  .piano-staff-wrap {
    padding-inline: 0.4rem;
  }

  .piano-keys-host {
    padding: 0.55rem 0.4rem 0.7rem;
  }

  .piano-options-panel {
    left: auto;
    right: 0;
    width: min(18rem, calc(100vw - 2rem));
  }
}
