/* Premiere のパネルに置いたときに馴染むよう、暗色・高密度で組む。
   将来 UXP パネル化するので、幅が狭くなっても破綻しないこと。 */

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

:root {
  --bg:      #1e1e1e;
  --panel:   #262626;
  --panel-2: #2e2e2e;
  --line:    #3a3a3a;
  --text:    #d6d6d6;
  --dim:     #8a8a8a;
  --accent:  #4a9eff;
  --radius:  4px;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 12px/1.5 "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  height: 100vh;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr 260px;
  gap: 1px;
  height: 100vh;
  background: var(--line);
}

.pane { background: var(--panel); display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  flex: 0 0 auto;
}
.pane-head h2 { font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.pane-head .note {
  color: var(--dim); font-size: 10px; font-weight: 400; letter-spacing: 0;
  white-space: nowrap;
}
.pane-head h2 { display: flex; align-items: baseline; gap: 2px; min-width: 0; }
.head-actions { display: flex; align-items: center; gap: 6px; }

/* ---------- 部品 ---------- */
.btn {
  background: #3a3a3a; color: var(--text);
  border: 1px solid #4a4a4a; border-radius: var(--radius);
  padding: 4px 9px; font-size: 11px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #454545; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: #333; }

input[type=text], input[type=number], select, textarea {
  background: #1a1a1a; color: var(--text);
  border: 1px solid #444; border-radius: var(--radius);
  padding: 4px 6px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
textarea { resize: vertical; font-size: 11px; }

input[type=range] { width: 100%; accent-color: var(--accent); }
.chk { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.chk input { width: auto; }

.hint { color: var(--dim); font-size: 10.5px; line-height: 1.45; }

/* ---------- 左: 行 ---------- */
.bulk { display: flex; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); align-items: stretch; }
.bulk textarea { flex: 1; }
.bulk-btns { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; }
.bulk-btns .btn { flex: 1; padding: 2px 8px; white-space: nowrap; }
.btn.accent { background: #2f6b4f; border-color: #3d8a66; color: #fff; }
.btn.accent:hover { background: #388057; }

.row-list { flex: 1 1 auto; overflow-y: auto; padding: 6px; }

.row {
  display: grid;
  grid-template-columns: 13px 16px 1fr;
  grid-template-areas: "grip n text" "grip ctrl ctrl";
  gap: 4px 5px;
  padding: 6px 6px 6px 3px; margin-bottom: 5px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
}
.row.dragging { opacity: .4; }
.row.over { border-color: var(--accent); box-shadow: 0 -2px 0 var(--accent); }

.row .grip {
  grid-area: grip; align-self: center; cursor: grab;
  color: #555; font-size: 11px; line-height: 1; text-align: center; user-select: none;
}
.row .grip:active { cursor: grabbing; }
.row:hover .grip { color: var(--dim); }

.row .idx  { grid-area: n; color: var(--dim); font-size: 10px; text-align: right; padding-top: 5px; }
/* 行はドラッグで並べ替えられるが、テキスト欄の中は文字選択のドラッグを
   優先させたい。-webkit-user-drag は一部ブラウザ向けの保険。 */
.row .text { grid-area: text; -webkit-user-drag: none; }
.row .ctrl { grid-area: ctrl; display: flex; gap: 4px; align-items: center; }
.row .ctrl select { width: auto; flex: 0 0 auto; font-size: 10.5px; padding: 2px 3px; }

/* 色ボタン: スウォッチ＋色名。行と全行まとめ操作で共用する */
.cp-btn {
  display: flex; align-items: center; gap: 4px; flex: 0 0 auto;
  background: #1a1a1a; color: var(--text);
  border: 1px solid #444; border-radius: var(--radius);
  padding: 2px 5px 2px 3px; font: inherit; font-size: 10.5px; cursor: pointer;
}
.cp-btn:hover { border-color: #666; }
.sw {
  width: 14px; height: 14px; flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.25); border-radius: 3px; background: #fff;
}
.cp-name { min-width: 3.2em; text-align: left; }

.rep {
  display: flex; align-items: center; gap: 2px;
  color: var(--dim); font-size: 10px; margin-left: 1px; white-space: nowrap;
}
.rep input { width: 32px; padding: 2px 3px; font-size: 10.5px; text-align: center; }
.row .dup { margin-left: auto; color: var(--dim); padding: 2px 5px; }
.row .dup:hover { background: #333; color: var(--text); }
.row .del { color: #a66; padding: 2px 6px; }
.row .del:hover { background: #4a2a2a; }

/* ---------- 色パレット(全行で使い回す1枚) ---------- */
.cp-pop {
  position: fixed; z-index: 100;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  padding: 7px;
  background: var(--panel-2); border: 1px solid #4a4a4a;
  border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.55);
}
.cp-pop[hidden] { display: none; }
.cp-opt {
  width: 26px; height: 26px; padding: 0;
  background: none; border: none; border-radius: 4px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.cp-opt > span {
  width: 100%; height: 100%; border-radius: 4px;
  border: 1px solid rgba(255,255,255,.2);
}
.cp-opt:hover > span { transform: scale(1.12); }
/* 選択中はチェックを重ねる */
.cp-opt.sel { position: relative; }
.cp-opt.sel::after {
  content: '✓'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 700;
  text-shadow: 0 0 3px rgba(0,0,0,.9), 0 0 2px rgba(0,0,0,.9);
  pointer-events: none;
}

.row-tools { display: flex; gap: 5px; padding: 8px 10px; border-top: 1px solid var(--line); }
.row-tools .btn { flex: 1; padding: 4px 2px; }

/* 全行まとめ操作。
   部品の左端が上の行リストと揃うよう、行の grip+idx ぶんだけ字下げする。 */
.bulk-set {
  padding: 7px 10px 9px;
  border-top: 1px solid var(--line);
  background: #232323;
}
.bulk-set .ctrl {
  display: flex; align-items: center; gap: 4px;
  padding-left: 18px; /* .row-list padding + grip + gap に合わせる */
}
.bulk-set .ctrl select { width: auto; font-size: 10.5px; padding: 2px 3px; }
.bulk-set .bl {
  margin-left: auto; color: var(--dim); font-size: 10px; white-space: nowrap;
}

/* ---------- 中央: プレビュー ---------- */
.preview-pane { background: #141414; }
.stage {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: center;
  padding: 12px; min-height: 0; overflow: hidden;
}
#cv {
  max-width: 100%; max-height: 100%;
  background: transparent;
  /* 背景OFF時に透明部分が見えるようチェッカー柄を敷く */
  background-image:
    linear-gradient(45deg, #2a2a2a 25%, transparent 25%, transparent 75%, #2a2a2a 75%),
    linear-gradient(45deg, #2a2a2a 25%, transparent 25%, transparent 75%, #2a2a2a 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  box-shadow: 0 0 0 1px var(--line);
}
#cv.with-bg { background-image: none; background-color: #000; }

.transport {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel);
}
.transport .play { width: 34px; font-size: 13px; }
.transport #scrub { flex: 1; }
.time { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 11px; white-space: nowrap; }
.stats { color: var(--dim); font-size: 10.5px; }

/* ---------- 右: 設定 ---------- */
.cfg-scroll { flex: 1 1 auto; overflow-y: auto; padding: 9px 10px; }

/* 設定パネルが縦に収まりきらず、書き出しボタンまでスクロールが要る
   ことがあったため詰めていたが、詰めすぎとの指摘で一段階戻した。 */
fieldset { border: none; margin-bottom: 13px; }
legend {
  font-size: 10.5px; font-weight: 600; color: var(--dim);
  text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: 6px; padding-bottom: 3px;
  border-bottom: 1px solid var(--line); width: 100%;
}
/* ラベルと入力を1行に並べて縦の情報量を下げる */
.field {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 6px;
}
.field .lbl { color: var(--dim); font-size: 11px; flex: 0 0 auto; }
.field select { width: auto; flex: 1 1 auto; max-width: 130px; font-size: 11px; }
.field .val { color: var(--text); font-variant-numeric: tabular-nums; font-size: 11px; }
.field.off { opacity: .4; }
/* .field は display:flex を持つため、hidden属性が付いていても
   ブラウザ既定の [hidden]{display:none} と詳細度が同点で負けることがある。
   実際に #exEngineRow が hidden=true でも表示され続けていた。 */
.field[hidden] { display: none; }

/* ラベル・スライダー・数値を1行に収める(単独の設定を縦に間延びさせないため) */
.field-slider input[type=range] { flex: 1 1 auto; width: auto; }
.field-slider .val { flex: 0 0 auto; min-width: 3.6em; text-align: right; }

.hint b { color: var(--text); font-weight: 600; }

/* 出力サイズ〜流し始めるタイミングは「デザインの調整」項目という共通の
   括りなので、legendの色を揃える(旧・並びの乱数の色をそのまま流用)。
   ラベルも白にして、実際に触る配置・行の高さ・順序・撒く時間を見やすくする。 */
.tune-field legend { color: #c9a34e; border-bottom-color: rgba(201, 163, 78, .3); }
.tune-field .lbl { color: var(--text); }

/* 「並びの乱数」はサイコロを回すイメージで赤系統。他と並んだときに
   浮きすぎないよう彩度は控えめにしつつ、少し明るめに調整。 */
.seed-field legend { color: #c17f77; border-bottom-color: rgba(193, 127, 119, .3); }

/* 「書き出し」= 設定ではなく操作。ひとまとまりの箱にして
   上のデザイン設定(出力サイズ〜流し始めるタイミング)と役割の違いを示す。 */
.action-zone {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 10px 2px;
  margin-bottom: 13px;
}
.action-zone legend { color: var(--accent); border-bottom-color: rgba(74, 158, 255, .3); }
.action-zone fieldset:last-child { margin-bottom: 5px; }

fieldset label.chk { color: var(--text); font-size: 11px; margin-bottom: 6px; }
fieldset > .mt, fieldset label.mt { margin-top: 7px; }
fieldset .hint { margin-top: 6px; }

.custom-res { display: flex; align-items: center; gap: 5px; margin-top: 5px; }
.custom-res input { flex: 1; text-align: center; }
.custom-res span { color: var(--dim); }
.custom-res[hidden] { display: none; }

.seed-row { display: flex; gap: 5px; }
.seed-row input { flex: 1; }

/* ---------- 書き出し ---------- */
.fmt-info {
  color: var(--dim); font-size: 10px; line-height: 1.45;
  margin: 5px 0 8px; padding: 6px 7px;
  background: #222; border-radius: var(--radius);
}
.fmt-info b { color: var(--text); font-weight: 600; }

.ex-estimate {
  color: var(--dim); font-size: 10px; line-height: 1.45; margin-top: 5px;
}
.ex-estimate.warn {
  color: #e8c07a; background: #3a2f1e; border-radius: var(--radius); padding: 5px 6px;
}

.btn.wide { width: 100%; padding: 6px; }
.btn:disabled { opacity: .5; cursor: default; }

.ex-progress { margin-top: 8px; }
.ex-bar { height: 4px; background: #1a1a1a; border-radius: 2px; overflow: hidden; }
.ex-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }
.ex-status { color: var(--dim); font-size: 10.5px; margin-top: 4px; }

.ex-result {
  margin-top: 8px; padding: 6px 7px; border-radius: var(--radius);
  font-size: 10px; line-height: 1.5; white-space: pre-wrap; word-break: break-all;
}
.ex-result.ok { background: #1e3a2c; color: #9edebe; }
.ex-result.ng { background: #3a1e1e; color: #e0a0a0; }
.ex-result[hidden] { display: none; }

/* ---------- このツールについて ---------- */
.about .hint { margin-bottom: 8px; }
.about a { color: #6ab0ff; text-decoration: none; }
.about a:hover { text-decoration: underline; }

/* ---------- スマホ警告 ---------- */
.mobile-warn {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(0, 0, 0, .8);
}
.mobile-warn[hidden] { display: none; }
.mw-box {
  max-width: 340px; padding: 18px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
}
.mw-box h2 { font-size: 14px; margin-bottom: 8px; }
.mw-box p { color: var(--dim); font-size: 11.5px; line-height: 1.7; margin-bottom: 14px; }
.mw-box .btn { width: 100%; padding: 7px; }

/* スクロールバー */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #555; }
