:root {
  --orange: #db7100;
  --orange-hover: #f08520;
  --blue: #067bc2;
  --blue-hover: #0890e0;
  --green: #154522;
  --red: #b23a2f;
  --cream: #f3eed6;
  --paper: #faf8f2;
  --paper-2: #fffdf8;
  --hover: #f0ead8;
  --ink: #202020;
  --muted: #777766;
  --hairline: #bdbdbd;
  --rule: #2a2a2a;
  --shadow: rgba(42, 42, 42, 0.16);
  --radius: 4px;
  --sidebar-w: 318px;
  --render-w: 336px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.35;
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.topbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 18px;
  background: var(--paper);
  border-bottom: 2px solid var(--rule);
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.topbar .sub {
  color: var(--orange);
  font-weight: 700;
}
.backend {
  max-width: 45vw;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(360px, 1fr) var(--render-w);
  height: calc(100vh - 54px);
  background: var(--hairline);
}

.panel {
  min-width: 0;
  background: var(--paper);
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--hairline);
  padding: 16px;
}
.panel:last-child { border-right: 0; }
.panel::-webkit-scrollbar,
.selected-list::-webkit-scrollbar,
.timeline-lists::-webkit-scrollbar { width: 7px; }
.panel::-webkit-scrollbar-thumb,
.selected-list::-webkit-scrollbar-thumb,
.timeline-lists::-webkit-scrollbar-thumb {
  background: #cfc8b9;
  border-radius: 8px;
}

.panel h2,
.panel h3,
legend,
.tl-group h4 {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.panel h2 {
  margin: 0 0 12px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--hairline);
}
.panel h3 { margin: 18px 0 9px; }

fieldset {
  margin: 0 0 12px;
  padding: 9px 0 3px;
  border: 0;
  border-top: 1px solid var(--hairline);
}
legend {
  padding: 0 8px 0 0;
  color: var(--orange);
  background: var(--paper);
}

.config-panel label,
.highlight-builder label,
.scrub-opts label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 7px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select {
  width: 132px;
  min-height: 30px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 5px 7px;
  font: inherit;
  outline: none;
}
select {
  cursor: pointer;
}
input:focus,
select:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(219, 113, 0, 0.16);
}
input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  accent-color: var(--orange);
}
input[type="range"] {
  width: 100%;
  min-height: 24px;
  padding: 0;
  accent-color: var(--orange);
}

button,
#download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 6px 11px;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:hover:not(:disabled),
#download-link:hover {
  background: var(--hover);
  border-color: var(--orange);
  color: var(--orange);
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
button.primary,
#download-link.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
button.primary:hover:not(:disabled),
#download-link.primary:hover {
  background: var(--blue-hover);
  border-color: var(--blue-hover);
  color: #fff;
}
button.danger {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
button.danger:hover:not(:disabled) {
  background: #cf463a;
  border-color: #cf463a;
  color: #fff;
}
button.big {
  width: 100%;
  min-height: 42px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.config-actions,
.action-buttons {
  display: flex;
  gap: 7px;
  margin-top: 4px;
}
.config-actions button { flex: 1; }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 0 14px;
  padding: 3px;
  background: var(--cream);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.mode-btn {
  min-height: 30px;
  background: transparent;
  border-color: transparent;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.mode-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.mode-btn:hover:not(.active) {
  background: #fff;
  border-color: var(--orange);
}

.highlight-builder {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 2px solid var(--rule);
}
#hl-name,
#hl-kind { width: 152px; }
#hl-add { width: 100%; margin-top: 6px; }
#hl-span-row {
  padding: 6px 8px;
  background: var(--cream);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}

.hl-sequence {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 10px 0 0;
}
.hl-sequence li {
  counter-increment: step;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 7px 8px;
  background: #fff;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.hl-sequence li:hover { background: var(--hover); }
.hl-sequence li::before {
  content: counter(step);
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  background: var(--orange);
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.hl-step-body { flex: 1; min-width: 0; }
.hl-step-title {
  overflow: hidden;
  color: var(--ink);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hl-step-meta {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.hl-step-actions {
  display: flex;
  gap: 3px;
  flex: none;
}
.hl-zoom-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  flex: none;
  white-space: nowrap;
}
.hl-zoom-toggle input { cursor: pointer; }
.hl-step-actions button {
  width: 25px;
  min-height: 24px;
  padding: 0;
  line-height: 1;
}
.hl-empty {
  margin: 10px 0 0;
  padding: 10px 8px;
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--hairline);
  border-radius: var(--radius);
  font-size: 12px;
  font-style: italic;
  text-align: center;
}
.hl-error {
  margin-top: 8px;
  padding: 7px 8px;
  color: var(--red);
  background: #fff6f3;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 650;
}
.hidden { display: none !important; }

.timeline-lists {
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
}
.timeline-lists summary {
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.tl-group { margin: 10px 0; }
.tl-group h4 {
  margin: 7px 0 4px;
  color: var(--orange);
}
.tl-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
  min-width: 0;
}
.tl-item span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tl-swatch {
  width: 12px;
  height: 12px;
  border: 1px solid rgba(42, 42, 42, 0.25);
  border-radius: 2px;
  flex: none;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  background: var(--cream);
  padding: 16px;
}
.preview-panel h2 { background: var(--cream); }
.preview-stage {
  position: relative;
  flex: 1;
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background:
    linear-gradient(45deg, rgba(42,42,42,0.045) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(42,42,42,0.045) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(42,42,42,0.045) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(42,42,42,0.045) 75%),
    #f8f5ea;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  border: 2px solid var(--rule);
  border-radius: 0;
  overflow: hidden;
}
#preview-img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 10px 28px var(--shadow);
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}
.preview-stage { cursor: default; }
.preview-stage.draggable { cursor: grab; touch-action: none; }
.preview-stage.panning { cursor: grabbing; }
.scrubber {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
#btn-play {
  width: 42px;
  padding: 0;
  font-size: 15px;
}
.frame-label,
#progress-pct,
.zoom-label {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  white-space: nowrap;
}
.render-stats {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  word-break: break-word;
  overflow-wrap: break-word;
}
.scrub-opts {
  margin-top: 8px;
  color: var(--muted);
}
.scrub-opts select { width: 104px; }

.spinner {
  position: absolute;
  width: 34px;
  height: 34px;
  background: var(--ink);
  border: 2px solid var(--ink);
  animation: ink-pulse 1.1s steps(2, end) infinite;
}
@keyframes ink-pulse {
  0%, 100% { background: var(--ink); }
  50% { background: #fff; }
}

.render-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.render-status {
  padding: 10px;
  background: #fff;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
.progress-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.progress-bar {
  height: 10px;
  background: var(--cream);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  overflow: hidden;
}
#progress-fill {
  width: 0%;
  height: 100%;
  background: var(--orange);
  border-radius: inherit;
  transition: width 0.2s;
}
.render-stats {
  margin-bottom: 10px;
  font-size: 11px;
  line-height: 1.55;
}
.render-result {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}
#result-video {
  width: 100%;
  background: #000;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
#download-link { min-height: 34px; }

.job-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
}
.job-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
  padding: 7px 8px;
  background: #fff;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.job-list li:hover {
  border-color: var(--blue);
}
.job-list li.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px var(--blue);
}
.job-list li > span:first-child {
  overflow: hidden;
  color: var(--muted);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.job-state {
  padding: 2px 7px;
  border-radius: 999px;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.job-state.starting { background: #777766; opacity: 0.7; }
.job-state.queued { background: #777766; }
.job-state.rendering { background: var(--blue); }
.job-state.done { background: var(--green); }
.job-state.failed,
.job-state.cancelled { background: var(--red); }
.job-actions button {
  min-height: 25px;
  padding: 3px 8px;
  font-size: 11px;
}

@media (max-width: 1000px) {
  html, body { overflow: auto; }
  .layout {
    grid-template-columns: 310px minmax(360px, 1fr);
    height: auto;
    min-height: calc(100vh - 54px);
  }
  .render-panel {
    grid-column: 1 / -1;
    border-top: 1px solid var(--hairline);
  }
}

@media (max-width: 760px) {
  .topbar {
    height: auto;
    min-height: 54px;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }
  .backend { max-width: 100%; white-space: normal; }
  .layout {
    display: block;
    height: auto;
  }
  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
  }
  .preview-stage { min-height: 300px; }
  .scrubber { grid-template-columns: 38px minmax(0, 1fr); }
  .frame-label { grid-column: 1 / -1; }
  input,
  select { width: min(152px, 52vw); }
}
