:root {
  color-scheme: dark;
  --bg: #1a202c;
  --panel: #2d3748;
  --panel-dark: #171923;
  --border: #4a5568;
  --text: #e2e8f0;
  --muted: #a0aec0;
  --blue: #60a5fa;
  --blue-strong: #2563eb;
  --purple: #c4b5fd;
  --green: #48bb78;
  --red: #f56565;
  --yellow: #f6e05e;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 280px;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(96, 165, 250, 0.65);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.app-header {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
  align-items: center;
  gap: 12px 20px;
  padding: calc(12px + var(--safe-top)) calc(18px + var(--safe-right)) 12px calc(18px + var(--safe-left));
  background: #252f3f;
  border-bottom: 1px solid #4a5568;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.brand-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2.4vw, 1.3rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

h1 span {
  color: var(--blue);
}

.version-label {
  color: #718096;
  font-size: 0.68rem;
  white-space: nowrap;
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 14px;
}

.tab-button {
  min-height: 38px;
  padding: 6px 2px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #e2e8f0;
  font-size: 0.92rem;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease;
}

.tab-button.active {
  border-bottom-color: var(--blue);
  color: var(--blue);
  font-weight: 700;
}

.tab-button.chords-tab {
  color: var(--purple);
}

.tab-button.chords-tab.active {
  border-bottom-color: #a78bfa;
  color: #c4b5fd;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.utility-button {
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid #4a5568;
  border-radius: 7px;
  background: #374151;
  color: var(--text);
  font-size: 0.77rem;
  font-weight: 700;
  cursor: pointer;
}

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

.utility-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.reload-button {
  border-color: #4c6f97;
  background: #2b4b70;
}

.midi-button {
  border-color: #6b5b95;
  background: #43386b;
}

.status-pill {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.disconnected,
.status-pill.unsupported {
  background: #742a2a;
  color: #fed7d7;
}

.status-pill.pending {
  background: #744210;
  color: #fefcbf;
}

.status-pill.connected {
  background: #22543d;
  color: #c6f6d5;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fc8181;
  flex: 0 0 auto;
}

.status-pill.pending .status-dot {
  background: #f6e05e;
}

.status-pill.connected .status-dot {
  background: #68d391;
}

.status-pill.activity .status-dot {
  background: #f6e05e;
}

.main-content {
  width: 100%;
  padding: clamp(14px, 3vw, 28px) calc(clamp(12px, 3vw, 24px) + var(--safe-right)) 18px calc(clamp(12px, 3vw, 24px) + var(--safe-left));
}

.practice-view {
  width: min(100%, 720px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.hidden {
  display: none !important;
}

.controls-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 16px;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.control-button {
  min-height: 42px;
  padding: 9px 15px;
  border: 0;
  border-radius: 6px;
  background: #374151;
  color: #d1d5db;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}

.control-button.selected {
  background: var(--blue-strong);
  color: white;
  font-weight: 700;
}

.score-block {
  flex: 0 0 auto;
  text-align: right;
}

.score-block p {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.score-block strong {
  display: block;
  color: var(--blue);
  font-size: 2rem;
  line-height: 1;
}

.chords-score strong {
  color: #b794f4;
}

.select-block {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: min(270px, 76vw);
}

.select-block label {
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 42px;
  padding: 8px 34px 8px 10px;
  border: 1px solid #4a5568;
  border-radius: 6px;
  background: #252f3f;
  color: white;
}

.staff-card {
  width: 100%;
  min-height: clamp(180px, 31vh, 230px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 3vw, 24px);
  overflow: hidden;
  border: 1px solid #4a5568;
  border-radius: 12px;
  background: var(--panel-dark);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.28);
}

.staff-card svg {
  display: block;
  width: min(100%, 560px);
  height: auto;
  max-height: 190px;
}

.feedback {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--yellow);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.83rem;
  text-align: center;
}

.feedback.success-feedback {
  color: #9ae6b4;
}

.feedback.error-feedback {
  color: #feb2b2;
}

.compatibility-note {
  width: min(100%, 720px);
  margin: 12px auto 0;
  padding: 10px 12px;
  border: 1px solid #805ad5;
  border-radius: 8px;
  background: rgba(76, 29, 149, 0.28);
  color: #e9d8fd;
  font-size: 0.78rem;
  line-height: 1.45;
}

.keyboard-footer {
  width: 100%;
  padding: 10px var(--safe-right) calc(10px + var(--safe-bottom)) var(--safe-left);
  background: #252f3f;
  border-top: 1px solid #4a5568;
  box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.3);
}

.keyboard-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 calc(10px + var(--safe-left)) 7px calc(10px + var(--safe-right));
  color: #cbd5e0;
  font-size: 0.72rem;
  font-weight: 700;
}

.keyboard-help {
  color: #718096;
  font-weight: 500;
  text-align: right;
}

.keyboard-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

.keyboard-scroll::-webkit-scrollbar {
  display: none;
}

.keyboard {
  position: relative;
  width: max-content;
  min-width: 100%;
  height: clamp(112px, 19vh, 150px);
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 0 12px 6px;
}

.key {
  position: relative;
  display: block;
  flex: 0 0 auto;
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: background-color 70ms linear, transform 70ms linear;
  touch-action: pan-x pan-y;
}

.key-white {
  z-index: 1;
  width: clamp(38px, 9.2vw, 48px);
  height: clamp(108px, 18vh, 142px);
  border: 1px solid #cbd5e0;
  border-radius: 0 0 5px 5px;
  background: #f7fafc;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.key-black {
  z-index: 2;
  width: clamp(25px, 5.8vw, 30px);
  height: clamp(66px, 11vh, 87px);
  margin-left: calc(clamp(25px, 5.8vw, 30px) / -2);
  margin-right: calc(clamp(25px, 5.8vw, 30px) / -2);
  border-radius: 0 0 4px 4px;
  background: #2d3748;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.55);
}

.key.active {
  background: #4299e1 !important;
  transform: translateY(2px);
  box-shadow: none !important;
}

.key.error {
  background: var(--red) !important;
}

.key.success {
  background: var(--green) !important;
}

.key-label {
  position: absolute;
  right: 0;
  bottom: 5px;
  left: 0;
  color: #718096;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.64rem;
  text-align: center;
  pointer-events: none;
}

.update-banner {
  position: fixed;
  z-index: 100;
  right: calc(14px + var(--safe-right));
  bottom: calc(14px + var(--safe-bottom));
  left: calc(14px + var(--safe-left));
  width: min(560px, calc(100% - 28px - var(--safe-left) - var(--safe-right)));
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 42px 12px 14px;
  border: 1px solid #63b3ed;
  border-radius: 10px;
  background: #1e3a5f;
  color: white;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
  font-weight: 700;
}

.update-banner button {
  min-height: 36px;
  padding: 7px 11px;
  border: 0;
  border-radius: 6px;
  background: white;
  color: #1a365d;
  font-weight: 800;
  cursor: pointer;
}

.update-banner .dismiss-button {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 32px;
  min-height: 32px;
  padding: 0;
  background: transparent;
  color: #bee3f8;
  font-size: 1.45rem;
  line-height: 1;
}

noscript {
  display: block;
  padding: 20px;
  background: #742a2a;
  color: white;
  text-align: center;
}

@media (max-width: 860px) {
  .app-header {
    grid-template-columns: 1fr auto;
  }

  .tabs {
    grid-column: 1 / -1;
    grid-row: 2;
    order: 3;
  }

  .header-actions {
    min-width: 0;
  }
}

@media (max-width: 600px) {
  .app-header {
    grid-template-columns: 1fr;
    gap: 9px;
    padding-top: calc(9px + var(--safe-top));
  }

  .brand-row,
  .header-actions,
  .tabs {
    grid-column: 1;
    width: 100%;
    justify-content: center;
  }

  .brand-row {
    justify-content: space-between;
  }

  .header-actions {
    gap: 6px;
  }

  .utility-button {
    flex: 1 1 auto;
    padding-right: 7px;
    padding-left: 7px;
  }

  .status-pill {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .tabs {
    grid-row: auto;
    gap: 18px;
  }

  .tab-button {
    font-size: 0.85rem;
  }

  .main-content {
    padding-top: 14px;
  }

  .keyboard-help {
    display: none;
  }
}

@media (max-width: 390px) {
  .controls-row {
    align-items: stretch;
  }

  .select-block {
    min-width: 0;
    flex: 1 1 auto;
  }

  .control-button {
    padding-right: 11px;
    padding-left: 11px;
  }

  .staff-card {
    min-height: 170px;
    padding: 7px;
  }

  .update-banner {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

@media (max-height: 560px) and (orientation: landscape) {
  .app-header {
    gap: 6px 12px;
    padding-top: calc(6px + var(--safe-top));
    padding-bottom: 6px;
  }

  .main-content {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .controls-row {
    margin-bottom: 8px;
  }

  .staff-card {
    min-height: 140px;
    max-height: 170px;
  }

  .feedback {
    min-height: 18px;
    margin-top: 5px;
  }

  .keyboard-footer {
    padding-top: 6px;
  }

  .keyboard-heading {
    display: none;
  }

  .keyboard,
  .key-white {
    height: 96px;
  }

  .key-black {
    height: 60px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}

/* Evita que el ancho intrínseco del piano ensanche la cuadrícula de la página. */
.app-shell,
.app-header,
.main-content,
.keyboard-footer,
.keyboard-scroll {
  min-width: 0;
  max-width: 100%;
}

.app-shell {
  width: 100%;
}

.keyboard-footer {
  overflow: hidden;
}

.keyboard-scroll {
  display: block;
}
