/* Isewan Typhoon storm tide map.
   The flood colors are fixed by the historical data, so the chrome stays quiet:
   ink on white, and one night-blue band (the time bar) for the night of 26 Sep 1959. */

:root {
  --ink: #1C2630;
  --slate: #5B6875;
  --paper: #FFFFFF;
  --rule: #D5DBE0;
  --wash: #F1F4F6;
  --night: #15233B;
  --night-2: #22324F;
  --amber: #F5B301;

  --font-ui: 'BIZ UDPGothic', 'Hiragino Sans', 'Yu Gothic UI', 'Meiryo', system-ui, sans-serif;
  --font-record: 'Shippori Mincho B1', 'Hiragino Mincho ProN', 'Yu Mincho', serif;

  --fs-xs: 11px;
  --fs-s: 12.5px;
  --fs-m: 14px;
  --fs-l: 22px;
  --fs-clock: 40px;

  --panel-w: 340px;
  --gap: 16px;
  --radius: 6px;

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;   /* no pull-to-refresh / bounce: the page itself never scrolls */
  background: var(--wash);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--fs-m);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

#map { position: fixed; inset: 0; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--night); outline-offset: 2px; }

input[type="radio"], input[type="checkbox"], input[type="range"] { accent-color: var(--night); }

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

.panel {
  position: absolute;
  top: var(--gap);
  left: var(--gap);
  width: var(--panel-w);
  max-height: calc(100% - 2 * var(--gap));
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(21, 35, 59, 0.12);
  z-index: 2;
}
body.has-timebar .panel { max-height: calc(100% - 3 * var(--gap) - 118px); }

.panel-head {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--rule);
}

.title {
  margin: 0;
  font-family: var(--font-record);
  font-weight: 800;
  font-size: var(--fs-l);
  line-height: 1.3;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 4px 0 0;
  font-size: var(--fs-s);
  line-height: 1.55;
  color: var(--slate);
}

.head-actions {
  display: flex;
  gap: 16px;
  margin-top: 10px;
}

.text-btn {
  padding: 2px 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: var(--fs-s);
  color: var(--night);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--rule);
  cursor: pointer;
}
.text-btn:hover { text-decoration-color: currentColor; }
.panel-toggle, .sheet-handle { display: none; }

.panel-body {
  overflow-y: auto;
  padding: 4px 20px 16px;
  overscroll-behavior: contain;
}

.group {
  margin: 0;
  padding: 14px 0;
  border: 0;
  border-bottom: 1px solid var(--rule);
}
.group legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: var(--fs-s);
  font-weight: 700;
  color: var(--slate);
}

.check-row.mesh-toggle-row { margin: 0 0 8px; font-size: var(--fs-m); font-weight: 700; }
.theme-list { display: grid; gap: 2px; }
.theme-list.is-disabled .theme-option { cursor: default; }
.theme-list.is-disabled .theme-option:hover { background: none; }

.theme-option {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: start;
  gap: 8px;
  padding: 7px 8px 7px 6px;
  border-left: 3px solid transparent;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}
.theme-option:hover { background: var(--wash); }
.theme-option:has(input:checked) { border-left-color: var(--night); background: var(--wash); }
.theme-option input { margin: 4px 0 0; }
.theme-text { display: grid; }
.theme-name { font-weight: 700; line-height: 1.45; }
.theme-note { font-size: var(--fs-xs); color: var(--slate); line-height: 1.5; }

.slider-row, .check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  font-size: var(--fs-s);
}
.slider-row span { flex: 0 0 auto; min-width: 6.5em; color: var(--slate); }
.slider-row input { flex: 1; min-width: 0; }
.check-row { flex-wrap: wrap; cursor: pointer; }
.check-row input { margin: 0; }
.check-row small { flex-basis: 100%; padding-left: 23px; }
.is-disabled { opacity: 0.5; cursor: default; }

.muted { color: var(--slate); font-size: var(--fs-xs); }

.segmented {
  display: inline-flex;
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow: hidden;
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block;
  padding: 4px 12px;
  font-size: var(--fs-s);
  border-left: 1px solid var(--rule);
}
.segmented label:first-child span { border-left: 0; }
.segmented input:checked + span { background: var(--night); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--night); outline-offset: -4px; }

.hint {
  margin: 14px 0 0;
  font-size: var(--fs-s);
  color: var(--slate);
}

.sources { margin-top: 12px; font-size: var(--fs-xs); color: var(--slate); }
.sources summary { cursor: pointer; font-size: var(--fs-s); color: var(--ink); }
.sources ul { margin: 8px 0; padding-left: 1.2em; }
.sources li { margin-bottom: 4px; }
.sources a { color: var(--night); }

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

.legend {
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--rule);
}
.legend-caption {
  margin: 0 0 6px;
  font-size: var(--fs-s);
  font-weight: 700;
  display: flex;
  justify-content: space-between;
}
.legend-unit { font-weight: 400; color: var(--slate); }
.legend-bar, .legend-labels {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
}
.legend-bar { height: 14px; border-radius: 2px; overflow: hidden; }
.legend-labels span {
  margin-top: 3px;
  font-size: var(--fs-xs);
  line-height: 1.2;
  color: var(--slate);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transform: translateX(-2px);
}

/* ------------------------------------------------------------ time bar */

.timebar {
  position: absolute;
  left: calc(var(--panel-w) + 2 * var(--gap));
  right: var(--gap);
  bottom: 44px;
  display: grid;
  grid-template-columns: 48px auto 1fr;
  grid-template-areas:
    "play clock track"
    "play caption caption";
  column-gap: 16px;
  row-gap: 2px;
  align-items: center;
  padding: 14px 22px 12px 16px;
  background: var(--night);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: 0 4px 18px rgba(21, 35, 59, 0.3);
  z-index: 2;
}

.play-btn {
  grid-area: play;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--amber);
  color: var(--night);
  cursor: pointer;
}
.play-btn svg { width: 22px; height: 22px; fill: currentColor; }
.play-btn .icon-pause { display: none; }
.is-playing .play-btn .icon-play { display: none; }
.is-playing .play-btn .icon-pause { display: inline; }
.play-btn:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

.clock {
  grid-area: clock;
  min-width: 3.1em;
  font-family: var(--font-record);
  font-weight: 800;
  font-size: var(--fs-clock);
  line-height: 1;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.track-wrap {
  grid-area: track;
  position: relative;
  padding-top: 6px;
}
.track-ramp {
  position: relative;
  height: 12px;
  border-radius: 2px;
}
/* Dims the part of the night that has not happened yet. */
.track-ramp::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--progress, 100%);
  right: 0;
  background: rgba(21, 35, 59, 0.72);
}

.time-slider {
  position: absolute;
  left: 0;
  right: 0;
  top: -4px;
  width: 100%;
  height: 32px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.time-slider::-webkit-slider-runnable-track { background: transparent; height: 32px; }
.time-slider::-moz-range-track { background: transparent; height: 32px; }
.time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 6px;
  height: 30px;
  margin-top: 1px;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 0 0 2px var(--night);
}
.time-slider::-moz-range-thumb {
  width: 6px;
  height: 30px;
  border: 0;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 0 0 2px var(--night);
}
.time-slider:focus-visible { outline: none; }
.time-slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--night), 0 0 0 4px var(--amber); }
.time-slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px var(--night), 0 0 0 4px var(--amber); }

.ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: var(--fs-xs);
  color: rgba(255, 255, 255, 0.62);
  font-variant-numeric: tabular-nums;
}
.ticks span:first-child { transform: translateX(-2px); }
.ticks span:last-child { transform: translateX(2px); }

.time-caption {
  grid-area: caption;
  margin: 2px 0 0;
  font-size: var(--fs-s);
  color: rgba(255, 255, 255, 0.85);
}

/* ------------------------------------------------------------ popup */

.maplibregl-popup-content {
  padding: 14px 16px 12px;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  box-shadow: 0 4px 16px rgba(21, 35, 59, 0.2);
}
.maplibregl-popup-close-button { font-size: 20px; width: 32px; height: 32px; color: var(--slate); }
.info h2 {
  margin: 0 28px 8px 0;
  font-family: var(--font-record);
  font-weight: 800;
  font-size: 16px;
  line-height: 1.4;
}
.info dl {
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px 16px;
  margin: 0;
}
.info dt { font-size: var(--fs-s); color: var(--slate); }
.info dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.info-msg { margin: 8px 0 0; font-size: var(--fs-s); color: var(--slate); }

.maplibregl-ctrl-attrib { font-family: var(--font-ui); font-size: var(--fs-xs); }

/* ------------------------------------------------------------ narrow screens: bottom sheet */

@media (max-width: 720px) {
  :root { --gap: 10px; --fs-l: 19px; --fs-clock: 30px; }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 62vh;
    border-radius: 12px 12px 0 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.has-timebar .panel { max-height: 62vh; }
  .panel-head { position: relative; padding: 4px 120px 8px 16px; }
  .subtitle { display: none; }
  .head-actions { margin-top: 4px; }
  .panel[data-open="false"] .panel-body { display: none; }

  .panel { transition: transform 0.2s ease-out; }
  .panel.is-dragging { transition: none; }
  .sheet-handle, .panel-head, .legend { touch-action: none; }
  .panel-body { overscroll-behavior: contain; }

  /* Grab handle: the universal "this sheet moves" cue; tap or drag it. */
  .sheet-handle {
    display: block;
    width: 100%;
    height: 20px;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    flex: none;
  }
  .sheet-handle::before {
    content: '';
    display: block;
    width: 40px;
    height: 5px;
    margin: 8px auto 0;
    border-radius: 3px;
    background: var(--rule);
  }

  .panel-toggle {
    position: absolute;
    top: 2px;
    right: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 36px;
    padding: 0 10px 0 14px;
    border: 1px solid var(--rule);
    border-radius: 18px;
    background: var(--paper);
    font: inherit;
    font-size: var(--fs-s);
    font-weight: 700;
    color: var(--night);
    cursor: pointer;
  }
  .panel-toggle svg { width: 18px; height: 18px; transition: transform 0.2s; }
  .panel-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
  .legend { padding: 10px 16px 12px; }
  .panel-body { padding: 0 16px 12px; }

  .timebar {
    top: var(--gap);
    bottom: auto;
    left: var(--gap);
    right: var(--gap);
    grid-template-columns: 40px auto 1fr;
    column-gap: 12px;
    padding: 10px 14px 8px 10px;
  }
  .play-btn { width: 40px; height: 40px; }
  .ticks span:nth-child(2), .ticks span:nth-child(4) { visibility: hidden; }
  body.has-timebar .maplibregl-ctrl-top-right { top: 118px; }
  .maplibregl-ctrl-bottom-right { bottom: 150px; }
  .maplibregl-ctrl-scale { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
