:root {
  color-scheme: dark;
  --bg: #050711;
  --bg-2: #090f22;
  --panel: rgba(14, 22, 43, 0.88);
  --panel-2: rgba(22, 32, 61, 0.9);
  --panel-3: rgba(31, 42, 78, 0.86);
  --line: rgba(148, 163, 184, 0.24);
  --line-strong: rgba(115, 231, 255, 0.38);
  --text: #eef6ff;
  --muted: #9eb1d4;
  --dim: #7485a7;
  --accent: #67e8f9;
  --accent-2: #a78bfa;
  --accent-3: #34d399;
  --warning: #fbbf24;
  --danger: #fb7185;
  --ok: #4ade80;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --gap: clamp(10px, 1vw, 16px);
  --pad: clamp(12px, 1.15vw, 20px);
  --topbar-h: clamp(110px, 16vh, 176px);
  --footer-h: 34px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(circle at 12% 0%, rgba(103, 232, 249, 0.20), transparent 26rem),
    radial-gradient(circle at 84% 9%, rgba(167, 139, 250, 0.18), transparent 34rem),
    linear-gradient(140deg, #06111b 0%, var(--bg) 42%, #060816 100%);
  color: var(--text);
}

button,
input,
output {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
}

.app-shell {
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--gap);
  padding: var(--gap);
  padding-top: max(var(--gap), env(safe-area-inset-top));
  padding-right: max(var(--gap), env(safe-area-inset-right));
  padding-bottom: max(var(--gap), env(safe-area-inset-bottom));
  padding-left: max(var(--gap), env(safe-area-inset-left));
  overflow: hidden;
}

.topbar {
  min-height: 102px;
  max-height: var(--topbar-h);
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(250px, 340px) auto;
  gap: var(--gap);
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, rgba(12, 22, 44, 0.94), rgba(9, 12, 31, 0.93)),
    linear-gradient(90deg, rgba(103, 232, 249, 0.13), rgba(167, 139, 250, 0.08));
  box-shadow: var(--shadow);
  padding: clamp(12px, 1.25vw, 20px);
  overflow: hidden;
}

.brand-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: clamp(12px, 1.4vw, 20px);
}

.brand-mark {
  width: clamp(54px, 5vw, 84px);
  height: clamp(54px, 5vw, 84px);
  flex: 0 0 auto;
  border-radius: 22px;
  filter: drop-shadow(0 14px 28px rgba(103, 232, 249, 0.18));
}

.brand-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 0.2rem;
  font-size: clamp(0.66rem, 0.74vw, 0.82rem);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 900;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.3rem;
  font-size: clamp(1.85rem, 3.6vw, 4.6rem);
  line-height: 0.94;
  letter-spacing: -0.055em;
}

.subtitle {
  max-width: 92ch;
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(0.82rem, 1.02vw, 1.05rem);
  line-height: 1.35;
}

.status-deck {
  display: grid;
  gap: 8px;
  align-content: center;
}

.status-pill,
.phase-tag,
.mini-readout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0.48rem 0.75rem;
  border: 1px solid rgba(103, 232, 249, 0.26);
  border-radius: 999px;
  background: rgba(20, 29, 54, 0.82);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.good {
  border-color: rgba(74, 222, 128, 0.48);
  color: #86efac;
}

.status-pill.warn {
  border-color: rgba(251, 191, 36, 0.5);
  color: #fde68a;
}

.status-pill.bad {
  border-color: rgba(251, 113, 133, 0.55);
  color: #fecdd3;
}

.top-actions {
  display: grid;
  gap: 8px;
  align-content: center;
  min-width: 118px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns:
    minmax(260px, clamp(280px, 22vw, 390px))
    minmax(460px, 1.34fr)
    minmax(290px, clamp(310px, 23vw, 430px));
  gap: var(--gap);
  overflow: hidden;
}

.panel {
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(16, 25, 49, 0.95), rgba(9, 14, 30, 0.92)),
    rgba(8, 12, 26, 0.9);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.controls-panel,
.intelligence-panel {
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  gap: var(--gap);
  padding: var(--pad);
  overflow: auto;
  scrollbar-gutter: stable;
}

.detector-panel {
  display: grid;
  grid-template-rows: auto minmax(116px, 0.72fr) minmax(200px, 1.25fr);
  gap: var(--gap);
  padding: var(--pad);
  overflow: hidden;
}

.panel-section,
.live-card,
.canvas-card {
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(24, 35, 66, 0.78), rgba(12, 18, 38, 0.78));
}

.panel-section {
  padding: clamp(12px, 1vw, 16px);
}

.section-heading,
.canvas-heading,
.meter-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-heading {
  margin-bottom: 0.75rem;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1rem, 1.05vw, 1.2rem);
  letter-spacing: -0.025em;
}

.hint {
  margin-bottom: 1rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.hint.tight {
  margin: 0.75rem 0 0;
  font-size: 0.82rem;
}

.button-grid {
  display: grid;
  gap: 10px;
}

.button-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.button {
  min-height: 44px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 16px;
  color: var(--text);
  font-weight: 900;
  background: linear-gradient(135deg, rgba(35, 47, 86, 0.95), rgba(21, 28, 55, 0.95));
  box-shadow: 0 9px 24px rgba(0, 0, 0, 0.16);
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--line-strong);
}

.button.primary {
  background: linear-gradient(135deg, rgba(103, 232, 249, 0.78), rgba(167, 139, 250, 0.72));
  color: #07111f;
}

.button.accent {
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.95), rgba(103, 232, 249, 0.72));
  color: #061017;
}

.button.danger {
  border-color: rgba(251, 113, 133, 0.45);
  background: linear-gradient(135deg, rgba(70, 31, 55, 0.78), rgba(24, 28, 52, 0.95));
}

.button.ghost {
  background: rgba(11, 18, 36, 0.72);
}

.control-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  align-items: center;
  margin: 0.8rem 0;
  color: var(--muted);
  font-size: 0.87rem;
  font-weight: 800;
}

.control-row output {
  color: var(--text);
  font-size: 0.82rem;
}

.control-row input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--accent);
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
  margin-top: 0.9rem;
}

.check-row input {
  margin-top: 0.15rem;
  accent-color: var(--accent);
}

.live-card {
  display: grid;
  grid-template-columns: minmax(174px, 0.45fr) minmax(220px, 0.55fr);
  grid-template-rows: auto auto;
  gap: clamp(10px, 1vw, 16px);
  padding: clamp(13px, 1vw, 18px);
  overflow: hidden;
}

.detected-note-block {
  grid-row: 1 / span 2;
  min-height: 128px;
  border: 1px solid rgba(103, 232, 249, 0.2);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 0% 0%, rgba(103, 232, 249, 0.18), transparent 45%),
    rgba(10, 17, 34, 0.78);
  display: grid;
  align-content: center;
  gap: 0.2rem;
  padding: clamp(14px, 1vw, 18px);
}

.label,
.metric span,
.canvas-heading,
.meter-label,
.mode-primary span {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 900;
}

.detected-note-block strong {
  font-size: clamp(2.55rem, 5.5vw, 6.5rem);
  line-height: 0.9;
  letter-spacing: -0.08em;
}

.detected-note-block small,
.mode-primary small {
  color: var(--muted);
  line-height: 1.35;
}

.meter-stack {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 9px;
}

.meter {
  height: 18px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--ok), var(--warning), var(--danger));
  transition: width 90ms linear;
}

.metrics-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  min-width: 0;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 16px;
  background: rgba(15, 22, 43, 0.62);
  padding: 0.75rem;
}

.metric strong {
  display: block;
  margin-top: 0.35rem;
  font-size: clamp(1rem, 1.3vw, 1.35rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.canvas-card {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: clamp(10px, 0.8vw, 14px);
  overflow: hidden;
}

.canvas-heading {
  padding: 0 0.35rem 0.65rem;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(8, 14, 30, 0.96), rgba(9, 13, 26, 0.98)),
    #08101f;
}

.mode-primary {
  display: grid;
  gap: 0.3rem;
  padding: 1rem;
  border: 1px solid rgba(103, 232, 249, 0.18);
  border-radius: var(--radius-lg);
  background: rgba(12, 18, 35, 0.7);
}

.mode-primary strong {
  font-size: clamp(1.45rem, 1.8vw, 2.1rem);
  letter-spacing: -0.04em;
}

.pitch-class-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 0.95rem;
}

.pc-cell {
  position: relative;
  min-height: 48px;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 14px;
  background: rgba(9, 15, 30, 0.66);
  padding: 0.6rem;
}

.pc-fill {
  position: absolute;
  inset: auto 0 0 0;
  height: 0%;
  background: linear-gradient(180deg, rgba(103, 232, 249, 0.18), rgba(52, 211, 153, 0.38));
  pointer-events: none;
}

.pc-name,
.pc-value {
  position: relative;
  z-index: 1;
}

.pc-name {
  display: block;
  font-weight: 950;
}

.pc-value {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
}

.mode-list {
  display: grid;
  gap: 8px;
  margin: 0.95rem 0 0;
  padding-left: 1.25rem;
  color: var(--muted);
}

.mode-list li {
  padding: 0.25rem 0;
}

.mode-list strong {
  color: var(--text);
}

.event-section {
  min-height: 230px;
}

.table-shell {
  max-height: min(34vh, 360px);
  overflow: auto;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 15px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

th,
td {
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(15, 22, 43, 0.98);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.68rem;
}

td {
  color: var(--text);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 1.2rem;
}

.phase-footer {
  min-height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 1rem;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 999px;
  background: rgba(7, 12, 26, 0.72);
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.phase-footer strong {
  color: var(--accent);
}

body.compact .topbar {
  min-height: 74px;
  grid-template-columns: minmax(360px, 1fr) minmax(240px, 340px) auto;
}

body.compact .subtitle {
  display: none;
}

body.compact h1 {
  font-size: clamp(1.45rem, 2.4vw, 3.1rem);
}

body.compact .brand-mark {
  width: clamp(44px, 3.6vw, 64px);
  height: clamp(44px, 3.6vw, 64px);
}

body.compact .detector-panel {
  grid-template-rows: auto minmax(100px, 0.55fr) minmax(220px, 1.45fr);
}

:fullscreen .app-shell {
  padding: clamp(8px, 0.8vw, 14px);
}

@media (max-width: 1280px) {
  .topbar {
    grid-template-columns: 1fr minmax(220px, 300px);
  }

  .top-actions {
    grid-column: 2;
    grid-row: 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: minmax(250px, 320px) minmax(430px, 1fr);
    grid-template-areas:
      "controls detector"
      "intel detector";
  }

  .controls-panel { grid-area: controls; }
  .detector-panel { grid-area: detector; }
  .intelligence-panel { grid-area: intel; }

  .intelligence-panel {
    min-height: 0;
  }

  .pitch-class-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .mode-list {
    display: none;
  }
}

@media (max-width: 980px) {
  html,
  body {
    overflow: auto;
    height: auto;
  }

  .app-shell {
    min-height: 100dvh;
    height: auto;
    overflow: visible;
  }

  .topbar,
  body.compact .topbar {
    max-height: none;
    grid-template-columns: 1fr;
  }

  .status-deck,
  .top-actions {
    grid-column: auto;
    grid-row: auto;
  }

  .top-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    overflow: visible;
    grid-template-columns: 1fr;
    grid-template-areas:
      "controls"
      "detector"
      "intel";
  }

  .panel {
    overflow: visible;
  }

  .controls-panel,
  .intelligence-panel {
    overflow: visible;
  }

  .detector-panel {
    min-height: 760px;
  }

  .live-card {
    grid-template-columns: 1fr;
  }

  .detected-note-block {
    grid-row: auto;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .phase-footer {
    white-space: normal;
    border-radius: 18px;
  }
}

@media (max-width: 560px) {
  :root {
    --gap: 8px;
    --pad: 10px;
  }

  h1 {
    font-size: clamp(1.9rem, 13vw, 3.4rem);
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .brand-mark {
    width: 50px;
    height: 50px;
    border-radius: 16px;
  }

  .button-grid.two,
  .metrics-grid,
  .pitch-class-grid {
    grid-template-columns: 1fr;
  }

  .detector-panel {
    min-height: 860px;
  }
}
