/* ============================================================
   デザイントークン
   ============================================================ */
:root {
  --color-bg: #EAF4FA;
  --color-panel: #FFFFFF;
  --color-border: #C9DEEA;
  --color-frame: #2E6DA4;      /* パネルを仕切る枠線・区切り線の色（青系） */
  --color-frame-soft: #E5F1FA; /* 枠内の淡い区切り・見出し背景用 */

  --color-text: #1F2A33;
  --color-text-soft: #5A6B77;

  --color-curve: #1B4B66;
  --color-grid: #DCEAF2;

  --color-vapor-solid: #4FB3D9;   /* 実際に含まれる水蒸気量の背景色・入力欄の文字色 */
  --color-vapor-headroom: #DCF1FA; /* 余地の背景色（薄い水色） */
  --color-condensed: #1565A6;      /* 結露部分の背景色（青） */

  --color-dashed: #8394A1;
  --color-accent-temp: #E8734A;    /* 動的な気温ラベル（暖色でメリハリ） */

  --radius-md: 10px;
  --radius-sm: 6px;

  --font-body: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui,
    -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
}

/* ============================================================
   全体レイアウト
   ============================================================ */
/* 画面いっぱいを占める外枠。#app を実寸のまま中央に置き、
   JS側で #app に transform: scale() をかけて画面に収める。
   #app 自体の見た目上の大きさ（レイアウト計算・クリック位置など）は
   scale() では変わらないため、ドラッグ操作の座標計算に影響しない。 */
#app-scale-wrap {
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* モバイルのアドレスバー分の誤差を減らす */
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

#app {
  display: flex;
  flex-direction: column;
  padding: 14px 18px 18px;
  gap: 12px;
  width: 1280px;
  max-width: 1280px;
  /* flexアイテムは既定で縮められるが、それをすると「元の大きさ」の計測自体が
     狂ってしまう（縮んだ値を測ってしまい、scale=1になる）。縮小はJS側の
     transform: scale() だけで行うので、ここでは絶対に縮まないようにする。 */
  flex-shrink: 0;
  transform-origin: center center;
  /* サイズ計測とスケールの切り替えでちらつかないよう、切り替え自体は一瞬にする */
  will-change: transform;
}

.app-header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-curve);
  letter-spacing: 0.02em;
}

.app-subtitle {
  margin: 4px 0 0;
  font-size: 1.15rem;
  color: var(--color-text-soft);
  line-height: 1.5;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
}

.humidity-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--color-frame);
  background: var(--color-frame-soft);
  color: var(--color-curve);
  font-family: inherit;
  font-size: 1.13rem;
  font-weight: 600;
  cursor: pointer;
}
.humidity-toggle-btn:hover {
  background: #DCEEF9;
}
.humidity-toggle-btn:active {
  background: #CDE6F5;
}

.humidity-toggle-icon .icon-eye-off {
  display: none;
}
.humidity-toggle-btn[aria-pressed="false"] {
  background: #FFFFFF;
  color: var(--color-text-soft);
  border-color: var(--color-border);
}
.humidity-toggle-btn[aria-pressed="false"] .icon-eye {
  display: none;
}
.humidity-toggle-btn[aria-pressed="false"] .icon-eye-off {
  display: inline;
}

/* ============================================================
   固定情報パネル（気温と飽和水蒸気量の表）
   ============================================================ */
.info-panel {
  flex: 1 1 auto;
  min-width: 0;
  /* 左右のパディングはグラフ(.graph-wrap)と同じにする。
     ずれると表の列とグラフの目盛りが揃わなくなる */
  padding: 10px 8px;
  overflow-x: auto;
  overflow-y: hidden;
}

/* 表の各列の中心を、グラフの気温目盛りの位置に合わせる。
   グラフのSVG(viewBox 1000幅)に対する比率で幅を指定している。
   ・グラフの左余白 82 / データ領域 888 (0〜40℃) → 5℃あたり 111
   ・表は 5〜35℃ の7列 + ラベル列。ラベル列は 0℃より左の領域(縦軸まわり)を使う。
   ・全体で 914.5 / 1000 = 91.45% */
.data-table {
  border-collapse: collapse;
  font-size: 1.22rem;
  white-space: nowrap;
  width: 91.45%;
  table-layout: fixed;
}
.data-table th,
.data-table td {
  border: 1.5px solid var(--color-text-soft);
  padding: 4px 2px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.data-table .row-label {
  width: 15.036%;
  padding-left: 8px;
  padding-right: 6px;
  background: #F2F8FC;
  color: var(--color-text-soft);
  text-align: left;
  font-weight: 600;
  white-space: normal;
  line-height: 1.3;
  word-break: keep-all;
  overflow-wrap: break-word;
}
.data-table tr#table-sat-row td {
  color: var(--color-curve);
  font-weight: 600;
}

/* ============================================================
   1つの枠（app-frame）の中に、表・操作パネル・グラフを
   隙間なく隣接させて配置する
   ============================================================ */
.app-frame {
  display: flex;
  flex-direction: column;
  border: 2px solid var(--color-frame);
  border-radius: var(--radius-md);
  background: var(--color-panel);
  overflow: hidden;
}

.top-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
}

.graph-wrap {
  padding: 8px;
  min-width: 0;
  display: flex;
  aspect-ratio: 1000 / 560;
}

#graph {
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ============================================================
   SVG内の要素スタイル
   ============================================================ */
.gridline {
  stroke: var(--color-grid);
  stroke-width: 1;
}
.axis-line {
  stroke: var(--color-text-soft);
  stroke-width: 1.5;
}
.tick-line {
  stroke: var(--color-text-soft);
  stroke-width: 1;
}
.axis-label {
  fill: var(--color-text-soft);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}
.axis-title {
  fill: var(--color-text);
  font-size: 19px;
  font-weight: 700;
  text-anchor: middle;
}

.curve {
  fill: none;
  stroke: var(--color-curve);
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.vapor-dashed-line {
  stroke: var(--color-dashed);
  stroke-width: 2;
  stroke-dasharray: 7 6;
}
.vapor-dashed-line.dragging {
  stroke: var(--color-vapor-solid);
  stroke-width: 2.5;
}

.vapor-line-hit-area {
  fill: transparent;
  cursor: ns-resize;
  touch-action: none;
}

.vapor-line-label {
  fill: var(--color-text-soft);
  font-size: 16px;
  font-weight: 700;
}

.curve-point {
  fill: var(--color-curve);
  stroke: #fff;
  stroke-width: 2;
}

.sat-label-bg {
  fill: var(--color-curve);
  opacity: 0.92;
}
.sat-label-text {
  fill: #fff;
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dot-solid {
  fill: url(#dot-gradient-blue);
  stroke: #1668A0;
  stroke-width: 0.75;
}
.dot-empty {
  fill: #FFFFFF;
  stroke: var(--color-text-soft);
  stroke-width: 1.4;
  stroke-dasharray: 3 2.5;
}
.dot-droplet {
  fill: url(#dot-gradient-droplet);
  stroke: #0B3F63;
  stroke-width: 0.75;
}

.bar-fill-solid {
  fill: var(--color-vapor-solid);
  opacity: 0.28;
}
.bar-fill-headroom {
  fill: var(--color-vapor-headroom);
  opacity: 0.6;
}
.bar-fill-condensed {
  fill: var(--color-condensed);
  opacity: 0.28;
}

.bar-outline {
  fill: none;
  stroke: var(--color-curve);
  stroke-width: 1.5;
}
.bar-hit-area {
  fill: transparent;
  cursor: ew-resize;
}
.bar-group.dragging .bar-hit-area {
  cursor: ew-resize;
}

/* ドラッグ中に出る赤い両矢印（マウスカーソルの代わりの目印） */
.drag-arrow {
  pointer-events: none;
}
.drag-arrow-line {
  stroke: #E03131;
  stroke-width: 4;
  stroke-linecap: round;
}
.drag-arrow-head {
  fill: #E03131;
}

.cube-face {
  stroke: var(--color-frame);
  stroke-width: 1.5;
  stroke-linejoin: round;
}
.cube-face-front {
  fill: #F3FAFE;
  fill-opacity: 0.9;
}
.cube-face-top {
  fill: #DCEFFA;
  fill-opacity: 0.9;
}
.cube-face-side {
  fill: #C7E4F5;
  fill-opacity: 0.9;
}

.temp-label-bg {
  fill: var(--color-accent-temp);
}
.temp-label-text {
  fill: #fff;
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.vapor-value-bg {
  fill: var(--color-vapor-solid);
}
.vapor-value-text {
  fill: #fff;
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.dew-label-group {
  transition: opacity 0.18s ease-out;
  pointer-events: none;
}
.dew-label-bg {
  fill: #D63B2F;
}
.dew-label-text {
  fill: #fff;
  font-size: 17px;
  font-weight: 700;
}

.cond-box {
  fill: var(--color-condensed);
}
.cond-title {
  fill: #fff;
  font-size: 12px;
  font-weight: 600;
}
.cond-formula {
  fill: #fff;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.cond-result {
  fill: #fff;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.head-box {
  fill: var(--color-vapor-headroom);
  fill-opacity: 0.75;
}
.head-title {
  fill: #000;
  font-size: 12px;
  font-weight: 600;
}
.head-formula {
  fill: #000;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.head-result {
  fill: #000;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.formula-box {
  fill: #FFFFFF;
  stroke: #000000;
  stroke-width: 1.2;
}
.formula-text {
  fill: #000000;
  font-weight: 600;
}
.formula-frac-num,
.formula-frac-den {
  fill: #000000;
}
.formula-frac-line {
  stroke: #000000;
  stroke-width: 1;
}
.formula-result-text {
  fill: #000000;
  font-weight: 700;
}

/* 画面サイズへの対応は、index.html側のJS（transform: scaleで#app全体を
   縮小・拡大する仕組み）で一括して行っている。#appは常に幅1280pxの
   「そのままの大きさ」でレイアウトされるため、幅に応じた調整用の
   メディアクエリは不要（後方互換のため以前のコメントのみ残す）。 */
