/* ============================================================
   テーマの切り替え（ライト / ダーク / システム）

   中身は js/theme.js が入れる。HTML には空の入れ物だけ置く。
   3つを等幅にして、つまみは割合（100%/3）で動かす。幅を測らないので、
   フォントの読み込みや言語で文字幅が変わってもずれない。
   ============================================================ */

.theme-seg {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  padding: 3px;
  background: var(--c-gray-bg);
  border-radius: var(--r-full, 999px);
  font-family: inherit;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

/* 白いつまみ。選んだところへ滑る（行き過ぎて少し戻る） */
.theme-seg__ind {
  position: absolute;
  z-index: 0;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / 3);
  background: var(--c-canvas);
  border-radius: var(--r-full, 999px);
  box-shadow: var(--c-shadow-sm, 0 1px 3px rgba(16, 25, 28, .06));
  transform: translateX(calc(var(--theme-i, 0) * 100%));
  transition: transform var(--puff-dur, 590ms) var(--puff, ease-out);
}

.theme-seg__btn {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  padding: 7px 12px;
  border: none;
  background: none;
  border-radius: var(--r-full, 999px);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--c-sub);
  white-space: nowrap;
  cursor: pointer;
  transition: color .18s ease, transform var(--puff-dur, 590ms) var(--puff, ease-out);
}

.theme-seg__btn.is-on { color: var(--c-primary); }

/* ピルなので角丸は変えず、つぶすだけ（小さい部品の段） */
.theme-seg__btn.is-pressed {
  transform: scale(1.05, .9);
  transition: transform 90ms ease-out, color .18s ease;
}

.theme-seg__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* アイコンだけの形。ログインの左上など、場所が狭いところ */
.theme-seg--compact .theme-seg__btn { padding: 7px 10px; }
.theme-seg--compact .theme-seg__icon { width: 17px; height: 17px; }

/* 閉じた形：ふだんは今のアイコン1つだけ。押すと3つに広がる。
   ボタンの幅を 0 ⇔ 37px で伸び縮みさせるので、等幅（flex:1）はやめて幅を決める。
   広がるときは --puff-firm（行き過ぎない）。幅が行き過ぎると隣のリンクを押してしまう */
.theme-seg--collapse .theme-seg__btn {
  flex: 0 0 auto;
  width: 37px;
  overflow: hidden;
  transition: width var(--puff-firm-dur, 390ms) var(--puff-firm, ease-out),
              padding var(--puff-firm-dur, 390ms) var(--puff-firm, ease-out),
              opacity .16s ease, color .18s ease,
              transform var(--puff-dur, 590ms) var(--puff, ease-out);
}
.theme-seg--collapse:not(.is-open) .theme-seg__btn:not(.is-on) {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  opacity: 0;
  pointer-events: none;
}
/* 閉じているあいだ、つまみは見えている1つの下にそのまま敷く */
.theme-seg--collapse .theme-seg__ind {
  transition: transform var(--puff-dur, 590ms) var(--puff, ease-out),
              width var(--puff-firm-dur, 390ms) var(--puff-firm, ease-out);
}
.theme-seg--collapse:not(.is-open) .theme-seg__ind {
  width: calc(100% - 6px);
  transform: none;
}

/* 閉じた形でシステムを選んでいるとき：モニターの代わりに、効いている太陽か月を出し、
   右下に「A」（自動）の印を添える。広げたときはモニターに戻す（3つを見分けるため） */
.theme-seg__auto { display: none; position: relative; }
.theme-seg--collapse:not(.is-open) .theme-seg__btn.is-on .is-sys { display: none; }
.theme-seg--collapse:not(.is-open) .theme-seg__btn.is-on .theme-seg__auto { display: inline-flex; }
.theme-seg__auto .is-eff-dark { display: none; }
[data-effective="dark"] .theme-seg__auto .is-eff-light { display: none; }
[data-effective="dark"] .theme-seg__auto .is-eff-dark { display: block; }
.theme-seg__badge {
  position: absolute;
  right: -6px;
  bottom: -5px;
  min-width: 11px;
  height: 11px;
  padding: 0 2px;
  border-radius: 999px;
  background: var(--c-primary);
  color: var(--c-on-primary);
  font-size: 8px;
  font-weight: 800;
  line-height: 11px;
  text-align: center;
  font-family: system-ui, sans-serif;
}

/* 見出しつきの1行：サイドのメニューなど、幅が 230px 前後しかない場所。
   文字つきの3つを詰めると「システム」が入りきらないので、アイコンだけにして
   左に「テーマ」と書く */
.theme-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.theme-row__label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--c-sub);
  white-space: nowrap;
}

/* ----- 置き場所ごとの寄せ ----- */

/* 型B（メニューの末尾・見出しつきの1行）：公開ページのスマホのメニュー。
   見出しはリンクの文字の頭（左 14px）にそろえ、線で区切る */
.mob-menu .theme-row {
  margin-top: 6px;
  padding: 12px 4px 4px 14px;
  border-top: 1px solid var(--c-hairline);
}

/* 公開ページ：PCのヘッダー。リンクの並びに混ぜる */
.nav-desktop .theme-seg { margin-left: 4px; }
/* 大きい画面ではヘッダーに合わせて一回り大きく（components.css の同じ段） */
@media (min-width: 1600px) {
  .nav-desktop .theme-seg--collapse .theme-seg__btn { width: 42px; padding-top: 9px; padding-bottom: 9px; }
  .nav-desktop .theme-seg__icon { width: 18px; height: 18px; }
}
@media (min-width: 2200px) {
  .nav-desktop .theme-seg--collapse .theme-seg__btn { width: 46px; padding-top: 11px; padding-bottom: 11px; }
  .nav-desktop .theme-seg__icon { width: 20px; height: 20px; }
}

/* 型A（右上・閉じた形）：ヘッダーの無いページの右上。
   ログイン・招待・404・メンテナンス。公開ページのヘッダーと同じ側にそろえる。
   固定にすると、長いページで本文の上に重なり続けるので、ページと一緒に流す */
.auth-theme,
.corner-theme {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 10;
}

/* マイページ：スマホはプロフィール（関連リンクの上）、PC は左のメニュー。
   同じ画面に2つ出ないよう、幅で出し分ける（管理ダッシュボードと同じ分け方）。
   プロフィールでは、ほかの設定の行（.set-group）と同じ箱に入れる */
.prof-theme {
  padding: 10px 10px 10px 16px;
  background: var(--c-canvas);
  border-radius: var(--r-lg, 20px);
  box-shadow: 0 1px 3px rgba(16, 25, 28, .06);
}
.prof-theme .theme-row__label { font-size: 14px; color: var(--c-ink); }
.bn-theme { display: none; }
@media (min-width: 900px) {
  .prof-theme-block { display: none; }
  .bn-theme {
    display: flex;
    margin-top: 8px;
    padding: 12px 6px 2px 14px;
    border-top: 1px solid var(--c-hairline);
  }
}

/* 管理ダッシュボード：PC はサイドバーの足元、スマホはメニューのパネルの上部 */
.sidebar-theme { padding: 0 12px 10px 16px; }
.more-sheet__theme { padding: 2px 20px 12px; }

/* 登録：ヘッダーの右端 */
.wiz-header .theme-seg { margin-left: auto; flex-shrink: 0; }

/* 台本の編集：上のバー。スマホではバーが狭く、題名の入力欄を潰して
   しまうので出さない（選んだテーマには従う。切り替えは管理画面のメニューで） */
.se-topbar .theme-seg { flex-shrink: 0; margin-right: 4px; }
@media (max-width: 720px) {
  .se-topbar .theme-seg { display: none; }
}

/* 台本の閲覧：目次のいちばん下 */
.sv-toc-theme .theme-row { padding: 2px 4px 0 8px; }

@media (hover: hover) and (pointer: fine) {
  .theme-seg__btn:not(.is-on):hover { color: var(--c-ink); }
}
