/* ============================================================
 * MLTD 9th Optimizer — テーマ
 * 「シアターデイズ」のステージを下敷きにした配色。
 *   ベースはティール、舞台奥はディープパープル、
 *   ステージライトにピンク／コーラルを差し色として添える。
 *   データ密度が高いツールなので、彩りはアクセントに集約し本文は静かに保つ。
 * ============================================================ */
:root {
  /* 面 */
  --bg: #eef6f4;
  --bg-warm: #e1f0ee;
  --panel: #ffffff;
  --panel-tint: #f4fbfa;

  /* 文字 */
  --text: #233533;
  --muted: #5f716e;

  /* 罫線 */
  --border: #c9e4e0;
  --border-strong: #a6d6d0;

  /* ベースアクセント：ティール */
  --teal: #5abfb7;
  --teal-deep: #2f867f;
  --teal-darker: #246b65;
  --teal-soft: #e2f4f2;
  --teal-line: #9bd8d2;

  /* 差し色：ステージライト */
  --pink: #f1becb;
  --coral: #f19591;
  --coral-deep: #d96f6a;

  /* 舞台奥：ディープパープル（ヘッダー） */
  --purple: #554171;
  --purple-deep: #382a51;

  /* 状態色 */
  --accent: var(--teal);
  --accent-dark: var(--teal-deep);
  --error-bg: #fdecea;
  --error-border: #e0796c;
  --error-text: #9b2c1c;
  --danger: #d32f2f;
  --danger-soft: #fdecea;
  --danger-text: #b71c1c;
  --danger-line: #ef9a9a;
  --danger-tint: rgba(211, 47, 47, 0.08);
  --danger-border: rgba(211, 47, 47, 0.3);
  --disabled-bg: #e3eae9;

  /* 角丸・影 */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(35, 53, 51, .05), 0 1px 3px rgba(35, 53, 51, .04);
  --shadow-md: 0 6px 22px rgba(35, 53, 51, .09);
  --shadow-teal: 0 8px 22px rgba(47, 134, 127, .3);

  /* フォームコントロール共通高さ */
  --control-height: 42px;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  /* 全環境で同一描画にするため Web フォントで固定。
     英字・数字は Inter（tabular-nums 対応で桁が揃う）、日本語は Noto Sans JP。
     読み込み前/失敗時は OS 標準へフォールバック。 */
  font-family: "Inter", "Noto Sans JP", "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(900px 320px at 88% -8%, rgba(90, 191, 183, .12), transparent 70%),
    radial-gradient(720px 280px at 4% 2%, rgba(241, 149, 145, .08), transparent 70%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.65;
}

/* 数字は等幅で桁を揃える */
.sc-value,
.result-table td,
.detail-table td,
.param-table td {
  font-variant-numeric: tabular-nums;
}

/* ── ヘッダー：シアターのステージ ─────────────────────────── */
header {
  position: relative;
  overflow: hidden;
  background: linear-gradient(150deg, var(--purple), var(--purple-deep));
  color: #fff;
  padding: 22px 24px 22px;
}

/* ステージ上方からのスポットライト（ティール） */
header::before {
  content: "";
  position: absolute;
  top: -55%;
  left: 50%;
  width: 70%;
  height: 170%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at top, rgba(90, 191, 183, .34), rgba(90, 191, 183, 0) 62%);
  pointer-events: none;
}

/* 足元のフットライト（ティール→コーラル→ピンク） */
header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--teal) 16%, var(--coral) 48%, var(--pink) 68%, var(--teal) 86%, transparent);
  opacity: .95;
}

header>* {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
}

header h1 {
  margin: 0 0 6px;
  font-size: clamp(1.2rem, 3.4vw, 1.65rem);
  font-weight: 800;
  letter-spacing: .01em;
  /* 折り返す場合は CJK を語の途中で割らず、語間（「周年イベント」と
     「オプティマイザー」の間）で改行する。末尾の「ー」だけが孤立するのを防ぐ。 */
  word-break: keep-all;
}

/* 「9th」をティールのバッジに */
header h1 .anniv {
  position: relative;
  display: inline-block;
  line-height: 1;
  /* 背景の高さをフォント metrics に依存させない */
  color: var(--purple-deep);
  background: linear-gradient(135deg, #7fd4cd, var(--teal));
  padding: .18em .42em;
  /* 上下も付けて環境差なく一定の厚みに */
  border-radius: 6px;
  font-weight: 900;
  box-shadow: 0 2px 10px rgba(90, 191, 183, .45);
}

/* バッジの真上に、赤×白水玉のリボン（蝶結び）を載せる。
   塗りベースのフラットな描画（立体感は付けない）。バッジ文字に被らないよう
   bottom: 100% でバッジ上に配置し、わずかに下げて結び目をバッジ上端に乗せる。 */
header h1 .anniv::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 2.6em;
  height: 1.45em;
  transform: translate(-50%, 0.50em);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 40'%3E%3Cdefs%3E%3CclipPath id='b'%3E%3Cpath d='M36 20 L13 9 Q8 21 13 33 L36 26 Z'/%3E%3Cpath d='M36 20 L59 9 Q64 21 59 33 L36 26 Z'/%3E%3Crect x='31.5' y='15' width='9' height='13' rx='3'/%3E%3C/clipPath%3E%3C/defs%3E%3Cg fill='%23e34f5f' stroke='%23c2384a' stroke-width='1' stroke-linejoin='round'%3E%3Cpath d='M36 20 L13 9 Q8 21 13 33 L36 26 Z'/%3E%3Cpath d='M36 20 L59 9 Q64 21 59 33 L36 26 Z'/%3E%3Crect x='31.5' y='15' width='9' height='13' rx='3'/%3E%3C/g%3E%3Cg fill='%23ffffff' clip-path='url(%23b)'%3E%3Ccircle cx='15' cy='13' r='2.9'/%3E%3Ccircle cx='18' cy='29' r='2.9'/%3E%3Ccircle cx='25' cy='20' r='2.9'/%3E%3Ccircle cx='28' cy='30' r='2.9'/%3E%3Ccircle cx='59' cy='15' r='2.9'/%3E%3Ccircle cx='52' cy='26' r='2.9'/%3E%3Ccircle cx='48' cy='17' r='2.9'/%3E%3Ccircle cx='36' cy='22' r='2.9'/%3E%3C/g%3E%3C/svg%3E") no-repeat center / contain;
  pointer-events: none;
}

header p {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.84);
}

/* ハンバーガーボタン：デスクトップでは隠し、ナビを常時表示する。
   モバイル時のみ下のメディアクエリで表示・機能させる。 */
.nav-toggle {
  display: none;
}

.nav-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.page-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.page-nav a,
.nav-video-link {
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 18px;
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-pill);
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
}

.page-nav a:hover,
.nav-video-link:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.62);
}

.page-nav a.current {
  background: linear-gradient(135deg, #7fd4cd, var(--teal));
  color: var(--purple-deep);
  font-weight: 800;
  border-color: transparent;
  box-shadow: 0 3px 12px rgba(90, 191, 183, .4);
}

.nav-video-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  padding-left: 12px;
}

.yt-icon {
  width: 20px;
  height: 14px;
  flex-shrink: 0;
}

.video-embed {
  position: relative;
  width: 100%;
  max-width: 720px;
  padding-bottom: min(56.25%, 405px);
  margin: 12px auto 0;
  border-radius: var(--radius);
  overflow: hidden;
}

.video-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 20px 40px;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--panel-tint);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.7;
  padding: 22px;
  text-align: center;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--teal-deep);
  font-weight: 600;
}

/* ── ツールバー ───────────────────────────────────────────── */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(var(--bg) 70%, rgba(238, 246, 244, 0));
  padding: 12px 0 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar-secondary {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.toolbar-secondary button {
  flex: 1 1 0;
  white-space: nowrap;
}

/* ── ボタン ───────────────────────────────────────────────── */
button {
  font: inherit;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: background .15s, box-shadow .15s, border-color .15s, transform .05s;
}

button:hover {
  background: var(--teal-soft);
  border-color: var(--teal-line);
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: linear-gradient(135deg, #54bcb4, #2a7d75);
  color: #fff;
  border-color: transparent;
  font-weight: 800;
  padding: 9px 22px;
  box-shadow: var(--shadow-teal);
}

button.primary:hover {
  background: linear-gradient(135deg, #61c6be, #226d66);
  border-color: transparent;
}

:focus-visible {
  outline: 2.5px solid var(--coral);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── パネル ───────────────────────────────────────────────── */
section.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

section.panel>h2 {
  margin: 0 0 6px;
  font-size: 1.08rem;
  font-weight: 700;
  padding-left: 12px;
  position: relative;
}

section.panel>h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(var(--teal), var(--coral));
}

section.panel>.hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.8rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px 18px;
}

.groups>.group+.group {
  border-top: 1px dashed var(--border-strong);
  margin-top: 14px;
  padding-top: 12px;
}

.group-title {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--teal-deep);
}

/* ── フィールド ───────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.82rem;
  color: var(--muted);
}

.field input,
.field select {
  font: inherit;
  height: var(--control-height);
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color .12s, box-shadow .12s;
}

.field input:focus,
.field select:focus,
table input:focus,
table select:focus {
  outline: none;
  border-color: var(--teal-deep);
  box-shadow: 0 0 0 3px rgba(90, 191, 183, .25);
}

input.invalid,
select.invalid {
  border-color: var(--error-border);
  background: #fdf2f0;
}

input.invalid:focus,
select.invalid:focus {
  border-color: var(--error-border);
  box-shadow: 0 0 0 3px rgba(224, 121, 108, .2);
}

.field-error {
  color: var(--error-text);
  font-size: 0.72rem;
  margin-top: 2px;
  line-height: 1.3;
}

td .field-error {
  font-size: 0.68rem;
}

input:disabled,
select:disabled {
  background: var(--disabled-bg);
  color: #98a2a0;
  cursor: not-allowed;
}

/* ── テーブル ─────────────────────────────────────────────── */
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.86rem;
}

/* 列幅をコンテンツ長に依存させない（エラーメッセージ表示時に横幅が変わらないように） */
#dayTable {
  table-layout: fixed;
}

#dayTable .daytable-day-col {
  width: 15%;
}

#dayTable th:first-child {
  padding-left: 2px;
  padding-right: 2px;
}

@media (max-width: 720px) {
  #dayTable th {
    font-size: 0.78rem;
  }

  #dayTable .pc-br {
    display: none;
  }
}

#dayTable th:first-child .rec-date,
#dayTable th:first-child .rec-weekday {
  display: block;
}

#dayTable .field-error {
  overflow-wrap: anywhere;
}

th,
td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: center;
}

th {
  background: var(--bg-warm);
  font-weight: 700;
}

table input,
table select {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 5px 6px;
  font: inherit;
}

tr.row-disabled td,
td.cell-disabled {
  background: var(--disabled-bg);
}

tr.row-disabled .rec-songtime {
  opacity: 0.4;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

@media (max-width: 720px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  /* モバイルではヘッダーを圧縮する。説明文はタイトルと内容が重複し
     （SEO 用途は meta description が担う）、毎ページ繰り返されて場所を
     取るため非表示に。タイトルは少し小さく行間も詰める。 */
  header {
    /* タイトル上のリボンがヘッダー上端とぶつからないよう、上側に余白を多めに取る */
    padding: 22px 16px 12px;
  }

  header h1 {
    font-size: 1.12rem;
    line-height: 1.3;
    margin-bottom: 0;
  }

  header p {
    display: none;
  }

  /* タイトルが右上のハンバーガーボタンに被らないよう余白を確保 */
  header h1 {
    padding-right: 52px;
  }

  /* 右上のハンバーガーボタン：枠・塗りを持たないアイコンのみ（浮きを抑える）。
     白の三本線、開くと×に変形。ホバー時だけ淡い円形ハイライト。 */
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 12px;
    right: 10px;
    width: 44px;
    height: 44px;
    min-height: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    box-shadow: none;
    z-index: 2;
  }

  .nav-toggle:hover {
    background: rgba(255, 255, 255, 0.14);
    border: none;
  }

  .nav-toggle-box {
    position: relative;
    width: 22px;
    height: 16px;
  }

  .nav-toggle-bar {
    position: absolute;
    left: 0;
    right: 0;
    height: 2.5px;
    border-radius: 2px;
    background: #fff;
    transition: transform .2s ease, opacity .15s ease, top .2s ease;
  }

  .nav-toggle-bar:nth-child(1) {
    top: 0;
  }

  .nav-toggle-bar:nth-child(2) {
    top: 7px;
  }

  .nav-toggle-bar:nth-child(3) {
    top: 14px;
  }

  .nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(1) {
    top: 7px;
    transform: rotate(45deg);
  }

  .nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(2) {
    opacity: 0;
  }

  .nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-child(3) {
    top: 7px;
    transform: rotate(-45deg);
  }

  /* ナビは既定で畳み、ボタンで開く。開いたら全幅の縦並びメニューにして
     右端を揃え、ピルではなくメニュー行（角丸小）として均一に見せる。 */
  .nav-row {
    margin-top: 10px;
    flex-direction: row-reverse;
  }

  .nav-video-link {
    margin-left: auto;
    font-size: 0.78rem;
    padding: 2px 4px 2px 2px;
    border-color: transparent;
    background: none;
    color: #fff;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .page-nav {
    display: none;
  }

  .page-nav.open {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    margin-top: 12px;
    width: 100%;
    order: 1;
  }

  .page-nav.open~.nav-video-link {
    order: 2;
    width: 100%;
    justify-content: center;
    padding: 0 16px;
    font-size: 0.92rem;
    margin-left: 0;
    border-color: rgba(255, 255, 255, 0.3);
    background: none;
  }

  .page-nav.open a {
    width: 100%;
    justify-content: center;
    padding: 0 16px;
    font-size: 0.92rem;
    border-radius: var(--radius-pill);
  }

  .wrap {
    padding: 14px 12px 28px;
  }

  section.panel {
    padding: 14px 14px;
  }

  .page-nav a,
  .page-nav.open~.nav-video-link {
    padding: 6px 14px;
    font-size: 0.85rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* 補助ボタン（書き出し/読み込み/リセット・すべて展開・共有・再シャッフル等）は
     一律の最小高さを設けず、各自のパディングで自然な高さにする（間延び防止）。
     快適なタップ行が活きるメニュー系のみ別途 44px を維持（.nav-toggle / .page-nav a）。 */

  /* テーブル内のフォーム要素：iOS はフォーカス時に 16px 未満の入力を
     強制ズームするため 16px に上げる。
     タップ領域の 44px は強制しない（密度の高い表が間延びして見えるため）。
     高さはパディングで程よく確保するに留める。独立ボタン・ナビは別途 44px。 */
  table input,
  table select,
  .preset-bar select,
  .preset-bar button {
    font-size: 16px;
  }

  /* おすすめ楽曲のアイドル選択は <select>（iOS はフォーカスでズームしない）かつ
     13日 × 4枠で多数並ぶ高密度領域なので、フォントを下げて詰める。 */
  table select {
    font-size: 14px;
    padding: 4px;
    line-height: 1.2;
  }

  /* 数値 <input> は 16px のままにしてズームを防ぎ、高さは padding で圧縮 */
  table input {
    padding: 3px 8px;
    line-height: 1.2;
  }

  /* モバイルでは「最適化」だけを画面上部に固定し、副次ボタン（書き出し等）は固定しない。
     display:contents で .toolbar のボックスを消すと、#runBtn の sticky 基準が
     縦に長い .wrap になり、ページ全体でピン留めが効く。
     副次ボタンは通常フローに戻るため、スクロールで自然に流れて省スペースになる。 */
  .toolbar {
    display: contents;
  }

  #runBtn {
    position: sticky;
    top: 0;
    z-index: 10;
    /* .wrap の左右パディング（12px）を相殺して画面端まで広げ、固定時に
       下の内容が透けない不透明なアクションバーにする。 */
    width: calc(100% + 24px);
    margin: 0 -12px 12px;
    border-radius: 0;
    box-shadow: var(--shadow-md);
    /* 横長のバーでは斜めグラデの色ムラが目立つため、ベタ塗りで均一に。
       teal-deep より一段明るいティール。白文字とのコントラスト比は約 3.4:1 で
       太字・大きめ文字の WCAG AA（3:1）を満たす範囲。
       （デスクトップの通常ボタンは button.primary のグラデのまま） */
    background: #349b91;
  }

  .toolbar-secondary {
    margin: 0 0 12px;
    width: 100%;
  }

  .toolbar-secondary button {
    font-size: 0.78rem;
    padding: 8px 10px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }

  .doc-section {
    padding: 14px 16px;
  }

  /* モバイルではサマリーカードの数値を縮小。
     ベース定義（.summary-card .sc-value / .summary-card.primary .sc-value）が
     このメディアクエリより後ろにあるため、詳細度を一段上げて確実に上書きする。 */
  .summary-cards .summary-card .sc-value {
    font-size: 1.2rem;
  }

  .summary-cards .summary-card.primary .sc-value {
    font-size: 1.4rem;
  }
}

/* ── details 開閉マーカー ─────────────────────────────────── */
details>summary {
  cursor: pointer;
  font-weight: 700;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
}

details>summary::-webkit-details-marker {
  display: none;
}

details>summary::before {
  content: "";
  width: 0;
  height: 0;
  flex-shrink: 0;
  border-style: solid;
  border-width: 5px 0 5px 7px;
  border-color: transparent transparent transparent var(--teal-deep);
  transition: transform 0.2s;
}

details[open]>summary::before {
  transform: rotate(90deg);
}

/* ── エラー領域 ───────────────────────────────────────────── */
#errors {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-left: 4px solid var(--error-border);
  color: var(--error-text);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  scroll-margin-top: 84px;
}

#resultPanel {
  scroll-margin-top: 130px;
}

#errors h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
}

#errors ul {
  margin: 0;
  padding-left: 20px;
}

/* 予期しないエラー表示（入力エラーより手厚い案内＋報告導線） */
#errors.unexpected-error {
  padding: 16px 18px;
}

#errors.unexpected-error h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

#errors .error-help {
  margin: 0 0 8px;
  font-size: 0.9rem;
  line-height: 1.7;
}

#errors .error-help:last-of-type {
  margin-bottom: 0;
}

#errors .error-help a {
  color: var(--error-text);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

#errors .error-copy-btn {
  display: inline-block;
  margin-top: 14px;
  padding: 9px 16px;
  background: #fff;
  color: var(--error-text);
  border: 1px solid var(--error-border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, box-shadow .12s, border-color .12s;
}

#errors .error-copy-btn:hover {
  background: #fff7f5;
  box-shadow: var(--shadow-sm);
}

#errors .error-copy-btn.copied {
  background: #eef8f0;
  border-color: #8bc99a;
  color: #2f7d44;
}

#errors .unexpected-error-details {
  margin-top: 14px;
  font-size: 0.85rem;
}

#errors .unexpected-error-details summary {
  cursor: pointer;
  color: var(--error-text);
  opacity: 0.85;
}

#errors .unexpected-error-details summary:hover {
  opacity: 1;
}

#errors .unexpected-error-details pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 8px 0 0;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(155, 44, 28, 0.18);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  line-height: 1.5;
}

#result.empty {
  color: var(--muted);
  padding: 6px 0;
}

.result-note {
  background: var(--danger-soft);
  border: 1px solid var(--danger-line);
  border-left: 4px solid var(--danger);
  color: var(--danger-text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}

.result-hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0 0 14px;
}

/* 結果コンテンツは、見出し行（h2＋右上の共有ボタン）と間隔を空けて
   ボタンと内容が近接して窮屈に見えないようにする。 */
.result-view {
  margin-top: 14px;
}

/* ── サマリーカード：スコアボード ─────────────────────────── */
.summary-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.summary-card {
  flex: 1 1 150px;
  position: relative;
  background: var(--panel-tint);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px 13px;
  overflow: hidden;
  /* ラベル・数値とも中央寄せ（ヒーロー数値として左右対称に見せる） */
  text-align: center;
}

.summary-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--teal-line);
}

.summary-card.primary {
  background: linear-gradient(135deg, var(--teal-soft), #f3fbfa);
  border-color: var(--teal-line);
}

.summary-card.primary::before {
  background: linear-gradient(90deg, var(--teal), var(--coral));
  height: 4px;
}

.summary-card .sc-label {
  font-size: 0.74rem;
  color: var(--muted);
  font-weight: 600;
}

.summary-card .sc-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--teal-deep);
  margin-top: 3px;
  letter-spacing: -0.01em;
}

.summary-card.primary .sc-value {
  font-size: 1.7rem;
}

.table-scroll {
  overflow-x: auto;
}

/* ── 計算中スピナー ───────────────────────────────────────── */
@keyframes mltd-spin {
  to {
    transform: rotate(360deg);
  }
}

#result.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

#result.loading::before {
  content: "";
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 2.5px solid var(--teal-line);
  border-top-color: var(--teal-deep);
  border-radius: 50%;
  animation: mltd-spin 0.7s linear infinite;
}

button.primary.is-loading::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: mltd-spin 0.7s linear infinite;
}

/* ── 横スクロールのアフォーダンス ─────────────────────────
   スクロールコンテナをラッパー（main.js が動的に挿入）で包み、
   その絶対配置の擬似要素でテーブルの上にフェードを重ねる。
   inset 影と違いセル背景に隠れず、端の隠れている側だけ表示される。 */
.scroll-shadow-wrap {
  position: relative;
}

.scroll-shadow-wrap::before,
.scroll-shadow-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 26px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
}

.scroll-shadow-wrap::before {
  left: 0;
  background: linear-gradient(to right, rgba(35, 53, 51, 0.22), rgba(35, 53, 51, 0));
}

.scroll-shadow-wrap::after {
  right: 0;
  background: linear-gradient(to left, rgba(35, 53, 51, 0.22), rgba(35, 53, 51, 0));
}

.scroll-shadow-wrap.scroll-start::before {
  opacity: 1;
}

.scroll-shadow-wrap.scroll-end::after {
  opacity: 1;
}

.result-table {
  font-size: 0.85rem;
}

.result-table th {
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.result-table td {
  white-space: nowrap;
}

/* 結果表の表示行に淡いゼブラ。詳細行は含めず、JS 側で表示行だけに付与する。 */
.result-table tr.result-row.striped-row td {
  background: var(--panel-tint);
}

.result-table .overtime-value {
  color: var(--danger);
  font-weight: 600;
}


.result-table .total-row th,
.result-table .total-row td {
  background: var(--teal-soft);
  font-weight: 700;
}

.result-table tr.day-row {
  cursor: pointer;
}

.result-table tr.result-row>th,
.result-table tr.result-row>td,
.result-table tr.total-row>th,
.result-table tr.total-row>td {
  border-top-width: 0;
}

.result-table tr.day-row:hover th,
.result-table tr.day-row:hover td,
.result-table tr.day-row:focus-visible th,
.result-table tr.day-row:focus-visible td {
  background: var(--teal-soft);
}

.result-table tr.day-row:focus-visible {
  outline: 2px solid var(--teal-deep);
  outline-offset: -2px;
}

.result-table .day-cell {
  position: relative;
}

.expand-caret {
  display: inline-block;
  margin-right: 5px;
  color: var(--teal-deep);
  font-size: 0.7em;
  transition: transform 0.2s ease;
}

.result-table tr.day-row.open .expand-caret {
  transform: rotate(90deg);
}

/* 詳細行：行高アニメーションで開閉 */
.result-table tr.detail-row>.detail-cell {
  padding: 0;
  border-width: 0;
  text-align: left;
  white-space: normal;
  background: var(--panel-tint);
}

.detail-inner {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}

.result-table tr.detail-row.open>.detail-cell {
  border-width: 1px;
}

.result-table tr.detail-row.open .detail-inner {
  grid-template-rows: 1fr;
}

.detail-clip {
  overflow: hidden;
  min-height: 0;
}

.day-detail {
  padding: 12px 16px;
}

.detail-table-scroll {
  overflow-x: auto;
}

.detail-table {
  font-size: 0.8rem;
  background: #fff;
  table-layout: fixed;
}

.detail-table th {
  background: var(--teal-soft);
  white-space: nowrap;
}

.detail-table td {
  white-space: nowrap;
}

.detail-table .detail-no {
  white-space: nowrap;
  color: var(--muted);
  width: 2.2em;
}

.detail-table .detail-act {
  text-align: left;
  white-space: normal;
  width: 60%;
  line-height: 1.5;
}

.detail-table th.detail-act {
  text-align: center;
}

.detail-table .detail-bullets {
  margin-top: 6px;
}

/* 注意書き（例：ブーストを確実に消化するため先に行う旨）。
   本文より小さく・コーラル系で、補足だと分かるように差別化する。 */
.detail-table .detail-note-inline {
  margin-top: 5px;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--coral-deep);
}

/* 結果表上部の開閉ヒント＋一括展開ボタン */
.detail-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.detail-tools-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.detail-toggle-all {
  margin-left: auto;
  padding: 6px 14px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.day-songtime-cols {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px 16px;
}

/* ── 開始日時の行 ─────────────────────────────────────────── */
.start-datetime-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.start-datetime-row select,
.start-datetime-row input[type="time"],
.start-datetime-row button {
  height: var(--control-height);
  min-height: 0;
}

.start-datetime-row select {
  flex-shrink: 0;
}

.start-datetime-row input[type="time"] {
  flex-shrink: 0;
  width: auto;
  margin-right: 10px;
}

.start-datetime-row button {
  flex-shrink: 0;
  padding: 6px 12px;
  white-space: nowrap;
}

.start-datetime-msg {
  font-size: 0.76rem;
  color: var(--teal-deep);
  margin-top: 2px;
}

.note {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 6px;
}

/* ── おすすめ楽曲プリセットバー ──────────────────────────── */
.preset-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.preset-bar select {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  height: 36px;
  min-width: 0;
  max-width: 100%;
  flex-shrink: 1;
}

.preset-bar button {
  height: 36px;
  padding-top: 0;
  padding-bottom: 0;
}

#recTable {
  table-layout: fixed;
}

#recTable th:first-child,
#recTable td:first-child {
  width: 100px;
}

/* PC では日付と曜日を 1 行に収める（モバイルは下のメディアクエリで 2 行に分ける） */
#recTable th:first-child {
  white-space: nowrap;
}

@media (max-width: 720px) {
  #recTable {
    min-width: 540px;
  }

  #recTable th:first-child,
  #recTable td:first-child {
    width: 52px;
    font-size: 0.78rem;
    padding-left: 6px;
    padding-right: 6px;
  }

  #recTable th:first-child .rec-weekday {
    display: block;
  }

  /* 横スクロール時に日付列を左端へ固定し、どの日の行か分かるようにする。
     1 列目は常に th（不透明な背景を持つ）なので、スクロールするセルを覆い隠せる。
     結果テーブルの見出し行の隅セルは上下固定とも重なるため z-index を一段上げる。 */
  #recTable th:first-child,
  #recTable td:first-child,
  .result-table th:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
  }

  .result-table tr:first-child th:first-child {
    z-index: 2;
  }
}

.rec-songtime {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  min-height: 1em;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.rec-songtime.rec-shortest {
  color: #8a5d00;
  font-weight: 700;
}

/* 最短曲のセルはアンバーで淡くハイライト。「いちばんお得」を直感的に示す。
   ティール基調（寒色）との補色対比が効き、エラーの赤とも色相が離れている。 */
tr:not(.row-disabled) td.rec-shortest-cell {
  background: #fdeecb;
}

.pill {
  display: inline-block;
  font-size: 0.72rem;
  background: var(--teal-soft);
  border: 1px solid var(--teal-line);
  border-radius: var(--radius-pill);
  padding: 1px 9px;
  color: var(--teal-deep);
  font-weight: 600;
}

/* ── コールアウト ─────────────────────────────────────────── */
.callout {
  background: #fff7e6;
  border: 1px solid #ecc879;
  border-left: 4px solid #e0a800;
  color: #6b5000;
  border-radius: var(--radius-sm);
  padding: 11px 15px;
  font-size: 0.85rem;
  margin: 10px 0;
  line-height: 1.7;
}

.callout p {
  margin: 0 0 4px;
  font-size: inherit;
}

.callout p:last-child {
  margin-bottom: 0;
}

.callout-info {
  background: var(--panel-tint);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
  color: var(--text);
}

.stale-banner {
  font-size: 0.78rem;
  font-weight: 700;
  background: #fdecea;
  border: 1px solid #e0796c;
  border-left-width: 4px;
  color: #9b2c1c;
  border-radius: var(--radius-sm);
  padding: 8px 13px;
  margin: 0 0 10px;
}

/* ── 共有（結果パネルの見出し行のトリガー＋ポップオーバーメニュー）── */
#resultPanel {
  position: relative;
}

/* 見出しと共有ボタンを 1 行に。ボタンが通常フローで場所を確保するので、
   横幅が狭くても結果コンテンツと重ならない。 */
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

/* h2 が panel 直下でなくなるため、section.panel>h2 のスタイルをここで再現。 */
.result-head h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  padding-left: 12px;
  position: relative;
}

.result-head h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(var(--teal), var(--coral));
}

/* トリガー: 控えめなピル型のゴーストボタン。共有アイコン＋「共有」。 */
.share-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--teal-deep);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
}

.share-btn:hover,
.share-btn[aria-expanded="true"] {
  background: var(--teal-soft);
  border-color: var(--teal-line);
}

.share-ico {
  width: 1.05em;
  height: 1.05em;
  flex: none;
}

@media (max-width: 600px) {
  .share-btn {
    padding: 5px 12px;
    font-size: 0.78rem;
  }
}

/* ポップオーバー: ボタン直下に出る小さなメニュー。 */
.share-popover[hidden] {
  display: none;
}

.share-popover {
  position: absolute;
  top: 52px;
  right: 18px;
  z-index: 50;
  min-width: 200px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  animation: sharePopIn .12s ease-out;
}

@keyframes sharePopIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 600px) {
  .share-popover {
    top: 46px;
    right: 14px;
  }
}

.share-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  font-size: 0.86rem;
  font-weight: 600;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  box-shadow: none;
}

.share-menu-item:hover {
  background: var(--teal-soft);
  border-color: transparent;
}

.share-menu-item .menu-ico {
  width: 1.2em;
  height: 1.2em;
  flex: none;
  color: var(--teal-deep);
}

/* X 公式風: 黒丸の中に白い X ロゴ。padding でロゴを内側に収める。 */
.x-icon {
  width: 1.2em;
  height: 1.2em;
  padding: 0.24em;
  box-sizing: border-box;
  background: #000;
  border-radius: 50%;
  fill: #fff;
  flex: none;
}

/* ── ドキュメントページ（usage.html / spec.html）─────────── */
.doc-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.doc-section h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
  font-weight: 700;
  padding-left: 12px;
  position: relative;
}

.doc-section h2::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(var(--teal), var(--coral));
}

.doc-section h3 {
  font-size: 0.95rem;
  margin: 22px 0 8px;
  color: var(--teal-deep);
}

.doc-section h2+h3,
.doc-section h3:first-child {
  margin-top: 0;
}

.doc-section h4 {
  font-size: 0.9rem;
  margin: 16px 0 6px;
  color: var(--text);
}

.doc-section p {
  margin: 0 0 10px;
  font-size: 0.9rem;
  line-height: 1.75;
}

.doc-section ul,
.doc-section ol {
  margin: 0 0 10px;
  padding-left: 22px;
  font-size: 0.9rem;
  line-height: 1.8;
}

.doc-section a {
  word-break: break-all;
  color: var(--teal-deep);
}

/* ── Cookie 同意バナー ─────────────────────────────────────── */
.analytics-consent-banner {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 360px;
  max-width: calc(100vw - 40px);
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow:
    0 2px 6px rgba(35, 53, 51, .12),
    0 14px 40px rgba(35, 53, 51, .22);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.analytics-consent-banner.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.analytics-consent-banner[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .analytics-consent-banner {
    transition: none;
    transform: none;
  }
}

.analytics-consent-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--muted, #6b7c7a);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.analytics-consent-close:hover {
  background: var(--bg-warm);
}

.analytics-consent-close:focus-visible {
  outline: 2px solid var(--teal-deep);
  outline-offset: 2px;
}

.analytics-consent-content strong {
  display: block;
  padding-right: 26px;
  font-size: 0.93rem;
}

.analytics-consent-content p {
  margin: 6px 0;
  font-size: 0.8rem;
  line-height: 1.65;
}

.analytics-consent-content a {
  color: var(--teal-deep);
  font-size: 0.8rem;
}

.analytics-consent-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.analytics-consent-actions button {
  flex: 1 1 0;
  padding: 8px 13px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.analytics-consent-decline {
  background: transparent;
  border-color: var(--border-strong);
}

.analytics-consent-accept {
  background: var(--teal-deep);
  color: #fff;
  border-color: var(--teal-deep);
}

.analytics-consent-accept:hover {
  background: var(--teal-darker);
  border-color: var(--teal-darker);
}

.analytics-consent-actions button:focus-visible {
  outline: 2px solid var(--teal-deep);
  outline-offset: 2px;
}

.consent-settings {
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--teal-deep);
  text-decoration: underline;
  background: transparent;
  border: 0;
  cursor: pointer;
}

@media (max-width: 600px) {
  .analytics-consent-banner {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
    padding: 16px;
  }
}

.param-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.86rem;
  margin-bottom: 10px;
}

.param-table th,
.param-table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

.param-table th:first-child,
.param-table td:first-child {
  width: 30%;
}

.param-table th {
  background: var(--bg-warm);
  font-weight: 700;
}

.param-table td:first-child {
  font-weight: 700;
  color: var(--teal-deep);
  background: var(--panel-tint);
  border-right: 2px solid var(--border-strong);
}

.param-table tbody tr:nth-child(even) td:not(:first-child) {
  background: var(--panel-tint);
}

.param-table td>p {
  margin: 0 0 6px;
}

.param-table td>p:last-child {
  margin-bottom: 0;
}

pre.math-block {
  background: var(--panel-tint);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: "JetBrains Mono", "Consolas", "Menlo", monospace;
  font-size: 0.85rem;
  margin: 8px 0;
  line-height: 1.7;
  overflow-x: auto;
  white-space: pre-wrap;
}

.var {
  font-family: "JetBrains Mono", "Consolas", "Menlo", monospace;
  font-size: 0.88em;
  background: var(--teal-soft);
  padding: 1px 5px;
  border-radius: 4px;
}

/* モーション低減 */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
