:root {
  --bg: #14110f; --bg2: #1c1814; --panel: #221d18; --panel2: #2b251f; --line: #3a322a;
  --text: #ece4d6; --muted: #9a8f7e; --brass: #d9a441; --brass2: #f0c46a; --danger: #d9534a; --ok: #58b368;
  --radius: 14px; --serif: "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: radial-gradient(1200px 600px at 20% -10%, #2a2118 0%, var(--bg) 60%) fixed; color: var(--text); font: 15px/1.4 var(--sans); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: .01em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* кнопки и поля */
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; min-height: 40px; transition: background .12s, border-color .12s; }
.btn:hover { border-color: var(--brass); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brass); color: #1b1408; border-color: var(--brass2); font-weight: 600; }
.btn.danger { background: #3a1d1b; border-color: #6d2a26; color: #ffb4ad; }
.btn.danger:hover { background: #512320; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { border-color: var(--line); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 13px; }
.btn.big { min-height: 48px; font-size: 17px; width: 100%; }
.icon-btn { background: none; border: 0; border-radius: 8px; min-width: 36px; min-height: 36px; color: var(--muted); }
.icon-btn:hover { color: var(--text); background: var(--panel2); }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; min-height: 40px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
input[type=range] { accent-color: var(--brass); width: 100%; min-height: 28px; }
.field { display: grid; gap: 5px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.field > input, .field > select, .field > textarea { color: var(--text); font-size: 15px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.grow > * { flex: 1; }
.form-error { color: #ff8f86; min-height: 1.3em; margin: 4px 0; }

/* верхняя панель */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: rgba(20,17,15,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--brass); color: #1b1408; font-size: 18px; }
.brand-name { font-family: var(--serif); font-size: 20px; font-weight: 700; }
.master { display: flex; align-items: center; gap: 8px; flex: 1 1 200px; max-width: 320px; color: var(--muted); font-size: 13px; }
.master output { width: 38px; text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.top-nav { margin-left: auto; display: flex; gap: 2px; align-items: center; }
.short { display: none; }
.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(217,164,65,.55); } 50% { box-shadow: 0 0 0 9px rgba(217,164,65,0); } }

/* каркас */
.layout { display: grid; grid-template-columns: 230px minmax(0, 1fr) 310px; gap: 14px; padding: 14px; align-items: start; max-width: 1700px; margin: 0 auto; }
.scenes, .mixer { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; position: sticky; top: 62px; max-height: calc(100vh - 76px); overflow: auto; }
.scenes h3, .mixer h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-family: var(--sans); margin: 4px 0 10px; }
.mixer-toggle { display: none; }

/* сцены */
.scene-item { display: flex; align-items: stretch; gap: 4px; margin-bottom: 6px; }
.scene-pick { flex: 1; text-align: left; display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); min-height: 44px; border-left: 5px solid var(--c, var(--brass)); }
.scene-item.view .scene-pick { background: #3a2f22; border-color: var(--brass); }
.scene-item.live .scene-pick::after { content: "● играет"; margin-left: auto; font-size: 11px; color: var(--ok); }

/* главный экран */
.main { min-width: 0; }
.scene-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.scene-head h1 { font-size: 26px; flex: 1 1 180px; border-left: 6px solid var(--c, var(--brass)); padding-left: 12px; }
.music-strip { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.music-strip .np { flex: 1 1 200px; min-width: 0; }
.music-strip .np b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.music-strip .vol { width: 150px; }
.pads { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.pad { position: relative; min-height: 124px; border-radius: 16px; border: 1px solid color-mix(in srgb, var(--c) 55%, #000); background: linear-gradient(160deg, color-mix(in srgb, var(--c) 34%, #1c1814) 0%, color-mix(in srgb, var(--c) 14%, #1c1814) 100%); padding: 10px 12px 14px; display: flex; flex-direction: column; justify-content: space-between; text-align: left; user-select: none; -webkit-user-select: none; overflow: hidden; box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 3px 10px rgba(0,0,0,.35); transition: transform .06s, box-shadow .15s; }
.pad:active { transform: scale(.975); }
.pad .icon { font-size: 30px; line-height: 1; }
.pad .name { font-weight: 600; font-size: 16px; line-height: 1.15; overflow-wrap: anywhere; }
.pad .state { font-size: 12px; color: color-mix(in srgb, var(--c) 45%, #fff); }
.pad .key { position: absolute; top: 9px; right: 9px; min-width: 24px; text-align: center; padding: 1px 7px; border-radius: 6px; font: 600 12px var(--sans); background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.18); }
.pad .bar { position: absolute; left: 0; bottom: 0; height: 5px; width: 100%; background: rgba(0,0,0,.4); }
.pad .bar i { display: block; height: 100%; width: 0; background: var(--c); }
.pad.playing { box-shadow: 0 0 0 2px var(--c), 0 0 22px color-mix(in srgb, var(--c) 60%, transparent); }
.pad.fading { opacity: .65; }
.pad.empty .state { color: var(--muted); }
.pad .mode { position: absolute; top: 40px; right: 9px; font-size: 11px; color: rgba(255,255,255,.55); }
.pad-wrap { position: relative; display: flex; }
.pad-wrap > .pad { width: 100%; }
.pad-tools { position: absolute; inset: auto 6px 10px auto; display: flex; gap: 3px; z-index: 2; }
.pad-tools button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid rgba(255,255,255,.2); background: rgba(0,0,0,.65); font-size: 14px; }
.pad-wrap.dragover .pad { outline: 2px dashed var(--brass); }
.pad-add { min-height: 124px; border: 2px dashed var(--line); border-radius: 16px; background: transparent; color: var(--muted); font-size: 28px; }
.pad-add:hover { color: var(--brass); border-color: var(--brass); }
.editing .pad { cursor: pointer; }

/* случайные события */
.events { margin-top: 20px; }
.events h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-family: var(--sans); margin-bottom: 8px; }
.event { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 8px; flex-wrap: wrap; }
.event .info { flex: 1 1 180px; min-width: 0; }
.event .info small { color: var(--muted); display: block; }
.event.on { border-color: var(--ok); }

/* переключатель */
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: .15s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; top: 3px; left: 3px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--brass); }

/* микшер */
.group-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; margin-bottom: 10px; }
.group-row .gname { font-weight: 600; }
.group-row input[type=range] { grid-column: 1 / 3; }
.mute { min-width: 44px; min-height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); }
.mute.on { background: #5a2623; border-color: #8c3a35; }
.voice { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--c, var(--brass)); border-radius: 10px; padding: 7px 9px; margin-bottom: 7px; }
.voice .vt { display: flex; align-items: center; gap: 6px; }
.voice .vt b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.voice .vt small { color: var(--muted); }
.voice .vprog { height: 3px; background: var(--bg); border-radius: 2px; margin: 4px 0; }
.voice .vprog i { display: block; height: 100%; width: 0; background: var(--c, var(--brass)); }
.voice.fading { opacity: .55; }
.empty-note { color: var(--muted); font-size: 13px; padding: 6px 2px; }

/* модальные окна */
dialog.modal { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 0; width: min(560px, 96vw); max-height: 92vh; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
dialog.modal.wide { width: min(860px, 96vw); }
dialog.modal::backdrop { background: rgba(0,0,0,.65); }
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal > header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
dialog.modal > header h2 { font-size: 20px; }
.modal-body { padding: 16px; overflow: auto; flex: 1; }
dialog.modal > footer { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: #fff; }
.icons { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.icons button { width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); font-size: 20px; }
.icons button.on { border-color: var(--brass); background: #3a2f22; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; background: var(--bg); border: 0; padding: 9px 6px; min-height: 40px; border-right: 1px solid var(--line); font-size: 14px; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brass); color: #1b1408; font-weight: 600; }
.seg button:disabled { opacity: .35; cursor: not-allowed; }
.keycap { min-width: 120px; }
.snd-list { display: grid; gap: 6px; }
.snd { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); flex-wrap: wrap; }
.snd .nm { flex: 1 1 160px; min-width: 0; }
.snd .nm b { display: block; overflow-wrap: anywhere; }
.snd .tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; color: var(--muted); }
.snd.sel { border-color: var(--brass); background: #3a2f22; }
.chosen { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 3px 4px 3px 10px; font-size: 13px; }
.chip button { border: 0; background: none; color: var(--muted); border-radius: 50%; width: 22px; height: 22px; padding: 0; }
.dropzone { border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; color: var(--muted); margin-bottom: 12px; }
.dropzone.over { border-color: var(--brass); color: var(--text); }
.upl { font-size: 13px; padding: 4px 0; }
.upl.err { color: #ff8f86; }
.upl.ok { color: var(--ok); }
ul.uses { margin: 8px 0 0; padding-left: 18px; color: #ffcf9a; }
.sec-title { font-family: var(--serif); font-size: 17px; margin: 16px 0 8px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }

/* уведомления */
.toasts { position: fixed; z-index: 100; left: 50%; bottom: 16px; transform: translateX(-50%); display: grid; gap: 8px; width: min(520px, 94vw); pointer-events: none; }
.toast { background: #2b251f; border: 1px solid var(--line); border-left: 5px solid var(--brass); border-radius: 10px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: #e0914a; }
#save-status { font-size: 12px; color: var(--muted); padding: 0 8px; }
#save-status[data-s=error], #save-status[data-s=conflict] { color: #ff8f86; }

/* вход */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; width: min(380px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.5); }

/* планшет и телефон */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; padding: 10px; gap: 10px; }
  .scenes { position: static; max-height: none; display: flex; gap: 8px; overflow-x: auto; padding: 8px; align-items: stretch; }
  .scenes h3 { display: none; }
  .scene-item { margin: 0; flex: none; }
  .scene-item .scene-pick { min-width: 130px; }
  .mixer { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; top: auto; max-height: 68vh; border-radius: 18px 18px 0 0; transform: translateY(105%); transition: transform .2s; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .mixer.open { padding-bottom: 76px; transform: none; box-shadow: 0 -10px 40px rgba(0,0,0,.6); }
  .mixer-toggle { display: inline-flex; gap: 6px; position: fixed; z-index: 31; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 4px 16px rgba(0,0,0,.6); background: var(--brass); color: #1b1408; border-color: var(--brass2); }
  .layout { padding-bottom: 80px; }
}
@media (max-width: 640px) {
  .top { padding: 6px 10px; gap: 6px; }
  .brand-name, .top-nav .lbl, .long { display: none; }
  .short { display: inline; }
  .master { order: 4; flex: 1 1 140px; max-width: none; font-size: 12px; }
  .master span { display: none; }
  #btn-fade, #btn-unlock { flex: 1; padding: 6px 8px; font-size: 14px; min-height: 40px; }
  #btn-unlock { flex: 2; }
  .top-nav { margin-left: 0; gap: 0; order: 5; }
  .top-nav .btn { min-width: 38px; padding: 6px; }
  .brand { order: 0; }
  .brand-mark { width: 30px; height: 30px; }
  .scene-head { gap: 6px; }
  .scene-head .btn { padding: 6px 10px; }
  .scene-head .launch-row { flex: 1 1 100%; }
  .scene-head .btn.primary { white-space: nowrap; }
  .music-strip { padding: 8px 10px; gap: 8px; }
  .music-strip .np { flex: 1 1 120px; }
  .music-strip .vol { flex: 1 1 100%; width: auto; }
  .pads { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .pad { min-height: 118px; }
  .scene-head h1 { font-size: 21px; flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.btn.primary.live { background: var(--ok); border-color: var(--ok); }

.launch-row { display: flex; gap: 8px; flex: 1 1 100%; }
.launch-row .btn.primary { flex: 1; }
#btn-stop { width: 52px; padding: 0; display: flex; align-items: center; justify-content: center; }
.stop-sq { width: 18px; height: 18px; border: 2px solid currentColor; border-radius: 3px; display: flex; align-items: center; justify-content: center; }
.stop-sq::after { content: ""; width: 8px; height: 8px; background: currentColor; border-radius: 1px; }
