@font-face {
  font-family: 'Digital7';
  src: url('../fonts/digital-7.ttf') format('truetype');
  font-display: block;
}
@font-face {
  font-family: 'ElegantIcons';
  src: url('../fonts/ElegantIcons.ttf') format('truetype');
  font-display: block;
}

:root {
  --back: #d0cecc;
  --front: rgba(0, 0, 0, 0.6);
  --front-soft: rgba(0, 0, 0, 0.38);
  --orange: #e47828;
  --alert: #e0261c;
  --ui-dark: #d0cdcb;
  --ui-light: #faf9f8;
  --bar: clamp(42px, 7vh, 64px);
  --side-full: clamp(170px, 22vw, 260px);
  --side-part: clamp(40px, 5vw, 52px);
  --gap: clamp(2px, 0.4vw, 5px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--back);
  color: var(--front);
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
input, select, textarea {
  touch-action: manipulation;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.icon { font-family: 'ElegantIcons'; font-weight: normal; font-style: normal; line-height: 1; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-t) + 3px) calc(var(--safe-r) + 3px) calc(var(--safe-b) + 3px) calc(var(--safe-l) + 3px);
  gap: 3px;
}

/* Gorny pasek */

#topbar {
  flex: 0 0 var(--bar);
  display: flex;
  gap: 4px;
  align-items: stretch;
  min-width: 0;
}

.abtn {
  flex: 0 0 calc(var(--bar) * 1.08);
  border-style: solid;
  border-width: 10px;
  border-image: url('../img/ui_button.png') 20 fill / 10px stretch;
  font-size: calc(var(--bar) * 0.55);
  color: rgba(0, 0, 0, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.abtn > * { margin: -10px; }
.abtn:active, .abtn.down { filter: brightness(0.9); }
.abtn.on { color: var(--alert); }
.abtn:disabled { opacity: 0.35; }
#btnRec.on { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { to { color: rgba(0, 0, 0, 0.62); } }

#lcd {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: stretch;
  border-style: solid;
  border-width: 12px;
  border-image: url('../img/ui_lcd.png') 24 fill / 12px stretch;
  padding: 0;
}
#lcd > * { margin: -6px 0; }
#lcdTitle {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
  font-family: 'Digital7', monospace;
  color: rgba(0, 0, 0, 0.62);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}
#presetName {
  font-size: calc(var(--bar) * 0.5);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#lcdInfo {
  font-size: calc(var(--bar) * 0.24);
  opacity: 0.7;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#lcdInfo:empty { display: none; }
.lcd-arrow {
  flex: 0 0 auto;
  font-size: calc(var(--bar) * 0.42);
  color: rgba(0, 0, 0, 0.45);
  padding: 0 2px;
}
.lcd-menu {
  flex: 0 0 calc(var(--bar) * 0.95);
  margin: -8px -8px -8px 4px !important;
  border-style: solid;
  border-width: 6px 6px 8px 8px;
  border-image: url('../img/ui_button_dark.png') 24 24 32 32 fill / 6px 6px 8px 8px stretch;
  color: rgba(208, 206, 204, 0.7);
  font-size: calc(var(--bar) * 0.45);
}

.otoggle {
  flex: 0 0 calc(var(--bar) * 0.42);
  border-style: solid;
  border-width: 10px 6px;
  border-image: url('../img/ui_toggle_orange.png') 20 12 fill / 10px 6px stretch;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  filter: saturate(0.25) brightness(1.1);
}
.otoggle.on { filter: none; }
.otoggle .led { margin-top: -6px; }

.led {
  display: inline-block;
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  background: url('../img/ui_led_off.png') center / contain no-repeat;
}
.led.on, .on > .led, .pad.lit .led, .grid-edit .pad .led { background-image: url('../img/ui_led_on.png'); }

/* Scena */

#stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 4px;
}

#side {
  flex: 0 0 auto;
  width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: width 0.2s ease;
}
#side[data-state="2"] { width: var(--side-full); }
#side[data-state="1"] { width: var(--side-part); }

.fx {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  gap: 3px;
}
.fx-track {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  border-style: solid;
  border-width: 10px;
  border-image: url('../img/ui_slider_track_back.png') 20 fill / 10px stretch;
  touch-action: none;
  cursor: ew-resize;
}
#side[data-state="1"] .fx-track { display: none; }
.fx-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 5px;
  margin-top: -2px;
  background: url('../img/ui_slider_track_line.png') center / 100% 100% no-repeat;
  opacity: 0.8;
}
.fx-knob {
  position: absolute;
  top: 50%;
  height: min(26px, 70%);
  transform: translateY(-50%);
  width: 26px;
  margin-left: -13px;
  left: 0;
  background: url('../img/ui_slider_hold.png') center / 100% 100% no-repeat;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}
.fx-label {
  position: absolute;
  z-index: 2;
  left: -4px;
  top: -8px;
  font-family: 'Digital7', monospace;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.5);
  text-transform: uppercase;
  pointer-events: none;
}
.fx-value {
  position: absolute;
  z-index: 2;
  right: -4px;
  top: -8px;
  font-family: 'Digital7', monospace;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.fx-instant {
  flex: 0 0 var(--side-part);
  border-style: solid;
  border-width: 14px 9px;
  border-image: url('../img/ui_toggle_dark.png') 28 18 fill / 14px 9px stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  touch-action: none;
  position: relative;
}
.fx-instant .led { margin-top: -8px; }
.fx-instant span {
  font-family: 'Digital7', monospace;
  font-size: 10px;
  color: rgba(208, 206, 204, 0.75);
  text-transform: uppercase;
  margin-bottom: -8px;
  white-space: nowrap;
}
.fx-instant.on { filter: brightness(1.25); }

/* Pady */

#grid {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: var(--gap);
  touch-action: none;
  position: relative;
}

.pad {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-style: solid;
  border-width: 18px;
  border-image: url('../img/ui_pad.png') 40 fill / 18px stretch;
  overflow: visible;
}
.pad-body {
  position: absolute;
  inset: -15px -15px -16px -15px;
  border-radius: 4px;
  pointer-events: none;
  transition: background-color 0.12s;
}
.pad.c1 .pad-body { background: rgba(0, 0, 0, 0.06); }
.pad.c2 .pad-body { background: rgba(0, 0, 0, 0.16); }
.pad.c3 .pad-body { background: rgba(0, 0, 0, 0.32); }
.pad.down .pad-body { background-color: rgba(0, 0, 0, 0.1); transition: none; }
.pad.c3.down .pad-body { background-color: rgba(0, 0, 0, 0.42); }
.pad-label {
  position: absolute;
  left: -12px;
  right: -12px;
  top: -12px;
  height: clamp(15px, 2.6vh, 22px);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  padding: 0 4px 0 6px;
  gap: 4px;
  pointer-events: none;
}
.pad.empty .pad-label { background: rgba(0, 0, 0, 0.1); }
.pad-text {
  flex: 1 1 auto;
  min-width: 0;
  font-family: 'Digital7', monospace;
  font-size: clamp(11px, 2.1vh, 17px);
  color: rgba(0, 0, 0, 0.62);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pad .led { width: clamp(10px, 1.8vh, 14px); height: clamp(10px, 1.8vh, 14px); }
.pad-key {
  position: absolute;
  right: -8px;
  bottom: -8px;
  font-family: 'Digital7', monospace;
  font-size: 13px;
  color: rgba(0, 0, 0, 0.25);
  text-transform: uppercase;
  pointer-events: none;
  display: none;
}
@media (hover: hover) and (pointer: fine) {
  .pad-key { display: block; }
}
.pad.missing .pad-label { background: rgba(224, 38, 28, 0.35); }
.pad.flash .pad-body { background: rgba(224, 38, 28, 0.25); }
.pad.drop .pad-body { background: rgba(228, 120, 40, 0.35); }
.pad.loading .pad-text { opacity: 0.4; }

#grid.grid-edit .pad .pad-body { box-shadow: inset 0 0 0 2px rgba(224, 38, 28, 0.35); }
.pad.ghost {
  position: fixed;
  z-index: 50;
  opacity: 0.6;
  pointer-events: none;
}
.pad.swap-target .pad-body { box-shadow: inset 0 0 0 3px var(--orange) !important; }

.swipe-dot {
  position: fixed;
  width: 100px;
  height: 100px;
  margin: -50px 0 0 -50px;
  border: 1.5px solid red;
  border-radius: 50%;
  pointer-events: none;
  z-index: 40;
  opacity: 0.5;
  animation: swipeDot 0.35s ease-out forwards;
}
@keyframes swipeDot { to { opacity: 0; transform: scale(0.1); } }

#info {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 18px;
  border-radius: 6px;
  background: rgba(130, 130, 130, 0.55);
  color: rgba(255, 255, 255, 0.95);
  font-size: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.45s;
  z-index: 60;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
#info.show { opacity: 1; transition: opacity 0.25s; }

/* Pionowo na telefonie: LCD w osobnym wierszu */
@media (max-aspect-ratio: 1/1) and (max-width: 700px) {
  :root { --bar: 46px; --side-full: 52vw; }
  #topbar { flex: 0 0 auto; flex-wrap: wrap; }
  #lcd { order: -1; flex: 1 1 100%; height: var(--bar); }
  #topbar .abtn { flex: 1 1 0; height: var(--bar); }
  #topbar .otoggle { height: var(--bar); }
  #stage { flex-direction: column; }
  #side { width: auto !important; height: 0; flex-direction: row; flex-wrap: wrap; transition: height 0.2s; }
  #side[data-state="2"] { height: 40vh; }
  #side[data-state="1"] { height: 64px; flex-wrap: nowrap; }
  #side[data-state="2"] .fx { flex: 1 1 100%; }
  #side[data-state="1"] .fx { flex: 1 1 0; }
  #side[data-state="1"] .fx-instant { flex: 1 1 auto; }
}

/* Ekran startowy */

#start {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--back);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#start.hidden { display: none; }
.start-box { text-align: center; }
.start-box img { border-radius: 22px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25); }
.start-title { font-family: 'Digital7', monospace; font-size: 40px; margin-top: 14px; color: rgba(0, 0, 0, 0.62); }
.start-tap {
  display: inline-block;
  margin-top: 18px;
  padding: 14px 26px;
  font-family: 'Digital7', monospace;
  font-size: 24px;
  border-style: solid;
  border-width: 12px;
  border-image: url('../img/ui_lcd.png') 24 fill / 12px stretch;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.55; } }
.start-hint { margin-top: 14px; font-size: 13px; opacity: 0.6; max-width: 320px; }

/* Okna (styl ekranow ustawien z wersji iOS) */

#modal-root:empty { display: none; }
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 12px);
  animation: fadeIn 0.15s;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  width: min(560px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--ui-light);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  touch-action: pan-y;
}
.modal.wide { width: min(760px, 100%); }
@media (max-width: 600px), (max-height: 500px) {
  .modal-back { padding: 0; }
  .modal { width: 100%; height: 100%; border-radius: 0; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
}
.modal-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  background: var(--ui-dark);
  padding: 10px 12px;
  gap: 8px;
}
.modal-title { flex: 1; text-align: center; font-size: 20px; color: rgba(0, 0, 0, 0.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modal-close, .modal-head .hbtn { font-family: 'ElegantIcons'; font-size: 26px; color: var(--orange); width: 36px; height: 36px; flex: 0 0 36px; }
.modal-head .spacer { width: 36px; flex: 0 0 36px; }
.modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 20px;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  font-size: 17px;
  color: rgba(0, 0, 0, 0.62);
}
.row > label, .row > .lbl { flex: 1 1 auto; min-width: 0; }
.row .grow { flex: 1 1 auto; min-width: 0; }
.row + .row { border-top: 1px solid rgba(0, 0, 0, 0.06); }
.note { font-size: 13px; color: rgba(0, 0, 0, 0.45); line-height: 1.4; margin: 6px 0 10px; }
.section { margin: 18px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: rgba(0, 0, 0, 0.4); }

.obtn {
  background: var(--orange);
  color: #fff;
  border-radius: 4px;
  padding: 10px 16px;
  font-size: 17px;
  min-height: 42px;
  white-space: nowrap;
}
.obtn:active { filter: brightness(0.9); }
.obtn.ghost { background: transparent; color: var(--orange); box-shadow: inset 0 0 0 1.5px var(--orange); }
.obtn.danger { background: #c9442f; }
.obtn.small { padding: 6px 10px; font-size: 14px; min-height: 32px; }
.obtn:disabled { opacity: 0.4; }
.obtn.rec { background: var(--alert); animation: pulse 1s infinite; }
.btn-row { display: flex; gap: 10px; margin: 10px 0; }
.btn-row > * { flex: 1 1 0; }

.switch { position: relative; display: inline-block; vertical-align: middle; width: 51px; height: 31px; flex: 0 0 51px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 31px;
  background: #e9e9ea;
  transition: background 0.2s;
  cursor: pointer;
}
.switch span::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch input:checked + span { background: var(--orange); }
.switch input:checked + span::after { transform: translateX(20px); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  height: 32px;
  accent-color: var(--orange);
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: var(--orange); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -12.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}
input[type="range"]::-moz-range-track { height: 3px; background: var(--orange); }
input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; border: 0; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); }

input[type="text"], input[type="number"] {
  font: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  background: #fff;
  color: #333;
  min-width: 0;
}

.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--orange); border-radius: 5px; overflow: hidden; }
.stepper button { width: 44px; height: 32px; color: var(--orange); font-size: 22px; }
.stepper button + button { border-left: 1px solid var(--orange); }
.stepper .val { min-width: 34px; text-align: center; font-variant-numeric: tabular-nums; }

.seg { display: flex; border: 1px solid var(--orange); border-radius: 5px; overflow: hidden; }
.seg button { flex: 1; padding: 6px 12px; color: var(--orange); font-size: 14px; }
.seg button + button { border-left: 1px solid var(--orange); }
.seg button.on { background: var(--orange); color: #fff; }

.wave {
  position: relative;
  height: 170px;
  border: 1px solid var(--orange);
  border-radius: 3px;
  background: #f0f0f0;
  overflow: hidden;
  touch-action: none;
}
.wave canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.wave .shade { position: absolute; top: 0; bottom: 0; background: rgba(208, 205, 203, 0.75); pointer-events: none; }
.wave .handle { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--orange); pointer-events: none; }
.wave .handle::after { content: ''; position: absolute; top: 0; left: -7px; width: 16px; height: 16px; background: var(--orange); border-radius: 0 0 8px 8px; }
.wave .handle.end::after { top: auto; bottom: 0; border-radius: 8px 8px 0 0; }
.wave .playhead { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(224, 38, 28, 0.8); pointer-events: none; display: none; }
.wave .empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: rgba(0, 0, 0, 0.35); font-size: 15px; }
.wave-meta { display: flex; justify-content: space-between; font-size: 12px; color: rgba(0, 0, 0, 0.45); margin-top: 4px; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 0; border: 1px solid var(--orange); border-radius: 5px; overflow: hidden; margin-bottom: 10px; }
.tabs button { flex: 1; padding: 8px 6px; color: var(--orange); font-size: 14px; }
.tabs button + button { border-left: 1px solid var(--orange); }
.tabs button.on { background: var(--orange); color: #fff; }

.list { display: flex; flex-direction: column; }
.item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}
.item.current { background: rgba(228, 120, 40, 0.1); margin: 0 -16px; padding: 4px 16px; }
.item-main { flex: 1 1 auto; min-width: 0; cursor: pointer; }
.item-name { font-size: 16px; color: rgba(0, 0, 0, 0.75); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12px; color: rgba(0, 0, 0, 0.42); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .ibtn { font-family: 'ElegantIcons'; font-size: 20px; color: var(--orange); width: 38px; height: 38px; flex: 0 0 38px; border-radius: 4px; }
.item .ibtn:active { background: rgba(228, 120, 40, 0.15); }
.item .ibtn.txt { font-family: inherit; font-size: 13px; width: auto; padding: 0 8px; flex: 0 0 auto; }
.empty-list { padding: 30px 0; text-align: center; color: rgba(0, 0, 0, 0.4); }
.tag { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; padding: 1px 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.08); margin-left: 6px; vertical-align: middle; }
.tag.o { background: rgba(228, 120, 40, 0.2); color: #a24e10; }
.pack-head { font-weight: 600; font-size: 14px; color: rgba(0, 0, 0, 0.55); padding: 14px 0 4px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); cursor: pointer; display: flex; justify-content: space-between; }
.kbd { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kbd b { font-family: ui-monospace, Menlo, monospace; font-weight: 600; color: rgba(0, 0, 0, 0.7); }

.progress { height: 3px; background: rgba(0, 0, 0, 0.08); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.progress > i { display: block; height: 100%; background: var(--orange); width: 0; transition: width 0.1s; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 18px);
  transform: translate(-50%, 20px);
  max-width: min(520px, 92vw);
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(40, 40, 40, 0.92);
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-line;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
