:root {
  --bg: #0e1014;
  --panel: #151820;
  --panel-2: #1b1f29;
  --line: #262b37;
  --text: #e8e6e1;
  --muted: #8d93a1;
  --accent: #e8a24a;
  --accent-ink: #1a1206;
  --bad: #ff7a6b;
  --good: #7fd49a;
  --radius: 10px;
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; font-size: 14px; }
button, select, input, textarea { font: inherit; color: inherit; }
button, a.primary { cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); padding: 7px 12px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover { border-color: #3a4152; }
button:disabled { opacity: 0.45; cursor: default; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.primary:hover { filter: brightness(1.06); }
.ghost { background: transparent; }
.small { font-size: 12px; padding: 5px 9px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
select, input:not([type]), input[type=text], textarea { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); user-select: none; }

#top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 600; letter-spacing: 0.02em; display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.mark { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffd79a, var(--accent) 45%, #8a4d14); box-shadow: 0 0 14px rgba(232, 162, 74, 0.5); }
.film-title { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: "Cormorant Garamond", Georgia, serif; font-size: 20px; }
#top nav { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

#studio { flex: 1; display: grid; grid-template-columns: 220px minmax(0, 1fr) 380px; min-height: 0; }
#library, #editor { background: var(--panel); border-right: 1px solid var(--line); padding: 14px; overflow: auto; min-height: 0; }
#editor { border-right: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.group-label { font-size: 11px; color: var(--muted); margin: 14px 0 6px; }
#library ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#library li { display: flex; align-items: center; gap: 6px; }
#library li button.film { flex: 1; text-align: left; justify-content: flex-start; background: transparent; border-color: transparent; padding: 8px 10px; flex-direction: column; align-items: flex-start; gap: 2px; }
#library li button.film:hover { background: var(--panel-2); }
#library li button.film.on { background: var(--panel-2); border-color: var(--accent); }
#library li button.film small { color: var(--muted); font-size: 11px; }
#library li button.del { padding: 4px 8px; font-size: 12px; color: var(--muted); background: transparent; border-color: transparent; }

#viewer { display: flex; flex-direction: column; gap: 10px; padding: 14px; min-width: 0; min-height: 0; overflow: auto; }
#frame { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45); }
#frame canvas#out { width: 100%; height: 100%; display: block; touch-action: none; }
#frame canvas#gl { position: absolute; left: -99999px; top: 0; width: 16px; height: 9px; }
#frame.dir canvas#out { cursor: grab; }
.badge { position: absolute; left: 10px; top: 10px; font-size: 11px; padding: 3px 8px; border-radius: 99px; background: rgba(0, 0, 0, 0.55); color: #ddd; pointer-events: none; }
#frame.dir .badge { background: var(--accent); color: var(--accent-ink); }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.6); color: var(--muted); }
#transport, #director { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.round { min-width: 72px; justify-content: center; }
#scrub { flex: 1; min-width: 160px; accent-color: var(--accent); }
#timeline { position: relative; height: 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; cursor: pointer; }
#marks { position: absolute; inset: 0; }
#marks i { position: absolute; top: 4px; bottom: 4px; width: 2px; border-radius: 1px; }
#marks i.cut { background: var(--accent); }
#marks i.cam { background: #6c7a96; width: 1px; }
#marks i.title { top: auto; bottom: 2px; height: 4px; width: auto; background: #7fa6d4; opacity: 0.8; }
#playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; pointer-events: none; }

#script { flex: 1; min-height: 240px; resize: none; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px; line-height: 1.5; background: #0b0d11; white-space: pre; tab-size: 2; }
.ed-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.ed-head h2 { margin: 0; }
.ed-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ed-foot { display: flex; align-items: center; gap: 10px; }
.errors { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow: auto; }
.errors li { font-size: 12px; color: var(--bad); background: rgba(255, 122, 107, 0.08); border: 1px solid rgba(255, 122, 107, 0.25); padding: 6px 8px; border-radius: 6px; font-family: ui-monospace, Consolas, monospace; }
#status.ok { color: var(--good); }

dialog { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 14px; padding: 0; max-width: min(560px, calc(100vw - 32px)); width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.sheet.wide { max-width: none; }
dialog:has(.wide) { max-width: min(820px, calc(100vw - 32px)); }
.sheet h3 { margin: 0; font-family: "Cormorant Garamond", Georgia, serif; font-size: 26px; font-weight: 600; }
.sheet p { margin: 0; line-height: 1.5; }
.sheet label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 12px; }
.sheet label input, .sheet label textarea, .sheet label select { color: var(--text); font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.steps { margin: 0; padding-left: 20px; line-height: 1.6; }
.progress { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
#ex-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.guide { max-height: 300px; overflow: auto; background: #0b0d11; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 11.5px; line-height: 1.5; white-space: pre-wrap; margin: 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: 0.25s; pointer-events: none; z-index: 10; }
.toast.on { opacity: 1; transform: translateX(-50%); }

@media (max-width: 1180px) {
  #studio { grid-template-columns: 190px minmax(0, 1fr); grid-template-rows: auto auto; align-content: start; overflow: auto; }
  #editor { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  #script { min-height: 320px; }
}
@media (max-width: 720px) {
  #top { flex-wrap: wrap; padding: 10px 16px; }
  .film-title { order: 3; flex-basis: 100%; }
  #studio { display: flex; flex-direction: column; }
  #library { border-right: 0; border-bottom: 1px solid var(--line); max-height: 180px; }
  #viewer { padding: 12px 16px; overflow: visible; }
  #editor { padding: 12px 16px; }
  .grid2 { grid-template-columns: 1fr; }
  #dir-hint { display: none; }
}
