/* アイラブ♥プリキュアシート Web版：アプリ画面とシート共通の調整
 * テンプレートごとの見た目は templates.css（design-rough から自動生成）にある */

:root {
  --ui-bg: #f7f5fa;
  --ui-surface: #ffffff;
  --ui-text: #2a2433;
  --ui-muted: #6c6478;
  --ui-line: #e3dcea;
  --ui-accent: #b8327a;
  --ui-accent-ink: #ffffff;
  --ui-accent-soft: #fbe8f2;
  --ui-warn: #b54708;
  --ui-danger: #b42318;
  --ui-radius: 12px;
  --ui-font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Noto Sans JP", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: var(--ui-font);
  font-size: 15px;
  line-height: 1.6;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- ヘッダー ---------- */
.app-header { background: linear-gradient(120deg, #3a2a5c 0%, #7a3a7e 55%, #c2457f 100%); color: #fff; }
.app-header-inner { max-width: 1320px; margin: 0 auto; padding: 18px 16px 16px; }
.app-title { margin: 0; font-size: 22px; font-weight: 900; letter-spacing: .03em; }
.app-title-sub { font-size: 13px; font-weight: 700; background: rgba(255,255,255,.2); border-radius: 999px; padding: 2px 10px; vertical-align: middle; }
.app-lead { margin: 6px 0 0; font-size: 14px; opacity: .95; }
.app-notice { margin: 4px 0 0; font-size: 12px; opacity: .85; }
/* ページ内リンクと「Xで共有する」：狭い幅では折り返す */
.app-header-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-top: 10px; }
.header-nav { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.header-nav a {
  color: #fff; text-decoration: none; font-size: 13px; font-weight: 700; line-height: 1.4;
  padding: 5px 11px; border: 1px solid rgba(255,255,255,.55); border-radius: 999px; background: rgba(255,255,255,.12);
}
.header-nav a:hover, .header-nav a:focus-visible { background: rgba(255,255,255,.26); }
.btn-share-x {
  display: inline-flex; align-items: center; flex-shrink: 0; white-space: nowrap;
  color: #fff; background: #000; text-decoration: none; font-size: 14px; font-weight: 800;
  padding: 7px 16px; border-radius: 999px; border: 1px solid rgba(255,255,255,.6);
}
.btn-share-x:hover, .btn-share-x:focus-visible { background: #222; }

/* ---------- タブ ---------- */
.view-tabs {
  position: sticky; top: 0; z-index: 20;
  display: flex; gap: 6px; padding: 8px 16px;
  background: rgba(247,245,250,.96); border-bottom: 1px solid var(--ui-line);
  max-width: 100%; overflow-x: auto;
}
.view-tabs button {
  border: 1px solid var(--ui-line); background: var(--ui-surface); border-radius: 999px;
  padding: 7px 16px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.view-tabs button[aria-selected="true"] { background: var(--ui-accent); color: var(--ui-accent-ink); border-color: var(--ui-accent); }

/* ---------- 2カラム ---------- */
.app-main { max-width: 1320px; margin: 0 auto; padding: 16px; display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 20px; align-items: start; }
.pane-preview { position: sticky; top: 64px; display: flex; flex-direction: column; gap: 14px; }
.only-narrow { display: none; }
body[data-view="form1"] #form2, body[data-view="form2"] #form1 { display: none; }
body[data-view="preview"] #form2 { display: none; }

@media (max-width: 999px) {
  .app-main { grid-template-columns: minmax(0, 1fr); }
  .pane-preview { position: static; }
  .only-narrow { display: inline-block; }
  body[data-view="form1"] .pane-preview, body[data-view="form2"] .pane-preview { display: none; }
  body[data-view="preview"] .pane-form { display: none; }
}

/* ---------- パネル・フォーム ---------- */
.panel, .grp { background: var(--ui-surface); border: 1px solid var(--ui-line); border-radius: var(--ui-radius); padding: 14px 16px; }
.panel-title { margin: 0 0 10px; font-size: 16px; font-weight: 800; }
/* ヘッダーのページ内リンクの移動先（上の固定タブに隠れないように）と、移動したときの目印 */
#panel-data, #panel-export { scroll-margin-top: 64px; }
.panel:focus { outline: none; }
.panel-flash { animation: panel-flash 1.6s ease-out; }
@keyframes panel-flash { 0%, 40% { box-shadow: 0 0 0 3px var(--ui-accent); } 100% { box-shadow: 0 0 0 3px transparent; } }
.panel-tip { color: var(--ui-text); background: var(--ui-accent-soft); border-radius: 8px; padding: 6px 10px; }
.grp { margin: 0 0 14px; min-width: 0; }
.grp legend { font-weight: 800; font-size: 15px; padding: 0 6px; margin-left: -6px; }
.grp-sub { margin: 0; font-size: 12px; color: var(--ui-muted); }
.f { margin: 10px 0 0; min-width: 0; }
.f label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.f input[type="text"], .f input:not([type]), .f input[type="number"], .f input[type="date"], .f select, .f textarea {
  width: 100%; border: 1px solid #cfc6da; border-radius: 8px; background: #fff; padding: 9px 10px;
  font-size: 16px; /* iOSでズームしないように16px */
}
.f textarea { resize: vertical; line-height: 1.6; }
.f input:focus, .f select:focus, .f textarea:focus, .ep-row select:focus, .ep-row input:focus { outline: 2px solid var(--ui-accent); outline-offset: 1px; border-color: transparent; }
.f-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; min-height: 18px; margin-top: 2px; }
.f-meta .hint { color: var(--ui-warn); }
.f-meta .count { color: var(--ui-muted); margin-left: auto; white-space: nowrap; }
.f-meta .count.warn { color: var(--ui-danger); font-weight: 700; }
.req { display: inline-block; margin-left: 6px; font-size: 11px; color: #fff; background: var(--ui-danger); border-radius: 4px; padding: 0 5px; vertical-align: 1px; }
.note { margin: 4px 0 0; font-size: 12px; color: var(--ui-muted); }
.f-inline { display: grid; grid-template-columns: 28px minmax(0, 1fr); column-gap: 6px; align-items: center; }
.f-inline label { margin: 0; }
.f-inline .f-meta { grid-column: 2; }
.f-date input { width: auto; min-width: 170px; display: inline-block; }
.f-date .btn-small { margin-left: 8px; vertical-align: middle; }
.pair { border-top: 1px dashed var(--ui-line); margin-top: 10px; padding-top: 2px; }
.pair:first-of-type { border-top: 0; }

/* 視聴済み */
.watched-form { margin-top: 10px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.watched-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--ui-line); }
.watched-name { font-size: 14px; min-width: 0; }
.wbtns { display: inline-flex; flex-shrink: 0; border: 1px solid #cfc6da; border-radius: 8px; overflow: hidden; }
.wbtn { border: 0; background: #fff; width: 40px; height: 32px; cursor: pointer; font-weight: 800; color: var(--ui-muted); }
.wbtn + .wbtn { border-left: 1px solid #cfc6da; }
.wbtn[aria-pressed="true"] { background: var(--ui-accent); color: #fff; }
.watched-sep { margin-top: 8px; font-size: 12px; font-weight: 700; color: var(--ui-muted); }

/* エピソード */
.ep-row { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 6px 8px; align-items: center; margin-top: 10px; }
.ep-row select, .ep-row input { border: 1px solid #cfc6da; border-radius: 8px; background: #fff; padding: 8px; font-size: 16px; min-width: 0; }
.ep-row select { width: 100%; }
.ep-row input { width: 72px; }
.ep-no-wrap { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; font-size: 14px; }
.ep-title { grid-column: 2 / -1; font-size: 14px; font-weight: 700; color: var(--ui-accent); min-height: 1.4em; }
.ep-title.muted { color: var(--ui-muted); font-weight: 500; font-size: 12px; }
.ep-idx { font-weight: 700; }

/* 画像欄 */
.image-field { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; margin-top: 6px; }
.image-thumb-frame { width: 126px; aspect-ratio: 210 / 268; border-radius: 10px; overflow: hidden; border: 2px solid var(--ui-accent); background: #eee; flex-shrink: 0; }
.image-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-ctrl { display: flex; flex-direction: column; gap: 8px; min-width: 180px; flex: 1; }
.range { display: flex; flex-direction: column; font-size: 12px; font-weight: 700; }
.range input { width: 100%; }

/* ボタン */
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid #cfc6da; background: #fff; border-radius: 10px; padding: 9px 14px;
  font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none; color: var(--ui-text);
}
.btn:hover { border-color: var(--ui-accent); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-primary { background: var(--ui-accent); color: #fff; border-color: var(--ui-accent); }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-quiet { background: transparent; }
.btn-danger { color: var(--ui-danger); }
.small { font-size: 12.5px; color: var(--ui-muted); margin: 6px 0; }

/* テンプレート選択 */
.template-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 560px) { .template-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tpl-card { border: 2px solid var(--ui-line); background: #fff; border-radius: 10px; padding: 8px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; text-align: left; }
.tpl-card[aria-checked="true"] { border-color: var(--ui-accent); box-shadow: 0 0 0 2px var(--ui-accent-soft); }
.tpl-swatches { display: flex; gap: 3px; flex-wrap: wrap; }
.tpl-dot { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); }
.tpl-name { font-size: 12.5px; font-weight: 700; line-height: 1.35; }

/* プレビュー */
.preview-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.preview-head .panel-title { margin: 0; }
.seg { display: inline-flex; border: 1px solid #cfc6da; border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 5px 14px; font-weight: 700; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ui-accent); color: #fff; }
.preview-stage { margin-top: 10px; position: relative; overflow: hidden; width: 100%; }
.preview-scaler { transform-origin: 0 0; position: absolute; left: 0; top: 0; }

/* 書き出し用の作業台（画面外） */
.export-stage { position: fixed; left: -12000px; top: 0; pointer-events: none; }

/* モーダル */
.modal { position: fixed; inset: 0; background: rgba(20, 12, 28, .6); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 14px; max-width: 920px; width: 100%; max-height: 92vh; overflow: auto; padding: 16px; }
.modal-images { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.modal-fig { margin: 0; }
.modal-fig img { width: 100%; height: auto; border: 1px solid var(--ui-line); border-radius: 8px; display: block; }
.modal-fig figcaption { margin-top: 8px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); background: #2a2433; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: .2s; z-index: 60; max-width: calc(100% - 32px); pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 規約 */
.terms { background: #fff; border-top: 1px solid var(--ui-line); margin-top: 24px; }
.terms-inner { max-width: 1320px; margin: 0 auto; padding: 18px 16px 40px; }
.terms h2 { font-size: 16px; margin: 14px 0 6px; }
.terms-list { margin: 0; padding-left: 0; list-style: none; font-size: 14px; }
.terms-list li { padding: 2px 0 2px 26px; position: relative; }
.terms-list li.ok::before { content: "✅"; position: absolute; left: 0; }
.terms-list li.ng::before { content: "❌"; position: absolute; left: 0; }
.terms-list.plain li::before { content: "・"; position: absolute; left: 8px; }
.terms-foot { margin: 14px 0 0; font-weight: 700; }

/* ---------- AIアシスト（長文欄の下書き） ---------- */
/* AIつきの欄は「ラベル→入力欄→AIアシスト→残り文字数」を枠で囲んでひとかたまりに見せる */
.f-ai { margin-top: 16px; padding: 10px 10px 4px; border: 1.5px solid #ecc6da; border-radius: var(--ui-radius); background: #fffafd; }
.f-ai + .f-ai { margin-top: 18px; }
.ai-assist { position: relative; margin-top: 4px; padding: 6px 8px; border-radius: 8px; background: var(--ui-accent-soft); }
.f-ai .ai-assist { margin-top: 10px; padding: 8px 10px; }
/* 上の入力欄を指す小さな三角（この欄に入ることを示す） */
.f-ai .ai-assist::before {
  content: ""; position: absolute; left: 22px; top: -7px;
  border: 7px solid transparent; border-top: 0; border-bottom-color: var(--ui-accent-soft);
}
.ai-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.ai-title { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--ui-accent); font-weight: 700; min-width: 0; }
.ai-title strong { font-weight: 800; }
.ai-tips-btn {
  flex-shrink: 0; border: 0; background: transparent; color: var(--ui-accent); cursor: pointer;
  font-size: 12.5px; font-weight: 700; padding: 2px 4px; margin: -2px -4px 0 0; text-decoration: underline; text-underline-offset: 3px;
  min-height: 28px; white-space: nowrap;
}
.ai-tips-btn[aria-expanded="true"] { text-decoration: none; background: #fff; border-radius: 6px; }
/* 「例を見る」のバルーン：見出しとメモの間に開く。AIアシストの幅に収まるので、スマホ幅でも画面からはみ出さない */
.ai-tips {
  position: relative; margin: 8px 0 8px;
  background: #fff; border: 1.5px solid var(--ui-accent); border-radius: 10px; padding: 10px 34px 10px 12px;
  box-shadow: 0 3px 10px rgba(42, 36, 51, .12); font-size: 13px; line-height: 1.6; color: var(--ui-text);
}
.ai-tips[hidden] { display: none; }
.ai-tips::before, .ai-tips::after { content: ""; position: absolute; right: 26px; border: 8px solid transparent; border-top: 0; }
.ai-tips::before { top: -9px; border-bottom-color: var(--ui-accent); }
.ai-tips::after { top: -6.5px; border-bottom-color: #fff; }
.ai-tips p { margin: 0; }
.ai-tips .ai-tips-h { margin-top: 6px; font-size: 12px; font-weight: 800; color: var(--ui-accent); }
.ai-tips .ai-tips-h:first-of-type { margin-top: 0; }
.ai-tips-ex { margin: 2px 0 0; padding: 0; list-style: none; }
.ai-tips-ex li { margin-top: 3px; padding: 3px 8px; background: var(--ui-bg); border-radius: 6px; overflow-wrap: anywhere; }
.ai-tips-close {
  position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border: 0; background: transparent;
  font-size: 18px; line-height: 1; color: var(--ui-muted); cursor: pointer; border-radius: 6px;
}
.ai-tips-close:hover { background: var(--ui-bg); }
.ai-row { display: flex; gap: 6px; align-items: center; }
.f .ai-row .ai-memo { flex: 1; min-width: 0; padding: 5px 8px; font-size: 16px; /* iOSでズームしないように16px */ }
.btn-ai { flex-shrink: 0; white-space: nowrap; }
.ai-status { margin: 2px 0 0; font-size: 12px; color: var(--ui-muted); }
.ai-status:empty { display: none; }

/* ====================================================================
 * シート（全テンプレート共通の調整）
 * 固定レイアウト：空の状態で高さを決めてから文字を入れ、はみ出す欄は文字を小さくする
 * ==================================================================== */
.sheet-wrap { padding: 0 !important; background: transparent !important; line-height: 1.5; width: max-content; }
.sheet-wrap .precure-sheet { box-shadow: none; }
.sheet-wrap .precure-sheet.sheet-no1 { height: 1540px; }
.sheet-wrap .precure-sheet.sheet-no2 { height: 1320px; min-height: 0; }
/* 自由入力欄（100字）が入る高さ */
.sheet-wrap .two-col-fav .free-note-box { min-height: 86px; }
.sheet-wrap .series-recommend-table + .free-note-box { min-height: 52px !important; }
/* 映画タイトルは2行まで */
.sheet-wrap .numbered-item > .slot-movie { height: 40px; line-height: 1.5; font-size: 13px; overflow: hidden; display: flex; align-items: center; white-space: normal; overflow-wrap: anywhere; }

.sheet-wrap .slot-line {
  display: inline-block; max-width: 100%; min-width: 0;
  white-space: nowrap; overflow: hidden; vertical-align: middle;
}
.sheet-wrap .field-value { width: 100%; min-width: 0; overflow: hidden; }
.sheet-wrap .numbered-item > strong { flex: 1 1 auto; min-width: 0; }
.sheet-wrap .slot-box { overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; }
.sheet-wrap .free-note-box.slot-box { flex: 1 1 auto; }
.sheet-wrap .has-box { display: flex; flex-direction: column; min-height: 0; }
.sheet-wrap .has-box > .slot-box { flex: 1 1 auto; min-height: 0; }

/* 推しシリーズ：理由は3行分の固定枠 */
.sheet-wrap .series-recommend-table { table-layout: fixed; }
.sheet-wrap .series-recommend-row td:first-child .slot-line { max-width: calc(100% - 30px); }
.sheet-wrap .slot-td-box { height: 57px; line-height: 1.5; }

/* エピソード表 */
.sheet-wrap .episode-table { table-layout: fixed; }
.sheet-wrap .episode-row td .slot-line { display: block; }

/* 記入日・記入者 */
.sheet-wrap .slot-date { white-space: nowrap; }
.sheet-wrap .slot-writer { max-width: 380px; overflow: hidden; }

/* 画像 */
.sheet-wrap .avatar-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.sheet-wrap .watch-mark.is-blank { opacity: .45; }
.sheet-wrap .watched-item .slot-line { flex: 1 1 auto; }
.sheet-wrap .footer-credit { white-space: nowrap; flex-shrink: 0; }
.sheet-wrap .sheet-footer { gap: 12px; }
/* No.2：エピソードは5件なので、行を高くして表を広げる */
.sheet-wrap .songs-episodes-grid { grid-template-columns: 0.72fr 1.48fr; }
.sheet-wrap .episode-row td { height: 38px; font-size: 12.5px; }
.sheet-wrap .episode-row td:first-child { width: 34%; }
.sheet-wrap .episode-row td.ep-num { width: 11%; }
.sheet-wrap .episode-table th:nth-child(1) { width: 34%; }
.sheet-wrap .episode-table th:nth-child(2) { width: 11%; }
.sheet-wrap .sheet-no2 .sheet-content > .section-card:last-child .text-area-box { font-size: 14px; }
.app-title-sub { white-space: nowrap; }
@media (max-width: 560px) {
  .app-title { font-size: 19px; }
  .view-tabs { padding: 8px 12px; gap: 5px; }
  .view-tabs button { padding: 6px 11px; font-size: 13.5px; }
  .tpl-name { font-size: 12px; }
  .app-main { padding: 12px; }
}
