/* Grade Studio – neutral grey UI so the interface never biases colour judgement. */
:root {
  --bg: #161617; --panel: #1d1d1f; --panel2: #242427; --line: #2f2f33; --line2: #3a3a3f;
  --text: #e6e6e8; --muted: #8d8d94; --faint: #5d5d63;
  --accent: #d9a441; --accent-ink: #1a1408; --ok: #5fb37a; --bad: #e0675c;
  --histo: #9a9aa2; --radius: 8px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
.small { font-size: 12px; } .muted { color: var(--muted); } .err { color: var(--bad); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ---------------------------------------------------------------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 14px; border-radius: 6px;
  border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s; }
.btn:hover:not(:disabled) { background: #2c2c30; border-color: #4a4a50; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #e5b456; border-color: #e5b456; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); background: var(--panel2); }
.btn.wide { width: 100%; margin-top: 8px; }
.link { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }
.link:hover { color: var(--text); }
.icon { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 6px; border: 0; background: transparent; cursor: pointer; color: var(--text); }
.icon:hover:not(:disabled) { background: var(--panel2); }
.icon:disabled { opacity: .4; cursor: not-allowed; }
.icon svg { width: 18px; height: 18px; fill: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- top bar */
.top { height: 48px; display: flex; align-items: center; gap: 16px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; letter-spacing: .01em; }
.brand-mark { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--accent); background: linear-gradient(90deg, transparent 50%, var(--accent) 50%); }
.top-title { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
.top-actions { display: flex; gap: 4px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); margin-right: 2px; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); }

/* ---------------------------------------------------------------- layout */
.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr) 310px; height: calc(100vh - 48px); overflow: hidden; }
@media (min-width: 961px) { body { overflow: hidden; } }
.panel { background: var(--panel); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }
.step { padding: 14px 16px 16px; border-bottom: 1px solid var(--line); }
.step h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: #c4c4ca; }
.step h2 .link, .step h2 .val { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; }
.step h2 .val { color: var(--text); font-family: var(--mono); font-size: 12px; }
.num { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line2); font-size: 10px; color: var(--muted); }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
select { width: 100%; height: 32px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--line2); background: var(--panel2); }
label { display: block; color: var(--muted); font-size: 12px; }
label select { margin-top: 4px; color: var(--text); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }

/* ---------------------------------------------------------------- upload + library */
.drop { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 18px 10px; border: 1.5px dashed var(--line2); border-radius: var(--radius);
  cursor: pointer; color: var(--muted); text-align: center; transition: border-color .15s, background .15s; }
.drop strong { color: var(--text); font-weight: 600; }
.drop:hover, .drop.over { border-color: var(--accent); background: rgba(217, 164, 65, .06); }
.upload-progress { margin-top: 10px; display: grid; gap: 6px; }
.bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.bar.indeterminate i { width: 35%; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
.library { margin-top: 12px; display: grid; gap: 6px; }
.clip { display: flex; align-items: center; border-radius: 6px; border: 1px solid transparent; }
.clip.on { background: var(--panel2); border-color: var(--line2); }
.clip:hover { background: var(--panel2); }
.clip-main { flex: 1; display: flex; align-items: center; gap: 10px; padding: 6px; background: none; border: 0; text-align: left; cursor: pointer; min-width: 0; }
.clip img, .clip .ph { width: 64px; height: 36px; object-fit: cover; border-radius: 4px; background: #000; flex: none; }
.clip-text { display: grid; min-width: 0; }
.clip-text b { font-weight: 550; }
.clip-text small { color: var(--muted); }
.clip .del { opacity: 0; color: var(--muted); }
.clip:hover .del { opacity: 1; }

/* ---------------------------------------------------------------- looks */
.looks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.look { padding: 0; border: 1px solid var(--line); background: var(--panel2); border-radius: 6px; overflow: hidden; cursor: pointer; text-align: left; transition: border-color .15s; }
.look canvas { display: block; width: 100%; aspect-ratio: 16 / 9; background: #0c0c0d; }
.look span { display: block; padding: 5px 7px; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.look:hover { border-color: #55555c; }
.look.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.look.on span { color: var(--accent); }

/* ---------------------------------------------------------------- range inputs */
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; margin: 0; background: transparent; cursor: pointer;
  --a: 0%; --b: 0%; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, var(--line2) var(--a), var(--accent) var(--a), var(--accent) var(--b), var(--line2) var(--b)); }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: linear-gradient(90deg, var(--line2) var(--a), var(--accent) var(--a), var(--accent) var(--b), var(--line2) var(--b)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; margin-top: -5px; border-radius: 50%; background: #d8d8dc; border: 0; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: #d8d8dc; border: 0; }
input[type="range"]:disabled { opacity: .4; }
#intensity, #scrub, #exCrf, #exBitrate { --a: 0%; }
.slider-group h3 { margin: 12px 0 4px; font-size: 11px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .07em; }
.slider-group:first-child h3 { margin-top: 0; }
.slider-row { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 8px; padding: 3px 0; color: #b9b9bf; }
.slider-row input { grid-column: 1 / -1; }
.slider-row output { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.slider-row.changed output { color: var(--text); }

/* ---------------------------------------------------------------- automatic */
.job-inline { display: grid; gap: 6px; margin-top: 10px; }
.switch { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--text); font-size: 12.5px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 30px; height: 17px; border-radius: 9px; background: var(--line2); position: relative; transition: background .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #ddd; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(13px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.auto-values { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; margin: 10px 0 0; }
.auto-values div { display: flex; justify-content: space-between; }
.auto-values dt { color: var(--muted); } .auto-values dd { margin: 0; font-family: var(--mono); font-size: 11.5px; }
.notes { margin: 10px 0 0; padding-left: 16px; color: var(--muted); font-size: 12px; }
.notes li { margin: 3px 0; }

/* ---------------------------------------------------------------- viewer */
.viewer { display: flex; flex-direction: column; min-width: 0; background: #0f0f10; }
.viewer-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 12px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line2); }
.seg button.on { background: var(--panel2); color: var(--text); }
.stage { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; padding: 16px; overflow: hidden; user-select: none; }
#stage:not(.has-video) #canvas, #stage:not(.has-video) .split-handle { display: none; }
#canvas { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; background: #000; box-shadow: 0 0 0 1px #222; touch-action: none; }
.split-handle { position: absolute; width: 2px; margin-left: -1px; background: rgba(255,255,255,.85); cursor: ew-resize; pointer-events: auto; }
.split-handle::before { content: ""; position: absolute; top: 50%; left: -11px; width: 24px; height: 24px; margin-top: -12px; border-radius: 50%; background: rgba(20,20,22,.75); border: 2px solid #fff; }
.split-handle span { position: absolute; top: 8px; padding: 2px 6px; font-size: 10.5px; background: rgba(0,0,0,.6); border-radius: 3px; white-space: nowrap; text-transform: uppercase; letter-spacing: .05em; }
.split-handle span:first-child { right: 10px; } .split-handle span:last-child { left: 10px; }
#exactImg { position: absolute; inset: 16px; width: calc(100% - 32px); height: calc(100% - 32px); object-fit: contain; cursor: zoom-out; }
.exact-badge { position: absolute; top: 24px; left: 50%; transform: translateX(-50%); padding: 4px 10px; background: var(--accent); color: var(--accent-ink); border-radius: 4px; font-size: 12px; font-weight: 600; cursor: pointer; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; text-align: center; color: var(--muted); padding: 24px; }
.empty p { max-width: 380px; margin: 0; }
.empty strong { color: var(--text); }
.empty-mark { width: 54px; height: 54px; border-radius: 50%; border: 3px solid var(--line2); background: linear-gradient(90deg, transparent 50%, var(--line2) 50%); }
.busy { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, 80%); display: grid; gap: 8px; text-align: center; color: var(--muted); background: rgba(22,22,23,.92); padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); }
.transport { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel); }
.tc { font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
#scrub { flex: 1; }
.meta-line { padding: 0 14px 6px; background: var(--panel); }
.histo { display: block; width: 100%; height: 56px; background: var(--panel); border-top: 1px solid var(--line); padding: 4px 12px 0; }

/* ---------------------------------------------------------------- export */
.exports { display: grid; gap: 8px; margin-top: 12px; }
.export { display: grid; gap: 7px; padding: 10px; border-radius: 6px; background: var(--panel2); border: 1px solid var(--line); }
.export b { font-weight: 600; font-size: 12.5px; }
.tag { font-size: 10.5px; padding: 1px 6px; border-radius: 3px; background: var(--line); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.export.done .tag { background: rgba(95,179,122,.18); color: var(--ok); }
.export.running .tag { background: rgba(217,164,65,.18); color: var(--accent); }
.export.error .tag { background: rgba(224,103,92,.18); color: var(--bad); }
.export .btn { height: 28px; }

/* ---------------------------------------------------------------- dialogs, toasts */
.dialog { width: min(560px, calc(100vw - 32px)); background: var(--panel); color: var(--text); border: 1px solid var(--line2); border-radius: 10px; padding: 0 18px 18px; }
.dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin: 0 -18px 4px; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h3 { margin: 0; font-size: 14px; }
.lut-form { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 14px 0; }
.lut-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.lut-list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; background: var(--panel2); border-radius: 6px; }
.lut-list small { display: block; color: var(--muted); }
.checks { width: 100%; border-collapse: collapse; margin-top: 10px; }
.checks td { padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.checks td:last-child { color: var(--muted); font-size: 12px; word-break: break-word; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: 380px; }
.toast { padding: 10px 14px; border-radius: 8px; background: #2a2a2e; border: 1px solid var(--line2); box-shadow: 0 8px 24px rgba(0,0,0,.4); transition: opacity .35s, transform .35s; }
.toast.error { border-color: rgba(224,103,92,.6); }
.toast.ok { border-color: rgba(95,179,122,.6); }
.toast.out { opacity: 0; transform: translateY(6px); }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(340px, 100%); display: grid; gap: 10px; padding: 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.login-card .brand { margin-bottom: 10px; font-size: 16px; }
.login-card input { height: 36px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--line2); background: var(--panel2); }
.login-card .err { margin: 0; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 260px minmax(0, 1fr) 280px; }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .viewer { order: -1; min-height: 56vh; }
  .panel { overflow: visible; border: 0 !important; }
  .top-title { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
