:root {
  color-scheme: dark;
  --ink: #f5f8fc;
  --muted: #a9b5c8;
  --dim: #75839a;
  --surface: rgba(7, 17, 31, 0.82);
  --surface-strong: rgba(7, 16, 29, 0.94);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.17);
  --blue: #53b9ff;
  --blue-deep: #1976e9;
  --green: #72d8a6;
  --yellow: #ffd26a;
  --orange: #ff9f5a;
  --red: #ff6878;
  --record-position: 99.333%;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #06101d;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
summary {
  font: inherit;
}

button,
summary,
input[type="range"],
input[type="checkbox"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(83, 185, 255, 0.55);
  outline-offset: 3px;
}

.app-shell,
#map {
  position: fixed;
  inset: 0;
}

#map {
  z-index: 1;
  background: #081523;
}

.leaflet-container {
  font-family: inherit;
}

.leaflet-tile-pane {
  filter: saturate(0.78) contrast(1.07) brightness(0.86);
}

.leaflet-image-layer.contour-overlay {
  mix-blend-mode: multiply;
}

.leaflet-control-zoom {
  border: 0 !important;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28) !important;
}

.leaflet-control-zoom a,
.leaflet-control-attribution {
  color: #eaf2ff !important;
  background: rgba(7, 17, 31, 0.82) !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
  backdrop-filter: blur(12px);
}

.leaflet-control-attribution {
  font-size: 10px;
}

.leaflet-control-attribution a {
  color: #9cd4ff !important;
}

.map-shade {
  position: fixed;
  inset: 0;
  z-index: 450;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(3, 9, 18, 0.2), transparent 34%),
    radial-gradient(circle at 58% 43%, transparent 46%, rgba(3, 9, 18, 0.24) 100%);
}

.glass {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(22px) saturate(1.18);
  -webkit-backdrop-filter: blur(22px) saturate(1.18);
}

.brand {
  position: fixed;
  z-index: 700;
  top: 1rem;
  left: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem 0.78rem 0.78rem;
  border-radius: 1.15rem;
}

.brand-mark {
  display: grid;
  width: 2.55rem;
  height: 2.55rem;
  place-items: center;
  border: 1px solid rgba(113, 204, 255, 0.34);
  border-radius: 0.82rem;
  background: linear-gradient(145deg, rgba(67, 183, 255, 0.23), rgba(20, 92, 181, 0.14));
  color: #a6dcff;
  font-family: Georgia, serif;
  font-size: 1.65rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0;
  color: #9eacc0;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0.12rem 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.43rem;
  font-weight: 500;
  letter-spacing: -0.035em;
}

.control-panel {
  position: fixed;
  z-index: 710;
  top: 1rem;
  right: 1rem;
  width: min(390px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  overflow: auto;
  padding: 1.1rem;
  border-radius: 1.45rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.17) transparent;
  transition: transform 240ms ease, opacity 180ms ease;
}

.panel-heading,
.level-row,
.section-title,
.action-row,
.range-labels,
.layer-row,
.opacity-controls label {
  display: flex;
  align-items: center;
}

.panel-heading {
  justify-content: space-between;
  gap: 1rem;
}

.level-row {
  margin-top: 0.3rem;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.main-level {
  font-size: 2.2rem;
  line-height: 1;
  letter-spacing: -0.055em;
}

.status {
  padding: 0.42rem 0.62rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 0.63rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.status-normal {
  color: var(--green);
  background: rgba(114, 216, 166, 0.1);
}

.status-attention {
  color: var(--yellow);
  background: rgba(255, 210, 106, 0.1);
}

.status-alert {
  color: var(--orange);
  background: rgba(255, 159, 90, 0.11);
}

.status-severe,
.status-record {
  color: var(--red);
  background: rgba(255, 104, 120, 0.12);
}

.status-record {
  box-shadow: 0 0 22px rgba(255, 104, 120, 0.16);
}

.status-copy {
  min-height: 2.6em;
  margin: 0.75rem 0 0;
  color: #c5cfdd;
  font-size: 0.79rem;
  line-height: 1.45;
}

.icon-button {
  display: none;
  width: 2.35rem;
  height: 2.35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  cursor: pointer;
}

.control-panel section,
.legend,
.notice {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.section-title {
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.7rem;
}

.section-title h2 {
  margin: 0;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
}

.section-title > span {
  color: var(--dim);
  font-size: 0.65rem;
}

.slider-shell {
  position: relative;
  padding-top: 1.6rem;
}

.slider-shell input,
.opacity-controls input {
  width: 100%;
  height: 1.15rem;
  margin: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
}

.slider-shell input::-webkit-slider-runnable-track,
.opacity-controls input::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, var(--blue-deep) var(--progress, 0%), rgba(255, 255, 255, 0.13) var(--progress, 0%));
}

.slider-shell input::-moz-range-track,
.opacity-controls input::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
}

.slider-shell input::-moz-range-progress,
.opacity-controls input::-moz-range-progress {
  height: 5px;
  border-radius: 999px;
  background: var(--blue-deep);
}

.slider-shell input::-webkit-slider-thumb,
.opacity-controls input::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  margin-top: -8.5px;
  border: 3px solid white;
  border-radius: 50%;
  background: var(--blue-deep);
  box-shadow: 0 4px 14px rgba(9, 87, 183, 0.5);
  appearance: none;
}

.slider-shell input::-moz-range-thumb,
.opacity-controls input::-moz-range-thumb {
  width: 17px;
  height: 17px;
  border: 3px solid white;
  border-radius: 50%;
  background: var(--blue-deep);
  box-shadow: 0 4px 14px rgba(9, 87, 183, 0.5);
}

.record-marker {
  position: absolute;
  z-index: 2;
  top: 0;
  left: var(--record-position);
  width: 0;
  height: 2.15rem;
  pointer-events: none;
}

.record-marker i {
  position: absolute;
  top: 1.35rem;
  left: -1px;
  width: 2px;
  height: 0.82rem;
  border-radius: 1px;
  background: var(--red);
  box-shadow: 0 0 9px rgba(255, 104, 120, 0.65);
}

.record-marker span {
  position: absolute;
  right: -1px;
  white-space: nowrap;
  color: #ff9aa6;
  font-size: 0.59rem;
  font-weight: 700;
}

.range-labels {
  justify-content: space-between;
  margin-top: 0.12rem;
  color: var(--dim);
  font-size: 0.63rem;
}

.action-row {
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.button {
  min-height: 2.5rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  color: var(--ink);
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  flex: 1;
  border-color: rgba(83, 185, 255, 0.34);
  background: linear-gradient(135deg, rgba(34, 133, 238, 0.9), rgba(23, 97, 201, 0.92));
}

.button-secondary {
  background: rgba(255, 255, 255, 0.055);
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.metrics article {
  min-height: 4.45rem;
  padding: 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 0.9rem;
  background: rgba(255, 255, 255, 0.035);
}

.metrics span,
.metrics small {
  display: block;
  color: var(--dim);
  font-size: 0.61rem;
}

.metrics strong {
  display: block;
  margin-top: 0.28rem;
  font-size: 0.98rem;
  letter-spacing: -0.025em;
}

.metrics small {
  margin-top: 0.12rem;
}

.layer-list {
  display: grid;
  gap: 0.42rem;
}

.layer-row {
  min-height: 3.25rem;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 0.85rem;
  background: rgba(255, 255, 255, 0.032);
}

label.layer-row {
  cursor: pointer;
}

.layer-row > div {
  flex: 1;
}

.layer-row strong,
.layer-row small {
  display: block;
}

.layer-row strong {
  font-size: 0.72rem;
}

.layer-row small,
.fixed-label {
  margin-top: 0.12rem;
  color: var(--dim);
  font-size: 0.6rem;
}

.layer-symbol {
  width: 1.65rem;
  height: 1.65rem;
  flex: 0 0 auto;
  border-radius: 0.52rem;
}

.map-symbol {
  background:
    linear-gradient(28deg, transparent 45%, rgba(255, 255, 255, 0.62) 46%, rgba(255, 255, 255, 0.62) 51%, transparent 52%),
    #2d735f;
}

.contour-symbol {
  background: repeating-radial-gradient(ellipse at 20% 90%, transparent 0 4px, #6d8098 5px 6px);
}

.water-symbol {
  background: linear-gradient(150deg, #56c5ff, #1256c2);
}

.layer-row input[type="checkbox"] {
  position: relative;
  width: 2.45rem;
  height: 1.35rem;
  flex: 0 0 auto;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  cursor: pointer;
  appearance: none;
  transition: background 160ms ease;
}

.layer-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 0.17rem;
  left: 0.17rem;
  width: 1.01rem;
  height: 1.01rem;
  border-radius: 50%;
  background: white;
  transition: transform 160ms ease;
}

.layer-row input[type="checkbox"]:checked {
  background: var(--blue-deep);
}

.layer-row input[type="checkbox"]:checked::after {
  transform: translateX(1.1rem);
}

.opacity-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
  margin-top: 0.65rem;
}

.opacity-controls label {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 0.4rem;
  color: var(--muted);
  font-size: 0.62rem;
}

.opacity-controls output {
  color: #dce8f7;
}

.opacity-controls input {
  grid-column: 1 / -1;
  margin-top: 0.22rem;
}

.opacity-controls input::-webkit-slider-runnable-track {
  height: 4px;
}

.opacity-controls input::-webkit-slider-thumb {
  width: 17px;
  height: 17px;
  margin-top: -6.5px;
  border-width: 2px;
}

.legend {
  color: #c6d0df;
}

.legend summary {
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 0.8rem;
  margin-top: 0.75rem;
}

.legend-grid span {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.63rem;
}

.legend-grid i {
  display: inline-block;
  width: 1.15rem;
  height: 0.42rem;
  border-radius: 999px;
}

.legend-map {
  background: #5a8068;
}

.legend-contour {
  border-top: 1px dashed #cad3df;
}

.legend-water {
  background: rgba(34, 145, 255, 0.65);
}

.legend-front {
  height: 2px !important;
  background: #b7e9ff;
  box-shadow: 0 0 7px #59bdff;
}

.legend-record {
  background: var(--red);
}

.notice {
  color: #9ba8ba;
  font-size: 0.63rem;
  line-height: 1.4;
}

.notice strong {
  color: #dbe4f0;
}

.notice p {
  margin: 0.25rem 0 0;
}

.map-context,
.map-error {
  position: fixed;
  z-index: 700;
  left: 1rem;
  bottom: 1rem;
  padding: 0.6rem 0.75rem;
  border-radius: 999px;
  color: #d8e3f1;
  font-size: 0.65rem;
}

.pulse {
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.35rem;
  border-radius: 50%;
  background: #70d0ff;
  box-shadow: 0 0 10px #36aef5;
}

.map-error {
  right: 1rem;
  bottom: auto;
  top: 5.7rem;
  max-width: 20rem;
  border-color: rgba(255, 104, 120, 0.34);
  border-radius: 0.8rem;
  color: #ffe6e9;
}

.panel-open {
  display: none;
}

.contour-line {
  stroke-linecap: round;
  stroke-linejoin: round;
}

.contour-label span {
  display: inline-block;
  padding: 3px 7px;
  border: 1px solid var(--cota-color);
  border-radius: 5px;
  background: rgba(7, 17, 31, .92);
  color: var(--cota-color);
  font: 600 11px/1.3 system-ui, sans-serif;
  white-space: nowrap;
}

@media (max-width: 760px) {
  .brand {
    top: max(0.65rem, env(safe-area-inset-top));
    left: 0.65rem;
    padding: 0.58rem 0.75rem 0.58rem 0.58rem;
  }

  .brand-mark {
    width: 2.15rem;
    height: 2.15rem;
    font-size: 1.35rem;
  }

  h1 {
    font-size: 1.18rem;
  }

  .eyebrow {
    font-size: 0.56rem;
  }

  .control-panel {
    top: auto;
    right: 0.5rem;
    bottom: calc(0.5rem + var(--safe-bottom));
    left: 0.5rem;
    width: auto;
    max-height: min(56dvh, 560px);
    padding: 1rem;
    border-radius: 1.35rem;
    transform: translateY(calc(100% + 1rem + var(--safe-bottom)));
    opacity: 0;
    pointer-events: none;
  }

  .control-panel.is-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  .icon-button {
    display: grid;
    place-items: center;
  }

  .panel-open {
    position: fixed;
    z-index: 705;
    right: 0.65rem;
    bottom: calc(0.65rem + var(--safe-bottom));
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-height: 3.15rem;
    padding: 0.62rem 0.75rem 0.62rem 0.95rem;
    border-radius: 999px;
    color: var(--ink);
    cursor: pointer;
  }

  .panel-open strong {
    padding: 0.42rem 0.62rem;
    border-radius: 999px;
    background: rgba(50, 149, 245, 0.2);
    color: #bde4ff;
  }

  .panel-open.is-hidden {
    display: none;
  }

  .map-context {
    display: none;
  }

  .leaflet-control-zoom {
    margin-top: 5.3rem !important;
  }

  .leaflet-control-attribution {
    max-width: 64vw;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

@media (max-width: 390px) {
  .metrics {
    grid-template-columns: 1fr 1fr;
  }

  .opacity-controls {
    grid-template-columns: 1fr;
  }

  .legend-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* Keep the everyday view to one height, one line and one direct action. */
.slider-shell { padding-top: .35rem; }
.status-copy { font-size: .88rem; }
.advanced-options { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.advanced-options > summary { color: var(--muted); cursor: pointer; font-size: .8rem; }
.map-readout {
  position: fixed; z-index: 700; left: 1rem; bottom: 5.4rem;
  display: flex; flex-direction: column; gap: .2rem; padding: .8rem 1rem;
  border-radius: 1rem; pointer-events: none;
}
.map-readout > span { font-size: .8rem; color: #d0e4f5; }
.map-readout strong { font-size: 1.8rem; line-height: 1.15; color: #8ee8ff; }
.map-readout .map-reference { color: #ffd26a; font-size: .75rem; }
.quick-flood {
  position: fixed; z-index: 705; left: 1rem; bottom: 1rem;
  display: flex; flex-direction: column; align-items: flex-start; gap: .2rem;
  min-height: 3.4rem; padding: .6rem 1rem; border-radius: 1rem; color: var(--ink); cursor: pointer;
}
.quick-flood span { font-size: .88rem; font-weight: 700; }
.quick-flood strong { color: #ffd26a; font-size: .8rem; }
.quick-flood[aria-pressed="true"] { border-color: #ffd26a; }
.map-context { display: none; }
@media (max-width: 760px) {
  .map-readout { left: .65rem; bottom: calc(5.2rem + var(--safe-bottom)); padding: .65rem .8rem; }
  .quick-flood { left: .65rem; bottom: calc(.65rem + var(--safe-bottom)); padding: .6rem .8rem; }
  .panel-open { gap: .35rem; padding: .65rem; }
  .panel-open strong { display: none; }
  .app-shell:has(.control-panel.is-open) .quick-flood,
  .app-shell:has(.control-panel.is-open) .map-readout { display: none; }
}

:root { --active-line-color: #63dcff; }
.main-level, .map-readout strong, .map-readout .map-reference { color: var(--active-line-color); }
.map-readout .map-reference { font-size: .82rem; font-weight: 800; }
.status-traced { color: #63dcff; background: #63dcff18; }
.status-estimated { color: #ffb04c; background: #ffb04c18; }
.step-controls { display: flex; gap: .65rem; margin-top: .65rem; }
.step-controls button { flex: 1; min-height: 42px; }
button:disabled { opacity: .4; cursor: default; }
.line-key { display: flex; flex-wrap: wrap; gap: .6rem 1rem; margin: .8rem 0; font-size: .8rem; }
.line-key span { display: inline-flex; align-items: center; gap: .4rem; }
.line-key i { width: 22px; border-top: 3px solid #63dcff; }
.line-key .key-estimated { border-top: 3px dashed #ffb04c; }
.history-control { display: grid; gap: .4rem; margin-top: 1rem; }
.history-control label { font-size: .88rem; font-weight: 700; }
.history-control select { width: 100%; min-height: 44px; padding: .6rem; border: 1px solid var(--line-strong); border-radius: .6rem; background: #0e2036; color: var(--ink); font: inherit; }
.history-control a { color: var(--muted); font-size: .75rem; }
select:focus-visible { outline: 3px solid #53b9ff88; outline-offset: 3px; }
.contour-label span { white-space: nowrap; }

/* Entry notice is visible before application scripts or map tiles load. */
.entry-notice {
  position: fixed; inset: 0; z-index: 2000; margin: auto;
  width: min(640px, calc(100vw - 24px)); max-width: none;
  max-height: calc(100dvh - 32px); padding: 0; overflow: hidden;
  border: 1px solid #ffb04c66; border-radius: 20px;
  background: #0c192a; color: #f5f8fc;
  box-shadow: 0 24px 100px #000a;
}
.entry-notice[open] { display: flex; flex-direction: column; }
.entry-notice::backdrop { background: #030b16e8; backdrop-filter: blur(6px); }
.entry-notice-body { padding: 26px 28px 12px; overflow-y: auto; min-height: 0; }
.notice-eyebrow { margin: 0 0 8px; color: #ffb04c; font-size: .85rem; font-weight: 800; letter-spacing: .08em; }
.entry-notice h2 { margin: 0 0 20px; color: #ffcf90; font-size: clamp(1.25rem, 4.5vw, 1.65rem); line-height: 1.25; }
.entry-notice h2:focus { outline: none; }
#noticeText { font-size: 1rem; line-height: 1.55; color: #e5ecf5; }
#noticeText p { margin: 0 0 16px; }
.entry-notice-footer { flex-shrink: 0; padding: 16px 28px 22px; border-top: 1px solid #ffffff18; }
.entry-notice-footer button { width: 100%; min-height: 50px; font-size: 1rem; }
@media (max-width: 430px) {
  .entry-notice-body { padding: 20px 20px 4px; }
  .entry-notice-footer { padding: 14px 20px 18px; }
}
