:root {
  --bg: #FBF6F0;
  --card: #FFFFFF;
  --ink: #3B2F2A;
  --sub: #8A7A70;
  --line: #EADFD4;
  --accent: #E0714A;
  --accent-ink: #FFFFFF;
  --soft: #FBE9DF;
  --ok: #4E9A6B;
  --telop-font: "Zen Maru Gothic";
  --telop-weight: 500;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  padding-bottom: calc(84px + var(--safe-b));
}
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 8px 0 4px; }
h2 { font-size: 15px; margin: 0 0 8px; }
h2 small, .note { color: var(--sub); font-weight: normal; font-size: 12px; }
.note { margin: 6px 0 0; }
.center { text-align: center; }
.lead { color: var(--sub); margin: 0 0 12px; font-size: 14px; }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 10;
  background: rgba(251, 246, 240, .94);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.top-inner { max-width: 1040px; margin: 0 auto; padding: 8px 16px; }
.brand { font-size: 13px; font-weight: 700; color: var(--sub); }
.mock-badge { background: var(--soft); color: var(--accent); border-radius: 99px; padding: 1px 8px; font-size: 11px; margin-left: 4px; }
.steps { list-style: none; display: flex; gap: 4px; margin: 6px 0 2px; padding: 0; }
.steps li { flex: 1; font-size: 11px; color: var(--sub); display: flex; align-items: center; gap: 4px; padding-top: 6px; border-top: 3px solid var(--line); }
.steps li span { font-weight: 700; }
.steps li.done { border-color: #F0B9A3; }
.steps li.current { border-color: var(--accent); color: var(--ink); font-weight: 700; }

main { max-width: 600px; margin: 0 auto; padding: 8px 16px; }
main:has(.screen.wide:not([hidden])) { max-width: 1040px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; }

/* ボタン */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 700; font-size: 15px;
  border-radius: 12px; padding: 12px 16px; min-height: 48px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.icon-btn { appearance: none; border: 1px solid var(--line); background: var(--card); border-radius: 10px; min-width: 36px; height: 36px; font-size: 14px; color: var(--sub); }
.icon-btn:disabled { opacity: .3; }

/* タブ */
.tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tabs button {
  flex: 1; appearance: none; border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 700;
  color: var(--sub); padding: 10px 4px; border-radius: 9px; position: relative; min-height: 44px;
}
.tabs button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.tabs button { white-space: nowrap; }
.tabs .dot { position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.tabs button.filled .dot { background: var(--ok); }
.tabs.big { background: var(--card); border: 1px solid var(--line); }
.tabs.big button.active { background: var(--soft); color: var(--accent); box-shadow: none; }

/* 素材選択 */
.video-panel, .pane { display: none; }
.video-panel.active, .pane.active { display: block; }
.pick {
  display: flex; align-items: center; justify-content: center; text-align: center;
  border: 2px dashed #E8C7B6; border-radius: 14px; background: var(--soft); color: var(--accent);
  font-weight: 700; min-height: 140px; cursor: pointer; padding: 12px;
}
.pick.small { min-height: 64px; font-size: 14px; }
.pick.has-file { min-height: 48px; border-style: solid; font-size: 13px; }
.video-panel video { width: 100%; max-height: 50vh; background: #000; border-radius: 12px; margin-top: 10px; display: block; }
.dur { font-size: 13px; color: var(--sub); margin-top: 6px; text-align: right; }
.photo-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photo-row .card { margin-bottom: 0; }
.photo-preview { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; margin-top: 8px; display: block; }

.pkg-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 8px; }
.pkg-grid:empty { display: none; }
.pkg-item { position: relative; }
.pkg-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.pkg-item button { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; }
.transcript summary { font-size: 14px; font-weight: 700; cursor: pointer; }
.transcript p { white-space: pre-wrap; font-size: 14px; margin: 8px 0 0; color: var(--sub); }

/* 録音 */
.day-card { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.day-field { font-size: 20px; color: var(--accent); }
.day-field input { width: 80px; font-size: 20px; font-weight: 700; }
.rec-card { text-align: center; padding: 24px 14px; }
.rec-btn {
  width: 112px; height: 112px; border-radius: 50%; border: 6px solid var(--soft);
  background: var(--accent); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.rec-icon { width: 36px; height: 36px; background: #fff; border-radius: 50%; transition: .2s; }
.rec-btn.recording { animation: pulse 1.4s infinite; }
.rec-btn.recording .rec-icon { border-radius: 6px; width: 32px; height: 32px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(224,113,74,.5); } 50% { box-shadow: 0 0 0 16px rgba(224,113,74,0); } }
.rec-time { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 10px; }
.rec-status { color: var(--sub); font-size: 13px; }
.rec-after { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.rec-after audio { width: 100%; }
.hints { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; }
.hints li { background: var(--soft); color: var(--ink); border-radius: 99px; padding: 4px 12px; font-size: 13px; }

input[type=number], input[type=text], textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid #F3B49B; border-color: transparent; }
.big-text { min-height: 320px; line-height: 1.7; }
.btn.wide { width: 100%; margin-top: 10px; }
.pane > .btn.copy { width: 100%; margin-top: 10px; }

/* フォント切り替え */
.font-switch { display: flex; gap: 6px; overflow-x: auto; margin: 4px 0 12px; padding-bottom: 2px; }
.font-switch button {
  appearance: none; flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); border-radius: 99px;
  padding: 6px 14px; font-size: 15px; color: var(--ink); min-height: 40px;
}
.font-switch button.active { border-color: var(--accent); background: var(--soft); color: var(--accent); }

/* プレビュー */
.split { display: grid; gap: 16px; }
.stage-col { display: flex; flex-direction: column; align-items: center; }
.stage {
  position: relative; width: min(100%, calc(52vh * 9 / 16)); aspect-ratio: 9/16;
  background: #222; border-radius: 14px; overflow: hidden; container-type: inline-size;
}
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.telop {
  position: absolute; left: 0; right: 0; top: 44.6875%; transform: translateY(-50%); /* 40%＋90px（1920px 換算） */
  text-align: center; color: #fff; white-space: nowrap;
  font-family: var(--telop-font), sans-serif; font-weight: var(--telop-weight);
  font-size: 5cqw;                 /* 1080px 幅換算で約 54px */
  letter-spacing: .09em;
  text-shadow: 0 .2cqw .9cqw rgba(0,0,0,.55), 0 0 .3cqw rgba(0,0,0,.25);
  padding: 0 4cqw; pointer-events: none;
}
.title-card {
  position: absolute; left: 0; right: 0; top: 46%; transform: translateY(-50%);
  text-align: center; color: #fff; pointer-events: none; padding: 0 4cqw;
  font-family: var(--telop-font), sans-serif; font-weight: var(--title-weight, 700);
  text-shadow: 0 .4cqw 2.2cqw rgba(0,0,0,.7), 0 0 .6cqw rgba(0,0,0,.45);
}
.tc-title { font-size: 14cqw; line-height: 1.18; letter-spacing: .02em; white-space: pre-line; }
.tc-kcal { font-size: 8cqw; margin-top: 2cqw; letter-spacing: .04em; }
.tc-kcal:empty { display: none; }
.stage video { transform-origin: center; }
.telop .stars { letter-spacing: 0; }
.telop .star { position: relative; display: inline-block; color: rgba(255,255,255,.45); }
.telop .star::before { content: '★'; position: absolute; left: 0; top: 0; width: var(--fill); overflow: hidden; color: #FFC93C; }
.inline-field select { font: inherit; font-size: 16px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
#eatDrink, #eatClosing { flex: 1; width: auto; }
.fixed-telop { background: #F7F2EE; border-radius: 10px; padding: 10px 12px; color: var(--sub); }
.scene-picker { display: block; margin-top: 10px; font-size: 13px; color: var(--sub); }
.scene-picker input { width: 100%; accent-color: var(--accent); }
.inline-field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--sub); margin-top: 8px; }
.inline-field input { width: 120px; }
.stage .overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.checklist label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px; color: var(--sub); }
.checklist input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: 0 0 auto; }
.checklist b { display: block; color: var(--ink); font-size: 14px; }
.checklist label:has(input:checked) { background: var(--soft); border-color: #F0B9A3; }
.missing { background: #FFF6E5; border-color: #F3D49B; font-size: 14px; }
.telop-row textarea { min-height: 0; padding: 6px 10px; resize: none; line-height: 1.4; }
.telop-row select { font: inherit; font-size: 13px; padding: 6px 4px; border: 1px solid var(--line); border-radius: 8px; background: #fff; flex: 0 0 auto; }
.step-item { border: 1px solid var(--line); border-radius: 12px; padding: 8px; margin-bottom: 8px; }
.step-item .scene-picker { margin-top: 4px; }
.add-row-pair { display: flex; gap: 8px; }
.add-row-pair .btn { flex: 1; }
.stage-label { position: absolute; left: 8px; top: 8px; font-size: 11px; color: #fff; background: rgba(0,0,0,.4); border-radius: 6px; padding: 1px 6px; }
.stage-label:empty { display: none; }
.stage-ctrl { display: flex; gap: 8px; margin-top: 10px; width: min(100%, 360px); }
.stage-ctrl .btn { flex: 1; }

.telop-group { margin-bottom: 16px; }
.telop-group h3 { font-size: 14px; margin: 0 0 6px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.telop-group h3 small { color: var(--sub); font-weight: normal; font-size: 12px; }
.telop-group h3 small.warn { color: var(--accent); }
.telop-row { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.telop-row .num { width: 22px; font-size: 12px; color: var(--sub); text-align: right; flex: 0 0 auto; }
.telop-row .field { position: relative; flex: 1; min-width: 0; }
.telop-row input { padding-right: 38px; }
.telop-row .count { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--sub); }
.telop-row .count.over { color: var(--accent); font-weight: 700; }
.telop-row.cut input { color: var(--sub); background: #F7F2EE; }
.add-row { width: 100%; min-height: 40px; font-size: 14px; border-style: dashed; color: var(--sub); }

/* サムネ */
.thumb-wrap { position: relative; width: min(100%, calc(52vh * 9 / 16)); }
#thumbCanvas { width: 100%; height: auto; display: block; border-radius: 14px; touch-action: none; background: #222; }
.grid-guide {
  position: absolute; left: 0; right: 0; top: 21.875%; height: 56.25%; pointer-events: none; /* 中央 1080×1080 */
  border-top: 2px dashed rgba(255,255,255,.8); border-bottom: 2px dashed rgba(255,255,255,.8);
  box-shadow: 0 0 0 999px rgba(0,0,0,.35); clip-path: inset(-999px 0);
}
.thumb-wrap { overflow: hidden; border-radius: 14px; }
.tpl-switch { display: flex; gap: 6px; margin-bottom: 12px; }
.tpl-switch button { flex: 1; appearance: none; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 4px; font: inherit; font-size: 13px; font-weight: 700; color: var(--sub); min-height: 44px; }
.tpl-switch button.active { border-color: var(--accent); background: var(--soft); color: var(--accent); }
.thumb-form label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 10px; }
.thumb-form label input, .thumb-form label textarea { margin-top: 2px; }
.thumb-form .check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; min-height: 36px; }
.thumb-form .check input { width: 20px; height: 20px; accent-color: var(--accent); }
.ttext-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.thumb-form #tTextReset { margin-bottom: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb-form .btn { width: 100%; }

/* 書き出し */
.export { display: grid; gap: 14px; }
.export img { width: min(100%, 240px); justify-self: center; border-radius: 12px; aspect-ratio: 9/16; object-fit: cover; background: #222; }
.export-btns { display: grid; gap: 8px; }
.howto { margin: 0; padding-left: 1.4em; }
.howto li { margin-bottom: 4px; }

/* 下部ナビ */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: rgba(251, 246, 240, .96); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + var(--safe-b));
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.nav-inner { max-width: 600px; margin: 0 auto; display: flex; gap: 10px; }
.nav-inner #backBtn { flex: 0 0 96px; }
.nav-inner #nextBtn { flex: 1; }

.loading {
  position: fixed; inset: 0; z-index: 30; background: rgba(251,246,240,.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-weight: 700;
}
.progress { width: min(80%, 320px); height: 10px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
#exporting p { text-align: center; padding: 0 24px; }
.reel-preview { width: min(100%, 240px); justify-self: center; border-radius: 12px; background: #000; aspect-ratio: 9/16; }
.spinner { width: 44px; height: 44px; border: 4px solid var(--soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 14px;
  opacity: 0; transition: .25s; pointer-events: none; z-index: 40; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* iPad・横向き */
@media (min-width: 820px) {
  .split { grid-template-columns: minmax(280px, 400px) 1fr; align-items: start; }
  .stage, .thumb-wrap { width: min(100%, calc(70vh * 9 / 16)); }
  .stage-col { position: sticky; top: 90px; }
  .export { grid-template-columns: 240px 1fr; align-items: start; }
}
@media (max-width: 360px) {
  .photo-row { grid-template-columns: 1fr; }
}
