/* ImageLab — style.css
 * 画面共有で見せる前提なので、暗い背景・大きめの文字・高いコントラストにしている。
 */

:root {
  /* 下部（ヒストグラム・プロファイル・数値）の高さ。
     数値の行数は処理によって変わる（比較 op は4手法ぶん増える）ので、
     足りないときだけ js/main.js の fitBottom() がこの値を書き換える。 */
  --bottom-h: 168px;

  --bg: #0d1017;
  --panel: #141821;
  --panel2: #182030;
  --line: #263043;
  --text: #dfe5ef;
  --dim: #8b95a8;
  --accent: #7fd4ff;
  --accent-dim: #2b6d8c;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 "Segoe UI", "Yu Gothic UI", system-ui, sans-serif;
  overflow: hidden;
}

/* ---------- ヘッダ ---------- */

#appbar {
  display: flex; align-items: center; gap: 18px;
  height: 52px; padding: 0 16px;
  background: linear-gradient(180deg, #182030, #131a26);
  border-bottom: 1px solid var(--line);
}
#appbar h1 {
  margin: 0; font-size: 17px; letter-spacing: .06em; font-weight: 600;
  color: var(--accent);
}
#appbar .bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.field { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 12px; }
.info { color: var(--dim); font-size: 12px; }

#sample-hint-bar {
  padding: 5px 16px; font-size: 12px; color: var(--dim);
  background: #101520; border-bottom: 1px solid var(--line);
}
#sample-hint { color: var(--accent); }

button {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px;
  padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
button:hover { background: #202a3d; border-color: #35415a; }

/* ヘッダの［使い方］。<a> だがボタンと同じ見た目にそろえる（guide.html へ） */
.btnlink {
  display: inline-block; text-decoration: none;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px;
  padding: 6px 12px; font-size: 13px; line-height: 1.4;
}
.btnlink:hover { background: #202a3d; border-color: #35415a; }
button.primary { background: var(--accent-dim); border-color: #3d8bad; color: #eaf7ff; }
button.primary:hover { background: #337f9f; }

select, input[type="range"] { font: inherit; }
select {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px; padding: 5px 8px; font-size: 13px;
}
input[type="range"] { accent-color: var(--accent); width: 100%; }

/* ---------- 全体レイアウト ---------- */

main {
  display: grid;
  grid-template-columns: 208px minmax(320px, 1fr) 360px;
  height: calc(100% - 52px - 29px - var(--bottom-h));
}

/* ---------- 処理リスト ---------- */

#oplist {
  border-right: 1px solid var(--line);
  background: #101520; overflow-y: auto; padding: 8px 0 24px;
}
#oplist .cat {
  padding: 12px 14px 5px; font-size: 11px; letter-spacing: .1em;
  color: var(--dim); text-transform: none;
}
#oplist .op {
  display: block; width: calc(100% - 12px); margin: 2px 6px;
  text-align: left; background: transparent; border: 1px solid transparent;
  padding: 7px 10px; border-radius: 5px; font-size: 13px;
}
#oplist .op:hover { background: var(--panel2); }
#oplist .op.active {
  background: var(--accent-dim); border-color: #3d8bad; color: #eaf7ff; font-weight: 600;
}

/* ---------- ビューア ---------- */

#stage { display: flex; flex-direction: column; min-width: 0; }

#viewer-wrap {
  position: relative; flex: 1; min-height: 0;
  background:
    repeating-conic-gradient(#171c26 0% 25%, #12161e 0% 50%) 0 0 / 20px 20px;
  overflow: hidden; cursor: crosshair;
}
#view { position: absolute; inset: 0; }

#loupe {
  position: absolute; display: none; pointer-events: none;
  border: 2px solid var(--accent); border-radius: 4px;
  box-shadow: 0 4px 18px rgba(0,0,0,.6);
}

#split-handle {
  position: absolute; width: 22px; margin-left: -11px;
  cursor: ew-resize; display: none; touch-action: none;
}
#split-handle i {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(255,255,255,.92); border: 2px solid var(--accent-dim);
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}

#viewer-tools {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 7px 14px; border-top: 1px solid var(--line);
  background: #101520; font-size: 12px;
}
#viewer-tools .group { display: flex; align-items: center; gap: 8px; }
#viewer-tools .gl { color: var(--dim); }
#viewer-tools label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
#viewer-tools input[type="range"] { width: 96px; }
#viewer-tools b { color: var(--accent); font-weight: 600; min-width: 30px; }
kbd {
  font: 11px/1 monospace; background: #222b3c; border: 1px solid var(--line);
  border-radius: 3px; padding: 2px 4px; color: var(--dim);
}

/* ---------- 右サイド ---------- */

#side {
  border-left: 1px solid var(--line); background: #101520;
  display: flex; flex-direction: column; min-height: 0;
}
.panel { display: flex; flex-direction: column; min-height: 0; }
.panel.grow { flex: 1; }
.ph {
  margin: 0; padding: 8px 14px; font-size: 11px; letter-spacing: .1em;
  color: var(--dim); font-weight: 600;
  border-bottom: 1px solid var(--line); background: #0d1219;
}

#params { padding: 12px 14px; max-height: 44vh; overflow-y: auto; }
.prow { margin-bottom: 14px; }
.plabel {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; font-size: 12px; color: var(--dim); margin-bottom: 5px;
}
.plabel .pval { color: var(--accent); font-weight: 600; font-size: 12px; }
.prow select { width: 100%; }
.pcheck { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.empty { color: var(--dim); font-size: 12px; margin: 0; }

.curvebox { display: flex; flex-direction: column; gap: 6px; align-items: center; }
canvas.curve {
  border: 1px solid var(--line); border-radius: 4px; cursor: crosshair; touch-action: none;
}
.presets { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.presets button { padding: 3px 7px; font-size: 11px; }

/* スペクトルマスクの編集欄。中身はトーンカーブと同じ流儀にそろえてある */
.maskbox { display: flex; flex-direction: column; gap: 6px; align-items: center; }
canvas.maskcanvas {
  border: 1px solid var(--line); border-radius: 4px; cursor: crosshair; touch-action: none;
}
.maskrow { display: flex; align-items: center; gap: 8px; width: 100%; font-size: 11px; color: var(--dim); }
.maskrow span { white-space: nowrap; }
.maskrow input[type="range"] { flex: 1; }
.maskrow b { color: var(--accent); font-weight: 600; min-width: 18px; text-align: right; }
.maskrow.guide { gap: 5px; cursor: pointer; }
.maskrow.guide input { flex: none; }
.maskhint { margin: 0; font-size: 11px; color: var(--dim); line-height: 1.5; }

#explain {
  padding: 4px 14px 20px; overflow-y: auto; flex: 1; font-size: 13px;
}
#explain h2 { font-size: 15px; margin: 12px 0 6px; color: var(--accent); }
#explain h3 {
  font-size: 11px; letter-spacing: .08em; color: var(--dim);
  margin: 16px 0 5px; padding-bottom: 3px; border-bottom: 1px solid var(--line);
}
#explain p { margin: 0 0 9px; }
#explain pre {
  background: #0b0f16; border: 1px solid var(--line); border-radius: 4px;
  padding: 9px 10px; overflow-x: auto; font: 12px/1.7 "Consolas", monospace;
  color: #bcd3e6; white-space: pre-wrap;
}
#explain ul { margin: 0; padding-left: 18px; }
#explain li { margin-bottom: 8px; }

/* ---------- 下部 ---------- */

#bottom {
  display: grid; grid-template-columns: 1fr 1fr 260px; grid-template-rows: var(--bottom-h);
  height: var(--bottom-h); border-top: 1px solid var(--line); background: #0d1219;
}
#bottom .cell { position: relative; border-right: 1px solid var(--line); overflow: hidden; }
/* canvas を絶対配置にしておかないと、canvas 自身の内部サイズが行の高さを押し広げ、
   それを測って内部サイズを決める → また広がる、という循環に入る */
#bottom canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cellbar {
  position: absolute; right: 8px; top: 6px; display: flex; gap: 10px;
  font-size: 11px; color: var(--dim); background: rgba(13,18,25,.75);
  padding: 2px 6px; border-radius: 4px;
}
.cellbar label { display: flex; align-items: center; gap: 3px; cursor: pointer; }

/* min-height:0 が無いと、grid の行が「中身の最小の高さ」に引っ張られて
   overflow-y が効かない。伸ばしても入り切らないとき（画面が低いとき）の
   最後の受け皿として、ここは必ずスクロールできるようにしておく */
#stats {
  padding: 12px 14px; display: flex; flex-direction: column; gap: 7px; font-size: 12px;
  min-height: 0; overflow-y: auto;
}
#stat-rows { display: flex; flex-direction: column; gap: 7px; }

/* 進捗バー。計算中だけ出す（.on が付いているあいだ）。
   場所を食わないよう、出ていないときは高さ 0 に畳む */
#prog { display: none; flex-direction: column; gap: 4px; }
#prog.on { display: flex; }
#prog .track { height: 5px; border-radius: 3px; background: var(--panel2); overflow: hidden; }
#prog i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--accent);
          transition: width .08s linear; }
#prog span { color: var(--accent); font-variant-numeric: tabular-nums; }
.stat { display: flex; justify-content: space-between; gap: 10px; }
.stat span { color: var(--dim); }
.stat b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
/* 数値のうしろに小さく添える但し書き（「（8 並列の合計）」など） */
.stat b i { margin-left: 4px; color: var(--dim); font-style: normal; font-weight: 400; }
/* 処理が返してきた数値（PSNR / SSIM）を、実行の情報と区切る */
.stat-sep { height: 1px; margin: 3px 0; background: var(--line); }

/* 画面が狭いときは解説を畳んで、ビューアを優先する */
@media (max-width: 1200px) {
  main { grid-template-columns: 176px 1fr 300px; }
  #bottom { grid-template-columns: 1fr 1fr 220px; }
}
