:root {
  color-scheme: dark;
  --bg: #060d0b;
  --panel: #0b1714;
  --panel-2: #10231e;
  --line: rgba(215, 255, 237, 0.13);
  --text: #eafff5;
  --dim: #83a398;
  --accent: #c7ff49;
  --mint: #62edbd;
  --cyan: #60d9ff;
  --red: #ff765f;
  --yellow: #ffdc68;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  color: var(--text);
  font-family: "Noto Sans CJK SC", "Source Han Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

button,
select,
input {
  font: inherit;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
#c3d:focus-visible {
  outline: 2px solid #ff8c55;
  outline-offset: 2px;
}

.viewer-titlebar {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.viewer-titlebar > div:first-child {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.viewer-titlebar strong {
  font-size: 13px;
  letter-spacing: 0.02em;
}

.viewer-titlebar span:last-child {
  overflow: hidden;
  color: var(--dim);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(199, 255, 73, 0.08);
}

#video-select {
  max-width: 200px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--dim);
  background: var(--panel-2);
  font-size: 11px;
}

.viewer-main {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
}

#left {
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 12px;
  border-right: 1px solid var(--line);
}

#videowrap {
  position: relative;
  width: 100%;
}

#video {
  width: 100%;
  display: block;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #000;
}

#overlay,
#overlay3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#panel3d {
  position: relative;
  min-width: 0;
  background:
    radial-gradient(circle at 70% 20%, rgba(96, 217, 255, 0.06), transparent 20rem),
    #07110f;
}

#c3d {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#c3d:active {
  cursor: grabbing;
}

#hud {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--dim);
  background: rgba(6, 13, 11, 0.72);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  white-space: pre-line;
  pointer-events: none;
}

#btn-free {
  position: absolute;
  top: 12px;
  right: 12px;
}

#cam-modes {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.viewer-button {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--dim);
  background: rgba(16, 35, 30, 0.92);
  font-size: 11px;
  cursor: pointer;
}

.viewer-button:hover {
  color: var(--text);
  border-color: rgba(199, 255, 73, 0.4);
}

.viewer-button.active {
  color: #07110f;
  border-color: var(--accent);
  background: var(--accent);
  font-weight: 750;
}

.viewer-controls {
  min-height: 102px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 9px 14px 11px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

#controls {
  display: flex;
  align-items: center;
  gap: 13px;
  color: var(--dim);
  font-size: 11px;
}

#controls label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}

#controls input {
  accent-color: var(--accent);
}

.hidden-control {
  display: none !important;
}

#time-label {
  margin-left: auto;
  color: var(--text);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

#chapters {
  min-height: 36px;
  flex: 1 1 auto;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.chap {
  position: relative;
  min-width: 64px;
  flex: var(--w, 1) 1 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 3px 7px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  cursor: pointer;
}

.chap.active {
  min-width: 280px;
  flex-grow: calc(var(--w, 1) * 4);
  border-color: rgba(199, 255, 73, 0.42);
  background: rgba(199, 255, 73, 0.05);
  cursor: default;
}

.chap-head {
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  color: var(--dim);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chap.active .chap-head {
  color: var(--accent);
  font-weight: 700;
}

.chap-track {
  position: relative;
  min-height: 11px;
  flex: 1;
  border-radius: 3px;
  background: #040806;
}

.chap:not(.active) .chap-track {
  opacity: 0.5;
}

.tl-span {
  position: absolute;
  inset-block: 0;
  border-radius: 2px;
  background: rgba(98, 237, 189, 0.28);
  pointer-events: none;
}

.tl-ev {
  position: absolute;
  pointer-events: auto;
}

.tl-bounce {
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.lc-in { background: var(--cyan); }
.lc-out { background: var(--red); }
.lc-close { background: var(--yellow); }

.tl-hit {
  top: 50%;
  width: 2px;
  height: 8px;
  background: #6d857c;
  transform: translate(-50%, -50%);
}

.tl-head {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--accent);
  pointer-events: none;
}

.chap:not(.active) .tl-head {
  display: none;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 118px;
  z-index: 40;
  transform: translateX(-50%);
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  background: rgba(11, 23, 20, 0.96);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
}

body.free-view #panel3d {
  position: fixed;
  inset: 0;
  z-index: 20;
}

body.free-view #left {
  position: fixed;
  right: 14px;
  bottom: 116px;
  z-index: 25;
  width: 300px;
  padding: 0;
  border: 0;
}

body.free-view .viewer-titlebar {
  position: relative;
  z-index: 30;
}

body.free-view .viewer-controls {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
}

@media (max-width: 900px) {
  .viewer-main {
    grid-template-columns: 1fr;
  }

  #left {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
