:root {
  color-scheme: dark;

  --surface: rgba(13, 18, 25, 0.9);
  --surface-soft: rgba(13, 18, 25, 0.72);
  --border: rgba(255, 255, 255, 0.18);
  --text: #fff;
  --muted: rgba(255, 255, 255, 0.72);
  --accent: #8dc7ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: #000;
  color: var(--text);
  font-family: Verdana, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.looper-player {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  user-select: none;
}

.looper-stage,
.looper-canvas {
  position: absolute;
  inset: 0;
}

.looper-canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.looper-loading {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 18px;
  text-align: center;
  pointer-events: none;
}

.looper-overlay {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 20;
  opacity: 1;
  visibility: visible;
  transition:
    opacity 180ms ease,
    visibility 180ms ease;
}

.looper-player.controls-hidden .looper-overlay {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.looper-header {
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 20px 20px;
  background:
    linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.8),
      transparent
    );
  pointer-events: none;
}

.looper-title {
  font-size: clamp(15px, 2vw, 22px);
  font-weight: 700;
  text-shadow: 0 1px 3px #000;
}

.looper-header-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  min-width: 0;
}

.looper-archive-badge {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid rgba(255, 196, 76, 0.65);
  border-radius: 999px;
  background: rgba(126, 78, 0, 0.82);
  color: #ffe5a3;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
}

.looper-status {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  text-shadow: 0 1px 3px #000;
}

.looper-controls {
  bottom: 0;
  padding: 20px 18px 16px;
  background:
    linear-gradient(
      to top,
      rgba(0, 0, 0, 0.92),
      rgba(0, 0, 0, 0.58) 58%,
      transparent
    );
}

.looper-timestamp {
  margin: 0 0 9px;
  font-size: clamp(13px, 1.7vw, 19px);
  font-weight: 600;
  text-shadow: 0 1px 3px #000;
}

.looper-timeline {
  display: block;
  width: 100%;
  margin: 0 0 10px;
  accent-color: var(--accent);
  cursor: pointer;
}

.looper-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.looper-spacer {
  flex: 1;
}

.looper-icon-button,
.looper-menu-button,
.looper-button {
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.looper-icon-button:hover,
.looper-menu-button:hover,
.looper-button:hover {
  background: rgba(45, 55, 68, 0.92);
}

button:disabled,
input:disabled,
select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.looper-play {
  min-width: 76px;
  font-weight: 700;
}

.looper-frame-info {
  min-width: 7ch;
  padding: 0 7px;
  color: var(--muted);
  text-align: center;
  line-height: 38px;
}

.looper-popover {
  position: absolute;
  right: 18px;
  bottom: 68px;
  z-index: 40;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100dvh - 100px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(16px);
}

.looper-popover h3 {
  margin: 0 0 14px;
  font-size: 17px;
}

.looper-setting-row {
  margin: 13px 0;
}

.looper-setting-row > label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.looper-setting-row select,
.looper-setting-row input[type="number"] {
  width: 100%;
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
}

.looper-inline-setting {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 11px 0;
}

.looper-speed-grid {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 10px;
  align-items: center;
}

.looper-speed-slider {
  width: 100%;
  accent-color: var(--accent);
}

.looper-speed-unit {
  position: relative;
}

.looper-speed-unit::after {
  content: "ms";
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  font-size: 12px;
}

.looper-speed-input {
  padding-right: 31px !important;
}

.looper-help {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.looper-layer-list {
  display: grid;
  gap: 10px;
}

.looper-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: auto;
  padding: 24px 12px;
  background: rgba(0, 0, 0, 0.68);
}

.looper-modal.is-open {
  display: grid;
  place-items: center;
}

.looper-modal-content {
  width: min(640px, 100%);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  background: #f7f8fa;
  color: #16191d;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.looper-modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.looper-modal-header h2 {
  margin: 0 0 4px;
  font-size: 21px;
}

.looper-modal-header p {
  margin: 0;
  color: #5f6873;
  font-size: 13px;
}

.looper-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #59616b;
  font-size: 25px;
  cursor: pointer;
}

.looper-close:hover {
  background: #e6e9ed;
  color: #111;
}

.looper-export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.looper-export-field {
  min-width: 0;
}

.looper-export-field.full {
  grid-column: 1 / -1;
}

.looper-export-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
}

.looper-export-field input,
.looper-export-field select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #b9c0c8;
  border-radius: 7px;
  background: #fff;
  color: #111;
}

.looper-export-field small {
  display: block;
  margin-top: 5px;
  color: #68717c;
  line-height: 1.35;
}

.looper-export-timing {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.looper-export-summary {
  margin-top: 16px;
  padding: 11px 12px;
  border: 1px solid #d4d9df;
  border-radius: 8px;
  background: #fff;
  color: #404852;
  font-size: 13px;
  line-height: 1.45;
}

.looper-progress {
  margin-top: 16px;
}

.looper-progress-track {
  position: relative;
  height: 30px;
  overflow: hidden;
  border-radius: 7px;
  background: #dfe3e7;
}

.looper-progress-bar {
  width: 0;
  height: 100%;
  background: #2878c8;
  transition: width 100ms linear;
}

.looper-progress-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

.looper-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  margin-top: 18px;
}

.looper-modal-actions button {
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid #aeb6bf;
  border-radius: 8px;
  background: #fff;
  color: #111;
  cursor: pointer;
}

.looper-modal-actions .primary {
  border-color: #1768ad;
  background: #1768ad;
  color: #fff;
}

.looper-toast {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 92px;
  z-index: 200;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(520px, calc(100vw - 24px));
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(13, 18, 25, 0.94);
  color: var(--text);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(14px);
  font-family: Verdana, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  text-align: left;
}

.looper-toast.error {
  border-color: rgba(255, 110, 110, 0.58);
  background: rgba(75, 19, 23, 0.95);
  color: #ffd9dc;
}

.looper-toast.success {
  border-color: rgba(93, 214, 133, 0.5);
  background: rgba(18, 65, 39, 0.95);
  color: #d8ffe5;
}

.looper-toast.info {
  border-color: rgba(141, 199, 255, 0.55);
  background: rgba(18, 47, 75, 0.95);
  color: #dceeff;
}

@media (max-width: 680px) {
  .looper-header {
    padding: 12px 12px 34px;
  }
  
  .looper-header-status {
    gap: 6px;
  }

  .looper-archive-badge {
    padding: 4px 7px;
    font-size: 10px;
  }

  .looper-status {
    font-size: 11px;
  }
  
  .looper-toast {
    bottom: 74px;
    max-width: calc(100vw - 20px);
    font-size: 13px;
  }

  .looper-controls {
    padding: 68px 10px 10px;
  }

  .looper-toolbar {
    flex-wrap: wrap;
    gap: 5px;
  }

  .looper-frame-info {
    flex: 1 1 auto;
  }

  .looper-spacer {
    flex-basis: 100%;
    height: 0;
  }

  .looper-menu-button {
    flex: 1 1 0;
  }

  .looper-icon-button,
  .looper-menu-button,
  .looper-button {
    min-height: 40px;
    padding: 7px 9px;
  }

  .looper-play {
    min-width: 66px;
  }

  .looper-desktop-label {
    display: none;
  }

  .looper-popover {
    right: 10px;
    bottom: 62px;
  }

  .looper-export-grid,
  .looper-export-timing {
    grid-template-columns: 1fr;
  }

  .looper-export-field.full {
    grid-column: auto;
  }

  .looper-modal-actions {
    flex-wrap: wrap;
  }

  .looper-modal-actions button {
    flex: 1 1 140px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .looper-overlay,
  .looper-progress-bar {
    transition: none;
  }
}
