:root {
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.92);
  --panel-dark: rgba(2, 6, 23, 0.72);
  --border: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.36);

  --text: #f8fafc;
  --muted: #94a3b8;
  --muted2: #64748b;

  --blue: #38bdf8;
  --blue2: #2563eb;
  --green: #22c55e;
  --green2: #15803d;
  --yellow: #f59e0b;
  --red: #ef4444;

  --staff-bg: #f8fafc;
  --staff-line: #111827;
  --live-note: #0284c7;
  --scale-note: #16a34a;
  --drill-note: #7c3aed;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    sans-serif;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.15), transparent 35%),
    radial-gradient(circle at bottom right, rgba(34, 197, 94, 0.08), transparent 35%), var(--bg);
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  width: 100vw;
  height: 100vh;
  padding: 10px;
  display: grid;
  grid-template-rows: 74px 1fr;
  gap: 10px;
}

.topbar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(2, 6, 23, 0.56);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 12px 14px;
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 32px;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.32);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1;
  letter-spacing: -0.04em;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status {
  min-width: 142px;
  text-align: center;
  padding: 9px 10px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.9);
  white-space: nowrap;
}

.status.connected {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.45);
}

.layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 10px;
}

.panel {
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
}

.main-panel {
  padding: 10px;
  display: grid;
  grid-template-rows: 46px 1fr 138px;
  gap: 10px;
}

.side-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: 144px 1fr 154px 200px;
  gap: 10px;
}

.chord-panel,
.scale-panel,
.drill-panel,
.metro-panel {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.modebar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-btn {
  height: 40px;
  padding: 0 15px;
  border-radius: 14px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(2, 6, 23, 0.7);
  font-weight: 900;
}

.mode-btn.active {
  color: white;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  border-color: transparent;
}

.mode-tools {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.btn {
  min-height: 38px;
  border: 0;
  border-radius: 13px;
  padding: 8px 12px;
  color: white;
  font-weight: 900;
  font-size: 12px;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--blue), var(--blue2));
}

.btn-green {
  background: linear-gradient(135deg, var(--green), var(--green2));
}

.btn-muted {
  color: var(--muted);
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid var(--border);
}

.btn-muted[data-active='true'] {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.45);
}

.btn.full {
  width: 100%;
}

.hidden {
  display: none !important;
}

.staff-card {
  min-height: 0;
  display: grid;
  grid-template-rows: 50px 1fr;
  gap: 8px;
}

.staff-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.staff-header h2,
.panel-title h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.staff-header p,
.panel-title p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.drill-target {
  padding: 10px 14px;
  border-radius: 14px;
  color: white;
  font-size: 18px;
  font-weight: 950;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
}

.staff-wrap {
  min-height: 0;
  overflow: hidden;
  background: var(--staff-bg);
  border-radius: 20px;
  border: 1px solid #dbe2ea;
}

#staffSvg {
  width: 100%;
  height: 100%;
  display: block;
}

.keyboard-card {
  min-height: 0;
  display: grid;
  grid-template-rows: 30px 1fr;
  gap: 8px;
  padding: 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: rgba(2, 6, 23, 0.78);
}

.keyboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.keyboard-options label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.keyboard-options select {
  min-height: 28px;
  height: 28px;
  padding: 2px 8px;
  border-radius: 9px;
  font-size: 12px;
}

.virtual-keyboard {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.white-key {
  position: relative;
  height: 100%;
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 7px;
  font-size: 11px;
  font-weight: 950;
  color: #0f172a;
  background: linear-gradient(#ffffff, #dbeafe);
  border: 1px solid #94a3b8;
  border-radius: 0 0 8px 8px;
}

.white-key.active {
  color: white;
  background: linear-gradient(#7dd3fc, #0284c7);
}

.white-key.scale {
  box-shadow: inset 0 -8px 0 rgba(34, 197, 94, 0.75);
}

.white-key.drill {
  box-shadow: inset 0 -8px 0 rgba(124, 58, 237, 0.85);
}

.black-key {
  position: absolute;
  top: 0;
  z-index: 3;
  height: 62%;
  background: linear-gradient(#020617, #1e293b);
  border: 1px solid #020617;
  border-radius: 0 0 7px 7px;
}

.black-key.active {
  background: linear-gradient(#38bdf8, #0369a1);
}

.black-key.scale {
  box-shadow: inset 0 -6px 0 rgba(34, 197, 94, 0.85);
}

.black-key.drill {
  box-shadow: inset 0 -6px 0 rgba(124, 58, 237, 0.95);
}

.chord-name {
  margin-top: 2px;
  font-size: 38px;
  font-weight: 950;
  line-height: 1;
  letter-spacing: -0.07em;
  color: white;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chord-quality {
  color: #bae6fd;
  font-size: 13px;
  font-weight: 850;
}

.chord-notes {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  min-width: 0;
}

select,
input {
  width: 100%;
  min-height: 38px;
  padding: 7px 9px;
  color: var(--text);
  background: rgba(2, 6, 23, 0.82);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
}

.info-box {
  flex: 1;
  min-height: 0;
  padding: 10px;
  color: var(--muted);
  background: rgba(2, 6, 23, 0.62);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
}

.info-box.small {
  max-height: 48px;
}

.beat-dots {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.beat-dot {
  width: 25px;
  height: 25px;
  border-radius: 999px;
  background: #334155;
  border: 1px solid #475569;
}

.beat-dot.active {
  background: var(--blue);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.9);
}

.beat-dot.strong.active {
  background: var(--green);
  box-shadow: 0 0 18px rgba(34, 197, 94, 0.95);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: 360px;
  padding: 13px 15px;
  border-radius: 16px;
  background: rgba(2, 6, 23, 0.94);
  border: 1px solid var(--border-strong);
  color: white;
  font-size: 13px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

@media (max-width: 980px) {
  .app {
    padding: 8px;
    grid-template-rows: 66px 1fr;
    gap: 8px;
  }

  .layout {
    grid-template-columns: 1fr 320px;
    gap: 8px;
  }

  .brand h1 {
    font-size: 19px;
  }

  .brand p {
    display: none;
  }

  .logo {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    font-size: 29px;
  }

  .topbar {
    padding: 10px 12px;
    border-radius: 19px;
  }

  .status {
    min-width: 120px;
  }

  .main-panel {
    padding: 8px;
    grid-template-rows: 42px 1fr 128px;
    gap: 8px;
  }

  .side-panel {
    grid-template-rows: 132px 1fr 142px 188px;
    gap: 8px;
  }

  .chord-panel,
  .scale-panel,
  .drill-panel,
  .metro-panel {
    padding: 10px;
  }

  .chord-name {
    font-size: 32px;
  }

  .mode-btn {
    height: 36px;
    padding: 0 11px;
    font-size: 12px;
  }

  .btn {
    min-height: 35px;
    padding: 7px 10px;
  }
}
