:root {
  --bg: #12141a;
  --panel: #1a1d26;
  --ink: #e8eaef;
  --muted: #9aa0ad;
  --line: #2c3140;
  --accent: #3dbf9a;
  --accent-hover: #2fa882;
  --input-bg: #0e1016;
  --btn-bg: #242836;
  --danger: #e06a5c;
  --preview-bg: #0a0b0f;
  --thumb: 76px;
  --radius: 8px;
  --font: "Segoe UI", "Candara", "Trebuchet MS", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  color-scheme: dark;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.brand-banner {
  position: relative;
  flex: 0 0 auto;
  height: clamp(88px, 14vw, 148px);
  overflow: hidden;
  background: #000;
}

.brand-banner-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 35%;
  display: block;
}

.brand-banner-logo {
  position: absolute;
  left: 1.1rem;
  top: 50%;
  transform: translateY(-50%);
  height: 62%;
  width: auto;
  max-width: min(220px, 38vw);
  object-fit: contain;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.55));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-left: auto;
}

.header-icon-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.header-icon-sep {
  width: 1px;
  height: 1.55rem;
  margin: 0 0.25rem;
  background: #5a6278;
  flex: 0 0 auto;
  align-self: center;
}

.btn {
  border: 1px solid var(--line);
  background: var(--btn-bg);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 0.45rem 0.9rem;
  transition: background 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
  box-sizing: border-box;
  cursor: pointer;
}

.btn:hover {
  background: #2e3344;
  border-color: #3d4458;
}

.btn-icon {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  color: #ffffff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.btn-icon svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: #ffffff;
  display: block;
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.85));
}

.btn-icon-insert {
  background: #2f6b55;
  border-color: #4aa882;
}

.btn-icon-insert:hover:not(:disabled) {
  background: #378f6c;
  border-color: #5ec89a;
  color: #ffffff;
}

.btn-icon-project {
  background: #3a4f72;
  border-color: #5b7eb0;
}

.btn-icon-project:hover:not(:disabled) {
  background: #4a638c;
  border-color: #7a9bce;
  color: #ffffff;
}

.btn-icon-help {
  background: #3a4f72;
  border-color: #5b7eb0;
}

.btn-icon-help:hover {
  background: #4a638c;
  border-color: #7a9bce;
}

.btn-icon-help svg {
  width: 1.7rem;
  height: 1.7rem;
  fill: none;
  filter: none;
  overflow: visible;
}

.btn-icon-help svg text {
  fill: #ffd54f;
  paint-order: stroke fill;
  stroke: #ffd54f;
  stroke-width: 0.9px;
}

.btn-transport {
  background: #2a3142;
  border-color: #4a5568;
}

.btn-transport:hover:not(:disabled) {
  background: #3a4558;
  border-color: #6a7a90;
  color: #ffffff;
}

.btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1210;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-primary:disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.tap-tempo-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.tap-tempo-row .btn {
  flex: 1;
}

.tap-led {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #2a303c;
  box-shadow: inset 0 0 0 1px #3d4458;
  transition: background 0.05s linear, box-shadow 0.05s linear;
}

.tap-led.is-on {
  background: #3dffb0;
  box-shadow: 0 0 10px rgba(61, 255, 176, 0.85), 0 0 2px #3dffb0;
}

.tap-mult-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  margin-top: 0.15rem;
}

.tap-mult {
  padding: 0.35rem 0.25rem;
  font-variant-numeric: tabular-nums;
}

.tap-mult.is-active {
  border-color: var(--accent);
  background: #1e3a32;
  color: var(--accent);
}

#tapTempoBtn.is-tapping {
  border-color: var(--accent);
  background: #1e3a32;
  color: var(--accent);
}

#tapTempoHint {
  margin-top: 0.15rem;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 0;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field[hidden],
[hidden] {
  display: none !important;
}

.field label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea,
.field input[type="file"] {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.45rem 0.55rem;
  background: var(--input-bg);
  color: var(--ink);
}

.field textarea {
  resize: vertical;
  min-height: 4.5rem;
  line-height: 1.35;
}

.field input[type="color"] {
  width: 3rem;
  height: 2rem;
  padding: 0.15rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--input-bg);
  cursor: pointer;
}

.field input:disabled,
.field select:disabled,
.field textarea:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.caption-hint {
  margin: -0.35rem 0 0;
}

.field input[type="file"] {
  font-size: 0.8rem;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.field-row-compact {
  justify-content: flex-start;
  gap: 0.35rem;
}

.field-row-compact input[type="number"] {
  width: 4.6rem;
  max-width: 42%;
  flex: 0 0 auto;
  padding: 0.35rem 0.4rem;
}

.field-row-compact span {
  color: var(--muted);
  flex: 0 0 auto;
}

.field-row-actions {
  justify-content: flex-start;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.field-row-actions .btn {
  flex: 1 1 0;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
}

.checkbox-row input {
  accent-color: var(--accent);
}

.section-title {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  font-weight: 700;
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
}

.fold {
  border-top: 1px solid var(--line);
  margin: 0.25rem 0 0;
  padding-top: 0.35rem;
}

.fold-summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.5rem 0.15rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  user-select: none;
}

.fold-summary::-webkit-details-marker {
  display: none;
}

.fold-summary::before {
  content: "▸";
  font-size: 0.75rem;
  color: var(--muted);
  transition: transform 0.15s ease;
  line-height: 1;
}

.fold[open] > .fold-summary::before {
  transform: rotate(90deg);
}

.fold-summary:hover {
  color: #fff;
}

.fold-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.15rem 0 0.55rem;
}

.field-flush {
  margin: 0;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.preview-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1rem 1rem 0.5rem;
  gap: 0.6rem;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.preview-stage {
  flex: 1;
  min-height: 240px;
  background: var(--preview-bg);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.player-root {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
}

.player-layer {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  opacity: 0;
  transform: scale(1);
  will-change: transform, opacity;
}

.player-layer.active {
  opacity: 1;
}

.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  z-index: 5;
}

.player-overlay.hidden {
  display: none;
}

.player-start-btn {
  border: 0;
  background: #fff;
  color: #111;
  padding: 0.85rem 1.4rem;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
}

.player-caption {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 12%;
  z-index: 4;
  margin: 0;
  text-align: center;
  pointer-events: none;
  font-weight: 600;
  line-height: 1.25;
  white-space: pre-wrap;
  word-break: break-word;
  text-shadow:
    0 2px 14px rgba(0, 0, 0, 0.75),
    0 0 3px rgba(0, 0, 0, 0.9);
  transition: opacity 0.25s ease;
}

.player-caption.is-empty {
  opacity: 0;
}

.player-title {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8%;
  background: #0a0b0f;
  color: #fff;
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.6rem, 5.5vw, 4.2rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.player-title.hidden {
  display: none;
}

.player-logo {
  position: absolute;
  right: 1.4%;
  bottom: 1.8%;
  left: auto;
  top: auto;
  z-index: 5;
  height: var(--logo-corner-h, 110px);
  width: auto;
  max-width: min(36vw, calc(var(--logo-corner-h, 110px) * 2.4));
  object-fit: contain;
  pointer-events: none;
  opacity: 0.92;
  transform: none;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.55));
  transition: opacity 0.8s ease, transform 0.8s ease, height 0.8s ease, max-width 0.8s ease,
    right 0.8s ease, bottom 0.8s ease, left 0.8s ease, top 0.8s ease;
}

.player-logo.is-corner-hiding {
  opacity: 0;
}

.player-logo.is-end {
  right: auto;
  bottom: auto;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: var(--logo-end-h, clamp(120px, 42vh, 360px));
  max-width: min(70vw, var(--logo-end-max-w, 520px));
  opacity: 1;
  z-index: 6;
}

.player-logo.hidden {
  display: none;
}

.player-end-veil {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1s ease;
}

.player-end-veil.is-visible {
  opacity: 1;
}

.preview-stage:fullscreen,
.preview-stage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  background: #000;
}

.header-actions .btn-primary {
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .header-actions {
    justify-content: flex-end;
  }
}

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0 0.15rem;
}

.timeline-wrap {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 0.65rem 1rem 0.9rem;
}

.timeline-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.timeline {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.25rem 0.1rem 0.45rem;
  min-height: calc(var(--thumb) + 18px);
  scroll-behavior: smooth;
}

.timeline-add {
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  margin: 0 0.15rem;
  border: 1px dashed #4a5166;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
  display: inline-grid;
  place-items: center;
  align-self: center;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.timeline-add:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(61, 191, 154, 0.08);
}

.timeline.is-empty {
  justify-content: center;
  min-height: calc(var(--thumb) + 28px);
}

.timeline.is-empty .timeline-add {
  width: 2.4rem;
  height: 2.4rem;
  font-size: 1.5rem;
}

.thumb {
  position: relative;
  flex: 0 0 auto;
  width: calc(var(--thumb) * 1.35);
  height: var(--thumb);
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  background: #2a2e3a;
  cursor: grab;
  user-select: none;
  box-sizing: border-box;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.thumb.selected {
  border-width: 4px;
  border-color: #f5d547;
  box-shadow: 0 0 0 1px rgba(245, 213, 71, 0.45), 0 0 10px rgba(245, 213, 71, 0.35);
}

.thumb.dragging {
  opacity: 0.45;
}

.thumb.drag-over {
  border-color: #e0a45a;
}

.thumb-index {
  position: absolute;
  left: 3px;
  bottom: 3px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.65rem;
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
}

.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  padding: 0;
  display: none;
}

.thumb:hover .thumb-remove {
  display: grid;
  place-items: center;
}

.progress-toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: #eceff5;
  color: #12141a;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.progress-toast.hidden {
  display: none;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }

  .brand-banner {
    height: 96px;
  }
}
