:root {
  --bg: #161616;
  --panel: #1f1f1f;
  --panel-2: #2a2a2a;
  --line: #333;
  --text: #e6e6e6;
  --muted: #8a8a8a;
  --accent: #ffb347;
  --accent-ink: #1a1206;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  font: 12px/1.4 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  user-select: none;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

/* ---------- sidebar ---------- */

#sidebar {
  width: 280px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.titlebar {
  -webkit-app-region: drag;
  height: 52px;
  padding: 0 14px 0 84px; /* clear the traffic lights */
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.app-name {
  font-weight: 700;
  letter-spacing: .04em;
}

.file-name {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  padding: 6px 14px 14px;
}

section {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

section:last-child {
  border-bottom: 0;
}

h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #333;
}

button:disabled {
  opacity: .4;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: #ffc36e;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row>button {
  flex: 1;
}

.row.small>button {
  flex: none;
}

.row output {
  margin-left: auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 12px 0;
}

.seg {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
  margin-bottom: 12px;
}

.seg button {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 5px 0;
  border-radius: 5px;
  color: var(--muted);
}

.seg button.on {
  background: var(--panel-2);
  color: var(--text);
  box-shadow: 0 1px 2px #0006;
}

.slider {
  display: block;
  margin-bottom: 10px;
}

.slider>span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}

.slider output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type=range] {
  width: 100%;
  accent-color: var(--accent);
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

kbd {
  margin-left: auto;
  font: 10px ui-monospace, monospace;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0 4px;
}

#status {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: grid;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  background: #666;
}

.dot.on {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

#render-status.error {
  color: #ff7a7a;
  user-select: text;
}

/* ---------- viewport ---------- */

#viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background:
    repeating-conic-gradient(#1b1b1b 0 25%, #181818 0 50%) 0 0 / 24px 24px;
  touch-action: none;
}

#viewport.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -10px;
}

#empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.drop-target {
  display: grid;
  gap: 6px;
  text-align: center;
  padding: 40px 56px;
  border: 1.5px dashed #444;
  border-radius: 14px;
  color: var(--muted);
}

.drop-target strong {
  color: var(--text);
  font-size: 15px;
}

.hint {
  font-size: 11px;
}

#stage {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  box-shadow: 0 10px 40px #000a;
}

#stage>* {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* the viewport handles all pointer input; an <img> target would start a native drag and cancel the stroke */
  pointer-events: none;
  -webkit-user-drag: none;
}

#stage canvas#source {
  position: relative;
}

/* same Ultra HDR file twice; the SDR copy is clamped to standard range */
#preview-hdr {
  dynamic-range-limit: no-limit;
}

#preview-sdr {
  dynamic-range-limit: standard;
}

/* gray mask -> warm tint; screen blend leaves black (no boost) untouched */
#mask,
#stroke {
  mix-blend-mode: screen;
  filter: sepia(1) saturate(6) hue-rotate(-20deg);
  pointer-events: none;
}

#stroke.erase {
  filter: sepia(1) saturate(6) hue-rotate(170deg);
}

#stage.pixelated>* {
  image-rendering: pixelated;
}

#divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: #fff;
  box-shadow: 0 0 0 1px #0008;
  cursor: ew-resize;
}

#divider::after {
  content: 'SDR  ·  HDR';
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  white-space: pre;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #000a;
  color: #fff;
}

#divider::before {
  content: '';
  position: absolute;
  inset: 0 -8px;
}

#cursor {
  position: absolute;
  pointer-events: none;
  border-radius: 50%;
  border: 1px solid #fff;
  box-shadow: 0 0 0 1px #000a, inset 0 0 0 1px #000a;
  transform: translate(-50%, -50%);
}

#cursor::after {
  content: '';
  position: absolute;
  inset: var(--inner, 0);
  border-radius: 50%;
  border: 1px dashed #fff8;
}

#viewport.panning,
#viewport.panning * {
  cursor: grabbing !important;
}

#viewport.can-pan {
  cursor: grab;
}

#viewport.brushing {
  cursor: none;
}

#busy {
  position: absolute;
  right: 14px;
  top: 14px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff3;
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}
