/* ===== Tokens ===== */
:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #e4e4e7;
  --text: #18181b;
  --muted: #71717a;
  --accent: #e5484d;
  --accent-hover: #d93d42;
  --accent-soft: rgba(229, 72, 77, .12);
  --on-accent: #ffffff;
  --stage: #0e0e10;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", Meiryo, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f11;
    --surface: #18181b;
    --surface-2: #232327;
    --border: #2e2e33;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --accent: #f2555a;
    --accent-hover: #ff6a6f;
    --accent-soft: rgba(242, 85, 90, .16);
    --stage: #070708;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }

/* ===== Header ===== */
.topbar {
  padding: 18px 16px 6px;
  max-width: 1360px;
  margin: 0 auto;
}
.brand { display: flex; gap: 12px; align-items: center; }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 4px; margin-top: 14px; border-bottom: 1px solid var(--border); }
.tabs button {
  appearance: none; border: 0; background: none; cursor: pointer;
  padding: 9px 16px; margin-bottom: -1px;
  font-size: 14px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px 6px 0 0; }
.manual-panel { max-width: 1360px; margin: 0 auto; padding: 12px 16px 16px; }
.manual-panel iframe {
  display: block; width: 100%; height: calc(100vh - 150px); min-height: 480px;
  border: 1px solid var(--border); border-radius: var(--radius); background: #f4f6f9;
}
.brand-mark {
  flex: none;
  width: 34px; height: 26px;
  border: 5px solid var(--accent);
  border-radius: 6px;
  background: var(--stage);
}
.brand h1 { margin: 0; font-size: 19px; letter-spacing: .02em; }
.brand p { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.5; }

/* ===== Layout ===== */
.app {
  max-width: 1360px;
  margin: 0 auto;
  padding: 12px 16px 48px;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 1000px) {
  .app { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
  .stage-col { position: sticky; top: 16px; }
}
.panel-col { display: grid; gap: 14px; min-width: 0; }

/* ===== Cards ===== */
.card, .stage-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 16px; display: grid; gap: 12px; }
.card h2 {
  margin: 0;
  font-size: 15px;
  display: flex; align-items: center; gap: 8px;
}
.step {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px; font-weight: 700;
}
.note { margin: 0; color: var(--muted); font-size: 13px; }
.note.sm { font-size: 12px; }

/* ===== Stage ===== */
.stage-card { padding: 10px; display: grid; gap: 10px; }
.stage {
  position: relative;
  background: var(--stage);
  border-radius: 10px;
  min-height: 240px;
  display: grid;
  place-items: center;
  padding: 10px;
  overflow: hidden;
}
.stage-empty { color: #71717a; text-align: center; padding: 24px; }
.stage-empty p { margin: 8px 0 0; font-size: 13px; }
.stage-wrap {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
}
#canvas {
  display: block;
  max-width: 100%;
  max-height: 58vh;
  width: auto; height: auto;
  background: #000;
}
@media (min-width: 1000px) { #canvas { max-height: calc(100vh - 220px); } }
.stage.picking .stage-wrap { cursor: crosshair; }
.stage.picking { outline: 2px solid var(--accent); outline-offset: -2px; }
.pick-hint {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  background: var(--accent); color: var(--on-accent);
  font-size: 12.5px; padding: 5px 12px; border-radius: 999px;
  pointer-events: none; white-space: nowrap;
}

/* Region editor */
.region {
  position: absolute;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 1px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.6);
  cursor: move;
  touch-action: none;
}
.stage.picking .region { pointer-events: none; opacity: .5; }
.region .h {
  position: absolute;
  width: 14px; height: 14px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 3px;
  touch-action: none;
}
@media (pointer: coarse) { .region .h { width: 22px; height: 22px; } }
.region .h[data-h="nw"] { left: 0; top: 0; transform: translate(-50%,-50%); cursor: nwse-resize; }
.region .h[data-h="n"]  { left: 50%; top: 0; transform: translate(-50%,-50%); cursor: ns-resize; }
.region .h[data-h="ne"] { right: 0; top: 0; transform: translate(50%,-50%); cursor: nesw-resize; }
.region .h[data-h="e"]  { right: 0; top: 50%; transform: translate(50%,-50%); cursor: ew-resize; }
.region .h[data-h="se"] { right: 0; bottom: 0; transform: translate(50%,50%); cursor: nwse-resize; }
.region .h[data-h="s"]  { left: 50%; bottom: 0; transform: translate(-50%,50%); cursor: ns-resize; }
.region .h[data-h="sw"] { left: 0; bottom: 0; transform: translate(-50%,50%); cursor: nesw-resize; }
.region .h[data-h="w"]  { left: 0; top: 50%; transform: translate(-50%,-50%); cursor: ew-resize; }
.region-label {
  position: absolute; left: 4px; top: 4px;
  background: var(--accent); color: var(--on-accent);
  font: 600 11px/1 var(--mono);
  padding: 4px 6px; border-radius: 4px;
  pointer-events: none; white-space: nowrap;
}

/* Player */
.player { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.player input[type=range] { flex: 1; min-width: 60px; }
.time { font: 12px var(--mono); color: var(--muted); white-space: nowrap; }
@media (max-width: 420px) { .time { display: none; } }
.icon-btn {
  flex: none;
  width: 38px; height: 38px;
  display: inline-grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); width: 44px; height: 44px; }
.icon-btn.primary:hover { background: var(--accent-hover); }
.icon-btn.toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.i-pause, .i-mute { display: none; }
.playing .i-play { display: none; }
.playing .i-pause { display: block; }
.muted .i-vol { display: none; }
.muted .i-mute { display: block; }

.stage-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 0 4px 2px; }
.out-size { margin-left: auto; font: 12px var(--mono); color: var(--muted); }

/* ===== Drop zones ===== */
.drops { display: grid; gap: 10px; }
@media (min-width: 560px) and (max-width: 999px) { .drops { grid-template-columns: 1fr 1fr; } }
.drop {
  position: relative;
  display: flex; gap: 12px; align-items: center;
  padding: 12px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .15s, background .15s;
  min-width: 0;
}
.drop:hover, .drop:focus-within { border-color: var(--accent); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); border-style: solid; }
.drop.loaded { border-style: solid; }
.drop input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-thumb {
  flex: none;
  width: 64px; height: 48px;
  border-radius: 8px;
  background: var(--surface) center / cover no-repeat;
  border: 1px solid var(--border);
  display: grid; place-items: center;
  overflow: hidden;
}
.drop-thumb:empty::before {
  content: "+";
  font-size: 22px; color: var(--muted); line-height: 1;
}
.drop-thumb img, .drop-thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.drop-body { display: grid; min-width: 0; }
.drop-body strong { font-size: 14px; }
.drop-hint { font-size: 11.5px; color: var(--muted); }
.drop-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drop.loaded .drop-meta { color: var(--text); }

/* ===== Form controls ===== */
.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; }
.field output { font: 12px var(--mono); color: var(--muted); font-weight: 400; }
.row { display: flex; gap: 8px; }
.row select { flex: 1; min-width: 0; }
select, input[type=number], input[type=text], input[type=date] {
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  min-width: 0;
  width: 100%;
}
input[type=number] { font-family: var(--mono); font-size: 13px; }
input[type=color] {
  width: 44px; height: 38px; padding: 3px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); cursor: pointer; flex: none;
}
input[type=range] { accent-color: var(--accent); width: 100%; margin: 0; height: 24px; }
select:focus-visible, input:focus-visible, button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.grid4 label { display: grid; gap: 3px; font-size: 11.5px; color: var(--muted); }
.grid4 input { padding: 0 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span {
  flex: none; position: relative;
  width: 34px; height: 20px; border-radius: 999px;
  background: var(--border);
  transition: background .15s;
}
.switch span::after {
  content: ""; position: absolute; left: 2px; top: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3);
  transition: transform .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + span { opacity: .45; }
.switch:has(input:disabled) { color: var(--muted); cursor: default; }

/* Segmented */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: 6px 4px; border-radius: 7px; font-size: 13px; cursor: pointer; }
.seg input:checked + span { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 600; color: var(--accent); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

/* Crop */
.crop { display: grid; gap: 8px; }
.crop-row { display: grid; grid-template-columns: 22px minmax(0,1fr) 76px; gap: 10px; align-items: center; }
.crop-row label { font-size: 13px; font-weight: 600; text-align: center; }
.crop-row input[type=number] { height: 32px; }
.pos-row { display: grid; grid-template-columns: 34px minmax(0,1fr) 76px; gap: 10px; align-items: center; }
.pos-row label { font-size: 13px; font-weight: 600; text-align: center; }
.pos-row input[type=number] { height: 32px; }
.stage.moving .stage-wrap { cursor: grab; touch-action: none; }
.stage.moving .stage-wrap:active { cursor: grabbing; }
.stage.moving .region { pointer-events: none; opacity: .5; }
.tc-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 10px; font-size: 13px; }
.tc-row > span:first-child { font-weight: 600; }
.tc { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.tc input { width: 58px; height: 32px; text-align: right; }
.vol { display: grid; gap: 4px; margin-top: 4px; }
.vol > label { font-size: 13px; font-weight: 600; }
.vol-ctl { display: flex; align-items: center; gap: 8px; }
.vol-ctl input[type=range] { flex: 1; min-width: 60px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row .btn { flex: 1; }
.btn-col { display: grid; gap: 8px; }
.btn-col .btn { height: 46px; font-size: 15px; }

/* Progress */
.premiere { display: grid; gap: 10px; border-top: 1px solid var(--border); padding-top: 14px; }
.premiere h3 { margin: 0; font-size: 14px; }
input[type=text] {
  height: 38px; padding: 0 10px; width: 100%; min-width: 0;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2);
  font-family: var(--mono); font-size: 12.5px;
}
.progress { display: grid; gap: 8px; }
.progress-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.result { display: grid; gap: 6px; }
.result .btn { height: 46px; }

/* Help */
.tip { background: var(--accent-soft); color: var(--text); padding: 8px 10px; border-radius: 8px; }
.brave-note { margin-top: 12px; font-size: 14px; line-height: 1.6; }
/* Brave のシールドがオンのときに、ページ全体を覆って作業できないようにする案内 */
.block-screen { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.72); }
.block-screen[hidden] { display: none; }
.block-box { max-width: 520px; width: 100%; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: grid; gap: 12px; font-size: 15px; line-height: 1.7; }
.block-box h2 { margin: 0; font-size: 18px; }
.block-box p, .block-box ol { margin: 0; }
.block-box ol { padding-left: 1.4em; }
body.blocked { overflow: hidden; }
.block-url { word-break: break-all; user-select: all; }
/* 案内が画面に収まらないときは、案内ごとスクロールできるようにする */
.block-screen { overflow-y: auto; }
.block-box.wide { max-width: 760px; }
.inline-icon { width: 1.6em; height: 1.6em; vertical-align: middle; margin: 0 4px; border-radius: 6px; }
.guide-figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.guide-figs figure { margin: 0; display: grid; gap: 6px; }
.guide-figs img { width: 100%; height: auto; max-height: 52vh; object-fit: contain; border-radius: 10px; border: 1px solid var(--border); background: #000; }
.guide-figs figcaption { font-size: 13px; font-weight: 600; text-align: center; }
.guide-figs figcaption.bad { color: var(--accent); }
.guide-figs figcaption.good { color: #16a34a; }
.block-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px; }
.block-links .btn { white-space: nowrap; }
.video-no { width: 7em; }
.video-date { width: 11em; }
/* タブが増えたので、狭い画面では横にスクロールできるようにする */
.tabs { overflow-x: auto; scrollbar-width: none; }
.tabs button { flex: none; white-space: nowrap; }
/* 更新情報・ライセンスのページ */
.info-page { max-width: 900px; margin: 0 auto; padding: 12px 16px 48px; }
.info-page h3 { margin: 10px 0 0; font-size: 14px; }
.changelog ul { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; font-size: 14px; line-height: 1.7; }
.license-item { display: grid; gap: 4px; font-size: 14px; line-height: 1.7; padding: 10px 0; border-bottom: 1px solid var(--border); }
.license-item a { color: var(--accent); }
.license-item summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.license-item pre { margin: 8px 0 0; max-height: 360px; overflow: auto; white-space: pre-wrap; font-size: 12px; line-height: 1.5; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.field > label.switch { display: inline-flex; justify-content: flex-start; font-weight: 400; margin-top: 2px; }

.help summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.help ol, .help ul { margin: 0; padding-left: 1.3em; font-size: 13px; color: var(--muted); display: grid; gap: 4px; }

/* Busy (exporting) */
body.busy .panel-col .card:not(:has(#progress)) { opacity: .55; pointer-events: none; }
body.busy .player, body.busy .stage-tools, body.busy .region { pointer-events: none; opacity: .5; }

/* Hidden source video (kept in layout so every browser keeps decoding frames) */
.src-video { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; z-index: -1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  background: #18181b; color: #fafafa;
  padding: 10px 16px; border-radius: 10px;
  font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #b4232a; }

/* はめ込み素材の一覧（複数を並べるとき） */
.clips { display: grid; gap: 6px; margin-top: 10px; }
.clips.locked { opacity: .6; pointer-events: none; }
.clip-row { display: flex; gap: 6px; align-items: stretch; }
.clip-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: transparent; color: inherit; font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.clip-main:hover { border-color: var(--accent); }
.clip-row.active .clip-main { border-color: var(--accent); background: var(--accent-soft); }
.clip-no {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; background: var(--accent-soft); color: var(--accent);
}
.clip-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clip-dur { flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.clip-btn {
  flex: none; width: 34px; border: 1px solid var(--border); border-radius: 10px;
  background: transparent; color: inherit; font: inherit; font-size: 14px; cursor: pointer;
}
.clip-btn:hover:not(:disabled) { border-color: var(--accent); }
.clip-btn:disabled { opacity: .35; cursor: default; }
/* まとめて書き出した動画の一覧 */
.result-list { display: grid; gap: 8px; margin-top: 10px; }
.result-row { display: grid; gap: 4px; }
.result-row .btn { overflow-wrap: anywhere; }

/* 枠素材を作る */
.maker-stage { background: #000; border-radius: 12px; overflow: hidden; }
.maker-stage canvas { display: block; width: 100%; height: auto; }
input[type=text], input[type=date] { font: inherit; font-size: 14px; color: inherit; }
.mk-name { display: flex; align-items: center; gap: 8px; }
.mk-name span { font: 13px var(--mono); color: var(--muted); }
#mkResult .btn { height: 46px; }

/* 素材の一覧の小さな札（コマの時刻を直した／乱れている） */
.clip-tag { flex: none; font-size: 11px; line-height: 1; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.clip-tag.warn { color: #c2410c; border-color: #c2410c; }
