@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #080b10;
  --bg-elevated: #0f141c;
  --surface: #151c28;
  --surface-hover: #1a2332;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e8edf5;
  --text-muted: #8b97a8;
  --text-dim: #5c6778;
  --accent: #c9a227;
  --accent-soft: rgba(201, 162, 39, 0.15);
  --cyan: #3dd6c6;
  --cyan-soft: rgba(61, 214, 198, 0.12);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.12);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --err: #f87171;
  --err-soft: rgba(248, 113, 113, 0.14);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body.dashboard {
  font-family: 'DM Sans', system-ui, sans-serif;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(201, 162, 39, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(61, 214, 198, 0.06), transparent),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.dashboard-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
}

.dashboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.65rem;
  background: linear-gradient(135deg, var(--accent), #e8c547);
  display: grid;
  place-items: center;
  font-size: 1rem;
  box-shadow: 0 0 24px rgba(201, 162, 39, 0.25);
}

.brand-name {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-name span {
  color: var(--accent);
}

.brand-tagline {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.header-meta {
  text-align: right;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.connection-alert {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 1rem 1.15rem;
  margin-bottom: 1.25rem;
  border-radius: var(--radius);
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: linear-gradient(90deg, var(--err-soft), rgba(248, 113, 113, 0.04));
  animation: alert-pulse 2.5s ease-in-out infinite;
}

.connection-alert[hidden] {
  display: none !important;
}

.connection-alert.is-connecting {
  border-color: rgba(251, 191, 36, 0.35);
  background: linear-gradient(90deg, var(--warn-soft), rgba(251, 191, 36, 0.04));
  animation: none;
}

@keyframes alert-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
  50% { box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.08); }
}

.alert-icon {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--err-soft);
  color: var(--err);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
}

.connection-alert.is-connecting .alert-icon {
  background: var(--warn-soft);
  color: var(--warn);
}

.alert-body strong {
  display: block;
  font-size: 0.98rem;
  margin-bottom: 0.15rem;
}

.alert-body p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 1.25rem;
  align-items: start;
}

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

  .dashboard-header {
    flex-direction: column;
  }

  .header-meta {
    text-align: left;
  }
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.card-title {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.status-pill::before {
  content: '';
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--text-dim);
}

.status-pill[data-state='connected'] {
  color: var(--ok);
  border-color: rgba(52, 211, 153, 0.25);
  background: var(--ok-soft);
}

.status-pill[data-state='connected']::before {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.status-pill[data-state='connecting'] {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.25);
  background: var(--warn-soft);
}

.status-pill[data-state='connecting']::before {
  background: var(--warn);
  animation: blink 1s step-end infinite;
}

.status-pill[data-state='error'] {
  color: var(--err);
  border-color: rgba(248, 113, 113, 0.25);
  background: var(--err-soft);
}

.status-pill[data-state='error']::before {
  background: var(--err);
}

.status-pill[data-state='ready'] {
  color: var(--cyan);
  border-color: rgba(61, 214, 198, 0.25);
  background: var(--cyan-soft);
}

.status-pill[data-state='ready']::before {
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}

.status-pill[data-state='idle'],
.status-pill[data-state='disconnected'] {
  color: var(--text-muted);
}

@keyframes blink {
  50% { opacity: 0.35; }
}

.status-detail {
  margin: 0 0 1rem;
  font-size: 0.92rem;
  color: var(--text);
  min-height: 1.4em;
}

.status-detail.is-error {
  color: var(--err);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.field:last-of-type {
  margin-bottom: 0;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.field-input,
.field-select {
  width: 100%;
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.62rem 0.75rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field-input:focus,
.field-select:focus {
  outline: none;
  border-color: rgba(201, 162, 39, 0.45);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-select:disabled,
.field-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.62rem 1rem;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.12s, background 0.12s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #dbb52e);
  color: #14120a;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.card-socket[data-state='disconnected'],
.card-socket[data-state='error'] {
  border-color: rgba(248, 113, 113, 0.22);
}

.card-socket[data-state='connected'] {
  border-color: rgba(52, 211, 153, 0.2);
}

.card-midi[data-state='ready'] {
  border-color: rgba(61, 214, 198, 0.2);
}

.right-column {
  min-width: 0;
}

.channel-meter-card {
  padding-bottom: 1rem;
  position: relative;
}

.channel-meter-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
}

.channel-meter-legend {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.legend-swatch {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 2px;
}

.legend-swatch--note {
  background: var(--ok);
}

.legend-swatch--cc {
  background: #60a5fa;
}

.channel-meter-window {
  color: var(--text-dim);
}

.channel-meter {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.25rem;
  padding: 0.35rem 0.15rem 0;
}

.channel-bar {
  flex: 1;
  min-width: 0;
  max-width: 2.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.channel-bar-pair {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  width: 100%;
  height: 25px;
}

.channel-bar-track {
  flex: 1;
  min-width: 0;
  height: 25px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 3px 3px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  cursor: default;
}

.channel-bar-track:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.channel-bar-fill {
  width: calc(100% - 2px);
  height: 0;
  max-height: 25px;
  border-radius: 2px 2px 0 0;
  transition: height 0.35s ease;
}

.channel-bar-fill--note {
  background: linear-gradient(to top, rgba(52, 211, 153, 0.45), var(--ok));
}

.channel-bar-fill--cc {
  background: linear-gradient(to top, rgba(96, 165, 250, 0.45), #60a5fa);
}

.channel-bar.is-active .channel-bar-fill--note {
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.3);
}

.channel-bar.is-active .channel-bar-fill--cc {
  box-shadow: 0 0 8px rgba(96, 165, 250, 0.3);
}

.channel-bar-label {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  line-height: 1;
}

.channel-bar.is-active .channel-bar-label {
  color: var(--text-muted);
}

.meter-tooltip {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text);
  background: rgba(15, 20, 28, 0.96);
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}

.log-card {
  min-height: 420px;
  display: flex;
  flex-direction: column;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.log-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.log-count {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
}

.log-panel {
  flex: 1;
  margin: 0;
  padding: 0.85rem 1rem;
  min-height: 320px;
  max-height: min(56vh, 520px);
  overflow: auto;
  background: #06080c;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  color: #b8c4d4;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-panel:empty::before {
  content: 'Waiting for MIDI events…';
  color: var(--text-dim);
  font-style: italic;
}

.log-panel::-webkit-scrollbar {
  width: 8px;
}

.log-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

.hint {
  margin: 0.75rem 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ── Homepage ─────────────────────────────────────────────────────────────── */

.brand-link {
  text-decoration: none;
  color: inherit;
}

.brand-link:hover .brand-name {
  filter: brightness(1.08);
}

.home-hero {
  margin-bottom: 2rem;
}

.home .header-meta {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}

.home-hero-title {
  margin: 0 0 0.85rem;
  font-size: clamp(1.85rem, 4vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  max-width: 18ch;
}

.home-hero-title em {
  font-style: normal;
  color: var(--accent);
}

.home-hero-lead {
  margin: 0;
  max-width: 42rem;
  font-size: 1.05rem;
  color: var(--text-muted);
  line-height: 1.65;
}

.home-hero-lead code,
.flow-step code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--cyan);
}

.home-section-title {
  margin: 0 0 1rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.flow-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  gap: 0.75rem;
  align-items: stretch;
  margin-bottom: 2rem;
}

@media (max-width: 900px) {
  .flow-row {
    grid-template-columns: 1fr;
  }

  .flow-arrow {
    transform: rotate(90deg);
    justify-self: center;
  }
}

.flow-step {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.flow-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
}

.flow-step h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.flow-step p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.flow-step-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

.flow-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.flow-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 1.25rem;
  padding: 0 0.15rem;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

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

.app-card {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s;
}

.app-card:hover {
  border-color: rgba(201, 162, 39, 0.35);
  transform: translateY(-2px);
}

.app-card-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.65rem;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}

.app-card-icon--send {
  background: var(--ok-soft);
  color: var(--ok);
}

.app-card-icon--receive {
  background: var(--cyan-soft);
  color: var(--cyan);
}

.app-card h3 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.app-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
  flex: 1;
}

.app-card-cta {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

@media (max-width: 768px) {
  .feature-grid {
    grid-template-columns: 1fr;
  }
}

.feature-item {
  padding: 0;
  border: none;
  background: none;
  box-shadow: none;
}

.feature-item h3 {
  margin: 0 0 0.35rem;
  font-size: 0.92rem;
  font-weight: 600;
}

.feature-item p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.site-footer {
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.production-footer {
  margin-top: 0.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.production-links {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.production-links a {
  color: var(--text-muted);
  text-decoration: none;
}

.production-links a:hover {
  color: var(--accent);
}
