:root {
  color-scheme: dark;
  --bg: #07050d;
  --panel: rgba(20, 17, 31, .88);
  --panel-strong: #171321;
  --border: rgba(255, 255, 255, .1);
  --text: #f8f6ff;
  --muted: #aaa3b8;
  --violet: #8b5cf6;
  --pink: #ec4899;
  --cyan: #22d3ee;
  --green: #34d399;
  --red: #fb7185;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 0%, rgba(139, 92, 246, .28), transparent 31rem),
    radial-gradient(circle at 100% 18%, rgba(34, 211, 238, .16), transparent 27rem),
    var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }
.shell { width: min(100% - 28px, 980px); margin: auto; padding: max(24px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom)); }
.hero { display: grid; grid-template-columns: 72px 1fr auto; gap: 15px; align-items: center; padding: 6px 2px 20px; }
.app-icon { width: 72px; height: 72px; border-radius: 19px; box-shadow: 0 12px 38px rgba(122, 74, 255, .32); }
.hero-copy h1 { margin: 0; font-size: clamp(30px, 7vw, 48px); line-height: 1; letter-spacing: -.04em; }
.hero-copy p { margin: 7px 0 0; color: var(--muted); line-height: 1.45; }
.hero-copy .eyebrow { color: #c6b8ff; font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.status { align-self: start; padding: 8px 11px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; white-space: nowrap; background: rgba(255,255,255,.05); }
.status.online { color: #9ff3d5; border-color: rgba(52, 211, 153, .35); background: rgba(52, 211, 153, .1); }
.status.busy { color: #bff6ff; border-color: rgba(34, 211, 238, .35); }
.status.offline { color: #d2cbdc; }

.notice { padding: 13px 15px; border-radius: 15px; margin-bottom: 14px; line-height: 1.5; }
.warning { color: #ffe7a3; background: rgba(245, 158, 11, .11); border: 1px solid rgba(245, 158, 11, .28); }
.card { background: linear-gradient(145deg, rgba(28, 23, 41, .94), rgba(15, 13, 24, .94)); border: 1px solid var(--border); border-radius: 22px; padding: 18px; box-shadow: 0 18px 55px rgba(0, 0, 0, .18); backdrop-filter: blur(18px); }
.connect-panel { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 14px; border-color: rgba(139, 92, 246, .27); }
.connect-panel h2, .section-title h2 { margin: 0; font-size: 17px; }
.connect-panel p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.full { grid-column: 1 / -1; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.section-title span { color: #bcb3cb; font-size: 11px; padding: 5px 8px; border-radius: 999px; background: rgba(255,255,255,.055); }
.section-title span strong { color: var(--text); font-size: 15px; }
.section-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
label { display: block; margin: 13px 0 7px; color: #c1bacb; font-size: 12px; font-weight: 650; }
select, input[type="number"], input[type="text"], .advanced input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 13px; color: var(--text);
  background: rgba(5, 4, 10, .6); border: 1px solid rgba(255,255,255,.12); outline: none;
}
select:focus, input:focus { border-color: rgba(139, 92, 246, .8); box-shadow: 0 0 0 3px rgba(139, 92, 246, .14); }
#effect { direction: ltr; }
input[type="range"] { width: 100%; accent-color: var(--violet); }
.color-picker { display: block; width: 100%; height: 64px; padding: 0; border: 0; border-radius: 16px; overflow: hidden; background: transparent; }
.color-picker::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker::-webkit-color-swatch { border: 1px solid rgba(255,255,255,.16); border-radius: 16px; }
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 7px; margin: 10px 0; }
.swatches button { height: 34px; border: 1px solid rgba(255,255,255,.2); border-radius: 11px; background: var(--swatch); box-shadow: inset 0 0 12px rgba(255,255,255,.16); }
.control-head { display: flex; align-items: end; justify-content: space-between; }
.control-head output { color: #d7ceff; font-size: 12px; padding-bottom: 6px; }
.button-row { display: flex; gap: 9px; margin-top: 16px; }
.button-row.compact { margin-top: 0; }
.button-row.three .button { flex: 1; }
.button { min-height: 44px; padding: 10px 14px; border: 1px solid transparent; border-radius: 13px; color: white; font-weight: 750; cursor: pointer; }
.button:disabled { opacity: .42; cursor: default; }
.button.primary { background: linear-gradient(135deg, var(--violet), var(--pink)); box-shadow: 0 9px 25px rgba(139, 92, 246, .2); }
.button.ghost { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.12); }
.button.success { background: rgba(52, 211, 153, .15); border-color: rgba(52, 211, 153, .3); color: #a9f5d9; flex: 1; }
.button.danger { background: rgba(251, 113, 133, .13); border-color: rgba(251, 113, 133, .28); color: #ffc1cb; flex: 1; }
.wide { width: 100%; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.55; margin-top: -5px; }
.layout-card { overflow: hidden; border-color: rgba(34, 211, 238, .22); }
.layout-toolbar { display: block; }
.count-control label { margin-top: 0; }
.stepper { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; gap: 8px; }
.stepper button { border: 1px solid rgba(255,255,255,.12); border-radius: 13px; color: var(--text); background: rgba(255,255,255,.06); font-size: 22px; cursor: pointer; }
.stepper input { min-width: 0; text-align: center; font-size: 20px; font-weight: 800; }
.count-control input[type="range"] { margin-top: 12px; }
.field-hint, .layout-note { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.quick-counts { display: flex; gap: 7px; margin: 16px 0 12px; }
.quick-counts button { flex: 1; min-height: 38px; border: 1px solid rgba(255,255,255,.1); border-radius: 11px; color: #c8c1d3; background: rgba(255,255,255,.045); font-weight: 700; cursor: pointer; }
.quick-counts button.active { color: #dffbff; border-color: rgba(34,211,238,.5); background: rgba(34,211,238,.12); }
.strip-frame { padding: 13px; direction: ltr; border: 1px solid rgba(255,255,255,.08); border-radius: 17px; background: rgba(4,3,9,.52); }
.strip-labels, .strip-legend { display: flex; justify-content: space-between; direction: rtl; color: #81798c; font-size: 10px; }
.strip-labels { margin-bottom: 9px; }
.strip-legend { justify-content: flex-start; gap: 14px; margin-top: 9px; }
.strip-legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.legend-dot.on { background: var(--pink); box-shadow: 0 0 8px var(--pink); }
.legend-dot.off { background: #302b39; }
.led-strip { display: grid; grid-template-columns: repeat(22, minmax(7px, 1fr)); gap: clamp(4px, 1vw, 8px); }
.led-pixel { aspect-ratio: 1; min-width: 0; padding: 0; border: 1px solid rgba(255,255,255,.09); border-radius: 50%; background: #27232f; box-shadow: inset 0 1px 2px rgba(255,255,255,.07); cursor: pointer; transition: transform .16s ease, background .16s ease, box-shadow .16s ease; }
.led-pixel.active { border-color: rgba(255,255,255,.42); background: var(--pixel-color, #ff006e); box-shadow: 0 0 8px var(--pixel-color, #ff006e), 0 0 15px color-mix(in srgb, var(--pixel-color, #ff006e) 45%, transparent); }
.led-pixel.edge { transform: scale(1.22); outline: 2px solid rgba(255,255,255,.72); outline-offset: 2px; }
.led-pixel:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.layout-note { margin-top: 11px; }
.layout-apply { margin-top: 12px; }
.source-panel { margin-top: 16px; padding-top: 2px; }
.source-panel[hidden] { display: none; }
.music-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hardware-modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 17px 0 13px; }
.mode-chip { min-height: 67px; padding: 9px 6px; color: var(--text); border: 1px solid rgba(255,255,255,.1); border-radius: 14px; background: rgba(255,255,255,.045); cursor: pointer; }
.mode-chip strong, .mode-chip span { display: block; }
.mode-chip strong { font-size: 13px; }
.mode-chip span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.mode-chip.active { border-color: rgba(139,92,246,.8); background: linear-gradient(145deg, rgba(139,92,246,.24), rgba(236,72,153,.12)); box-shadow: 0 0 0 2px rgba(139,92,246,.12); }
.engine-panel { margin-top: 14px; padding: 13px; border: 1px solid rgba(139,92,246,.2); border-radius: 16px; background: rgba(8,6,14,.35); }
.engine-panel[hidden] { display: none; }
.engine-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 13px; }
.engine-stats div { padding: 10px 7px; border-radius: 12px; text-align: center; background: rgba(255,255,255,.045); }
.engine-stats span, .engine-stats strong { display: block; }
.engine-stats span { color: var(--muted); font-size: 9px; letter-spacing: .08em; }
.engine-stats strong { margin-top: 4px; color: #e0d9ff; font-size: 15px; }
.meter { height: 13px; overflow: hidden; margin-top: 17px; border-radius: 999px; background: rgba(0,0,0,.38); }
.meter div { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--cyan), var(--violet), var(--pink)); transition: width .08s linear; }
.music-status { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 8px; }
.beat-dot { width: 12px; height: 12px; border-radius: 50%; background: #393346; transition: .09s; }
.beat-dot.active { background: var(--pink); transform: scale(1.6); box-shadow: 0 0 20px var(--pink); }
.log-card { margin-top: 14px; }
.log-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.advanced { margin-top: 14px; }
.advanced summary { cursor: pointer; color: #c4bbce; font-size: 13px; }
.advanced input { direction: ltr; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
footer { padding: 25px 5px 5px; color: #6f6878; text-align: center; font-size: 11px; }

@media (max-width: 680px) {
  .shell { width: min(100% - 20px, 980px); }
  .hero { grid-template-columns: 60px 1fr; }
  .app-icon { width: 60px; height: 60px; border-radius: 16px; }
  .status { grid-column: 1 / -1; justify-self: stretch; text-align: center; }
  .connect-panel { align-items: stretch; flex-direction: column; }
  .grid { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .music-grid { grid-template-columns: 1fr; gap: 0; }
  .layout-toolbar { grid-template-columns: 1fr; gap: 14px; }
  .led-strip { grid-template-columns: repeat(11, minmax(10px, 1fr)); gap: 8px; }
  .hardware-modes { grid-template-columns: repeat(2, 1fr); }
  .engine-stats { grid-template-columns: repeat(2, 1fr); }
  .button-row.three { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
