/* 撮影カンペツール — UI
 * 方針: 無彩色のクローム（スタジオ機材のような静かな黒）。色は「録音中」の赤点と、台本の強調2色だけ。
 * 主役はステージ（台本）。UI は後ろに下がる。 */
:root {
  --ink: #0b0b0c;
  --panel: #121214;
  --raised: #19191c;
  --hover: #202024;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --fg: #f3f2ee;
  --fg-2: #9d9c96;
  --fg-3: #625f58;
  --rec: #ff5c4d;
  --ok: #7fcf9a;
  --warn: #e3b765;

  --font-ui: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  --font-stage: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", "Meiryo", -apple-system, sans-serif;

  /* ステージ（本番表示）既定: 黒 */
  --stage-bg: #000;
  --stage-fg: #fff;
  --stage-read: 0.28;
  --stage-unread: 0.52;
  --stage-guide: rgba(255, 255, 255, 0.22);
  --stage-caret: rgba(255, 255, 255, 0.55);
  --stage-accent-a: #e6b65c;
  --stage-accent-b: #7fb8e6;
  --stage-memo: #8b8a84;
  --stage-memo-bg: rgba(255, 255, 255, 0.06);

  --side-w: 380px;
  --top-h: 52px;
  --bottom-h: 68px;
  --radius: 6px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  background: var(--ink);
  color: var(--fg);
  font-size: 13.5px;
  line-height: 1.5;
  overflow: hidden;
  display: grid;
  grid-template-rows: var(--top-h) 1fr var(--bottom-h);
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
h2 { font-size: 14px; margin: 0 0 4px; font-weight: 600; letter-spacing: .01em; }
h3 { font-size: 11.5px; margin: 22px 0 6px; color: var(--fg-2); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
code { background: var(--raised); padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: var(--font-mono); }
kbd { display: inline-block; min-width: 20px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--raised); font-size: 11.5px; font-family: var(--font-mono); text-align: center; margin-right: 2px; color: var(--fg-2); }

/* ---------- ヘッダー ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--ink);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: .06em; font-size: 13px; white-space: nowrap; }
.brand-mark { width: 18px; height: 18px; border-radius: 4px; border: 1px solid var(--line-strong); position: relative; }
.brand-mark::before { content: ""; position: absolute; left: 4px; right: 4px; top: 8px; height: 1.5px; background: var(--fg); }
.steps { display: flex; gap: 2px; margin-left: 4px; height: 100%; }
.step {
  display: flex; align-items: center; gap: 7px; padding: 0 12px; border: 0; border-bottom: 2px solid transparent;
  background: transparent; color: var(--fg-3); height: 100%; font-weight: 500;
}
.step .num { font-family: var(--font-mono); font-size: 11px; color: var(--fg-3); }
.step:hover { color: var(--fg-2); }
body[data-step="1"] .step[data-step="1"], body[data-step="2"] .step[data-step="2"], body[data-step="3"] .step[data-step="3"] {
  color: var(--fg); border-bottom-color: var(--fg);
}
body[data-step="1"] .step[data-step="1"] .num, body[data-step="2"] .step[data-step="2"] .num, body[data-step="3"] .step[data-step="3"] .num { color: var(--fg); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.status-pill { display: flex; align-items: center; gap: 8px; padding: 0 12px 0 10px; height: 30px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; color: var(--fg-2); max-width: 380px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-3); flex: none; }
.status-pill[data-level="ok"] .dot { background: var(--ok); }
.status-pill[data-level="warn"] .dot { background: var(--warn); }
.status-pill[data-level="err"] .dot { background: var(--rec); }
.status-pill[data-level="err"] { color: var(--fg); border-color: rgba(255, 92, 77, .4); }
.status-pill[data-level="live"] .dot { background: var(--rec); animation: pulse 1.4s ease-in-out infinite; }
.status-pill[data-level="live"] { color: var(--fg); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 92, 77, .45); } 50% { box-shadow: 0 0 0 5px rgba(255, 92, 77, 0); } }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 13px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: transparent; color: var(--fg);
  white-space: nowrap; transition: background .12s, border-color .12s, color .12s; font-weight: 500;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .35; cursor: default; }
.btn.primary { background: var(--fg); color: #0b0b0c; border-color: var(--fg); font-weight: 600; }
.btn.primary:hover { background: #fff; }
.btn.ghost { border-color: transparent; color: var(--fg-2); text-decoration: none; }
.btn.ghost:hover { color: var(--fg); background: var(--hover); }
.btn.danger { color: var(--fg-2); }
.btn.danger:hover { color: var(--rec); }
.btn.sq { width: 34px; padding: 0; font-family: var(--font-mono); font-size: 13px; }
.btn.play { min-width: 116px; background: var(--fg); color: #0b0b0c; border-color: var(--fg); font-weight: 600; }
.btn.play:hover { background: #fff; }
.btn.play .icon-play { width: 0; height: 0; border-left: 9px solid currentColor; border-top: 5.5px solid transparent; border-bottom: 5.5px solid transparent; margin-right: 2px; }
.btn.play.playing .icon-play { width: 9px; height: 11px; border: 0; border-left: 3px solid currentColor; border-right: 3px solid currentColor; }
.btn.play.playing { background: transparent; color: var(--fg); border-color: var(--line-strong); }
.btn.play.playing:hover { background: var(--hover); }
.link { background: none; border: 0; color: var(--fg); text-decoration: underline; text-underline-offset: 3px; padding: 0; }

/* ---------- レイアウト ---------- */
.layout { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 0; }
body.side-hidden .layout { grid-template-columns: 1fr; }
body.side-hidden .side { display: none; }
.side { border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; min-height: 0; scrollbar-width: thin; }
.panel { display: none; padding: 18px 18px 28px; }
body[data-step="1"] .panel[data-panel="1"], body[data-step="2"] .panel[data-panel="2"], body[data-step="3"] .panel[data-panel="3"] { display: block; }
.hint { color: var(--fg-2); font-size: 12.5px; margin: 0 0 14px; line-height: 1.55; }
.field { display: block; margin: 14px 0; }
.field .label { display: flex; justify-content: space-between; font-size: 12px; color: var(--fg-2); margin-bottom: 7px; }
.field input[type="text"] { width: 100%; height: 34px; padding: 0 10px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: transparent; }
.field input[type="text"]:focus { outline: none; border-color: var(--fg); }
.range-row { display: flex; align-items: center; gap: 8px; }
.range-row input[type="range"] { flex: 1; }
input[type="range"] { width: 100%; accent-color: var(--fg); height: 20px; }
output { color: var(--fg); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.row.end { justify-content: flex-end; }
.check { display: flex; align-items: center; gap: 9px; margin: 12px 0; font-size: 13px; color: var(--fg-2); }
.check input { accent-color: var(--fg); width: 15px; height: 15px; }
.help { margin-top: 14px; border-top: 1px solid var(--line); padding: 10px 0 2px; }
.help summary { cursor: pointer; color: var(--fg-2); font-size: 12.5px; list-style: none; display: flex; align-items: center; gap: 6px; }
.help summary::-webkit-details-marker { display: none; }
.help summary::before { content: "+"; font-family: var(--font-mono); color: var(--fg-3); width: 10px; }
.help[open] summary::before { content: "−"; }
.help ul { margin: 10px 0 4px; padding-left: 16px; font-size: 12.5px; color: var(--fg-2); }
.help li { margin: 5px 0; }
.help .keys { list-style: none; padding-left: 0; }
.autosave { font-size: 11.5px; color: var(--fg-3); margin-top: 14px; font-family: var(--font-mono); }

.toolbar { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin: 10px 0 8px; }
.toolbar-label { font-size: 11.5px; color: var(--fg-3); margin-right: 4px; }
.tool { height: 28px; padding: 0 10px; border-radius: 4px; border: 1px solid var(--line-strong); background: transparent; font-size: 12.5px; color: var(--fg); }
.tool:hover { background: var(--hover); }
.tool-bold { font-weight: 700; }
.tool-a { color: var(--stage-accent-a); }
.tool-b { color: var(--stage-accent-b); }
.tool-memo { color: var(--fg-2); }
.tool.ghost { border-color: transparent; color: var(--fg-3); margin-left: auto; }
.tool.ghost:hover { color: var(--fg); }

#scriptInput {
  width: 100%; min-height: 300px; height: 42vh; resize: vertical; padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--ink); color: var(--fg); line-height: 1.7; font-size: 13.5px;
  font-family: var(--font-ui); scrollbar-width: thin;
}
#scriptInput:focus { outline: none; border-color: var(--fg); }
#scriptInput::placeholder { color: var(--fg-3); }

.seg-control { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg-control button { height: 32px; padding: 0 12px; border: 0; background: transparent; color: var(--fg-2); border-right: 1px solid var(--line); font-size: 12.5px; white-space: nowrap; }
.seg-control button:last-child { border-right: 0; }
.seg-control button:hover { color: var(--fg); }
.seg-control button.on { background: var(--fg); color: #0b0b0c; font-weight: 600; }

.mode-list { display: grid; gap: 1px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); }
.mode-item { display: flex; gap: 11px; align-items: flex-start; padding: 11px 12px; background: var(--panel); cursor: pointer; border-left: 2px solid transparent; }
.mode-item:hover { background: var(--raised); }
.mode-item:has(input:checked) { border-left-color: var(--fg); background: var(--raised); }
.mode-item input { margin-top: 3px; accent-color: var(--fg); }
.mode-body strong { display: block; font-size: 13.5px; font-weight: 600; }
.mode-body small { display: block; color: var(--fg-2); font-size: 12px; margin-top: 3px; line-height: 1.5; }
body:not([data-mode="auto"]) #speedField { display: none; }
body:not([data-mode="voice"]) #voiceBox { display: none; }

.voice-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 12px; margin-top: 10px; }
.voice-status { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; }
.voice-status .label { color: var(--fg-2); }
.voice-note { font-size: 12px; color: var(--fg-2); margin: 8px 0 0; line-height: 1.55; }
.voice-note strong { color: var(--fg); font-weight: 600; }

/* ---------- ステージ（本番表示） ---------- */
.stage {
  position: relative; min-height: 0; background: var(--stage-bg); color: var(--stage-fg); overflow: hidden;
  font-family: var(--font-stage);
}
.stage[data-theme="dark"] { --stage-bg: #17171a; --stage-fg: #f4f4f2; }
.stage[data-theme="white"] {
  --stage-bg: #ffffff; --stage-fg: #111; --stage-read: 0.3; --stage-unread: 0.5;
  --stage-guide: rgba(0, 0, 0, 0.22); --stage-caret: rgba(0, 0, 0, 0.5);
  --stage-accent-a: #9a6b00; --stage-accent-b: #1f6fb2; --stage-memo: #6b6a66; --stage-memo-bg: rgba(0, 0, 0, 0.06);
}
/* 読み位置ガイド: 細い上下の線と左のキャレットだけ。塗りはしない */
.guide {
  position: absolute; left: 0; right: 0; top: var(--guide-top, 38%); height: var(--guide-h, 1.6em);
  pointer-events: none; z-index: 2; font-size: var(--stage-font, 56px);
  border-top: 1px solid var(--stage-guide); border-bottom: 1px solid var(--stage-guide);
}
.guide::before {
  content: ""; position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 0; height: 0; border-left: 8px solid var(--stage-caret); border-top: 6px solid transparent; border-bottom: 6px solid transparent;
}
.guide-label { position: absolute; right: 14px; top: -20px; font-size: 10.5px; letter-spacing: .14em; color: var(--stage-guide); font-family: var(--font-mono); }
.scroller {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scroll-behavior: auto;
  outline: none;
}
.scroller::-webkit-scrollbar { width: 8px; }
.scroller::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, .3); border-radius: 4px; }
.sheet {
  margin: 0 auto; width: var(--sheet-w, 80%); max-width: 100%;
  padding: var(--pad-top, 38vh) 32px 100vh;
  font-size: var(--stage-font, 56px); line-height: var(--stage-lh, 1.7); font-weight: 600;
  overflow-wrap: anywhere; word-break: normal; line-break: strict; text-wrap: pretty;
}
.para { margin: 0 0 .5em; min-height: 1em; }
.para:empty::after { content: "\00a0"; }
.seg { cursor: pointer; transition: opacity .3s ease; }
.seg.read { opacity: var(--stage-read); }
body.no-dim .seg.read { opacity: var(--stage-unread); }
.seg.unread { opacity: var(--stage-unread); }
.seg.current { opacity: 1; }
.seg:hover { opacity: .85; }
.seg.current:hover { opacity: 1; }
.b { font-weight: 800; }
.ca { color: var(--stage-accent-a); }
.cb { color: var(--stage-accent-b); }
.memo {
  display: inline-block; vertical-align: middle; font-family: var(--font-ui); font-size: .4em; font-weight: 500; line-height: 1.3;
  color: var(--stage-memo); background: var(--stage-memo-bg); border-radius: .35em;
  padding: .2em .65em; margin: 0 .4em .15em 0; letter-spacing: .06em; user-select: none;
}
.memo::before { content: "▸ "; opacity: .6; }
.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--stage-fg); opacity: .7; font-family: var(--font-ui); font-size: 15px; padding: 20px; z-index: 3; }
.empty .link { color: var(--stage-fg); }
.empty p { margin: 6px 0; }

/* ---------- 操作バー ---------- */
.controls {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px;
  padding: 0 16px; border-top: 1px solid var(--line); background: var(--ink);
}
.controls-left, .controls-right { display: flex; align-items: center; gap: 8px; }
.controls-center { display: flex; align-items: center; gap: 14px; min-width: 0; }
.speed-inline { display: none; align-items: center; gap: 6px; font-size: 12.5px; color: var(--fg-2); }
.speed-inline span { font-family: var(--font-mono); }
body[data-mode="auto"] .speed-inline { display: flex; }
.transcript { display: none; align-items: center; gap: 9px; min-width: 0; font-size: 12.5px; color: var(--fg-2); height: 34px; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--line); max-width: 42vw; }
body[data-mode="voice"] .transcript { display: flex; }
.transcript span:last-child { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.match-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fg-3); flex: none; }
.match-dot.hit { background: var(--ok); }
.match-dot.miss { background: var(--warn); }
.progress { font-size: 12px; color: var(--fg-2); font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: .04em; }

/* ---------- 集中表示（全画面） ---------- */
/* ヘッダー・サイドは display:none にするので、グリッドの行・列も 1 本だけにする（0 行/列へ自動配置されて台本が消えるのを防ぐ） */
body.focus { grid-template-rows: 1fr; }
body.focus .topbar, body.focus .side { display: none; }
body.focus .layout { grid-template-columns: 1fr; }
body.focus .controls {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(1040px, calc(100vw - 40px)); height: var(--bottom-h);
  border: 1px solid var(--line-strong); border-radius: 10px; background: rgba(11, 11, 12, .9); backdrop-filter: blur(10px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .55); transition: opacity .25s, transform .25s; z-index: 10;
}
body.focus.hide-controls .controls { opacity: 0; transform: translate(-50%, 10px); pointer-events: none; }
body.focus.hide-controls { cursor: none; }
body.focus .controls::before {
  content: "ESC"; position: absolute; right: 16px; top: -22px; font-size: 10.5px; color: var(--fg-3); letter-spacing: .16em; font-family: var(--font-mono);
}

/* ---------- 文字数・目安時間 ---------- */
.stats { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 8px; margin: 10px 0 4px; }
.stats-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 2px 0; }
.stats-k { font-size: 11.5px; color: var(--fg-3); letter-spacing: .06em; min-width: 56px; }
.stats-v { font-size: 14px; }
.stats-v output { font-weight: 700; font-size: 16px; }
.stats-v small { color: var(--fg-2); font-size: 12px; margin-left: 6px; }
.stats-v small output { font-weight: 600; font-size: 12.5px; color: var(--fg-2); }
.stats-time output:first-child { font-size: 18px; }
.stats-sel { margin-left: auto; font-size: 12px; color: var(--fg-2); }
.stats-sel output { font-weight: 600; color: var(--fg); }
.pace-row { display: flex; gap: 4px; flex-wrap: wrap; margin: 8px 0 6px; }
.pace-row button { height: 26px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--line-strong); background: transparent; color: var(--fg-2); font-size: 12px; white-space: nowrap; }
.pace-row button b { font-family: var(--font-mono); font-weight: 600; color: var(--fg); margin-left: 3px; }
.pace-row button:hover { color: var(--fg); background: var(--hover); }
.pace-row button.on { background: var(--fg); color: #0b0b0c; border-color: var(--fg); }
.pace-row button.on b { color: #0b0b0c; }
.stats-note { font-size: 11.5px; color: var(--fg-3); margin: 6px 0 0; line-height: 1.5; }
.stats-note output { color: var(--fg); font-weight: 600; }
.stats-note .link { font-size: 11.5px; color: var(--fg-2); margin-left: 4px; }
#remainText:empty { display: none; }

/* ---------- デスクトップアプリ ---------- */
.install-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 11px 12px; }
.install-box .hint { margin-bottom: 8px; }
.install-box .row { margin: 6px 0; }
.install-box .help { margin-top: 6px; }
body.standalone .topbar { -webkit-app-region: drag; }
body.standalone .topbar button, body.standalone .topbar .status-pill { -webkit-app-region: no-drag; }

/* ---------- ダイアログ・トースト ---------- */
.dialog { border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); color: var(--fg); padding: 24px 26px; max-width: 560px; width: calc(100vw - 40px); }
.dialog::backdrop { background: rgba(0, 0, 0, .7); }
.dialog h2 { margin-bottom: 12px; font-size: 16px; }
.dialog ul { padding-left: 18px; color: var(--fg-2); font-size: 13.5px; margin: 0; }
.dialog li { margin: 7px 0; line-height: 1.6; }
.dialog strong { color: var(--fg); font-weight: 600; }
.toast {
  position: fixed; left: 50%; top: 68px; transform: translateX(-50%); z-index: 50;
  background: var(--raised); color: var(--fg); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 9px 14px; font-size: 13px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5); max-width: min(560px, calc(100vw - 32px));
}
.toast[data-level="err"] { border-color: rgba(255, 92, 77, .55); }
.toast[data-level="ok"] { border-color: rgba(127, 207, 154, .5); }

@media (prefers-reduced-motion: reduce) {
  .seg, .btn, body.focus .controls { transition: none; }
  .status-pill[data-level="live"] .dot { animation: none; }
}

/* ---------- 狭い幅 ---------- */
@media (max-width: 1000px) {
  :root { --side-w: 330px; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); max-height: 45vh; }
  body.side-hidden .layout { grid-template-rows: 1fr; }
  .steps .step { padding: 0 8px; }
  .steps .step .lbl { display: none; }
  .status-pill { max-width: 160px; }
  .controls { gap: 8px; }
  .transcript { max-width: 30vw; }
  .progress { display: none; }
}
