:root {
  --bg: #0b0d0c;
  --panel: rgba(20, 23, 22, 0.86);
  --panel-solid: #151817;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e6e9e4;
  --muted: #8f978f;
  --accent: #5cc4d6;
  --accent-dim: rgba(92, 196, 214, 0.18);
  --danger: #e2735f;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }

#stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
#out {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
#drop-hint {
  position: fixed; inset: 16px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: rgba(11, 13, 12, 0.7);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; letter-spacing: 0.02em; color: var(--accent);
  pointer-events: none; z-index: 5;
}
#stats {
  position: fixed; left: 14px; bottom: 12px;
  font: 11px/1.4 ui-monospace, Consolas, monospace;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.45);
  padding: 4px 8px; border-radius: 6px;
  pointer-events: none;
}
#stats:empty { display: none; }

/* ---------- floating panel ---------- */
.panel {
  position: fixed; top: 16px; right: 16px; z-index: 10;
  width: 300px; max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  font-size: 12px;
  user-select: none;
}
.panel.collapsed .panel-body { display: none; }
.panel.hidden { display: none; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 12px;
  cursor: grab;
  border-bottom: 1px solid var(--line);
}
.panel.collapsed .panel-head { border-bottom: 0; }
.panel-head:active { cursor: grabbing; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: 0.02em; }
.brand-chip {
  width: 14px; height: 14px; border-radius: 3px;
  background: linear-gradient(135deg, #2c4a33 0 33%, #3aa0b4 33% 66%, #9fe0e8 66%);
}
.head-actions { display: flex; gap: 4px; }

.panel-body { overflow-y: auto; padding: 4px 0 10px; }
.panel-body::-webkit-scrollbar { width: 8px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }

.section { border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); cursor: pointer;
}
.section-title:hover { color: var(--text); }
.section-title::after { content: "▾"; font-size: 10px; transition: transform 0.15s; }
.section.closed .section-title::after { transform: rotate(-90deg); }
.section.closed .section-content { display: none; }
.section-content { padding: 0 12px 10px; display: grid; gap: 7px; }

/* ---------- controls ---------- */
.row { display: grid; grid-template-columns: 88px 1fr; align-items: center; gap: 8px; min-height: 22px; }
.row > label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row > label[data-reset] { cursor: help; }
.range-wrap { display: grid; grid-template-columns: 1fr 44px; align-items: center; gap: 6px; }
.range-val { text-align: right; font: 11px ui-monospace, Consolas, monospace; color: var(--text); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 18px; background: transparent; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: var(--line-strong); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4.5px;
  border-radius: 50%; background: var(--text); border: 2px solid var(--panel-solid);
  box-shadow: 0 0 0 1px var(--line-strong);
}
input[type="range"]:hover::-webkit-slider-thumb { background: var(--accent); }
input[type="range"]::-moz-range-track { height: 3px; background: var(--line-strong); }
input[type="range"]::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: var(--text); border: 0; }

select, input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
}
select:focus, textarea:focus, input:focus-visible { outline: 1px solid var(--accent); outline-offset: 0; }
option { background: var(--panel-solid); }
textarea { resize: vertical; min-height: 90px; font: 11px/1.4 ui-monospace, Consolas, monospace; }

input[type="color"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; padding: 0; border: 1px solid var(--line-strong);
  border-radius: 6px; background: none; cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 4px; }

.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle input { accent-color: var(--accent); margin: 0; }

button {
  font: inherit; color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
}
button:hover { background: rgba(255, 255, 255, 0.12); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent-dim); border-color: var(--accent); color: #d8f6fb; }
button.primary:hover { background: rgba(92, 196, 214, 0.3); }
button.danger { border-color: var(--danger); color: var(--danger); }
.icon-btn { width: 24px; height: 24px; padding: 0; line-height: 1; font-size: 14px; background: transparent; border-color: transparent; display: inline-grid; place-items: center; }
.icon-btn:hover { border-color: var(--line-strong); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn-row button { flex: 1 1 auto; }

/* ---------- palette ---------- */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(22px, 1fr)); gap: 3px; }
.swatch {
  aspect-ratio: 1; border-radius: 3px; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  position: relative;
}
.swatch.off { opacity: 0.25; }
.swatch.off::after {
  content: ""; position: absolute; inset: 45% -2px auto; height: 1px;
  background: var(--text); transform: rotate(-45deg);
}
.hint { color: var(--muted); font-size: 11px; line-height: 1.4; }

/* ---------- transport / progress ---------- */
.transport { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center; }
.transport .time { font: 11px ui-monospace, Consolas, monospace; color: var(--muted); min-width: 70px; text-align: right; }
.progress { height: 6px; border-radius: 3px; background: var(--line-strong); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.1s; }
.status { font-size: 11px; color: var(--muted); min-height: 14px; }

/* ---------- phones: the panel becomes a bottom sheet ---------- */
.sheet-grip { display: none; }

@media (max-width: 700px) {
  #stage { padding: 8px 8px 58px; }
  .panel {
    top: auto; bottom: 0; left: 0; right: 0;
    width: auto; max-width: none;
    max-height: 78vh;
    border-radius: 16px 16px 0 0;
    border-left: 0; border-right: 0; border-bottom: 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.6);
    font-size: 13px;
  }
  .sheet-grip { display: block; flex: 0 0 auto; padding: 8px 0 2px; }
  .sheet-grip::before {
    content: ""; display: block; width: 42px; height: 4px; margin: 0 auto;
    border-radius: 2px; background: var(--line-strong);
  }
  .panel-head { cursor: pointer; padding: 6px 10px 10px 14px; }
  .panel-body { padding-bottom: calc(14px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }
  .section-title { padding: 13px 14px; font-size: 11px; }
  .section-content { padding: 0 14px 12px; gap: 10px; }
  .row { grid-template-columns: 84px 1fr; min-height: 34px; }
  .swatches { grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 4px; }
  #stats { font-size: 10px; left: 10px; bottom: 8px; }
}

/* ---------- touch: hit targets a thumb can actually land on ---------- */
@media (pointer: coarse) {
  input[type="range"] { height: 34px; touch-action: none; }
  input[type="range"]::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -8.5px; }
  input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; }
  select, button { min-height: 40px; touch-action: manipulation; }
  select { padding: 6px 8px; }
  button { padding: 8px 12px; }
  .icon-btn { width: 36px; height: 36px; font-size: 17px; }
  input[type="color"] { height: 34px; }
  .toggle input { width: 22px; height: 22px; }
  .range-wrap { grid-template-columns: 1fr 48px; }
  .section-title { cursor: default; }
}
