* {
  box-sizing: border-box;
  touch-action: none;
}
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: Inter, system-ui, sans-serif;
  background: radial-gradient(circle at top, #1e293b 0%, #020617 70%);
  color: #e2e8f0;
}
button, select, input {
  font: inherit;
}
body {
  display: flex;
  align-items: center;
  justify-content: center;
}
.app-shell {
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0.85rem;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

/* ── TOOLBAR ─────────────────────────────────────────────── */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.12);
  border-radius: 1rem;
}
.toolbar-title h1 {
  margin: 0 0 0.15rem 0;
  font-size: 1.1rem;
}
.toolbar-title p {
  margin: 0;
  color: #94a3b8;
  font-size: 0.8rem;
}
.controls {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.controls label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: #cbd5e1;
}
.controls select,
.controls input {
  border-radius: 0.85rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.95);
  color: #e2e8f0;
  padding: 0.5rem 0.75rem;
}
.controls input[type="range"] {
  width: 120px;
}

/* ── RECORDER ────────────────────────────────────────────── */
.recorder {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}
.rec-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.9);
  color: #e2e8f0;
  cursor: pointer;
  font-size: 0.82rem;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.rec-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.rec-btn:not(:disabled):hover {
  background: rgba(30, 41, 59, 0.95);
  border-color: rgba(148, 163, 184, 0.4);
}
.rec-btn.active {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
  color: #fca5a5;
}
#btnRecord .rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  display: inline-block;
  flex-shrink: 0;
}
#btnRecord.active .rec-dot {
  animation: blink 0.8s step-start infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}
#btnPlay.active {
  background: rgba(34, 197, 94, 0.15);
  border-color: #22c55e;
  color: #86efac;
}

/* ── KEYBOARD ────────────────────────────────────────────── */
.keyboard {
  position: relative;
  width: 100%;
  min-height: 0;
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.white-keys,
.black-keys {
  position: relative;
  display: grid;
  width: min(100%, 1800px);
}
.white-keys {
  grid-template-columns: repeat(14, minmax(0, 1fr));
  gap: 0.15rem;
  padding: 0 0.5rem 0.5rem;
  align-self: flex-end;
}
.key {
  border: none;
  border-radius: 0.85rem;
  position: relative;
  user-select: none;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 0.6rem;
  gap: 0.25rem;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}
.white {
  aspect-ratio: 1 / 3.8;
  background: linear-gradient(180deg, #f8fafc 0%, #cbd5e1 100%);
  color: #0f172a;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.06), 0 18px 30px rgba(15, 23, 42, 0.16);
}
.black-keys {
  position: absolute;
  top: 0;
  left: 0.5rem;
  right: 0.5rem;
  height: 73%;
  pointer-events: none;
}
.black {
  position: absolute;
  width: calc(100% / 14 * 0.7);
  aspect-ratio: 1 / 2.4;
  background: linear-gradient(180deg, #111827 0%, #0f172a 100%);
  color: #e2e8f0;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.42);
  z-index: 10;
  pointer-events: auto;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 0.4rem;
  gap: 0.2rem;
}
.black:nth-of-type(1)  { left: calc(100% / 14 * 0.55); }
.black:nth-of-type(2)  { left: calc(100% / 14 * 1.55); }
.black:nth-of-type(3)  { left: calc(100% / 14 * 3.55); }
.black:nth-of-type(4)  { left: calc(100% / 14 * 4.55); }
.black:nth-of-type(5)  { left: calc(100% / 14 * 5.55); }
.black:nth-of-type(6)  { left: calc(100% / 14 * 7.55); }
.black:nth-of-type(7)  { left: calc(100% / 14 * 8.55); }
.black:nth-of-type(8)  { left: calc(100% / 14 * 10.55); }
.black:nth-of-type(9)  { left: calc(100% / 14 * 11.55); }
.black:nth-of-type(10) { left: calc(100% / 14 * 12.55); }

/* ── 4. LABEL DA TECLA BLUETOOTH ────────────────────────── */
.kb-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.1rem 0.3rem;
  border-radius: 0.35rem;
  line-height: 1;
  pointer-events: none;
}
.white .kb-label {
  background: rgba(15, 23, 42, 0.1);
  color: #475569;
}
.black .kb-label {
  background: rgba(255,255,255, 0.08);
  color: #94a3b8;
}

/* nota (texto original da tecla) */
.key > :not(.kb-label) {
  font-size: 0.72rem;
}

.key.pressed {
  transform: translateY(0.18rem) scale(0.98);
}
.white.pressed {
  background: linear-gradient(180deg, #e2e8f0 0%, #cbd5e1 100%);
}
.black.pressed {
  background: linear-gradient(180deg, #27272a 0%, #111827 100%);
}

/* ── ORIENTATION MASK ───────────────────────────────────── */
.orientation-mask {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.95);
  z-index: 50;
  text-align: center;
  padding: 2rem;
}
.orientation-mask.active {
  display: flex;
}
.orientation-message {
  max-width: 26rem;
  color: #f8fafc;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 1.5rem;
  border-radius: 1.25rem;
}
.orientation-message strong {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
}

@media (max-aspect-ratio: 3/2) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .controls {
    justify-content: space-between;
  }
}
