/* A-GPTプロジェクト - スタイル定義
   色はdataviz skillの検証済みパレット(references/palette.md)を踏襲。
   ライト/ダーク両対応。 */

:root {
  color-scheme: light;
  --surface-page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ee;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --gridline: #e1e0d9;

  --series-blue: #2a78d6;
  --series-red: #e34948;
  --diverging-mid: #f0efec;

  --seq-100: #cde2fb;
  --seq-250: #86b6ef;
  --seq-400: #3987e5;
  --seq-550: #1c5cab;
  --seq-700: #0d366b;

  /* 「学習前」と「現在」の文字色(赤/緑)。白地で読めるよう、濃いめの色 */
  --label-before: #c62828;
  --label-after: #2e7d32;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --gridline: #2c2c2a;

    --series-blue: #3987e5;
    --series-red: #e66767;
    --diverging-mid: #383835;

    --label-before: #ff8a80;
    --label-after: #81c784;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--surface-page);
  color: var(--text-primary);
  padding: 24px 16px 64px;
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin: 0 0 20px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 1rem;
  margin: 0 0 12px;
  color: var(--text-primary);
}

.card h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin: 16px 0 8px;
  font-weight: 600;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.meta-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 4px;
  font-size: 0.78rem;
}

.vocab-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  text-align: center;
}

.vocab-item .id {
  color: var(--text-muted);
  font-size: 0.68rem;
}

.input-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

input[type="text"] {
  flex: 1;
  min-width: 220px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 0.95rem;
}

button {
  background: var(--series-blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.9rem;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }
button.secondary {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

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

.token-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 4px;
}

.token-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 0.82rem;
}

.token-chip.active {
  background: var(--series-blue);
  color: #fff;
  border-color: var(--series-blue);
}

/* --- ヒートマップ(表) --- */
table.heatmap {
  border-collapse: collapse;
  font-size: 0.72rem;
  margin-bottom: 6px;
}

table.heatmap th {
  color: var(--text-muted);
  font-weight: 500;
  padding: 3px 6px;
  text-align: center;
}

table.heatmap td {
  width: 34px;
  height: 26px;
  text-align: center;
  border: 1px solid var(--surface-1);
  color: #0b0b0b;
  font-variant-numeric: tabular-nums;
}

.heatmap-wrap {
  overflow-x: auto;
}

.layer-block {
  border-top: 1px solid var(--gridline);
  padding-top: 12px;
  margin-top: 12px;
}

/* --- 確率バー --- */
.prob-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  font-size: 0.82rem;
}

.prob-label {
  width: 70px;
  flex-shrink: 0;
  color: var(--text-secondary);
  text-align: right;
}

.prob-bar-track {
  flex: 1;
  background: var(--surface-2);
  border-radius: 4px;
  height: 14px;
  overflow: hidden;
}

.prob-bar-fill {
  background: var(--series-blue);
  height: 100%;
  border-radius: 4px;
}

.prob-value {
  width: 46px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.76rem;
}

/* --- 生成ステップ --- */
.gen-step {
  border-bottom: 1px solid var(--gridline);
  padding: 10px 0;
}

.gen-step:last-child { border-bottom: none; }

.gen-step-head {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.gen-step-head b {
  color: var(--text-primary);
}

.legend-note {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.loading {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.final-result {
  font-size: 1.05rem;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 8px;
  margin-top: 8px;
}

/* ===================== ここから、学習パート追加分 ===================== */

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}

button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--series-blue);
  outline-offset: 2px;
}

/* --- 説明文 --- */
.lead { font-size: 0.92rem; line-height: 1.7; margin: 0 0 12px; }
.desc { font-size: 0.85rem; line-height: 1.7; color: var(--text-secondary); margin: 0 0 14px; }
.desc.small { font-size: 0.8rem; }
.desc b, .lead b { color: var(--text-primary); }

.part-badge {
  color: var(--series-blue);
  font-weight: 700;
  margin-right: 4px;
}

.parts-list {
  margin: 0 0 12px;
  padding-left: 0;
  list-style: none;
  font-size: 0.88rem;
  line-height: 1.7;
}
.parts-list li { margin: 8px 0; padding-left: 0; }

.step-note {
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text-secondary);
  margin: -2px 0 8px;
}

.model-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 4px 0 6px;
}

.pos-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin: 10px 0 2px;
}

.warn-note {
  background: var(--surface-2);
  border-left: 3px solid var(--series-red);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 0.82rem;
  margin: 0 0 10px;
}

.error-note {
  color: var(--series-red);
  font-size: 0.82rem;
  margin: 8px 0;
}

/* --- 現在の状態 --- */
.status-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.stat-label { font-size: 0.74rem; color: var(--text-secondary); }
.stat-value { font-size: 1.5rem; font-weight: 600; margin-top: 2px; }
.stat-sub { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* --- ボタン群 --- */
.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
button.chip {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.8rem;
}

/* --- 進捗 --- */
.progress { margin: 10px 0; }
.progress-track {
  background: var(--surface-2);
  border-radius: 4px;
  height: 8px;
  overflow: hidden;
}
.progress-fill {
  background: var(--series-blue);
  height: 100%;
  width: 0;
  transition: width 0.2s;
}
.progress-text { font-size: 0.78rem; color: var(--text-secondary); margin-top: 4px; }

/* --- グラフ --- */
.chart-host { width: 100%; }
svg.chart { display: block; max-width: 100%; }
svg.chart .grid { stroke: var(--gridline); stroke-width: 1; }
svg.chart .ref { stroke: var(--text-muted); stroke-width: 1; opacity: 0.6; }
svg.chart .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.chart .axis-title { fill: var(--text-secondary); font-size: 11px; }
svg.chart .ref-label { fill: var(--text-muted); font-size: 11px; }
svg.chart .line { fill: none; stroke: var(--series-blue); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.chart .line.val { stroke: var(--series-red); }
svg.chart .end-dot, svg.chart .hover-dot { fill: var(--series-blue); stroke: var(--surface-1); stroke-width: 2; }
svg.chart .end-dot.val, svg.chart .hover-dot.val { fill: var(--series-red); }
svg.chart .end-label { fill: var(--series-blue); font-size: 11px; font-weight: 600; }
svg.chart .end-label.val { fill: var(--series-red); }
svg.chart .end-label.wiki { fill: var(--label-after); }
svg.chart .line.wiki { stroke: var(--label-after); stroke-dasharray: 5 3; }
svg.chart .end-dot.wiki, svg.chart .hover-dot.wiki { fill: var(--label-after); }
svg.chart .end-value { fill: var(--text-primary); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
svg.chart .cross { stroke: var(--text-muted); stroke-width: 1; }
svg.chart .chart-hit { fill: transparent; cursor: crosshair; }

.table-view { margin: 4px 0 0; font-size: 0.8rem; }
.table-view summary { cursor: pointer; color: var(--text-secondary); padding: 4px 0; }
table.data-table { border-collapse: collapse; margin-top: 6px; font-size: 0.78rem; }
table.data-table th, table.data-table td {
  border-bottom: 1px solid var(--gridline);
  padding: 4px 14px 4px 0;
  text-align: left;
  font-variant-numeric: tabular-nums;
}
table.data-table th { color: var(--text-muted); font-weight: 500; }

/* --- 学習前/現在/お手本のヒートマップ --- */
.heatmap-trio {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 14px 18px;
}
.heatmap-title { font-size: 0.82rem; font-weight: 600; margin-bottom: 4px; }
.heatmap-sub { font-weight: 400; color: var(--text-muted); font-size: 0.74rem; }

table.heatmap.compact { font-size: 0.66rem; }
table.heatmap.compact td { width: 22px; height: 20px; padding: 0; }
table.heatmap.compact th { padding: 2px 4px; white-space: nowrap; }
table.heatmap.compact th.col-h {
  writing-mode: vertical-rl;
  height: 62px;
  padding: 4px 0;
}
/* 単語ごとの詳しい表(約100×100): 数字は出さず、小さいマスで並べる */
table.heatmap.tiny { font-size: 0.6rem; }
table.heatmap.tiny td { width: 11px; height: 11px; padding: 0; border-width: 0.5px; }
table.heatmap.tiny th { padding: 0 3px; white-space: nowrap; line-height: 1; }
table.heatmap.tiny th.col-h { writing-mode: vertical-rl; padding: 3px 0; }
table.heatmap td { cursor: default; }
table.heatmap td:hover { outline: 2px solid var(--text-primary); outline-offset: -2px; }

.ramp-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.74rem;
  color: var(--text-muted);
}
.ramp { display: inline-block; width: 140px; height: 10px; border-radius: 3px; border: 1px solid var(--border); }

/* --- 例の確率(学習前 vs 現在) --- */
.probe { margin-bottom: 14px; }
.probe-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.probe-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 8px 24px;
}
.probe-sub { font-size: 0.8rem; font-weight: 600; margin-bottom: 2px; }
.lbl-before { color: var(--label-before); font-weight: 600; }
.lbl-after { color: var(--label-after); font-weight: 600; }

/* --- 使える単語の一覧 --- */
.word-palette {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.palette-title { font-size: 0.82rem; font-weight: 600; margin-bottom: 6px; }
.palette-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
}
.palette-label {
  width: 56px;
  flex-shrink: 0;
  font-size: 0.74rem;
  color: var(--text-muted);
}
.word-palette button.chip {
  background: var(--surface-1);
  padding: 4px 12px;
  font-size: 0.86rem;
}
.word-palette button.chip:hover { border-color: var(--series-blue); }

/* --- 生成結果 --- */
.gen-box {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 60px;
}
.gen-samples { margin: 6px 0 0; padding-left: 22px; }
.gen-samples li { font-size: 1.02rem; line-height: 1.8; padding: 2px 0; }
.gen-prefix { font-weight: 700; color: var(--series-blue); }
.cut { font-size: 0.74rem; color: var(--text-muted); }

/* --- 参考: 学習に使った文章 --- */
.corpus-group { margin: 6px 0 10px; }
.corpus-group summary { cursor: pointer; font-size: 0.88rem; font-weight: 600; padding: 4px 0; }
.corpus-group .count { font-weight: 400; color: var(--text-muted); font-size: 0.78rem; margin-left: 6px; }
.corpus-sentences {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  columns: 2 340px;
  column-gap: 24px;
  font-size: 0.78rem;
  line-height: 1.75;
  color: var(--text-secondary);
}
.corpus-sentences li { break-inside: avoid; padding: 1px 0; border-bottom: 1px solid var(--gridline); }

/* --- ツールチップ(値が主、説明が従) --- */
.tooltip {
  position: fixed;
  z-index: 20;
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 0.76rem;
  line-height: 1.5;
  white-space: pre-line;
  pointer-events: none;
  max-width: 260px;
}

@media (max-width: 520px) {
  .heatmap-trio { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.25rem; }
}

/* --- モデル2〜: 学習データの量の選択・小さいボタン --- */
.data-choice {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px 10px;
  margin: 10px 0 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  font-size: 0.88rem;
}
.data-choice legend { font-size: 0.78rem; color: var(--text-muted); padding: 0 4px; }
.data-choice label { cursor: pointer; }
.stat-value-sm { font-size: 1.05rem; }
.small-buttons { margin: 6px 0; }
.small-buttons button { padding: 4px 10px; font-size: 0.78rem; }
.small-buttons button.active { background: var(--series-blue); color: #fff; border-color: var(--series-blue); }

/* --- モデルの選択 --- */
.model-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
button.model-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: left;
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 10px 14px;
}
button.model-option.active {
  border: 2px solid var(--series-blue);
  padding: 9px 13px;
  background: var(--surface-1);
}
button.model-option:disabled { cursor: wait; opacity: 0.6; }
.model-name { font-weight: 700; font-size: 1rem; }
.model-option.active .model-name { color: var(--series-blue); }
.model-summary { font-size: 0.8rem; color: var(--text-secondary); }
.model-desc { font-size: 0.88rem; margin: 10px 0 0; line-height: 1.6; }

/* --- Mac で学習済みのモデル(モデル3〜) --- */
.vocab-details summary { cursor: pointer; }
.vocab-details summary h3 { display: inline; }
svg.chart .ref.best { stroke: var(--series-red); stroke-dasharray: 4 3; opacity: 0.8; }
.table-scroll { overflow-x: auto; }
table.data-table.samples td { min-width: 180px; vertical-align: top; line-height: 1.6; }
table.data-table.samples td:first-child { min-width: 90px; white-space: nowrap; }
.gen-controls { display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: center; margin: 4px 0; font-size: 0.88rem; }
.gen-controls input[type="range"] { vertical-align: middle; width: 140px; }
.works-list { columns: 3 200px; column-gap: 24px; font-size: 0.82rem; line-height: 1.8; padding-left: 22px; }
.works-list .count { color: var(--text-muted); font-size: 0.74rem; }
table.data-table.samples tr.best-row td { background: var(--surface-2); }

/* --- BPE のモデル(モデル4〜): トークンの区切りを色の帯で示す --- */
.gen-samples.bpe .tok { border-bottom: 3px solid; padding: 0 1px; }
.gen-samples.bpe .tok0 { border-color: var(--series-blue); }
.gen-samples.bpe .tok1 { border-color: var(--series-red); }
.token-chip.small { font-size: 0.74rem; padding: 1px 6px; margin: 2px; }

/* --- 常識クイズ --- */
.quiz-score-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 8px 0; }
table.quiz-table td { vertical-align: top; }
table.quiz-table td.quiz-ok { color: var(--label-after); font-weight: 600; }
table.quiz-table td.quiz-ng { color: var(--label-before); }
table.quiz-table td.quiz-na { color: var(--text-muted); text-align: center; }
.quiz-pct { display: block; font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }
.quiz-form { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.quiz-form input { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); font-size: 0.95rem; }
.quiz-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.quiz-form button { align-self: flex-start; }

/* --- チャット(チャット版のモデル) --- */
.chat-log { display: flex; flex-direction: column; gap: 10px; max-height: 520px; overflow-y: auto;
  padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); margin: 10px 0; min-height: 120px; }
.bubble { max-width: 85%; padding: 9px 13px; border-radius: 14px; line-height: 1.6; white-space: pre-wrap; font-size: 0.95rem; }
.bubble.user { align-self: flex-end; background: var(--series-blue); color: #fff; border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--surface-1); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble-name { display: block; font-size: 0.72rem; color: var(--text-muted); margin-bottom: 2px; }
.bubble-base { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--border); font-size: 0.85rem; color: var(--text-secondary); }
