/*
 * カンププレゼンターの表示部分。書き出した単体の HTML にもそのまま入るので、
 * Bootstrap やサイト共通の CSS に頼らず、ここだけで完結させる。
 */

.cv-root {
  --cv-stage: #eceef1;
  --cv-ink: #1f2328;
  --cv-sub: #5b6470;
  --cv-bar: #ffffff;
  --cv-line: #d5d9df;
  --cv-face: #e9ecf0;
  --cv-sel: #0d6efd;
  --cv-sel-ink: #ffffff;
  --cv-sel-text: #0a58ca;
  --cv-chrome: #dfe3e8;
  --cv-dot: #9aa3ae;
  --cv-bezel: #1f2328;
  --cv-main: #ffc107;
  --cv-main-ink: #1f2328;
  --cv-page: #ffffff;
  --cv-shadow: 0 8px 28px rgba(31, 35, 40, 0.18);

  position: relative;
  display: flex;
  flex-direction: column;
  height: clamp(520px, 82vh, 1000px);
  overflow: hidden;
  border-radius: 6px;
  background: var(--cv-stage);
  color: var(--cv-ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  text-align: left;
}

/* 暗い色の組: サイトのダークモードと、プレゼン表示 */
[data-bs-theme="dark"] .cv-root,
.cv-root.cv-present {
  --cv-stage: #17191d;
  --cv-ink: #e6e8eb;
  --cv-sub: #aab2bd;
  --cv-bar: #2a2e35;
  --cv-line: #4a515c;
  --cv-face: #3a3f47;
  --cv-sel: #9db8d3;
  --cv-sel-ink: #17191d;
  --cv-sel-text: #e6e8eb;
  --cv-chrome: #2a2e35;
  --cv-dot: #6b7380;
  --cv-bezel: #4a515c;
  --cv-shadow: none;
}

.cv-root *,
.cv-root *::before,
.cv-root *::after {
  box-sizing: border-box;
}

/* ---------- 操作の帯 ---------- */

.cv-bar {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 16px;
  background: var(--cv-bar);
  border-bottom: 1px solid var(--cv-line);
}

/* 1段目: 案（伸び縮みし、入りきらなければ中で折り返す）・表示・右端のボタン。2段目: チェック */
.cv-row {
  display: flex;
  align-items: flex-end;
  gap: 10px 20px;
  min-width: 0;
}

.cv-row-sub {
  flex-wrap: wrap;
  align-items: center;
  gap: 0 20px;
}

.cv-group-plan {
  flex: 0 1 auto;
}

.cv-main-slot {
  flex: none;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-left: auto;
}

.cv-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cv-glabel {
  font-size: 11px;
  color: var(--cv-sub);
}

.cv-seg {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  padding-left: 1px;
}

.cv-seg input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.cv-seg label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  min-width: 48px;
  margin-left: -1px;
  padding: 0 14px;
  border: 1px solid var(--cv-sel);
  background: var(--cv-bar);
  color: var(--cv-sel-text);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.cv-seg label:first-of-type {
  border-radius: 6px 0 0 6px;
}

.cv-seg label:last-of-type {
  border-radius: 0 6px 6px 0;
}

.cv-seg label:hover {
  background: color-mix(in srgb, var(--cv-sel) 12%, var(--cv-bar));
}

.cv-seg input:checked + label {
  background: var(--cv-sel);
  color: var(--cv-sel-ink);
}

.cv-seg input:disabled + label {
  border-style: dashed;
  background: var(--cv-bar);
  color: var(--cv-sub);
  cursor: not-allowed;
}

.cv-seg input:focus-visible + label {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--cv-sel);
  outline-offset: 2px;
}

.cv-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.cv-check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--cv-sel);
}

.cv-hint {
  display: none;
  align-self: center;
  font-size: 12px;
  color: var(--cv-sub);
  white-space: nowrap;
}

.cv-spacer {
  flex: 1 1 0;
}

.cv-btn {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: var(--cv-face);
  color: var(--cv-ink);
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}

.cv-btn:hover {
  background: color-mix(in srgb, var(--cv-ink) 14%, var(--cv-face));
}

.cv-btn-main {
  background: var(--cv-main);
  color: var(--cv-main-ink);
  font-weight: 700;
}

.cv-btn-main:hover {
  background: color-mix(in srgb, #000000 8%, var(--cv-main));
}

.cv-btn:focus-visible,
.cv-check input:focus-visible,
.cv-scroll:focus-visible {
  outline: 2px solid var(--cv-sel);
  outline-offset: 2px;
}

.cv-scroll:focus-visible {
  outline-offset: -2px;
}

/* ---------- ステージと枠 ---------- */

.cv-stage {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 40px;
  padding: 16px 24px 0;
  overflow: hidden;
  /* スマホの枠の高さを、ステージの高さ（100cqh）から決めるための入れ物 */
  container-type: size;
}

.cv-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  min-height: 0;
}

.cv-col-pc {
  flex: 1 1 0;
  max-width: 1280px;
}

.cv-col-sp {
  flex: 0 1 auto;
  align-items: center;
  padding-bottom: 20px;
}

.cv-cap {
  flex: none;
  font-size: 12px;
  color: var(--cv-sub);
}

.cv-frame {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--cv-page);
  box-shadow: var(--cv-shadow);
}

.cv-frame-pc {
  flex: 1 1 0;
  border-radius: 10px 10px 0 0;
}

/* 高さを先に決め、幅は縦横比から出す。64px は、ステージの上の余白・見出しの行・列の下の余白の合計 */
.cv-frame-sp {
  flex: none;
  height: min(740px, 100cqh - 64px);
  aspect-ratio: 9 / 19;
  max-width: 100%;
  border: 10px solid var(--cv-bezel);
  border-radius: 36px;
}

.cv-chrome {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px;
  background: var(--cv-chrome);
}

.cv-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cv-dot);
}

.cv-pill {
  flex: 1 1 0;
  height: 20px;
  margin-left: 10px;
  border-radius: 10px;
  background: var(--cv-page);
  opacity: 0.85;
}

.cv-scroll {
  flex: 1 1 0;
  min-height: 0;
  /* 中の画像の元の幅が、枠や列の幅を押し広げないようにする（幅 0 から始めて、枠いっぱいに広げる） */
  width: 0;
  min-width: 100%;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--cv-page);
}

.cv-scroll img {
  flex: none;
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
}

/* 元の大きさで表示: 画像を引き伸ばさず、枠より大きいときだけ枠の幅まで縮める */
.cv-actual .cv-scroll img {
  align-self: center;
  width: auto;
  max-width: 100%;
}

.cv-empty {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  color: #5b6470;
  font-size: 13px;
  text-align: center;
}

/* ---------- プレゼン表示 ---------- */

html.cv-lock {
  overflow: hidden;
}

.cv-root.cv-present {
  position: fixed;
  inset: 0;
  z-index: 3000;
  height: auto;
  border-radius: 0;
}

.cv-root.cv-present:fullscreen {
  width: 100%;
  height: 100%;
}

.cv-present .cv-bar {
  position: absolute;
  left: 50%;
  bottom: 20px;
  z-index: 2;
  transform: translateX(-50%);
  /* 入りきらない幅では、帯の中で折り返す（横にはみ出させない） */
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  transition: opacity 0.15s;
}

.cv-present.cv-idle .cv-bar {
  opacity: 0;
  pointer-events: none;
}

.cv-present .cv-glabel {
  display: none;
}

/* プレゼン表示の小さな帯では、段を分けずに1つの並びにする */
.cv-present .cv-bar {
  flex-direction: row;
  gap: 10px 20px;
}

.cv-present .cv-row {
  display: contents;
}

.cv-present .cv-main-slot {
  order: 1;
  margin-left: 0;
  align-self: center;
}

.cv-present .cv-spacer {
  display: none;
}

.cv-present .cv-hint {
  display: block;
}

.cv-present .cv-seg {
  flex-wrap: nowrap;
}

.cv-present .cv-seg label,
.cv-present .cv-btn,
.cv-present .cv-check {
  min-height: 44px;
}

.cv-present .cv-stage {
  padding-top: 20px;
  gap: 56px;
}

.cv-present .cv-chrome {
  display: none;
}

.cv-present .cv-frame-pc {
  border-radius: 6px 6px 0 0;
}

.cv-present .cv-frame-sp {
  border-width: 2px;
  border-radius: 26px;
}

/* ---------- 狭い画面 ---------- */

@media (max-width: 1400px) {
  .cv-present .cv-hint {
    display: none;
  }
}

@media (max-width: 700px) {
  .cv-root:not(.cv-present) {
    height: auto;
  }

  /* 狭い幅では、案を1行目にまるごと使い、表示とボタンを2行目に置く */
  .cv-root:not(.cv-present) .cv-row-main {
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  .cv-root:not(.cv-present) .cv-group-plan {
    flex: 1 1 100%;
  }

  /* 狭い幅では、プレゼン表示を横いっぱいのボタンにして、行の右に浮かせない */
  .cv-root:not(.cv-present) .cv-main-slot {
    flex: 1 1 100%;
    margin-left: 0;
  }

  .cv-root:not(.cv-present) .cv-main-slot .cv-glabel {
    display: none;
  }

  .cv-root:not(.cv-present) .cv-main-slot .cv-btn {
    width: 100%;
  }

  .cv-stage {
    flex: none;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 16px;
    overflow: visible;
    container-type: normal;
  }

  .cv-present .cv-stage {
    flex: 1 1 0;
    justify-content: flex-start;
    padding: 16px 16px 120px;
    overflow-y: auto;
  }

  .cv-col {
    flex: none;
    width: 100%;
    padding-bottom: 0;
  }

  .cv-frame {
    flex: none;
    height: 70vh;
  }

  .cv-frame-pc {
    border-radius: 10px;
  }

  .cv-present .cv-bar {
    left: 16px;
    right: 16px;
    transform: none;
    width: auto;
    max-width: none;
  }

  /* スマホのプレゼン表示では帯を低く保つ: 案の列は折り返さず横にスクロールし、チェックは隠す */
  .cv-present .cv-bar {
    gap: 8px 12px;
    padding: 8px;
  }

  .cv-present .cv-group {
    max-width: 100%;
  }

  .cv-present .cv-seg {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .cv-present .cv-check {
    display: none;
  }

  /* 表示の切り替えと「編集に戻る」を1行に収める */
  .cv-present .cv-seg label,
  .cv-present .cv-btn {
    padding: 0 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cv-present .cv-bar {
    transition: none;
  }
}
