*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:      #0f0f11;
  --bg-panel:     #16161a;
  --bg-card:      #1e1e24;
  --bg-hover:     #2a2a33;
  --border:       #2e2e38;
  --border-light: #3a3a46;
  --text-pri:     #e8e8f0;
  --text-sec:     #8888a0;
  --text-dim:     #55556a;
  --accent:       #4f8ef7;
  --accent-dim:   #2a4a8a;
  --green:        #22c55e;
  --green-dim:    #14532d;
  --yellow:       #eab308;
  --yellow-dim:   #713f12;
  --red:          #ef4444;
  --red-dim:      #7f1d1d;
  --gray-btn:     #6b7280;
  --gray-dim:     #1f2937;
  --font-mono:    'Courier New', Courier, monospace;
  --font-ui:      -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  --radius:       10px;
  --radius-sm:    6px;
  --bottom-h:     52px;
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg-base);
  color: var(--text-pri);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ─── APP SHELL ─────────────────────────────────────────── */
#app { display: flex; flex-direction: column; width: 100vw; height: 100vh; }

/* ─── HEADER ────────────────────────────────────────────── */
#header {
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 16px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  flex-shrink: 0; z-index: 50;
}
.header-logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 30px; height: 30px; background: var(--accent);
  border-radius: 7px; display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 900; color: #fff; letter-spacing: -1px;
}
.logo-text { font-size: 15px; font-weight: 700; letter-spacing: 0.5px; }
.logo-sub  { font-size: 10px; color: var(--text-sec); letter-spacing: 1.5px; text-transform: uppercase; }
.header-center { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-sec); }
.prod-name { color: var(--text-pri); font-weight: 600; }
.header-pill { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; }
.pill-rec     { background: #7f1d1d; color: #fca5a5; }
.pill-day     { background: var(--bg-card); color: var(--text-sec); border: 1px solid var(--border); }
.pill-online  { background: #14532d; color: #86efac; }
.pill-offline { background: #78350f; color: #fde68a; animation: pill-pulse 1.6s ease-in-out infinite; }
@keyframes pill-pulse { 0%,100%{ opacity:1 } 50%{ opacity:.55 } }
.header-actions { display: flex; align-items: center; gap: 8px; }
.hdr-btn {
  height: 34px; padding: 0 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-pri); border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 6px; transition: background 0.15s;
}
.hdr-btn:active { background: var(--bg-hover); }
.hdr-btn.accent { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ─── MAIN ──────────────────────────────────────────────── */
#main { flex: 1; display: flex; overflow: hidden; min-height: 0; }

/* ─── LEFT PANEL ────────────────────────────────────────── */
#left-panel {
  width: 58%; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); overflow: hidden; position: relative; min-height: 0;
}

/* Tool Dock */
#tool-dock {
  display: flex; align-items: center; gap: 5px;
  padding: 7px 12px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: nowrap; overflow-x: auto;
}
#tool-dock::-webkit-scrollbar { display: none; }
.tool-sep { width: 1px; height: 26px; background: var(--border); margin: 0 3px; flex-shrink: 0; }
.tool-btn {
  height: 36px; padding: 0 11px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-sec);
  font-size: 12px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  transition: all 0.15s; white-space: nowrap; flex-shrink: 0;
}
.tool-btn:active { opacity: 0.7; }
.tool-btn.active        { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.tool-btn.active-highlight { background: #422006; border-color: var(--yellow); color: var(--yellow); }
.tool-btn.active-pen    { background: #1a1a3e; border-color: #818cf8; color: #818cf8; }
.tool-btn.undo-btn      { color: var(--text-sec); }
.tool-btn.undo-btn:disabled { opacity: 0.3; cursor: default; }
.tool-icon { font-size: 13px; }
.tool-dock-right { margin-left: auto; display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
select.tool-select {
  height: 36px; padding: 0 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-sec); border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 600; cursor: pointer;
}
select.tool-select:focus { outline: none; }

/* Scene Tabs */
#scene-tabs {
  display: flex; gap: 4px; padding: 0 12px;
  border-bottom: 1px solid var(--border); background: var(--bg-panel);
  overflow-x: auto; flex-shrink: 0; scrollbar-width: none;
}
#scene-tabs::-webkit-scrollbar { display: none; }
.scene-tab {
  padding: 9px 14px; font-size: 12px; font-weight: 600;
  color: var(--text-dim); cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap; transition: all 0.15s;
}
.scene-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Canvas Wrap */
#canvas-wrap { flex: 1; position: relative; overflow: hidden; }
#script-scroll {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  padding: 24px 20px 32px 64px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
#lining-gutter {
  position: absolute; left: 0; top: 0; width: 60px; height: 100%;
  pointer-events: none; z-index: 5;
}
.lining-line { position: absolute; width: 4px; border-radius: 2px; opacity: 0.85; }
.lining-label {
  position: absolute; font-size: 9px; font-weight: 800; letter-spacing: 0.5px;
  writing-mode: vertical-rl; transform: rotate(180deg);
}
#draw-canvas { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#draw-canvas.drawing-mode { pointer-events: all; cursor: crosshair; }

/* Script */
.script-page { max-width: 580px; font-family: var(--font-mono); font-size: 13.5px; line-height: 1.75; color: var(--text-pri); }
.scene-heading {
  font-weight: 700; text-transform: uppercase; color: #e2e8ff;
  margin: 28px 0 8px; letter-spacing: 0.5px; padding: 6px 10px;
  background: rgba(79,142,247,0.08); border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
}
.scene-heading:first-child { margin-top: 0; }
.action-line { color: #c8c8de; margin: 8px 0; line-height: 1.8; }
.dialogue-block { margin: 16px 0 16px 60px; position: relative; }
.character-name { text-align: center; font-weight: 700; text-transform: uppercase; color: #a0a0c0; margin-bottom: 2px; font-size: 13px; }
.parenthetical { text-align: center; color: var(--text-sec); font-style: italic; font-size: 12.5px; margin-bottom: 2px; }
.speech { text-align: center; color: var(--text-pri); max-width: 320px; margin: 0 auto; line-height: 1.85; }
.highlight-mark { background: rgba(234,179,8,0.25); border-radius: 2px; }

/* Script left-panel image zone */
.img-attachment-zone {
  margin: 20px 0; border: 1.5px dashed var(--border-light);
  border-radius: var(--radius); padding: 14px; background: rgba(255,255,255,0.02);
}
.img-zone-label { font-size: 10px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-dim); margin-bottom: 10px; }
.img-thumbnails { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
.img-thumb {
  width: 80px; height: 60px; border-radius: var(--radius-sm); overflow: hidden;
  border: 2px solid var(--border); cursor: pointer; position: relative;
  background: var(--bg-card); display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--text-dim); transition: border-color 0.15s;
}
.img-thumb:active { border-color: var(--accent); }
.img-thumb img { width: 100%; height: 100%; object-fit: cover; }
.img-thumb .del-thumb {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: rgba(0,0,0,0.7); color: #fff;
  font-size: 10px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.add-img-btn {
  width: 80px; height: 60px; border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border-light); background: transparent;
  color: var(--text-dim); font-size: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.add-img-btn:active { border-color: var(--accent); color: var(--accent); }

/* ─── RIGHT PANEL ───────────────────────────────────────── */
#right-panel { width: 42%; display: flex; flex-direction: column; overflow: hidden; min-height: 0; background: var(--bg-panel); }
#right-scroll {
  flex: 1; overflow-y: auto; min-height: 0; padding: 14px 14px 32px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.r-section { margin-bottom: 14px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.r-section-head {
  padding: 8px 14px; font-size: 10px; font-weight: 800;
  letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--text-dim); background: rgba(0,0,0,0.2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.r-section-body { padding: 14px; }

/* Counters */
.counters-row { display: flex; gap: 10px; }
.counter-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.counter-label { font-size: 10px; font-weight: 800; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-sec); }
.counter-controls {
  display: flex; align-items: center;
  background: var(--bg-base); border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
}
.cnt-btn {
  width: 44px; height: 50px; background: transparent; border: none;
  color: var(--text-sec); font-size: 20px; font-weight: 300;
  cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.1s;
}
.cnt-btn:active { background: var(--bg-hover); color: var(--text-pri); }
.cnt-val { min-width: 52px; text-align: center; font-size: 28px; font-weight: 800; color: var(--text-pri); letter-spacing: -1px; font-variant-numeric: tabular-nums; }

/* Status */
.status-row { display: flex; gap: 8px; }
.status-btn {
  flex: 1; height: 52px; border: 2px solid; border-radius: var(--radius);
  font-size: 15px; font-weight: 900; letter-spacing: 1.5px; cursor: pointer;
  transition: all 0.15s; display: flex; align-items: center; justify-content: center;
}
.status-btn.ng    { border-color: var(--red);    color: var(--red);    background: transparent; }
.status-btn.ng.active { background: var(--red-dim); }
.status-btn.ok    { border-color: var(--yellow);  color: var(--yellow); background: transparent; }
.status-btn.ok.active { background: var(--yellow-dim); }
.status-btn.print { border-color: var(--green);  color: var(--green);  background: transparent; }
.status-btn.print.active { background: var(--green-dim); }
.status-btn.fs    { border-color: var(--gray-btn); color: var(--gray-btn); background: transparent; }
.status-btn.fs.active { background: var(--gray-dim); }
.status-btn:active { opacity: 0.75; transform: scale(0.97); }

/* Fields */
.dropdowns-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-sec); }
.field-select, .field-input, .field-textarea {
  height: 44px; padding: 0 12px;
  background: var(--bg-base); border: 1px solid var(--border);
  color: var(--text-pri); border-radius: var(--radius-sm);
  font-size: 14px; font-family: var(--font-ui);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238888a0' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  cursor: pointer; transition: border-color 0.15s;
}
.field-select:focus, .field-input:focus, .field-textarea:focus { outline: none; border-color: var(--accent); }
.field-input { background-image: none; }
.field-textarea { height: auto; min-height: 72px; padding: 10px 12px; resize: none; line-height: 1.6; background-image: none; }
.field-full { grid-column: 1 / -1; }
.dir-row { display: flex; gap: 6px; }
.dir-btn {
  flex: 1; height: 40px; background: var(--bg-base); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-sec); font-size: 12px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 4px; transition: all 0.15s;
}
.dir-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ─── CONTINUITY PHOTO GRID (right panel) ───────────────── */
.cont-photos-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 0;
}
.cont-photo-card {
  position: relative; border-radius: var(--radius-sm);
  border: 2px solid var(--border); overflow: hidden;
  background: var(--bg-base); aspect-ratio: 4/3;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: border-color 0.15s;
}
.cont-photo-card:active { border-color: var(--accent); }
.cont-photo-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cont-photo-card .card-emoji { font-size: 26px; color: var(--text-dim); }
.cont-photo-card .card-annotated-badge {
  position: absolute; bottom: 4px; left: 4px;
  background: rgba(79,142,247,0.85); color: #fff;
  font-size: 9px; font-weight: 800; letter-spacing: 0.5px;
  padding: 2px 6px; border-radius: 4px; pointer-events: none;
}
.cont-photo-card .card-del {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,0.75); color: #fff;
  font-size: 11px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: 1px solid rgba(255,255,255,0.15);
}
.cont-photo-card .card-annotate-btn {
  position: absolute; bottom: 4px; right: 4px;
  height: 22px; padding: 0 7px; border-radius: 4px;
  background: rgba(79,142,247,0.9); color: #fff;
  font-size: 10px; font-weight: 700; cursor: pointer; border: none;
  display: flex; align-items: center; gap: 3px;
}
.cont-add-card {
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border-light);
  background: transparent; aspect-ratio: 4/3;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; cursor: pointer; color: var(--text-dim);
  transition: all 0.15s; font-size: 11px; font-weight: 600;
}
.cont-add-card .add-plus { font-size: 22px; }
.cont-add-card:active { border-color: var(--accent); color: var(--accent); }

/* Save button */
.save-btn {
  width: 100%; height: 52px;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  border: none; border-radius: var(--radius);
  color: #fff; font-size: 16px; font-weight: 800; letter-spacing: 1px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: opacity 0.15s, transform 0.1s;
  box-shadow: 0 4px 20px rgba(34,197,94,0.3);
}
.save-btn:active { opacity: 0.85; transform: scale(0.98); }
.save-btn-update {
  background: linear-gradient(135deg, #b45309, #f59e0b) !important;
  box-shadow: 0 4px 20px rgba(245,158,11,0.35) !important;
}

/* ─── BOTTOM SHEET ──────────────────────────────────────── */
#bottom-sheet {
  flex-shrink: 0;
  height: 46vh;
  background: var(--bg-panel); border-top: 1px solid var(--border);
  transition: height 0.35s cubic-bezier(.4,0,.2,1);
  z-index: 100; display: flex; flex-direction: column; overflow: hidden;
}
#bottom-sheet.collapsed { height: var(--bottom-h); }
.bs-handle {
  height: var(--bottom-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; cursor: pointer; flex-shrink: 0; border-bottom: 1px solid var(--border);
}
.bs-handle-left { display: flex; align-items: center; gap: 10px; }
.bs-pill { width: 40px; height: 4px; background: var(--border-light); border-radius: 2px; }
.bs-title { font-size: 13px; font-weight: 700; color: var(--text-pri); }
.bs-count { background: var(--accent-dim); color: var(--accent); padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.bs-actions { display: flex; align-items: center; gap: 8px; }
.export-btn {
  height: 34px; padding: 0 14px;
  background: #064e3b; border: 1px solid var(--green); color: var(--green);
  border-radius: var(--radius-sm); font-size: 12px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; gap: 6px; transition: background 0.15s;
}
.export-btn:active { background: var(--green-dim); }
#log-scroll { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
#log-table { width: 100%; border-collapse: collapse; font-size: 12px; }
#log-table thead tr { background: rgba(0,0,0,0.3); position: sticky; top: 0; z-index: 2; }
#log-table th { padding: 10px 12px; text-align: left; font-weight: 700; font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--text-dim); border-bottom: 1px solid var(--border); white-space: nowrap; }
#log-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-sec); vertical-align: middle; }
#log-table tbody tr:hover { background: var(--bg-hover); }
.log-row { cursor: pointer; transition: background 0.12s; }
.log-row:active { background: rgba(79,142,247,0.08); }
.log-row-active { background: rgba(245,158,11,0.10) !important; outline: 1px solid rgba(245,158,11,0.4); outline-offset: -1px; }
.log-num   { color: var(--text-dim); width: 32px; }
.log-scene { color: var(--text-pri); font-weight: 600; white-space: nowrap; }
.log-slate { color: var(--text-pri); white-space: nowrap; }
.log-lens  { color: var(--text-sec); white-space: nowrap; font-size: 11px; }
.log-note  { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-sec); }
.log-time  { color: var(--text-dim); white-space: nowrap; font-size: 11px; }
.result-badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 800; letter-spacing: 0.5px; }
.badge-ng { background: var(--red-dim); color: var(--red); }
.badge-ok { background: var(--yellow-dim); color: var(--yellow); }
.badge-print { background: var(--green-dim); color: var(--green); }
.badge-fs { background: var(--gray-dim); color: var(--gray-btn); }
.empty-log { text-align: center; padding: 40px; color: var(--text-dim); font-size: 13px; }

/* ─── TOAST ─────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 70px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-pri); padding: 10px 20px;
  border-radius: 30px; font-size: 13px; font-weight: 600;
  opacity: 0; transition: all 0.3s; z-index: 400;
  pointer-events: none; white-space: nowrap;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── ANNOTATION MODAL ──────────────────────────────────── */
#annotate-modal {
  position: fixed; inset: 0;
  background: #080809;
  z-index: 500;
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
#annotate-modal.open { opacity: 1; pointer-events: all; }

/* Annotation toolbar */
#ann-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 14px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  flex-shrink: 0; overflow-x: auto; scrollbar-width: none;
}
#ann-toolbar::-webkit-scrollbar { display: none; }
.ann-btn {
  height: 38px; padding: 0 13px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-sec);
  font-size: 12px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: all 0.15s; flex-shrink: 0;
}
.ann-btn:active { opacity: 0.7; }
.ann-btn.active       { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.ann-btn.active-hl    { background: #422006; border-color: var(--yellow); color: var(--yellow); }
.ann-btn.active-pen   { background: #1a1a3e; border-color: #818cf8; color: #818cf8; }
.ann-btn.active-text  { background: #1a2e1a; border-color: var(--green); color: var(--green); }
.ann-btn.active-erase { background: #2e1a1a; border-color: var(--red); color: var(--red); }
.ann-sep { width: 1px; height: 28px; background: var(--border); margin: 0 3px; flex-shrink: 0; }
.ann-save-btn {
  height: 38px; padding: 0 18px;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  border: none; border-radius: var(--radius-sm);
  color: #fff; font-size: 13px; font-weight: 800; cursor: pointer;
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(34,197,94,0.35); transition: opacity 0.15s;
}
.ann-save-btn:active { opacity: 0.8; }
.ann-close-btn {
  height: 38px; padding: 0 14px;
  background: var(--red-dim); border: 1px solid var(--red);
  border-radius: var(--radius-sm); color: var(--red);
  font-size: 12px; font-weight: 700; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; gap: 6px;
}
.ann-close-btn:active { opacity: 0.7; }
select.ann-select {
  height: 38px; padding: 0 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-sec); border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; cursor: pointer; flex-shrink: 0;
}
select.ann-select:focus { outline: none; }
.ann-color-dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3); cursor: pointer;
  flex-shrink: 0; transition: transform 0.1s;
}
.ann-color-dot:active { transform: scale(0.85); }
.ann-color-dot.selected { border-color: #fff; }

/* Canvas body */
#ann-body {
  flex: 1; overflow: hidden; position: relative;
  display: flex; align-items: center; justify-content: center;
  background: #080809;
}
#ann-canvas {
  display: block; touch-action: none;
  cursor: crosshair;
  border: 1px solid var(--border-light);
  max-width: 100%; max-height: 100%;
}

/* Note label strip */
#ann-note-strip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--bg-panel); border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#ann-note-input {
  flex: 1; height: 38px; padding: 0 12px;
  background: var(--bg-base); border: 1px solid var(--border);
  color: var(--text-pri); border-radius: var(--radius-sm);
  font-size: 13px; font-family: var(--font-ui);
}
#ann-note-input:focus { outline: none; border-color: var(--accent); }
#ann-note-input::placeholder { color: var(--text-dim); }
.ann-note-label { font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-sec); white-space: nowrap; }

/* ─── RIGHT PANEL TABS ──────────────────────────────────── */
#r-tabs {
  display: flex; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  overflow-x: auto; scrollbar-width: none;
}
#r-tabs::-webkit-scrollbar { display: none; }
.r-tab {
  flex: 1; padding: 9px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 15px; color: var(--text-dim); cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.r-tab:active { background: var(--bg-hover); }
.r-tab.active { color: var(--accent); border-bottom-color: var(--accent); background: rgba(79,142,247,0.06); }
.r-tab-label { font-size: 9px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; color: inherit; }
.r-tab-pane { display: none; }
.r-tab-pane.active { display: block; animation: rPaneFadeIn 0.18s ease; }
@keyframes rPaneFadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ═══════════════════════════════════════════════════════════
   IMPORT MODAL
═══════════════════════════════════════════════════════════ */
#import-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(3px);
  z-index: 900;
}
#import-overlay.open { display: block; }

#import-modal {
  display: none; position: fixed;
  top: 50%; left: 50%; transform: translate(-50%,-50%) scale(0.95);
  width: min(540px, 92vw);
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 14px; z-index: 901;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
  opacity: 0; transition: opacity 0.18s ease, transform 0.18s ease;
}
#import-modal.open {
  display: flex; flex-direction: column;
}
#import-modal.visible {
  opacity: 1; transform: translate(-50%,-50%) scale(1);
}

.import-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.import-modal-title { font-size: 15px; font-weight: 700; color: var(--text); }
.import-close-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer; padding: 2px 6px; border-radius: 6px;
  line-height: 1;
}
.import-close-btn:active { background: var(--bg-hover); }

#import-drop-zone {
  margin: 18px; padding: 36px 20px;
  border: 2px dashed var(--border); border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center; transition: border-color 0.15s, background 0.15s;
  cursor: default;
}
#import-drop-zone.drag-over {
  border-color: var(--accent); background: rgba(79,142,247,0.08);
}
.import-drop-icon { font-size: 40px; line-height: 1; }
.import-drop-text { font-size: 15px; font-weight: 600; color: var(--text); }
.import-drop-sub  { font-size: 12px; color: var(--text-dim); }
.import-browse-btn {
  margin-top: 10px; padding: 8px 22px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 13px; cursor: pointer;
  transition: background 0.15s;
}
.import-browse-btn:active { background: var(--bg-hover); }

#import-status {
  min-height: 20px; margin: 0 18px;
  font-size: 12px; color: var(--text-dim); text-align: center;
}
#import-status.ok  { color: var(--green); }
#import-status.err { color: var(--red); }

.import-modal-footer {
  padding: 14px 18px 16px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}
.import-action-btn {
  padding: 9px 26px; border-radius: 8px;
  background: var(--accent); border: none;
  color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s;
}
.import-action-btn:disabled { opacity: 0.35; cursor: default; }
.import-action-btn:not(:disabled):active { opacity: 0.8; }

/* ═══ Imported Script Viewer ══ */
/* #script-imported-view sits inside .script-page so it inherits
   font-family, font-size, line-height, color from .script-page.
   Individual block styles come from the shared screenplay classes. */
#script-imported-view {
  padding-bottom: 32px;
}
/* Transition line (only class not shared with hardcoded script) */
.sc-transition {
  color: var(--text-dim); font-style: italic;
  text-align: right; margin: 14px 0 6px;
  font-size: 12.5px;
}

/* ═══════════════════════════════════════════════════════════
   NEW PROJECT MODAL
═══════════════════════════════════════════════════════════ */
#newproj-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.72); backdrop-filter: blur(4px);
  z-index: 910;
}
#newproj-overlay.open { display: block; }

#newproj-modal {
  display: none; position: fixed;
  top: 50%; left: 50%; transform: translate(-50%,-50%) scale(0.95);
  width: min(460px, 90vw);
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 14px; z-index: 911;
  box-shadow: 0 28px 70px rgba(0,0,0,0.7);
  opacity: 0; transition: opacity 0.18s ease, transform 0.18s ease;
  flex-direction: column;
}
#newproj-modal.open    { display: flex; }
#newproj-modal.visible { opacity: 1; transform: translate(-50%,-50%) scale(1); }

.np-warning {
  margin: 14px 18px 4px;
  padding: 10px 14px; border-radius: 8px;
  background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.35);
  color: #fca5a5; font-size: 12px; line-height: 1.5;
}

.np-form { padding: 14px 18px 6px; display: flex; flex-direction: column; gap: 14px; }
.np-field { display: flex; flex-direction: column; gap: 5px; }
.np-label { font-size: 11px; font-weight: 700; letter-spacing: 0.6px;
            text-transform: uppercase; color: var(--text-dim); }
.np-input {
  padding: 9px 12px; border-radius: 8px;
  background: var(--bg-base); border: 1px solid var(--border);
  color: var(--text); font-size: 14px; outline: none;
  transition: border-color 0.15s;
}
.np-input:focus { border-color: var(--accent); }
.np-input-short { width: 90px; }

.import-modal-footer { display: flex; justify-content: flex-end; gap: 8px; }
.np-cancel-btn {
  background: var(--bg-card); color: var(--text-dim);
  border: 1px solid var(--border);
}
.np-cancel-btn:not(:disabled):active { opacity: 0.7; }
.np-start-btn { background: var(--green); }

/* ═══════════════════════════════════════════════════════════
   SCENE CONTAINER  (imported script grouping)
═══════════════════════════════════════════════════════════ */
.scene-container {
  margin-bottom: 28px;
  border-radius: 6px;
  overflow: hidden;
}
.scene-container + .scene-container {
  border-top: 1px solid var(--border);
  padding-top: 4px;
}
/* First heading inside a container resets its own top margin */
.scene-container > .scene-heading:first-child { margin-top: 0; }

/* ═══════════════════════════════════════════════════════════
   SAVE BUTTON
═══════════════════════════════════════════════════════════ */
.hdr-btn-save {
  border-color: rgba(34,197,94,0.45);
  color: var(--green);
}
.hdr-btn-save:active { background: rgba(34,197,94,0.12); }

/* ═══════════════════════════════════════════════════════════
   PROJECT SWITCHER MODAL
════════════════════════════════════════════════════════════ */
#projswitch-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.72); backdrop-filter: blur(4px);
  z-index: 920;
}
#projswitch-overlay.open { display: block; }

#projswitch-modal {
  display: none; position: fixed;
  top: 50%; left: 50%; transform: translate(-50%,-50%) scale(0.95);
  width: min(520px, 92vw);
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 14px; z-index: 921;
  box-shadow: 0 28px 70px rgba(0,0,0,0.7);
  opacity: 0; transition: opacity 0.18s ease, transform 0.18s ease;
  flex-direction: column; overflow: hidden;
}
#projswitch-modal.open    { display: flex; }
#projswitch-modal.visible { opacity: 1; transform: translate(-50%,-50%) scale(1); }

#projswitch-list {
  overflow-y: auto; max-height: 62vh;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.projswitch-loading {
  padding: 40px; text-align: center;
  color: var(--text-dim); font-size: 13px; line-height: 1.6;
}
.projswitch-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.12s;
}
.projswitch-item:last-child { border-bottom: none; }
.projswitch-item:hover      { background: var(--bg-hover); }
.projswitch-item.current    { background: rgba(79,142,247,0.08); cursor: default; }
.projswitch-item-info { flex: 1; min-width: 0; }
.projswitch-name {
  font-size: 14px; font-weight: 700; color: var(--text-pri);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.projswitch-meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.projswitch-badge {
  flex-shrink: 0; margin-left: 12px;
  padding: 3px 10px; border-radius: 20px;
  background: var(--accent-dim); color: var(--accent);
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px;
}
.projswitch-arrow {
  flex-shrink: 0; margin-left: 12px;
  color: var(--text-dim); font-size: 20px; line-height: 1;
}
.projswitch-del-btn {
  flex-shrink: 0; margin-left: 8px;
  width: 32px; height: 32px;
  background: transparent; border: 1px solid transparent;
  border-radius: 8px; color: var(--text-dim);
  font-size: 15px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.projswitch-del-btn:hover {
  background: var(--red-dim); border-color: var(--red); color: var(--red);
}
.projswitch-del-btn:active { opacity: 0.7; }

/* ═══════════════════════════════════════════════════════════
   CROP MODE
════════════════════════════════════════════════════════════ */
#crop-overlay {
  display: none;
  position: fixed; inset: 0;
  z-index: 800;
  cursor: crosshair;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}
#crop-overlay.active { display: block; }
#crop-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.crop-hint {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.72); backdrop-filter: blur(6px);
  color: #fff; font-size: 15px; font-weight: 600;
  padding: 16px 28px; border-radius: 14px;
  pointer-events: none; text-align: center; line-height: 1.7;
  border: 1px solid rgba(255,255,255,0.12);
  transition: opacity 0.2s;
}
.crop-hint.hidden { opacity: 0; }

.crop-esc-btn {
  position: absolute; top: 16px; right: 16px;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff; font-size: 12px; font-weight: 600;
  padding: 7px 16px; border-radius: 20px; cursor: pointer;
  transition: background 0.15s;
}
.crop-esc-btn:hover { background: rgba(255,255,255,0.18); }

/* ─── Crop Preview Modal ─────────────────────────────── */
#crop-modal {
  display: none; position: fixed; inset: 0;
  z-index: 850;
  background: rgba(0,0,0,0.78); backdrop-filter: blur(6px);
  align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.18s;
}
#crop-modal.open    { display: flex; }
#crop-modal.visible { opacity: 1; }

#crop-modal-inner {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 16px; overflow: hidden;
  width: min(540px, 94vw);
  display: flex; flex-direction: column;
  box-shadow: 0 28px 70px rgba(0,0,0,0.75);
}
.crop-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.crop-modal-title { font-size: 14px; font-weight: 700; color: var(--text-pri); }

.crop-preview-wrap {
  padding: 18px; background: #080809;
  display: flex; align-items: center; justify-content: center;
  min-height: 140px; max-height: 52vh; overflow: hidden; flex-shrink: 0;
}
#crop-preview-img {
  max-width: 100%; max-height: 50vh;
  border-radius: 8px; object-fit: contain;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  display: block;
}

.crop-modal-footer {
  padding: 16px 18px 18px; border-top: 1px solid var(--border); flex-shrink: 0;
}
.crop-dest-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 10px;
}
.crop-dest-btns { display: flex; gap: 10px; margin-bottom: 10px; }
.crop-dest-btn {
  flex: 1; padding: 11px 14px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-pri);
  font-size: 13px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all 0.15s;
}
.crop-dest-btn:hover  { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.crop-dest-btn:active { opacity: 0.75; }
.crop-cancel-btn {
  width: 100%; padding: 9px;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-dim);
  font-size: 13px; cursor: pointer; transition: background 0.15s;
}
.crop-cancel-btn:hover { background: var(--bg-hover); }
