:root {
  --bg: #060607;
  --bg-panel: #0e0b0c;
  --line: #2a1418;
  --fg: #f2e4e6;
  --dim: #7a6468;
  --dimmer: #4a3236;
  --accent: #ff2f4e;
  --accent2: #ff8a3d;
  --wood: #b5652b;
  --cell: #150a0c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 32px 16px 72px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  overflow-x: hidden;
}

/* the hub's purple whisper + analogue grain */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(ellipse at 12% 8%, rgba(58, 23, 80, .3), transparent 55%),
    radial-gradient(ellipse at 88% 92%, rgba(105, 40, 10, .22), transparent 55%);
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

main { width: 100%; max-width: 900px; min-width: 0; }

.labs-link { position: fixed; top: calc(14px + env(safe-area-inset-top, 0px)); right: 16px; color: var(--accent); text-decoration: none; font-size: 13px; z-index: 50; background: rgba(6, 6, 7, .85); padding: 4px 8px; border-radius: 4px; }
.labs-link:hover { text-decoration: underline; }

/* ---------------- header */
.head { position: relative; text-align: center; }
.cello {
  display: table;
  text-align: left;
  color: var(--accent);
  font-size: 13px;
  line-height: 1.2;
  margin: 0 auto 6px;
  text-shadow: 0 0 12px rgba(255, 47, 78, .4);
  transition: text-shadow .08s ease, color .08s ease;
}
.cello.hit { color: var(--accent2); text-shadow: 0 0 18px rgba(255, 138, 61, .65); }
.title { text-align: center; font-size: 28px; letter-spacing: 2px; margin: 0; }
.blink { animation: blink 1.1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.tagline { text-align: center; color: var(--dim); margin: 6px 0 12px; font-size: 13px; }
.scope { display: block; width: 100%; max-width: 420px; height: 36px; margin: 8px auto 22px; opacity: .9; }

.start { text-align: center; margin: 40px 0; }
.start-btn {
  background: var(--accent); color: #1a0004; border: none; font-family: inherit; font-weight: 700;
  font-size: 16px; padding: 16px 26px; border-radius: 6px; cursor: pointer; letter-spacing: .5px;
  box-shadow: 0 0 24px rgba(255, 47, 78, .35);
}
.start-btn:hover { filter: brightness(1.08); }
.start-btn:active { transform: translateY(1px); }
.start-btn:disabled { opacity: .6; }
.hint { color: var(--dim); font-size: 12px; margin: 12px 0 0; }
#startErr { color: var(--accent); }

/* ---------------- panel */
.panel { border: 1px solid var(--line); background: var(--bg-panel); border-radius: 10px; padding: 18px; min-width: 0; }
.row { margin-bottom: 20px; min-width: 0; }
.row:last-child { margin-bottom: 0; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--dim); margin: 0 0 10px; font-weight: 600; }
.section-label .dim { text-transform: none; letter-spacing: 0; color: var(--dimmer); font-weight: 400; }
.dim { color: var(--dim); }
.small-note { font-size: 11.5px; margin: 6px 0 10px; line-height: 1.5; }
h3.sub { font-size: 11.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--accent2); margin: 18px 0 8px; font-weight: 700; }
h3.sub .dim { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--dim); }

/* ---------------- buttons + inputs */
.btn {
  background: #150a0c; color: var(--fg); border: 1px solid var(--line); border-radius: 6px;
  font-family: inherit; font-size: 13px; font-weight: 700; padding: 10px 14px; cursor: pointer;
  letter-spacing: .3px; touch-action: manipulation; min-height: 40px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 6px 10px; font-size: 12px; min-height: 34px; }
.btn.big { font-size: 15px; padding: 14px 18px; min-width: 104px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0004; }
.btn.primary:hover { filter: brightness(1.08); color: #1a0004; }
.btn.on { background: var(--accent); border-color: var(--accent); color: #1a0004; }
.btn.on2 { background: var(--accent2); border-color: var(--accent2); color: #200a02; }
.btn.rec.armed, .btn.rec.on { background: #ff0033; border-color: #ff0033; color: #fff; animation: pulse .9s ease-in-out infinite; }
.btn.rec.dub { background: var(--accent2); border-color: var(--accent2); color: #200a02; animation: pulse .9s ease-in-out infinite; }
.btn.danger:hover { border-color: #ff0033; color: #ff0033; }
.btn:disabled { opacity: .4; cursor: default; }
@keyframes pulse { 50% { filter: brightness(1.5); } }

input[type="text"], input[type="number"], select {
  background: #150a0c; color: var(--fg); border: 1px solid var(--line); border-radius: 5px;
  font-family: inherit; font-size: 13px; padding: 7px 8px; min-width: 0; max-width: 100%; min-height: 34px;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus { outline: none; border-color: var(--accent); }
input[type="number"] { width: 72px; }
input[type="checkbox"] { accent-color: var(--accent); width: 18px; height: 18px; flex: 0 0 auto; }
label.inline { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 1px; min-width: 0; }
label.inline.check { text-transform: none; letter-spacing: 0; color: var(--fg); cursor: pointer; }
label.grow { flex: 1 1 200px; }
label.grow select { flex: 1; width: 100%; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; background: var(--line);
  border-radius: 2px; outline: none; margin: 10px 0; touch-action: pan-y;
}
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 0 8px rgba(255, 47, 78, .55); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; border: none; background: var(--accent); cursor: pointer; box-shadow: 0 0 8px rgba(255, 47, 78, .55); }
.knob-group { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.knob-group label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); min-width: 0; }
.field input, .field select { text-transform: none; letter-spacing: 0; width: 100%; }
.file-btn { display: inline-flex; align-items: center; }
.file-btn input { display: none; }
.ed-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px 18px; align-items: end; }
.ed-flags { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 8px; }
.ex-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.status { min-height: 1.4em; font-size: 12px; color: var(--accent2); margin: 10px 0 0; line-height: 1.5; white-space: pre-line; }
.status.err { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

/* ---------------- articulations */
.arts { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 6px; }
.art {
  font-family: inherit; background: #150a0c; color: var(--fg); border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 4px; cursor: pointer; text-align: center; touch-action: manipulation; min-height: 48px; min-width: 0;
}
.art .k { display: block; font-size: 9.5px; color: var(--dim); }
.art .n { display: block; font-size: 11.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.art:hover { border-color: var(--accent); }
.art.on { background: var(--accent); border-color: var(--accent); color: #1a0004; }
.art.on .k { color: #3a0010; }
.art[data-art="chug"] .n::after { content: " \26A1"; }

.quick { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.oct-group { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.oct-btn { width: 34px; height: 34px; border-radius: 6px; border: 1px solid var(--line); background: #150a0c; color: var(--fg); cursor: pointer; font-size: 16px; line-height: 1; touch-action: manipulation; }
.oct-btn:hover { border-color: var(--accent); color: var(--accent); }
#octLabel { min-width: 18px; text-align: center; color: var(--accent); font-weight: 700; }

/* ---------------- play surface */
.surface-bar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.tab { font-family: inherit; background: #150a0c; color: var(--dim); border: none; padding: 9px 14px; font-weight: 700; font-size: 12px; cursor: pointer; min-height: 38px; }
.tab.on { background: var(--accent); color: #1a0004; }
.fb-opts { display: inline-flex; flex-wrap: wrap; gap: 10px; }
.fingerboard {
  display: block; width: 100%; height: 300px; border-radius: 8px; border: 1px solid var(--line);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: crosshair;
  background: #0c0909;
}
.keys-wrap { min-width: 0; }
.keyboard { display: flex; gap: 3px; padding-bottom: 4px; touch-action: none; user-select: none; -webkit-user-select: none; }
.key {
  flex: 1 1 0; min-width: 0; height: 150px; border-radius: 5px; border: 1px solid var(--line); background: #f2e4e6; color: #180a0c;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 8px; font-size: 11px; font-weight: 700;
  cursor: pointer; transition: transform .04s ease, background .06s ease;
}
.key small { font-size: 9px; font-weight: 400; opacity: .6; }
.key.black { background: #1a0e10; color: var(--dim); height: 96px; align-self: flex-start; border-color: #000; }
.key.out { opacity: .45; }
.key.root { box-shadow: inset 0 -4px 0 var(--accent); }
.key.active { background: var(--accent); color: #1a0004; transform: translateY(2px); }
.key.black.active { background: var(--accent2); color: #200a02; }

/* ---------------- bow + knobs */
.bowrow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 20px; align-items: start; }
.bowpad { position: relative; width: 100%; height: 150px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #0c0909; touch-action: none; cursor: crosshair; }
.bowpad canvas { width: 100%; height: 100%; display: block; }
.bow-labels { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--dim); margin: 5px 2px 8px; }
.knobs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; }

/* ---------------- looper */
.looper { border-top: 1px solid var(--line); padding-top: 16px; }
.loop-main { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 16px; align-items: center; }
.loop-ring { width: 110px; height: 110px; }
.loop-btns { display: grid; grid-template-columns: repeat(2, auto); gap: 8px; }
.loop-opts { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.layers { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.layer { display: grid; grid-template-columns: 70px minmax(0, 1fr) 110px auto; gap: 8px; align-items: center; background: #0a0607; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.layer .nm { font-size: 11.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer canvas { width: 100%; height: 30px; display: block; }
.layer input[type="range"] { margin: 0; }
.layer .lb { display: flex; gap: 4px; }
.layer .lb .btn { min-height: 30px; padding: 4px 8px; font-size: 11px; }
.layer.muted { opacity: .5; }

/* ---------------- drawers */
.drawers { margin-top: 18px; display: flex; flex-direction: column; gap: 6px; }
.drawer { border: 1px solid var(--line); border-radius: 8px; background: var(--bg-panel); min-width: 0; }
.drawer > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 12px; padding: 13px 14px; user-select: none; min-height: 44px; }
.drawer > summary::-webkit-details-marker { display: none; }
.drawer > summary::before { content: "+"; color: var(--accent); width: 10px; font-weight: 700; flex: 0 0 auto; }
.drawer[open] > summary::before { content: "\2212"; }
.drawer > summary:hover .d-name { color: var(--accent); }
.d-name { font-size: 13px; font-weight: 700; letter-spacing: .5px; min-width: 110px; flex: 0 0 auto; }
.d-sub { font-size: 11.5px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.d-body { padding: 4px 16px 16px 36px; font-size: 13px; line-height: 1.6; color: #d9c3c6; min-width: 0; }
.d-body p { margin: 8px 0; }

.tuner { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.tuner-read { display: flex; align-items: baseline; gap: 10px; min-width: 150px; }
.tuner-note { font-size: 34px; font-weight: 700; color: var(--accent); min-width: 70px; }
#tunerCanvas { width: 320px; max-width: 100%; height: 44px; }
.ref-strings { display: flex; gap: 6px; flex-wrap: wrap; }
.meter { height: 8px; background: #150a0c; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; align-self: center; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent2); transition: width .05s linear; }

.slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; margin-top: 12px; }
.slot { border: 1px solid var(--line); border-radius: 7px; padding: 10px; background: #0a0607; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.slot.sel { border-color: var(--accent); box-shadow: 0 0 10px rgba(255, 47, 78, .25); }
.slot .top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.slot .nm { font-weight: 700; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot .meta { font-size: 11px; color: var(--dim); }
.slot canvas { width: 100%; height: 34px; display: block; }
.slot .acts { display: flex; flex-wrap: wrap; gap: 4px; }
.slot .acts .btn { min-height: 30px; padding: 4px 8px; font-size: 11px; }
.slot select { font-size: 11px; min-height: 30px; padding: 3px 4px; }

.phrases { display: flex; flex-direction: column; gap: 6px; }
.phrase { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: #0a0607; }
.phrase .nm { font-weight: 700; font-size: 12.5px; }
.phrase .cr { font-size: 11px; color: var(--dim); }
.phrase.playing { border-color: var(--accent2); }

.rec-time { font-size: 18px; font-weight: 700; color: var(--dim); min-width: 56px; }
.rec-time.on { color: #ff0033; }
#recBtn.on { background: #ff0033; border-color: #ff0033; color: #fff; animation: pulse .9s ease-in-out infinite; }

.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px; }
.preset { text-align: left; font-family: inherit; background: #150a0c; color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; cursor: pointer; min-height: 44px; }
.preset:hover { border-color: var(--accent); }
.preset.on { border-color: var(--accent); background: #2a0c12; }
.preset b { display: block; font-size: 12px; }
.preset span { display: block; font-size: 10.5px; color: var(--dim); line-height: 1.35; margin-top: 2px; }
.preset .x { float: right; color: var(--dim); font-weight: 700; padding-left: 8px; }
#userPresetName { flex: 1 1 180px; }

.view3d { width: 100%; aspect-ratio: 4 / 3; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 10px 0; background: #050304; position: relative; touch-action: none; }
.view3d canvas { display: block; width: 100%; height: 100%; }
.view3d .hud { position: absolute; left: 8px; bottom: 6px; font-size: 11px; color: var(--dim); pointer-events: none; }
.vr-help p { max-width: 72ch; }
.vr-help label { margin-right: 14px; }

.learn > p { max-width: 70ch; }
.lesson { border-top: 1px solid var(--line); padding: 2px 0; }
.lesson > summary { cursor: pointer; padding: 10px 0; color: var(--fg); font-weight: 700; font-size: 12.5px; }
.lesson > summary:hover { color: var(--accent); }
.lesson p { max-width: 70ch; }
.lesson .try { margin: 4px 0 12px; }

.keys-table { border-collapse: collapse; font-size: 12px; width: 100%; }
.keys-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.keys-table td:first-child { color: var(--accent2); font-weight: 700; white-space: nowrap; width: 1%; }

/* ---------------- mobile dock */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; gap: 6px; justify-content: center;
  padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  background: rgba(10, 6, 7, .94); border-top: 1px solid var(--line); backdrop-filter: blur(6px);
}
.dock .btn { flex: 1 1 0; max-width: 120px; padding: 8px 4px; font-size: 12px; }
.dock[hidden] { display: none; }

footer { text-align: center; color: var(--dim); font-size: 11.5px; margin-top: 28px; line-height: 1.6; }
footer a { color: var(--dim); }
footer a:hover { color: var(--accent); }
footer .mark { letter-spacing: 4px; opacity: .5; }

/* ---------------- responsive */
@media (max-width: 760px) {
  .bowrow { grid-template-columns: 1fr; }
  .loop-main { grid-template-columns: auto minmax(0, 1fr); }
  .loop-opts { grid-column: 1 / -1; }
  .arts { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .layer { grid-template-columns: 56px minmax(0, 1fr) auto; }
  .layer input[type="range"] { grid-column: 1 / -1; order: 5; }
}
@media (max-width: 560px) {
  body { padding: 20px 10px 90px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .panel { padding: 12px 10px; }
  .cello { font-size: 10px; }
  .title { font-size: 22px; }
  .tagline { font-size: 12px; }
  .fingerboard { height: 62vh; min-height: 360px; }
  .knobs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 14px; }
  .d-body { padding: 4px 12px 14px 14px; }
  .d-name { min-width: 0; }
  .d-sub { display: none; }
  .loop-ring { width: 88px; height: 88px; }
  .btn.big { min-width: 0; padding: 12px 12px; }
  .key { height: 120px; }
  .key.black { height: 76px; }
  .labs-link { font-size: 11px; top: calc(6px + env(safe-area-inset-top, 0px)); right: 8px; }
}
/* phones upright: once playing, the strings come first */
@media (max-width: 560px) {
  body.playing .head .cello, body.playing .tagline { display: none; }
  body.playing .title { font-size: 18px; margin-top: 2px; }
  body.playing .scope { height: 24px; margin: 4px auto 10px; }
  .arts { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 4px; scroll-snap-type: x proximity; scrollbar-width: none; }
  .arts::-webkit-scrollbar { display: none; }
  .art { flex: 0 0 auto; min-width: 74px; min-height: 44px; scroll-snap-align: start; }
  .arts-row { margin-bottom: 10px; }
  .quick { gap: 6px; margin-bottom: 12px; }
  .quick .lbl, .fb-opts .lbl { display: none; }
  .quick .btn.small { padding: 6px 8px; font-size: 11.5px; }
  .quick label.grow { flex: 1 1 100%; }
  .surface-bar { gap: 6px; flex-wrap: nowrap; }
  .tabs { flex: 0 0 auto; }
  .fb-opts { gap: 6px; flex-wrap: nowrap; min-width: 0; flex: 1 1 0; justify-content: flex-end; }
  .fb-opts label { flex: 1 1 0; min-width: 0; }
  .fb-opts select { font-size: 11.5px; width: 100%; padding: 5px 2px; }
  #panicBtn, #droneBtn { display: none; }
  .tab { padding: 8px 10px; font-size: 11.5px; }
  .fingerboard { height: 58vh; min-height: 330px; }
}
/* phones sideways: long horizontal strings, compact chrome */
@media (max-height: 500px) and (orientation: landscape) {
  .head .cello, .tagline, .scope { display: none; }
  .title { font-size: 18px; margin-bottom: 8px; }
  .fingerboard { height: calc(100vh - 70px); height: calc(100dvh - 70px); min-height: 200px; }
  #fbHelp { display: none; }
  body { padding-top: 10px; }
}
/* big pointers (Quest browser, TVs): bigger targets */
@media (pointer: coarse) {
  .btn.small { min-height: 40px; }
  select, input[type="number"], input[type="text"] { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .blink, .btn.rec.armed, .btn.rec.on, .btn.rec.dub, #recBtn.on { animation: none; }
}
