:root {
  color-scheme: dark;
  --sidebar: clamp(180px, 16vw, 270px);
  --accent: #ff5a36;
  --panel: #151515;
  --muted: #8c8c8c;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #090909;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}

button { font: inherit; }

.app {
  width: 100%;
  height: 100%;
}

.sidebar {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--panel);
  border-right: 1px solid #2c2c2c;
  box-shadow: 18px 0 60px rgba(0, 0, 0, .45);
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform .22s ease, visibility 0s linear .22s;
}

body.sidebar-open .sidebar {
  transform: translateX(0);
  visibility: visible;
  transition: transform .22s ease;
}

.sidebar-scrim {
  position: fixed;
  z-index: 20;
  inset: 0;
  background: rgba(0, 0, 0, .48);
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility 0s linear .22s;
}

body.sidebar-open .sidebar-scrim {
  opacity: 1;
  visibility: visible;
  transition: opacity .22s ease;
}

.sidebar-toggle {
  position: fixed;
  z-index: 15;
  top: 14px;
  left: 14px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  background: rgba(18,18,18,.82);
  color: #eee;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
  cursor: pointer;
  backdrop-filter: blur(10px);
}
.sidebar-toggle:hover { border-color: var(--accent); color: var(--accent); }
body.sidebar-open .sidebar-toggle { opacity: 0; pointer-events: none; }

.sidebar-actions { display: flex !important; grid-auto-flow: column; gap: 5px !important; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 12px 12px;
  border-bottom: 1px solid #2c2c2c;
}

.sidebar-header div { display: grid; gap: 2px; }
.sidebar-header strong { color: #f4f4f4; font-size: 14px; letter-spacing: .04em; }
.sidebar-header span { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

.sidebar-header button {
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  padding: 5px 7px;
  background: #202020;
  color: #aaa;
  cursor: pointer;
  font-size: 10px;
}
.sidebar-header button:hover { color: white; border-color: #666; }
.sidebar-header #saveOrder { color: #fff; border-color: var(--accent); background: var(--accent); }
.sidebar-header #saveOrder.saved { color: #bff2ca; border-color: #347b48; background: #183d24; }

.thumbs {
  margin: 0;
  padding: 10px 10px 24px;
  overflow-y: auto;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: #454545 transparent;
}

.thumb {
  position: relative;
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 7px;
  align-items: start;
  margin: 0 0 9px;
  cursor: grab;
  user-select: none;
}
.thumb:active { cursor: grabbing; }
.thumb.dragging { opacity: .32; }
.thumb.drop-before::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 28px;
  right: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.thumb-number {
  padding-top: 4px;
  color: #777;
  font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: right;
}

.thumb-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 2px solid transparent;
  border-radius: 3px;
  background: #222;
  transition: border-color .15s ease, transform .15s ease;
}
.thumb:hover .thumb-frame { transform: translateY(-1px); border-color: #666; }
.thumb.active .thumb-frame { border-color: var(--accent); }
.thumb.active .thumb-number { color: var(--accent); font-weight: 700; }
.thumb-frame img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.thumb-frame .thumb-insert {
  position: absolute;
  left: 6%;
  top: 50%;
  width: 88%;
  height: auto;
  transform: translateY(-50%);
}
.thumb-page-number {
  position: absolute;
  z-index: 5;
  left: 90.2%;
  right: 2.6%;
  bottom: 4.2%;
  min-height: 3.2%;
  background: #000;
  color: #fff;
  font: 400 3.7px/1 Arial, sans-serif;
  text-align: left;
  white-space: nowrap;
  pointer-events: none;
}

.viewer {
  position: relative;
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: radial-gradient(circle at 50% 45%, #202020 0, #0c0c0c 66%);
}

.stage {
  position: relative;
  width: min(calc(100vw - 56px), calc((100vh - 56px) * 16 / 9));
  height: min(calc(100vh - 56px), calc((100vw - 56px) * 9 / 16));
  aspect-ratio: 16 / 9;
  flex: none;
  overflow: hidden;
  outline: none;
  background: #000;
  box-shadow: 0 18px 70px rgba(0, 0, 0, .55);
  cursor: pointer;
}
.stage img { display: block; width: 100%; height: 100%; object-fit: contain; }
.page-number {
  position: absolute;
  z-index: 8;
  left: 89.8%;
  right: 2.2%;
  top: 90.2%;
  bottom: 2.2%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  color: #fff;
  font: 400 clamp(10px, 1.55vw, 30px)/1 Arial, sans-serif;
  letter-spacing: -.02em;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}
.stage .page-25-insert {
  position: absolute;
  z-index: 2;
  left: 6%;
  top: 50%;
  width: 88%;
  height: auto;
  object-fit: contain;
  transform: translateY(-50%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.stage.show-page-25-insert .page-25-insert { opacity: 1; visibility: visible; }
.page-36-video-wrap,
.page-38-video-wrap {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: 56%;
  aspect-ratio: 3438 / 1912;
  transform: translate(-50%, -50%);
  overflow: hidden;
  background: #000;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .2);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.page-38-video-wrap { aspect-ratio: 800 / 564; }
.stage.show-page-36-video .page-36-video-wrap,
.stage.show-page-38-video .page-38-video-wrap {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.page-36-video-wrap video,
.page-38-video-wrap video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.stage:focus-visible { box-shadow: 0 18px 70px rgba(0, 0, 0, .55); }

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #111;
  color: #888;
  font-size: 13px;
  letter-spacing: .08em;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s ease;
}
.stage.is-loading .loading { opacity: 1; }

.hint {
  position: absolute;
  right: 15px;
  bottom: 9px;
  color: #666;
  font-size: 10px;
  pointer-events: none;
}

@media (max-width: 760px) {
  :root { --sidebar: 138px; }
  .viewer { padding: 10px; }
  .stage {
    width: min(calc(100vw - 20px), calc((100vh - 20px) * 16 / 9));
    height: min(calc(100vh - 20px), calc((100vw - 20px) * 9 / 16));
  }
  .sidebar-header #resetOrder { display: none; }
  .thumb { grid-template-columns: 18px 1fr; gap: 4px; }
  .thumb.drop-before::before { left: 21px; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
