:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --panel-2: #eef0f6;
  --text: #1b1e27;
  --muted: #646b7d;
  --border: #d9dce6;
  --primary: #5b5bf6;
  --primary-text: #ffffff;
  --accent: #0f9d7a;
  --danger: #d93c4a;
  --active: #e7e7ff;
  --deleted-bg: #fbecee;
  --stage: #0b0c10;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141a;
    --panel: #1a1d25;
    --panel-2: #232733;
    --text: #e8eaf0;
    --muted: #9aa1b3;
    --border: #2f3442;
    --primary: #7474ff;
    --accent: #23b48f;
    --danger: #ff6370;
    --active: #2b2d52;
    --deleted-bg: #3a2228;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12141a; --panel: #1a1d25; --panel-2: #232733; --text: #e8eaf0; --muted: #9aa1b3;
  --border: #2f3442; --primary: #7474ff; --accent: #23b48f; --danger: #ff6370; --active: #2b2d52;
  --deleted-bg: #3a2228; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  display: flex;
  flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--panel-2); cursor: pointer; white-space: nowrap; user-select: none;
  list-style: none;
}
.btn::-webkit-details-marker { display: none; }
a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: var(--primary-text); }
.btn:hover:not(:disabled) { filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.round { width: 38px; height: 38px; border-radius: 50%; justify-content: center; padding: 0; }
.small-btn { padding: 4px 10px; font-size: 13px; }
select, input[type="number"], input[type="search"], input[type="text"] {
  padding: 5px 8px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel);
}
input[type="number"] { width: 64px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.menu { position: relative; }
.menu-body {
  position: absolute; right: 0; top: calc(100% + 4px); min-width: 240px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 6px; display: flex; flex-direction: column; gap: 2px; z-index: 20;
}
.menu-item { text-align: left; padding: 8px 10px; background: none; border: 0; border-radius: 6px; cursor: pointer; }
.menu-item:hover:not(:disabled) { background: var(--panel-2); }
.menu-item:disabled { opacity: .45; cursor: not-allowed; }
.menu-item b { display: block; font-weight: 600; }
.menu-item small { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.menu-label { padding: 8px 10px 2px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--border); margin-top: 4px; }

.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; padding: 16px;
}
.left, .right { min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.right { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-height: 0; }

.stage-wrap {
  background: var(--stage); border-radius: var(--radius); display: flex; justify-content: center; align-items: center;
  min-height: 220px; overflow: hidden; border: 2px dashed transparent;
}
.stage-wrap.drag { border-color: var(--primary); }
.stage { position: relative; width: 100%; height: 100%; min-height: 220px; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: auto; cursor: pointer; }
.drop-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #c6cad6; text-align: center; padding: 16px; pointer-events: none;
}
.drop-hint .big { font-size: 18px; font-weight: 700; margin: 0 0 6px; color: #fff; }
.drop-hint p { margin: 0; }

.transport { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.transport input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--primary); }
.time-label { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 96px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.small { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.panel summary { cursor: pointer; font-weight: 600; }
.style-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 16px; margin-top: 10px; }
.style-grid label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.style-grid input[type="range"] { width: 100px; accent-color: var(--primary); }
.style-grid input[type="color"] { width: 40px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: none; }

.edit-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.edit-tools input[type="search"], .edit-tools input[type="text"] { width: 130px; }
.stats { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
kbd { font: 11px ui-monospace, monospace; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; background: var(--panel-2); }

.clip-list { flex: 1; min-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.empty { color: var(--muted); text-align: center; padding: 48px 16px; }
.clip { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 8px; background: var(--panel); transition: background .15s; }
.clip.active { background: var(--active); border-color: var(--primary); }
.clip.deleted { background: var(--deleted-bg); }
.clip.deleted .clip-text { text-decoration: line-through; color: var(--muted); }
.clip-head { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.clip-head .time { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font-variant-numeric: tabular-nums; }
.clip-head .dur { color: var(--muted); }
.actions { margin-left: auto; display: flex; gap: 2px; opacity: .55; }
.clip:hover .actions, .clip:focus-within .actions { opacity: 1; }
.actions button { background: none; border: 1px solid transparent; border-radius: 5px; padding: 1px 6px; cursor: pointer; font-size: 12px; color: var(--text); }
.actions button:hover { background: var(--panel-2); border-color: var(--border); }
.actions .danger { color: var(--danger); }
.clip-text {
  display: block; width: 100%; resize: none; overflow: hidden; border: 0; background: transparent;
  font-size: 15px; line-height: 1.55; padding: 2px 0; margin-top: 2px;
}
.clip-text:focus { outline: none; }

.dialog {
  border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text);
  width: min(520px, calc(100vw - 32px)); padding: 20px;
}
.dialog::backdrop { background: rgba(0,0,0,.5); }
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
.dialog progress { width: 100%; height: 10px; accent-color: var(--primary); }
.status { margin: 0 0 8px; min-height: 1.5em; font-variant-numeric: tabular-nums; }
.note { font-size: 12px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.form-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.turnstile-box { display: flex; justify-content: center; margin: 8px 0; min-height: 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #23263a; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: min(640px, calc(100vw - 32px));
  box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: opacity .2s, transform .2s; z-index: 50; white-space: pre-line;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 書き出し用の非表示 video (完全に隠すとデコードが止まるブラウザがあるため、極小・半透明で配置) */
.offscreen-video { position: fixed; right: 0; bottom: 0; width: 2px; height: 2px; opacity: 0.01; pointer-events: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .clip-list { max-height: 70vh; }
  .stats { margin-left: 0; width: 100%; }
}
.style-grid label.check { justify-content: flex-start; color: var(--text); }

/* ---- 字幕の見た目 ---- */
.style-layout { display: grid; grid-template-columns: minmax(240px, 1.35fr) minmax(230px, 1fr); gap: 14px; margin-top: 10px; align-items: start; }
@media (max-width: 1100px) { .style-layout { grid-template-columns: 1fr; } }
.style-preview canvas { display: block; width: 100%; height: auto; border-radius: 6px; border: 1px solid var(--border); background: #000; }
.style-preview small { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); }
.style-controls { display: flex; flex-direction: column; gap: 8px; }
.preset-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.style-group { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; margin: 0; padding: 6px 10px 8px; border: 1px solid var(--border); border-radius: var(--radius); }
.style-group legend { padding: 0 4px; font-size: 12px; font-weight: 600; color: var(--text); }
.style-group label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.style-group label.check { justify-content: flex-start; color: var(--text); }
.style-group input[type="range"] { width: 100px; accent-color: var(--primary); }
.style-group input[type="color"] { width: 40px; height: 26px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: none; }
.style-group input:disabled { opacity: .35; cursor: not-allowed; }
.group-hint { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }

/* ---- account / plans ---- */
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.account-btn { gap: 8px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--border); color: var(--text); }
.badge.paid { background: var(--accent); color: #fff; }
.usage-label { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.menu-info { padding: 6px 10px; font-size: 13px; color: var(--muted); white-space: pre-line; word-break: break-all; }
.small-text { font-size: 12px; }
.danger-text { color: var(--danger); }
.danger-btn { background: var(--danger); border-color: var(--danger); color: #fff; }
.dialog.wide { width: min(760px, calc(100vw - 32px)); }
.dialog input[type="text"] { width: 100%; }
.plan-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 12px 0; }
.plan-card { border: 1px solid var(--border); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.plan-card.current { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }
.plan-card h3 { margin: 0; font-size: 16px; }
.plan-card p { margin: 0; }
.plan-price { font-weight: 700; font-size: 15px; }
.plan-card .btn { margin-top: auto; }
.dialog a, .footer a { color: var(--primary); }

/* ---- narration ---- */
.narr-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.narr-warn { font-size: 11px; color: #b7791f; background: rgba(214, 158, 46, .15); padding: 0 6px; border-radius: 4px; }
#narrationPanel .note { margin: 8px 0 0; }

/* ---- footer ---- */
.footer { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; padding: 10px 16px 14px; font-size: 12px; }
.footer a { color: var(--muted); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
@media (max-width: 900px) { .account { margin-left: 0; } }

/* ページ全体はスクロール可能にし、字幕リストは右側で独立スクロール */
html, body { height: auto; min-height: 100%; }
.layout { flex: 1 0 auto; align-items: start; }
.right { position: sticky; top: 64px; max-height: calc(100vh - 80px); }
@media (max-width: 900px) { .right { position: static; max-height: none; } }

/* ---- PowerPoint import ---- */
.form-col { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.file-field { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: var(--radius); }
.file-field span { font-weight: 600; }
.file-field em { font-style: normal; font-size: 11px; margin-left: 8px; padding: 1px 6px; border-radius: 999px; background: var(--danger); color: #fff; }
.file-field em.opt { background: var(--accent); }
.file-field small { color: var(--muted); font-size: 12px; }
.file-field .drop-note { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }
.file-field.dragover { border: 2px solid var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); padding: 9px 11px; }
#dlgSlides.dragover { outline: 3px dashed var(--primary); outline-offset: -8px; }
.stage-wrap.dragover { outline: 3px dashed var(--primary); outline-offset: -6px; }
.form-row input[type="number"] { width: 64px; }
#exportMenu .menu-body { width: min(340px, calc(100vw - 32px)); }
