:root {
  --bg: #08070b;
  --panel: rgba(18, 16, 22, 0.82);
  --panel-solid: #121018;
  --line: #2a2634;
  --text: #f2efe8;
  --muted: #9a948a;
  --accent: #ff6b35;
  --accent2: #c9a227;
  --ok: #3dd68c;
  --danger: #ff4d6d;
  --inst: #d4a017;
  --shadow: 0 18px 48px rgba(0,0,0,.5);
  --radius: 16px;
  --font: "Outfit", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: var(--font); color: var(--text); background: var(--bg); }
body { overflow-x: hidden; letter-spacing: 0.01em; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.glass {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.06);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.brand { font-weight: 800; letter-spacing: .12em; font-size: 1.05rem; text-transform: uppercase; }
.brand span { color: var(--accent); }
.lead { color: var(--muted); line-height: 1.5; }
.muted { color: var(--muted); }
.small, .hint { font-size: .82rem; color: var(--muted); }
.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; cursor: pointer;
  background: #2a2144; color: var(--text); transition: .2s transform, .2s filter, .2s background;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ff3d6e); font-weight: 700; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.sm { padding: 6px 10px; font-size: .85rem; }
.btn.wide { width: 100%; }
.btn.round { width: 46px; height: 46px; border-radius: 50%; font-size: 1.1rem; }
.btn.round.is-loading { opacity: 0.7; animation: playPulse 1s ease-in-out infinite; }
@keyframes playPulse {
  50% { transform: scale(0.94); opacity: 0.55; }
}
#audioReadyTip { color: var(--muted, #9aa3b2); font-size: 0.85rem; }
.alert { padding: 12px 14px; border-radius: 12px; margin: 10px 0; }
.alert.danger { background: rgba(255,77,109,.15); border: 1px solid rgba(255,77,109,.35); }
.alert.success { background: rgba(61,214,140,.12); border: 1px solid rgba(61,214,140,.35); }

.auth-body { display: grid; place-items: center; min-height: 100vh; position: relative; }
.auth-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 18% 18%, rgba(255,107,53,.22), transparent 42%),
    radial-gradient(circle at 82% 12%, rgba(201,162,39,.16), transparent 36%),
    radial-gradient(circle at 50% 85%, rgba(61,214,140,.1), transparent 40%),
    var(--bg);
  animation: drift 16s ease-in-out infinite alternate;
}
@keyframes drift {
  from { filter: hue-rotate(0deg) saturate(1); }
  to { filter: hue-rotate(25deg) saturate(1.2); }
}
.auth-card { position: relative; width: min(420px, 92vw); padding: 28px; }
.auth-card label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: .85rem; }
.auth-card input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: #100c1a;
}

.app-body { min-height: 100vh; position: relative; }
.app-glow {
  pointer-events: none; position: fixed; inset: 0;
  background:
    radial-gradient(ellipse at 12% 0%, rgba(255,107,53,.14), transparent 42%),
    radial-gradient(ellipse at 88% 8%, rgba(201,162,39,.1), transparent 38%),
    radial-gradient(ellipse at 50% 100%, rgba(61,214,140,.06), transparent 45%),
    linear-gradient(180deg, #0c0a10 0%, var(--bg) 55%);
  z-index: 0;
}
.topbar {
  position: sticky; top: 0; z-index: 20; margin: 14px; padding: 12px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.storage-pill {
  padding: 8px 12px; border-radius: 999px; background: rgba(255,107,53,.1);
  border: 1px solid rgba(255,107,53,.28); font-size: .85rem;
  font-variant-numeric: tabular-nums;
}

.studio-layout {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: 300px 1fr; gap: 14px;
  padding: 0 14px 24px; min-height: calc(100vh - 100px);
}
@media (max-width: 980px) {
  .studio-layout { grid-template-columns: 1fr; }
}
.sidebar { padding: 16px; overflow: auto; max-height: calc(100vh - 110px); }
.side-head { display: flex; justify-content: space-between; align-items: center; }
.side-head h2, .side-block h3, .tool-card h3, .stage-head h1 { margin: 0 0 8px; }
.project-list { display: grid; gap: 8px; margin: 12px 0 18px; }
.project-item {
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); cursor: pointer;
  background: rgba(255,255,255,.02); transition: .2s border-color, .2s background;
  display: flex; align-items: center; gap: 8px;
}
.project-item-main { flex: 1; min-width: 0; }
.project-item:hover, .project-item.active {
  border-color: rgba(255,107,53,.55); background: rgba(255,107,53,.08);
}
.project-item small { display: block; color: var(--muted); margin-top: 4px; }
.project-del {
  flex-shrink: 0; width: 32px; height: 32px; padding: 0; border-radius: 8px;
  font-size: 1.1rem; line-height: 1; opacity: .7;
}
.project-del:hover { opacity: 1; background: rgba(255,77,109,.2); border-color: rgba(255,77,109,.45); }
.side-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.side-block input, .side-block select, .tool-card select, .tool-card input[type=file],
.form-grid input, .form-grid textarea, .form-grid select, .modal input, .modal textarea,
.table input, .table select, .table textarea,
.admin-card input, .admin-card select, .admin-card textarea {
  width: 100%; margin: 6px 0; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line);
  background: #100e14 !important;
  color: #f2efe8 !important;
  caret-color: #ff6b35;
  color-scheme: dark;
}
.table input[type=checkbox] {
  width: auto; accent-color: var(--accent);
}
.table input[type=number] {
  min-width: 90px;
}
.admin-card input::placeholder,
.form-grid input::placeholder {
  color: #8a7aa8;
}
.sample-results { max-height: 220px; overflow: auto; margin-top: 8px; display: grid; gap: 6px; }
.sample-item { padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.03); border: 1px solid var(--line); font-size: .85rem; }
.sample-item .sample-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.modal-sample { width: min(460px, 94vw); }
.sample-audio { width: 100%; margin: 12px 0 4px; border-radius: 8px; }
.clip-tag {
  font-size: .7rem; font-weight: 600; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; margin-left: 6px;
  vertical-align: middle;
}
.lane.is-clip .wave { cursor: ew-resize; }

.stage { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stage-head { padding: 16px 18px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.transport { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.track-map { padding: 12px; min-height: 360px; overflow: auto; }
.empty-state { color: var(--muted); padding: 40px 20px; text-align: center; }

.stem-group {
  margin: 4px 0 14px;
  padding: 10px 10px 6px;
  border-radius: 16px;
  border: 1px solid rgba(212,160,23,.28);
  background:
    linear-gradient(165deg, rgba(212,160,23,.08), transparent 55%),
    rgba(255,255,255,.02);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
  animation: laneIn .4s ease;
}
.stem-group-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 14px;
  padding: 4px 8px 10px; border-bottom: 1px solid rgba(212,160,23,.18);
  margin-bottom: 8px;
}
.stem-group-head h3 {
  margin: 0; font-size: .95rem; font-weight: 700; letter-spacing: .04em;
  color: var(--inst); text-transform: uppercase;
}
.stem-group-head .hint { margin: 0; flex: 1; min-width: 180px; }
.stem-group-body { display: grid; gap: 0; }
.stem-group .lane {
  margin-bottom: 8px;
  border-color: rgba(212,160,23,.16);
  background: linear-gradient(90deg, rgba(212,160,23,.06), transparent 42%);
}
.stem-group .lane.is-instrument:not(:first-child) {
  margin-left: 8px;
  border-left: 2px solid rgba(212,160,23,.35);
}
.lane.is-instrument .clip-tag {
  border-color: rgba(212,160,23,.4); color: var(--inst);
}

.lane {
  display: grid; grid-template-columns: 200px 1fr 120px; gap: 10px; align-items: center;
  padding: 10px; margin-bottom: 10px; border-radius: 14px; border: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(255,255,255,.03), transparent);
  animation: laneIn .35s ease;
  transition: border-color .2s, background .2s;
}
@keyframes laneIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.lane.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.lane-meta h4 { margin: 0 0 6px; cursor: pointer; }
.lane-meta .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: .72rem; padding: 5px 9px; border-radius: 999px; border: 1px solid var(--line); cursor: pointer;
  background: transparent; color: var(--muted); white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: rgba(255,255,255,.2); }
.chip.on { background: var(--accent); border-color: transparent; color: #1a0b08; font-weight: 700; }
.wave {
  height: 64px; width: 100%; border-radius: 10px; background: #0a090e;
  position: relative; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04);
}
.wave::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 2px;
  left: var(--ph, 0%); background: #fff; box-shadow: 0 0 12px #fff; pointer-events: none;
}
.wave canvas { width: 100%; height: 100%; display: block; }
.lane-ops { display: grid; gap: 6px; }
.lane-ops input[type=range] { width: 100%; }
.tools-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 1100px) { .tools-row { grid-template-columns: 1fr; } .lane { grid-template-columns: 1fr; } }
.tool-card { padding: 14px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; font-size: .9rem; color: var(--muted); }
.range-label { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; }
.download-list { display: grid; gap: 8px; margin: 12px 0; max-height: min(50vh, 360px); overflow: auto; }
.download-group {
  display: grid; gap: 6px;
  padding: 10px; border-radius: 12px;
  border: 1px solid rgba(212,160,23,.28);
  background: rgba(212,160,23,.06);
}
.download-group-title {
  font-size: .78rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--inst); margin-bottom: 2px;
}
.download-group .download-row {
  border-color: rgba(212,160,23,.18);
  background: rgba(0,0,0,.18);
}
.download-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.03);
}
.download-row span { font-size: .92rem; color: var(--text); font-family: var(--mono); font-size: .82rem; }
.download-row .btn { flex-shrink: 0; }
.download-row.is-busy { opacity: 0.7; pointer-events: none; }
.modal-downloads { width: min(520px, 94vw); }

.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 60; min-width: 220px; max-width: min(360px, 92vw);
  padding: 12px 16px; border-radius: 12px; background: #1b1430; border: 1px solid var(--line);
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(12px);
  transition: opacity .22s ease, transform .22s ease, visibility .22s;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1; visibility: visible; pointer-events: auto;
  transform: translateY(0);
}
.toast.error { border-color: rgba(255,77,109,.5); }
.toast.ok { border-color: rgba(61,214,140,.5); }

.busy-overlay {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(5, 4, 10, .82);
  backdrop-filter: blur(8px);
  overflow: auto;
}
.busy-overlay[hidden] { display: none !important; }
.busy-panel {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(300px, 440px);
  gap: 14px;
  width: min(920px, 96vw);
  align-items: stretch;
}
@media (max-width: 820px) {
  .busy-panel { grid-template-columns: 1fr; }
}
.busy-card, .busy-game-card {
  padding: 22px 20px; border-radius: 18px;
  background: var(--panel-solid); border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.busy-card { text-align: center; }
.busy-card h2 { margin: 14px 0 8px; font-size: 1.25rem; }
.busy-card p { margin: 0; color: var(--muted); line-height: 1.45; }
.busy-sub { margin-top: 10px !important; font-size: .82rem; opacity: .85; }
.busy-steps {
  list-style: none; margin: 16px 0 0; padding: 0;
  text-align: left; display: grid; gap: 8px;
}
.busy-steps li {
  display: flex; align-items: center; gap: 10px;
  font-size: .88rem; color: var(--muted);
  padding: 6px 8px; border-radius: 10px;
  background: rgba(255,255,255,.02); border: 1px solid transparent;
}
.busy-steps li.is-done { color: var(--ok); border-color: rgba(61,214,140,.25); }
.busy-steps li.is-active {
  color: var(--text); border-color: rgba(255,107,53,.4);
  background: rgba(255,107,53,.08);
}
.busy-steps .step-mark {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--line); display: grid; place-items: center;
  font-size: .75rem; font-weight: 800;
}
.busy-steps li.is-done .step-mark {
  border-color: var(--ok); background: rgba(61,214,140,.2); color: var(--ok);
}
.busy-steps li.is-done .step-mark::after { content: "✓"; }
.busy-steps li.is-active .step-mark {
  border-color: var(--accent); border-top-color: transparent;
  animation: busy-spin .7s linear infinite;
}
.busy-progress { margin-top: 12px; text-align: left; }
.busy-progress-bar {
  height: 8px; border-radius: 999px; background: rgba(255,255,255,.08);
  overflow: hidden; margin-bottom: 6px;
}
.busy-progress-bar i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #ff3d6e);
  transition: width .35s ease;
}
.busy-game-levels {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px;
}
.busy-game-levels .hop-lvl.is-on {
  background: rgba(255,107,53,.25); border-color: var(--accent); color: var(--text);
}
.busy-icon-wrap { height: 56px; display: grid; place-items: center; position: relative; }
.busy-spinner,
.busy-check,
.busy-fail {
  display: none !important;
  width: 48px; height: 48px; margin: 0 auto;
  border-radius: 50%;
  place-items: center;
}
.busy-spinner.is-on {
  display: block !important;
  border: 3px solid rgba(255,255,255,.12);
  border-top-color: var(--accent);
  animation: busy-spin .7s linear infinite;
  background: transparent;
}
.busy-check.is-on {
  display: grid !important;
  width: 56px; height: 56px;
  background: rgba(61,214,140,.18); border: 2px solid var(--ok);
  color: var(--ok); font-size: 1.8rem; font-weight: 800;
  animation: busy-pop .35s ease;
}
.busy-fail.is-on {
  display: grid !important;
  width: 56px; height: 56px;
  background: rgba(255,77,109,.15); border: 2px solid var(--danger);
  color: var(--danger); font-size: 1.8rem; font-weight: 800;
  animation: busy-pop .35s ease;
}
.busy-error,
.busy-actions {
  display: none !important;
}
.busy-error.is-on,
.busy-actions.is-on {
  display: block !important;
}
.busy-actions.is-on {
  display: flex !important;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }
@keyframes busy-pop { from { transform: scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }
.busy-card.is-ok h2 { color: var(--ok); }
.busy-card.is-err h2 { color: var(--danger); }
.busy-error { margin-top: 14px; text-align: left; }
.busy-error textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(255,77,109,.4); background: #100c1a; color: #ffc9d3;
  font-family: ui-monospace, Consolas, monospace; font-size: .78rem; resize: vertical;
}
.busy-error-actions, .busy-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.busy-game-card { display: flex; flex-direction: column; gap: 8px; }
.busy-game-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.busy-game-head h3 { margin: 0; font-size: 1rem; }
.busy-game-stats { display: flex; gap: 10px; align-items: baseline; font-size: .9rem; }
.busy-game-stats span:first-child { font-weight: 800; color: var(--accent); font-size: 1.15rem; }
#hopCanvas {
  width: 100%; height: auto; border-radius: 12px; background: #0b0814;
  border: 1px solid var(--line); touch-action: manipulation; cursor: pointer;
}
.busy-game-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

.modal { border: 1px solid var(--line); border-radius: 16px; padding: 18px; background: var(--panel-solid); color: var(--text); width: min(420px, 92vw); }
.modal::backdrop { background: rgba(0,0,0,.55); }
.modal menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin-top: 12px; }

.admin-layout { position: relative; z-index: 1; display: grid; gap: 14px; padding: 0 14px 24px; }
.admin-card { padding: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin-bottom: 12px; }
.table { overflow: auto; }
.table table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stat {
  padding: 14px 18px; border-radius: 14px; background: rgba(255,107,53,.1);
  border: 1px solid rgba(255,107,53,.28); min-width: 140px;
}
.stat b { display: block; font-size: 1.4rem; }
.logs { max-height: 320px; }
