/* ===== YukkuriGen Studio — Video Layout Editor ===== */

/* ─── エディタオーバーレイ ─── */
#editorOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
}
#editorOverlay.open { display: flex; }

#editorModal {
  background: #0f172a;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
  width: min(1160px, 97vw);
  height: min(780px, 94vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: editorIn .22s ease;
}
@keyframes editorIn {
  from { opacity:0; transform:scale(.96) translateY(12px); }
  to   { opacity:1; transform:scale(1)  translateY(0); }
}

/* ─── ヘッダー ─── */
.editor-header {
  height: 52px;
  flex-shrink: 0;
  background: #1e293b;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
}
.editor-title {
  font-size: 14px;
  font-weight: 700;
  color: #f1f5f9;
  flex: 1;
}
.editor-header-badge {
  font-size: 11px;
  background: rgba(99,102,241,.35);
  color: #a5b4fc;
  padding: 3px 10px;
  border-radius: 100px;
  font-weight: 600;
}
.editor-close-btn {
  width: 32px; height: 32px;
  border: none; background: rgba(255,255,255,.08);
  color: #94a3b8; border-radius: 8px;
  cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.editor-close-btn:hover { background: rgba(255,255,255,.15); color: #f1f5f9; }

/* ─── タイムライン ─── */
.editor-timeline {
  height: 72px;
  flex-shrink: 0;
  background: #1e293b;
  border-bottom: 1px solid rgba(255,255,255,.07);
  padding: 10px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}
.timeline-label {
  font-size: 10px;
  color: #475569;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.timeline-track {
  flex: 1;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
  padding-bottom: 8px;
}
.timeline-track::-webkit-scrollbar { height: 4px; }
.timeline-track::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.timeline-seg {
  height: 30px;
  border-radius: 5px;
  flex-shrink: 0;
  min-width: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: rgba(255,255,255,.7);
  transition: filter .12s, transform .1s;
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}
.timeline-seg:hover { filter: brightness(1.2); transform: scaleY(1.05); }
.timeline-seg.active {
  border-color: #f1f5f9;
  filter: brightness(1.3);
  box-shadow: 0 0 0 2px rgba(255,255,255,.2);
}
.timeline-seg.char-marisa { background: rgba(99,102,241,.7); }
.timeline-seg.char-reimu  { background: rgba(20,184,166,.7); }
.timeline-seg.has-image::after {
  content: '';
  position: absolute;
  bottom: 3px; left: 50%; transform: translateX(-50%);
  width: 6px; height: 6px;
  background: #fbbf24;
  border-radius: 50%;
}
.timeline-seg.has-override::before {
  content: '';
  position: absolute;
  top: 3px; right: 3px;
  width: 5px; height: 5px;
  background: #a855f7;
  border-radius: 50%;
}

/* ─── エディタ本体 ─── */
.editor-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ─── キャンバスエリア ─── */
.editor-canvas-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0f1a;
  padding: 20px 20px 12px;
  min-width: 0;
  gap: 0;
}

.editor-canvas {
  position: relative;
  width: 640px;
  height: 360px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 10px 10px 0 0;   /* KFパネルと合わせて上角のみ丸く */
  overflow: hidden;
  box-shadow: 0 8px 16px rgba(0,0,0,.4);
  flex-shrink: 0;
}
.canvas-subtitle-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 115px; /* 230/2 (scale 0.5) */
  background: rgba(0,0,0,.88);
  pointer-events: none;
}
.canvas-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

/* ─── キャンバス上の要素 ─── */
.canvas-elem {
  position: absolute;
  cursor: move;
  user-select: none;
  border: 2px solid transparent;
  border-radius: 6px;
  transition: border-color .12s;
  box-sizing: border-box;
}
.canvas-elem:hover { border-color: rgba(255,255,255,.4); }
.canvas-elem.selected { border-color: #6366f1; box-shadow: 0 0 0 2px rgba(99,102,241,.4); }
.canvas-elem.selected.char-b { border-color: #14b8a6; box-shadow: 0 0 0 2px rgba(20,184,166,.4); }
.canvas-elem.selected.ref-img { border-color: #f59e0b; box-shadow: 0 0 0 2px rgba(245,158,11,.4); }

/* キャラプレビュー（立ち絵サムネイル） */
.canvas-char-inner {
  width: 100%; height: 100%;
  display: flex; align-items: flex-end; justify-content: center;
  font-size: 10px; font-weight: 700;
  color: rgba(255,255,255,.8);
  text-shadow: 0 1px 3px rgba(0,0,0,.9);
  pointer-events: none;
}
.canvas-char-img {
  width: 100%; height: 100%;
  object-fit: contain;
  object-position: bottom center;
  pointer-events: none;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.5));
}

/* 画像プレビュー */
.canvas-img-inner {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  overflow: hidden;
  pointer-events: none;
  background: rgba(255,255,255,.08);
}
.canvas-img-inner img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}
.canvas-img-placeholder {
  font-size: 11px; color: rgba(255,255,255,.4); text-align: center;
}

/* リサイズハンドル（四隅） */
.resize-handle {
  position: absolute;
  width: 10px; height: 10px;
  background: #6366f1;
  border: 2px solid #fff;
  border-radius: 3px;
  z-index: 10;
}
.resize-handle.nw { top:-5px; left:-5px; cursor:nw-resize; }
.resize-handle.ne { top:-5px; right:-5px; cursor:ne-resize; }
.resize-handle.sw { bottom:-5px; left:-5px; cursor:sw-resize; }
.resize-handle.se { bottom:-5px; right:-5px; cursor:se-resize; }

/* ─── プロパティパネル ─── */
.editor-props {
  width: 260px;
  flex-shrink: 0;
  background: #1e293b;
  border-left: 1px solid rgba(255,255,255,.07);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.props-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.props-title {
  font-size: 11px;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: .6px;
}
.props-elem-name {
  font-size: 13px;
  font-weight: 700;
  color: #f1f5f9;
  margin-top: 4px;
}
.props-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}
.props-empty {
  color: #475569;
  font-size: 13px;
  text-align: center;
  padding: 32px 16px;
  line-height: 1.7;
}

.prop-group { margin-bottom: 16px; }
.prop-group-label {
  font-size: 10px;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}
.prop-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}
.prop-field { display: flex; flex-direction: column; gap: 4px; }
.prop-label { font-size: 11px; color: #64748b; font-weight: 600; }
.prop-input {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #f1f5f9;
  font-size: 13px;
  padding: 6px 10px;
  width: 100%;
  box-sizing: border-box;
  outline: none;
  transition: border-color .15s;
}
.prop-input:focus { border-color: #6366f1; }
.prop-input[type=range] {
  padding: 4px 0;
  accent-color: #6366f1;
  background: transparent;
  border: none;
  cursor: pointer;
}
.prop-range-row {
  display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
}
.prop-range-val {
  font-size: 12px; color: #a5b4fc; font-weight: 700; min-width: 36px; text-align: right;
}

.prop-checkbox-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.prop-checkbox-label { font-size: 13px; color: #94a3b8; cursor: pointer; }
.prop-checkbox {
  width: 16px; height: 16px; accent-color: #6366f1; cursor: pointer;
}

.prop-img-swap {
  width: 100%;
  background: rgba(245,158,11,.1);
  border: 1px solid rgba(245,158,11,.35);
  border-radius: 8px;
  padding: 8px 12px;
  color: #fbbf24;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  display: flex; align-items: center; gap: 8px;
  transition: background .15s;
  margin-bottom: 8px;
}
.prop-img-swap:hover { background: rgba(245,158,11,.2); }

.prop-reset-btn {
  width: 100%;
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 8px;
  padding: 8px 12px;
  color: #f87171;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background .15s;
  margin-top: 4px;
}
.prop-reset-btn:hover { background: rgba(239,68,68,.2); }

.prop-apply-all {
  width: 100%;
  background: rgba(99,102,241,.15);
  border: 1px solid rgba(99,102,241,.35);
  border-radius: 8px;
  padding: 8px 12px;
  color: #a5b4fc;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background .15s;
  margin-bottom: 6px;
}
.prop-apply-all:hover { background: rgba(99,102,241,.25); }

/* ─── フッター（再レンダリングボタン） ─── */
.editor-footer {
  padding: 12px 16px;
  background: #1e293b;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex;
  gap: 10px;
  align-items: center;
}
.editor-hint {
  flex: 1;
  font-size: 11px;
  color: #475569;
  line-height: 1.5;
}
.editor-rerender-btn {
  padding: 10px 22px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff;
  border: none;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.editor-rerender-btn:hover { opacity: .9; transform: translateY(-1px); }
.editor-rerender-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* セグメント情報テキスト */
.seg-info {
  font-size: 11px;
  color: #64748b;
  padding: 4px 0 12px;
  line-height: 1.6;
}
.seg-info b { color: #94a3b8; }

/* 画像ファイル選択 */
.img-file-select {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #f1f5f9;
  font-size: 12px;
  padding: 7px 10px;
  box-sizing: border-box;
  outline: none;
  margin-bottom: 8px;
}
.img-file-select:focus { border-color: #f59e0b; }

/* ─── Phase2: Undo/Redo ボタン ─── */
.editor-undo-btn, .editor-redo-btn {
  width: 32px; height: 32px;
  border: none; background: rgba(255,255,255,.08);
  color: #94a3b8; border-radius: 8px;
  cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.editor-undo-btn:hover:not(:disabled), .editor-redo-btn:hover:not(:disabled) {
  background: rgba(99,102,241,.25); color: #a5b4fc;
}
.editor-undo-btn:disabled, .editor-redo-btn:disabled {
  opacity: .3; cursor: not-allowed;
}

/* ─── Phase2: 画像アップロードゾーン ─── */
.upload-zone {
  border: 2px dashed #334155;
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: rgba(255,255,255,.02);
}
.upload-zone.drop-active {
  border-color: #f59e0b;
  background: rgba(245,158,11,.07);
}
.upload-zone:hover { border-color: #475569; }
.upload-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  margin-bottom: 8px;
  pointer-events: none;
}
.upload-icon { font-size: 22px; line-height: 1; }
.upload-zone-inner span {
  font-size: 11px;
  color: #64748b;
  line-height: 1.4;
}

/* ─── Phase2: プロパティパネル追加スタイル ─── */
.prop-hint {
  font-size: 10px;
  color: #475569;
  margin-top: -4px;
  margin-bottom: 4px;
  line-height: 1.4;
}

.prop-copy-btn {
  background: rgba(20,184,166,.12);
  border: 1px solid rgba(20,184,166,.3);
  border-radius: 7px;
  padding: 6px 10px;
  color: #5eead4;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.prop-copy-btn:hover { background: rgba(20,184,166,.22); }

.prop-seg-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

/* ─── Phase3: キャンバス上スクラバーインジケーター ─── */
.kf-scrub-indicator {
  position: absolute;
  top: 8px;
  right: 10px;
  background: rgba(168,85,247,.85);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 100px;
  pointer-events: none;
  z-index: 20;
  backdrop-filter: blur(4px);
}

/* ─── Phase3: キーフレームパネル ─── */
.editor-kf-panel {
  width: 640px;
  flex-shrink: 0;
  background: #131e30;
  border-top: 1px solid rgba(255,255,255,.07);
  border-radius: 0 0 10px 10px;
  padding: 10px 14px 12px;
  min-height: 60px;
}

.kf-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.kf-title {
  font-size: 12px;
  font-weight: 700;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kf-seg-badge {
  font-size: 10px;
  background: rgba(168,85,247,.3);
  color: #c4b5fd;
  padding: 2px 8px;
  border-radius: 100px;
}
.kf-hint {
  font-size: 10px;
  color: #334155;
  flex: 1;
}
.kf-header-actions { display: flex; gap: 6px; }

.kf-add-btn {
  background: rgba(168,85,247,.2);
  border: 1px solid rgba(168,85,247,.45);
  border-radius: 7px;
  padding: 5px 11px;
  color: #c4b5fd;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.kf-add-btn:hover { background: rgba(168,85,247,.35); }

.kf-clear-btn {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 7px;
  padding: 5px 10px;
  color: #f87171;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.kf-clear-btn:hover { background: rgba(239,68,68,.2); }

/* スクラバーレール */
.kf-track-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.kf-t-edge {
  font-size: 10px;
  color: #334155;
  font-weight: 700;
  min-width: 22px;
  text-align: center;
}
.kf-t-cur {
  font-size: 11px;
  color: #a855f7;
  font-weight: 700;
  min-width: 34px;
  text-align: right;
}
.kf-track-wrap {
  flex: 1;
  position: relative;
  height: 28px;
  display: flex;
  align-items: center;
}
.kf-track {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
}
.kf-scrub {
  width: 100%;
  accent-color: #a855f7;
  cursor: pointer;
  position: relative;
  z-index: 1;          /* ダイヤモンド(z-index:3)より低くする */
  background: transparent;
}

/* ダイヤモンドマーカー */
.kf-diamond {
  position: absolute;
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
  width: 14px;
  height: 14px;
  background: #a855f7;
  border: 2px solid #c4b5fd;
  border-radius: 3px;
  cursor: pointer;
  z-index: 3;
  pointer-events: all;
  transition: background .12s;
}
.kf-diamond.active { background: #f59e0b; border-color: #fbbf24; }
.kf-diamond:hover { background: #c084fc; }
.kf-del-x {
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%) rotate(-45deg);
  font-size: 9px;
  color: #f87171;
  cursor: pointer;
  line-height: 1;
  display: none;
}
.kf-diamond:hover .kf-del-x { display: block; }

/* キーフレームリスト */
.kf-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.kf-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(168,85,247,.1);
  border: 1px solid rgba(168,85,247,.25);
  border-radius: 7px;
  padding: 4px 8px;
  cursor: pointer;
  transition: background .12s;
}
.kf-item.active {
  background: rgba(245,158,11,.15);
  border-color: rgba(245,158,11,.4);
}
.kf-item:hover { background: rgba(168,85,247,.2); }
.kf-item-t {
  font-size: 11px;
  font-weight: 700;
  color: #c4b5fd;
  min-width: 28px;
}
.kf-item.active .kf-item-t { color: #fbbf24; }
.kf-item-keys { display: flex; gap: 3px; }
.kf-tag {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
}
.kf-tag-a   { background: rgba(99,102,241,.3); color: #a5b4fc; }
.kf-tag-b   { background: rgba(20,184,166,.3); color: #5eead4; }
.kf-tag-img { background: rgba(245,158,11,.3); color: #fbbf24; }
.kf-item-del {
  background: none;
  border: none;
  color: #475569;
  font-size: 10px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}
.kf-item-del:hover { color: #f87171; }

.kf-empty {
  font-size: 11px;
  color: #334155;
  padding: 4px 0;
  line-height: 1.5;
}

/* ─── Phase3: プリセット ─── */
.preset-section {
  border-top: 1px solid rgba(255,255,255,.06);
  padding-top: 12px;
  margin-top: 16px;
}
.preset-label {
  margin-bottom: 8px !important;
}
.preset-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}
.preset-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.04);
  border-radius: 7px;
  padding: 5px 8px;
}
.preset-name {
  flex: 1;
  font-size: 12px;
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preset-load-btn {
  background: rgba(99,102,241,.18);
  border: 1px solid rgba(99,102,241,.35);
  border-radius: 6px;
  padding: 3px 8px;
  color: #a5b4fc;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}
.preset-load-btn:hover { background: rgba(99,102,241,.3); }
.preset-del-btn {
  background: none;
  border: none;
  color: #475569;
  font-size: 13px;
  cursor: pointer;
  padding: 0 3px;
  line-height: 1;
}
.preset-del-btn:hover { color: #f87171; }
.preset-empty {
  font-size: 11px;
  color: #334155;
  margin-bottom: 8px;
}
.preset-save-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.preset-name-input {
  flex: 1;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #f1f5f9;
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  min-width: 0;
}
.preset-name-input:focus { border-color: #6366f1; }
.preset-save-btn {
  background: rgba(99,102,241,.2);
  border: 1px solid rgba(99,102,241,.4);
  border-radius: 6px;
  padding: 6px 12px;
  color: #a5b4fc;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.preset-save-btn:hover { background: rgba(99,102,241,.35); }
.preset-io-row {
  display: flex;
  gap: 6px;
}
.preset-io-btn {
  flex: 1;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  padding: 5px 0;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: background .12s, color .12s;
}
.preset-io-btn:hover { background: rgba(255,255,255,.1); color: #94a3b8; }

/* タイムラインのキーフレームドット（::after は has-image が使用しているので border-top で代替） */
.timeline-seg.has-keyframe {
  border-top: 3px solid rgba(196,181,253,.8);
}

