:root {
  --bg: #ffffff;
  --fg: #14181d;
  --muted: #5c6672;
  --line: #d7dde4;
  --accent: #0b5cad;
  --warn-bg: #fff8e1;
  --warn-line: #e0b400;
  --alert: #b3261e;
  --panel-w: 260px;
  /* シートが下に来るときの最大の高さ。app.js の SHEET_MAX_FRACTION と揃える */
  --sheet-max-h: 58%;
  font-synthesis-weight: none;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171b20;
    --fg: #e8ecf1;
    --muted: #9aa5b1;
    --line: #333c46;
    --accent: #7db4f0;
    --warn-bg: #2e2713;
    --warn-line: #8a7100;
  --alert: #ff8a80;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
  font-family: system-ui, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  color: var(--fg);
  background: var(--bg);
}

#map { position: absolute; inset: 0; }

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
#topbar h1 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .02em; }
#panel-toggle {
  margin-left: auto;
  font: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
#panel-toggle:hover { border-color: var(--accent); }

/* ---- 地名・住所の検索 ---- */

#search { display: flex; gap: 6px; flex: 1 1 auto; max-width: 340px; }
#search input {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}
#search input:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
#search button {
  flex: none;
  font: inherit;
  font-size: 13px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
#search button:hover { border-color: var(--accent); }

#results {
  position: absolute;
  z-index: 4;
  top: 46px;
  left: 10px;
  width: min(340px, calc(100% - 20px));
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgb(0 0 0 / .18);
  font-size: 13px;
}
#results[hidden] { display: none; }
#results button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--fg);
  cursor: pointer;
}
#results button:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
#results .msg { padding: 7px 9px; color: var(--muted); }

#panel {
  position: absolute;
  z-index: 3;
  top: 46px;
  left: 10px;
  width: var(--panel-w);
  max-height: calc(100% - 150px);
  overflow-y: auto;
  padding: 4px 10px 10px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}
#panel[hidden] { display: none; }

#panel fieldset {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0;
  padding: 8px 0;
}
#panel fieldset:first-of-type { border-top: 0; }
#panel legend { font-weight: 700; font-size: 12px; color: var(--muted); padding: 0; }
#panel label { display: flex; align-items: center; gap: 6px; padding: 3px 0; cursor: pointer; }
#panel input { accent-color: var(--accent); margin: 0; flex: none; }
.lb { flex: none; }

.t { margin-left: auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.t.warn, .status.warn { color: var(--alert); font-weight: 600; }

.status {
  margin: 5px 0 0;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.note {
  margin: 6px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

#legend:empty { display: none; }
#legend { border-top: 1px solid var(--line); padding-top: 8px; }
#legend h2 { font-size: 12px; margin: 8px 0 4px; color: var(--muted); }
#legend h2:first-child { margin-top: 0; }
#legend ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 8px; }
#legend li { display: flex; align-items: center; gap: 5px; font-size: 11px; }
#legend i { width: 13px; height: 13px; border: 1px solid var(--line); border-radius: 2px; flex: none; }

#legend .bar { height: 11px; border: 1px solid var(--line); border-radius: 3px; }
#legend .ticks { display: flex; margin-top: 2px; }
#legend .ticks span {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  font-size: 9.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#bottom {
  position: absolute;
  z-index: 3;
  left: 10px; right: 10px; bottom: 0;
}

/* ---- 時刻スライダー ---- */

#timebar {
  margin-bottom: 6px;
  padding: 7px 10px 5px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(6px);
}
#timebar[hidden] { display: none; }

#time-head { display: flex; align-items: center; gap: 8px; }
#time-head button {
  flex: none;
  font: inherit;
  font-size: 12px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
#time-head button:hover { border-color: var(--accent); }
#play { font-size: 11px; min-width: 32px; }
#now[disabled] { opacity: .45; cursor: default; }
#now[disabled]:hover { border-color: var(--line); }

#time-label {
  flex: 1 1 auto;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
#time-label .fc {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}

#time-range { width: 100%; margin: 6px 0 0; accent-color: var(--accent); }
#time-ends {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#disclaimer {
  padding: 7px 10px;
  padding-bottom: max(7px, env(safe-area-inset-bottom));
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
}
#disclaimer p { margin: 0; }
#credits { margin-top: 3px; color: var(--muted); font-size: 11px; }
#credits a { color: inherit; }

/* MapLibre 既定のロゴ・帰属表示は #credits に自前で出すので隠す */
.maplibregl-ctrl-attrib, .maplibregl-ctrl-logo { display: none !important; }
.maplibregl-ctrl-top-right { margin-top: 44px; }

@media (max-width: 560px) {
  #panel { width: auto; right: 10px; max-height: 46%; }
  /* 幅が足りないので見出しは畳む。タブのタイトルとfaviconで判別できる */
  #topbar h1 { display: none; }
  #search { max-width: none; }
  #panel-toggle { padding: 5px 8px; }
}

/* ---- 冠水の報告 ---- */

#report-open {
  flex: none;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 5px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
#report-open:hover { filter: brightness(1.08); }
#report-open[aria-pressed="true"] { background: var(--muted); }

/* 報告する場所を示す十字。地図の中央に固定する */
/* 位置は JS が決める（シートに隠れない場所に置く） */
#crosshair {
  position: absolute;
  z-index: 4;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  pointer-events: none;
}
#crosshair[hidden] { display: none; }
#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: var(--accent);
  box-shadow: 0 0 0 1.5px #fff;
}
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; margin-left: -1px; }
#crosshair::after  { top: 50%; left: 0; height: 2px; width: 100%; margin-top: -1px; }

/* 画面が広いときは右端に寄せる。中央に置くと、報告しようとしている
   地点（十字）をシート自身が覆ってしまう。 */
#sheet {
  position: absolute;
  z-index: 5;
  top: 52px;
  right: 10px;
  width: 340px;
  max-height: calc(100% - 62px);
  overflow-y: auto;
  padding: 14px 16px 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 34px rgb(0 0 0 / .24);
  font-size: 13px;
}
#sheet[hidden] { display: none; }

.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
#sheet-close {
  margin-left: auto;
  font: inherit;
  font-size: 18px;
  line-height: 1;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}

.sheet-where { margin: 10px 0 0; font-size: 12.5px; line-height: 1.6; color: var(--muted); }
#to-here {
  font: inherit;
  font-size: 12px;
  padding: 3px 9px;
  margin-left: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  white-space: nowrap;
}

.depths { border: 0; margin: 12px 0 0; padding: 0; }
.depths legend { font-size: 12px; font-weight: 700; color: var(--muted); padding: 0 0 6px; }
.depths label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.depths label:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.depths input { accent-color: var(--accent); margin: 0; flex: none; }
.depths .sw { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.depths .sw[data-sev="1"] { background: #f2b705; }
.depths .sw[data-sev="2"] { background: #f26b0f; }
.depths .sw[data-sev="3"] { background: #c62828; }

#human-check { margin-top: 12px; min-height: 0; }
#human-check:empty { display: none; }

.sheet-msg { margin: 10px 0 0; font-size: 12.5px; line-height: 1.6; min-height: 0; }
.sheet-msg:empty { display: none; }
.sheet-msg.bad { color: var(--alert); font-weight: 600; }
.sheet-msg.good { color: var(--accent); font-weight: 600; }

#sheet-send {
  width: 100%;
  margin-top: 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
#sheet-send[disabled] { opacity: .45; cursor: default; }

/* 投稿の吹き出し */
.report-popup { font-size: 12.5px; line-height: 1.6; }
.report-popup b { display: block; font-size: 13.5px; }
.report-popup .when { color: var(--muted); }
.report-popup button {
  margin-top: 8px;
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #14181d;
  cursor: pointer;
}
.maplibregl-popup-content { border-radius: 8px; }

/* 狭い画面では下に置く。親指で届く位置のほうが扱いやすい。
   十字はシートの上の空いた部分に JS が置く。 */
@media (max-width: 700px) {
  #sheet {
    top: auto;
    bottom: 10px;
    left: 10px;
    right: 10px;
    width: auto;
    max-height: var(--sheet-max-h);
  }
}
@media (max-width: 560px) {
  #report-open { padding: 5px 9px; }
}
