/* ダム旅 / DAM TABI — 地図画面のスタイル */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #16202b;
  --ink-soft: #5b6875;
  --ink-faint: #8a95a1;
  --line: #dde3ea;
  --accent: #14507d;
  --nodata: #94a3b8;
  --shadow: 0 2px 4px rgba(16, 32, 48, .06), 0 8px 24px rgba(16, 32, 48, .10);
  --topbar-h: 58px;
  --panel-w: 372px;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic",
               "Noto Sans JP", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------------------------------------------------------- topbar */

#topbar {
  flex: 0 0 auto;
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 16px;
  padding: 7px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

#topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .03em;
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  gap: 7px;
}

/* 当面は富山県のみなので、対象範囲を控えめに添える */
#topbar h1 .region {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--ink-faint);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
}

/* 制作名義は控えめに */
#credits .producer {
  margin-left: 10px;
  letter-spacing: .08em;
  font-weight: 700;
  opacity: .55;
}

#meta {
  display: flex;
  align-items: center;
  gap: 6px 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-soft);
  min-width: 0;
}

#status-summary { color: var(--ink-faint); }

#list-link {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  white-space: nowrap;
}

#list-link:hover { background: #eef4fa; }
#status-summary .warn { color: #b4530a; font-weight: 600; }

#obs-time .age { color: var(--ink); font-weight: 600; margin-left: 3px; }

#obs-time .warn {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 4px;
  background: #fdf3e8;
  color: #8a4b12;
  font-weight: 700;
}

#obs-time .warn.strong { background: #fbe9e7; color: #a5291a; }

/* ---------------------------------------------------------- map */

#map { flex: 1 1 auto; min-height: 0; }

/* 出典は #credits に常時表示するので、内蔵の attribution は隠す
   （コントロール自体は MapLibre の初期化に必要なので消さない） */
.maplibregl-ctrl-attrib { display: none !important; }

/* ---------------------------------------------------------- markers */

/* ピンは「リングの色 + 弧の長さ」で残量を示し、中身はイラスト（あれば）。
   色が見分けにくくても弧の長さで量が読めるようにしている。

   外側の .dam-pin は MapLibre が transform を毎フレーム書き換えるので、
   ここに transition を付けてはいけない（付けると地図に追従できなくなる）。
   見た目の変化はすべて内側の .dam-pin__inner 以下に持たせる。 */
.dam-pin {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  will-change: transform;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.dam-pin__inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transition: transform .12s ease, filter .12s ease;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .3)) drop-shadow(0 3px 6px rgba(0, 0, 0, .18));
}

.dam-pin__gauge {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.dam-pin__disc {
  position: absolute;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.dam-pin__disc img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dam-pin__fill { position: absolute; inset: 0; }

.dam-pin__fill.is-nodata {
  background: repeating-linear-gradient(
    -45deg, #c3ccd5, #c3ccd5 3px, #dde3ea 3px, #dde3ea 6px);
}

/* 数字の下だけ薄く落とす。イラストを帯で潰さない */
.dam-pin__scrim {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 52%;
  background: linear-gradient(180deg, rgba(8, 20, 32, 0) 0%, rgba(8, 20, 32, .72) 100%);
}

.dam-pin__num {
  position: relative;
  align-self: end;
  margin-bottom: 5%;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .55);
}

.dam-pin__num.is-center {
  align-self: center;
  margin-bottom: 0;
  text-shadow: none;
}

.dam-pin:hover .dam-pin__inner { transform: scale(1.1); }
.dam-pin:active .dam-pin__inner { transform: scale(1.03); }

.dam-pin.is-active .dam-pin__inner {
  transform: scale(1.16);
  filter: drop-shadow(0 0 0 rgba(0, 0, 0, 0))
          drop-shadow(0 2px 5px rgba(0, 0, 0, .35));
}

.dam-pin.is-active .dam-pin__disc {
  box-shadow: 0 0 0 3px #ffd54a;
}

/* 地図を動かしている間はホバー拡大を止める */
.is-moving .dam-pin:hover .dam-pin__inner { transform: none; }

/* ------------------------------------------------- 出典（常時表示） */

/* 地図の操作や状態にかかわらず、常に画面に出しておく。
   ヘッダ内の独立した行にしているので、詳細パネルにも凡例にも隠されない。 */
#credits {
  flex: 1 0 100%;
  margin: 0;
  padding-top: 3px;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--ink-faint);
}

#credits a { color: var(--accent); }

/* ---------------------------------------------------------- legend */

#controls {
  position: absolute;
  left: 12px;
  bottom: 24px;
  z-index: 4;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: 12px;
  max-width: 232px;
}

#basis-switch {
  border: 0;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#basis-switch legend {
  padding: 0;
  font-weight: 700;
  font-size: 11px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

#basis-switch label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
#basis-switch input { margin: 0; accent-color: var(--accent); }

#legend {
  list-style: none;
  margin: 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#legend li { display: flex; align-items: center; gap: 7px; color: var(--ink-soft); }

#legend .legend-note {
  margin-top: 3px;
  padding-top: 5px;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 10.5px;
}

#legend .sw {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 1.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .12);
}

#legend .sw.nodata {
  background: repeating-linear-gradient(
    -45deg, var(--nodata), var(--nodata) 3px, #b6c0cb 3px, #b6c0cb 6px);
}

/* ---------------------------------------------------------- panel */

#panel {
  position: absolute;
  max-width: 100vw;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  z-index: 6;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 24px rgba(16, 32, 48, .10);
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: transform .2s ease;
}

#panel.is-hidden { transform: translateX(100%); pointer-events: none; }

#panel-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(4px);
  font-size: 20px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  z-index: 2;
}

#panel-close:hover { background: #eef1f4; color: var(--ink); }

/* --- イラスト差し込み領域（後日ここに絵を入れる） --- */

.dam-illust {
  position: relative;
  aspect-ratio: 16 / 10;
  background: linear-gradient(160deg, #e8eef4 0%, #dbe6ef 100%);
  border-bottom: 1px solid var(--line);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.dam-illust img { width: 100%; height: 100%; object-fit: cover; display: block; }

.dam-illust .placeholder {
  text-align: center;
  color: #93a5b6;
  font-size: 11px;
  line-height: 1.7;
  padding: 8px;
}

.dam-illust .placeholder svg { display: block; margin: 0 auto 6px; opacity: .55; }

.panel-inner { padding: 16px 18px 32px; overflow-wrap: anywhere; word-break: normal; }

.dam-name {
  margin: 0 0 2px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .01em;
}

.dam-sub {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--ink-soft);
}

.dam-sub .sep { color: var(--ink-faint); margin: 0 5px; }

.detail-link {
  display: inline-block;
  margin: 0 0 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}

.detail-link:hover { text-decoration: underline; }

/* --- 貯水率の 2 枚組。片方に丸めない --- */

.rates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.rate {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px 11px;
  background: #fbfcfd;
  min-width: 0;
}

.rate .k {
  font-size: 11px;
  color: var(--ink-soft);
  font-weight: 600;
  display: block;
  margin-bottom: 3px;
}

.rate .v {
  font-size: 27px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.rate .v .unit { font-size: 14px; font-weight: 600; color: var(--ink-soft); }

.rate.is-nodata .v { color: var(--nodata); }

.rate .why {
  margin-top: 5px;
  font-size: 10.5px;
  line-height: 1.5;
  color: #a3562a;
  background: #fdf3e8;
  border-radius: 5px;
  padding: 4px 6px;
}

.rate .bar {
  margin-top: 7px;
  height: 5px;
  border-radius: 3px;
  background: #e6ebf0;
  overflow: hidden;
}

.rate .bar > i { display: block; height: 100%; border-radius: 3px; }

.panel-freshness {
  margin: -6px 0 12px;
  font-size: 11.5px;
  color: var(--ink-soft);
}


/* --- 用語ヘルプ（〇で囲んだ「?」） --------------------------------
   details/summary なので JS が無くても開閉できる。
   本文は .rates を基準に絶対配置し、カード幅ではなく全幅で読ませる。 */

.rates { position: relative; }

.rate .k {
  display: flex;
  align-items: center;
  gap: 5px;
}

details.help { display: inline; }

details.help > summary {
  list-style: none;
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1.2px solid currentColor;
  color: var(--ink-faint);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .12s ease, color .12s ease, border-color .12s ease;
}

details.help > summary::-webkit-details-marker { display: none; }
/* 見た目は小さいままで、指で押せるようタップ領域だけ広げる */
details.help > summary { position: relative; }
details.help > summary::after {
  content: "";
  position: absolute;
  inset: -13px;
}

details.help > summary::marker { content: ""; }

details.help > summary:hover,
details.help[open] > summary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

details.help > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.help-body {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 6;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 11px 13px;
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.8;
  color: var(--ink);
  text-align: left;
}

.help-body b { color: var(--accent); font-weight: 700; }

/* --- 明細テーブル --- */

.facts { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 12.5px; }

.facts th, .facts td {
  text-align: left;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.facts th { width: 40%; color: var(--ink-soft); font-weight: 600; }
.facts td { font-variant-numeric: tabular-nums; }
.facts td.muted { color: var(--nodata); }

.callout {
  margin-top: 14px;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1.65;
  background: #eef4fa;
  color: #2a4f72;
  border-left: 3px solid #7ba7cc;
}

.callout.note { background: #f4f5f7; color: var(--ink-soft); border-left-color: #c3cbd4; }

.src {
  margin-top: 14px;
  font-size: 10.5px;
  color: var(--ink-faint);
  line-height: 1.6;
}

.src a { color: inherit; }
.src b { color: var(--ink-soft); font-weight: 700; }

.noscript { padding: 24px; font-size: 14px; }

/* ---------------------------------------------------------- narrow */

@media (max-width: 720px) {
  :root { --topbar-h: 52px; }

  /* 高さを固定しない。行が増えても切り落とさない */
  #topbar {
    min-height: var(--topbar-h);
    gap: 2px 12px;
    flex-wrap: wrap;
    align-content: center;
    padding: 7px 12px;
  }
  #topbar h1 { font-size: 14px; }
  #meta { font-size: 11px; width: 100%; gap: 2px 10px; }
  #status-summary { display: flex; flex-wrap: wrap; gap: 0 4px; min-width: 0; }

  #controls {
    left: 8px;
    right: 8px;
    bottom: 8px;
    max-width: none;
    padding: 8px 10px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
  }

  #basis-switch { margin: 0; flex: 0 0 auto; }
  #legend { border-top: 0; border-left: 1px solid var(--line); padding: 0 0 0 12px; flex: 1 1 auto; }
  #legend li { font-size: 10.5px; }

  #panel {
    top: auto;
    left: 0;
    right: 0;
    width: auto;
    max-height: 76%;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 24px rgba(16, 32, 48, .16);
  }

  #panel.is-hidden { transform: translateY(100%); }

  .dam-illust { aspect-ratio: 16 / 6; max-height: 22vh; }

  #list-link { order: 2; }
  #meta { order: 3; }
  #credits { order: 4; font-size: 9.5px; line-height: 1.45; padding-top: 2px; }
}
