:root {
  --bg-1: #05130b;
  --bg-2: #0b2a16;
  --panel: rgba(12, 45, 24, 0.75);
  --panel-strong: rgba(14, 58, 30, 0.9);
  --line: #2a7f45;
  --text: #e7f8ec;
  --muted: #a9cfb6;
  --accent: #53d47e;
  --danger: #d94b52;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, #154b2b 0%, var(--bg-1) 45%),
    linear-gradient(120deg, var(--bg-1), var(--bg-2));
  overscroll-behavior-y: none;
}

html.touch-reordering-root,
body.touch-reordering {
  overscroll-behavior: none;
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background-image: radial-gradient(#8cdfa722 0.8px, transparent 0.8px);
  background-size: 8px 8px;
}

.page {
  position: relative;
  padding: 0.55rem 0.65rem;
  max-width: none;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.55rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.user-pill {
  border: 1px solid #2d6d42;
  background: #0a2a17;
  color: #b8dfc5;
  border-radius: 999px;
  padding: 0.22rem 0.58rem;
  font-size: 0.72rem;
  white-space: nowrap;
}

.auth-modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(1, 6, 3, 0.74);
  z-index: 20000;
  padding: 1rem;
}

.auth-modal {
  width: min(94vw, 420px);
  border: 1px solid #2f7b48;
  border-radius: 14px;
  padding: 0.9rem;
  background: linear-gradient(170deg, rgba(21, 70, 40, 0.95), rgba(8, 30, 17, 0.98));
  box-shadow: 0 22px 40px rgba(0, 0, 0, 0.52);
}

.auth-modal h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

.auth-modal-help {
  margin: 0 0 0.6rem;
  color: #a3ceb2;
  font-size: 0.82rem;
}

.auth-modal-label {
  display: grid;
  gap: 0.22rem;
  margin-top: 0.42rem;
  color: #b3d9c0;
  font-size: 0.78rem;
}

.auth-modal-input {
  border: 1px solid #2f7b48;
  border-radius: 8px;
  background: #082515;
  color: #e7f8ec;
  padding: 0.34rem 0.45rem;
}

.auth-modal-error {
  min-height: 1rem;
  margin: 0.55rem 0 0;
  color: #ffb1b1;
  font-size: 0.75rem;
}

.auth-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.42rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
}

.topbar p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(420px, 2.8fr) minmax(260px, 1fr);
  gap: 0.55rem;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  padding: 0.65rem;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.3);
}

.panel h2 {
  margin-top: 0;
}

.dropzone {
  display: grid;
  place-items: center;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: 12px;
  min-height: 180px;
  padding: 1rem;
  cursor: pointer;
  background: var(--panel-strong);
}

.playlist-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.playlist-head-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.drop-help {
  color: var(--muted);
  font-size: 0.75rem;
}

.dropzone.dragging {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.dropzone input {
  display: none;
}

.playlist {
  display: grid;
  gap: 0.38rem;
  max-height: 72vh;
  overflow: auto;
  padding-right: 0.2rem;
}

.item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.45rem;
  background: linear-gradient(170deg, rgba(20, 60, 36, 0.92), rgba(9, 31, 18, 0.94));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}

.item.touch-dragging {
  opacity: 0.65;
  transform: scale(0.99);
}

.item.drop-target {
  outline: 2px solid #6adf92;
  outline-offset: 2px;
}

.touch-drag-preview {
  position: fixed;
  width: min(88vw, 420px);
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  opacity: 0.92;
  box-shadow: 0 20px 36px rgba(0, 0, 0, 0.45);
}

body.touch-reordering {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  overscroll-behavior: none;
}

.item-head {
  display: grid;
  grid-template-columns: 62px 34px 1fr auto;
  align-items: center;
  gap: 0.45rem;
}

.item-thumb-wrap {
  width: 62px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  background: #05140b;
  border: 1px solid #2d6d42;
}

.item-thumb-image,
.item-thumb-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.item-thumb-video {
  display: none;
}

.item-thumb-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 0.63rem;
  letter-spacing: 0.08em;
  color: #9ac7aa;
  font-weight: 700;
}

.drag-handle {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-size: 1.12rem;
  line-height: 1;
  border-radius: 8px;
  border: 1px solid #2d6d42;
  background: #0a2a17;
  color: var(--accent);
  cursor: grab;
}

.drag-handle:active {
  cursor: grabbing;
}

.item-name {
  margin: 0;
  font-size: 0.94rem;
  line-height: 1.15;
}

.item-title-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.item-title-edit {
  border: 1px solid #2d6d42;
  background: #0a2a17;
  color: #9bd8b0;
  border-radius: 6px;
  font-size: 0.72rem;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}

.item-title-edit[hidden] {
  display: none;
}

.item-meta {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.1;
}

.item-controls {
  margin-top: 0.35rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 0.35rem;
}

.toggle-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
}

.item-controls label,
.field label {
  display: grid;
  gap: 0.15rem;
  font-size: 0.74rem;
  color: var(--muted);
}

.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 0.22rem;
  align-content: end;
  white-space: nowrap;
}

.toggle-wrap input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

input,
select,
button {
  font: inherit;
}

input[type="number"],
select,
input[type="range"] {
  width: 100%;
}

input[type="range"] {
  accent-color: var(--accent);
  height: 18px;
  margin: 0;
}

input[type="number"],
select {
  border: 1px solid #2d6d42;
  border-radius: 6px;
  background: #082515;
  color: var(--text);
  padding: 0.22rem 0.34rem;
}

input[type="text"] {
  width: 100%;
  border: 1px solid #2d6d42;
  border-radius: 6px;
  background: #082515;
  color: var(--text);
  padding: 0.22rem 0.34rem;
  font-size: 0.78rem;
}

.item .btn {
  padding: 0.26rem 0.46rem;
  font-size: 0.72rem;
}

.item-delete {
  align-self: start;
}

.field {
  margin-bottom: 0.8rem;
}

.settings-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.text-preset-list {
  display: grid;
  gap: 0.35rem;
  max-height: 130px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.text-preset-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 0.4rem;
}

.text-preset-row input[type="text"] {
  font-size: 0.72rem;
}

.icon-btn {
  border: 1px solid #2d6d42;
  background: #0a2a17;
  color: #b9e7c8;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  line-height: 1;
  font-size: 0.72rem;
}

.preset-delete-btn {
  justify-self: end;
  border-color: #8d2f34;
  background: #4a171b;
  color: #ffd8da;
}

.volume-wrap {
  align-items: end;
}

.item-volume-preview {
  justify-self: end;
  padding: 0.14rem 0.42rem;
  font-size: 0.66rem;
  min-width: 56px;
}

.text-preset-empty {
  font-size: 0.72rem;
  color: var(--muted);
}

.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-inline label {
  margin: 0;
}

.field-inline input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.btn {
  border: 1px solid var(--line);
  background: #0a331b;
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(120deg, #0f5f2f, #148247);
  border-color: #1fa459;
}

.btn-danger {
  border-color: #a7363a;
  background: #5b1c21;
}

.item-delete-wrap {
  display: flex;
  align-items: end;
  justify-content: flex-end;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
}

.display-body {
  margin: 0;
  overflow: hidden;
  cursor: default;
  background: #000;
}

.display-root {
  position: fixed;
  inset: 0;
  background: #000;
}

.black-curtain {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  transition: opacity 300ms ease;
}

.black-curtain.active {
  opacity: 1;
}

.display-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #000;
  overflow: hidden;
  opacity: 1;
  transition: opacity 1s ease;
  z-index: 2;
}

.display-layer.active {
  opacity: 1;
}

.display-layer.transition-crossfade,
.display-layer.transition-fade-black {
  opacity: 0;
}

.display-layer.transition-crossfade.active,
.display-layer.transition-fade-black.active {
  opacity: 1;
}

.display-layer.transition-slide-left {
  opacity: 1;
  transform: translateX(24%);
}

.display-layer.transition-slide-left.active {
  transform: translateX(0);
}

.display-layer.outgoing-slide-left {
  transform: translateX(-24%);
}

.display-layer.transition-zoom-fade {
  opacity: 1;
  transform: scale(1.45);
}

.display-layer.transition-zoom-fade.active {
  transform: scale(1);
}

.display-layer.transition-zoom-in {
  opacity: 1;
  transform: scale(0.62);
}

.display-layer.transition-zoom-in.active {
  transform: scale(1);
}

.display-layer.outgoing-fade {
  opacity: 0;
}

.display-layer.transition-fade-black {
  filter: brightness(0.7);
}

.display-layer.transition-fade-black.active {
  filter: brightness(1);
}

.display-layer img,
.display-layer video {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center center;
}

.display-layer img.media-fit,
.display-layer video.media-fit {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}

.display-layer img.media-fill,
.display-layer video.media-fill {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: cover;
}

.audio-text {
  position: relative;
  text-align: center;
  max-width: 90vw;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: 0.01em;
  word-break: break-word;
}

.audio-text.text-effect-glow {
  text-shadow:
    0 0 10px currentColor,
    0 0 22px currentColor,
    0 0 34px currentColor;
}

.audio-text.text-effect-rainbow {
  animation: rainbow-cycle 5s linear infinite;
}

.audio-text.text-rainbow-enabled {
  animation: rainbow-cycle 5s linear infinite;
}

.audio-text.text-effect-pulse {
  animation: text-pulse 1.8s ease-in-out infinite;
}

.audio-text.text-rainbow-enabled.text-effect-pulse {
  animation: rainbow-cycle 5s linear infinite, text-pulse 1.8s ease-in-out infinite;
}

.audio-text.text-rainbow-enabled.text-effect-glow {
  animation: rainbow-cycle 5s linear infinite;
}

.audio-text.text-effect-dvd {
  position: absolute;
  margin: 0;
  top: 0;
  left: 0;
  will-change: transform;
  backface-visibility: hidden;
}

@keyframes rainbow-cycle {
  0% { color: #ff4d4d; }
  20% { color: #ffb84d; }
  40% { color: #59ff85; }
  60% { color: #4dd2ff; }
  80% { color: #8f6bff; }
  100% { color: #ff4d4d; }
}

@keyframes text-pulse {
  0%, 100% { transform: scale(1); opacity: 0.95; }
  50% { transform: scale(1.08); opacity: 1; }
}

.display-overlay {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  color: #d6e8da;
  background: #173722cc;
  border: 1px solid #2f764a;
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
}

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .settings-panel {
    order: -1;
  }

  .playlist {
    max-height: none;
  }

  .playlist-head {
    align-items: center;
    gap: 0.45rem;
  }

  .playlist-head-actions {
    gap: 0.35rem;
  }

  .toggle-row {
    justify-content: space-between;
    gap: 0.25rem;
  }
}
