:root {
  color-scheme: light;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --header-h: calc(60px + var(--safe-top));
  --page-bg: #eef1f3;
  --text: #202124;
  --muted: #5f6368;
  --accent: #1a73e8;
  --accent-hover: #1765cc;
  --accent-soft: rgba(26, 115, 232, 0.1);
  --danger: #d93025;
  --panel-bg: #ffffff;
  --panel-bg-translucent: rgba(255, 255, 255, 0.98);
  --panel-line: rgba(0, 0, 0, 0.09);
  --panel-shadow: 0 1px 2px rgba(60, 64, 67, 0.15), 0 2px 6px 2px rgba(60, 64, 67, 0.1);
  --radius: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font-family: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  background: var(--page-bg);
  color: var(--text);
}

body {
  min-height: 100vh;
  min-height: var(--app-height, 100vh);
}

.viewer-wrap {
  position: relative;
  min-height: 100vh;
  min-height: var(--app-height, 100vh);
}

#cesiumContainer {
  position: absolute;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  touch-action: none;
}

/* --- APP HEADER --- */
.app-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  padding-top: var(--safe-top);
  z-index: 300;
  background: var(--panel-bg-translucent);
  border-bottom: 1px solid var(--panel-line);
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.12);
}

.app-header-inner {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(20px, var(--safe-right)) 0 max(20px, var(--safe-left));
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-logo {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: flex;
}

.app-logo svg {
  width: 100%;
  height: 100%;
}

.app-title {
  font-size: 1.02rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
}

.app-badge {
  font-size: 0.66rem;
  font-weight: 500;
  color: var(--muted);
  background: #f1f3f4;
  border: 1px solid var(--panel-line);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.coord-pill {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: #f1f3f4;
  border: 1px solid var(--panel-line);
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

/* --- SEARCH BAR PANEL (left-aligned, clears the Controls panel) --- */
.search-panel {
  position: absolute;
  top: calc(var(--header-h) + 16px);
  left: 250px;
  z-index: 120;
  width: min(420px, calc(100vw - 250px - 24px));
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  padding: 4px 6px 4px 12px;
  box-shadow: var(--panel-shadow);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  min-width: 0;
}

.search-input-wrap input::placeholder {
  color: var(--muted);
  opacity: 0.9;
}

.search-input-wrap button {
  background: var(--accent-soft);
  border: 1px solid rgba(26, 115, 232, 0.28);
  color: var(--accent);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.search-input-wrap button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.search-results {
  display: none;
  margin-top: 6px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  box-shadow: var(--panel-shadow);
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
}

.search-results.is-active {
  display: block;
}

.search-result-item {
  padding: 8px 10px;
  font-size: 0.75rem;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-item:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.search-results-loading,
.search-results-empty {
  padding: 10px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

/* --- FIX SHIP INFOBOX POSITIONING & STACKING ---
   The container spans a fixed box even with no ship selected, so it must stay
   pointer-events:none by default or it silently blocks clicks on whatever sits
   underneath it (e.g. the mobile reopen pills). Only the visible box re-enables
   interaction. */
.cesium-viewer-infoBoxContainer {
  position: absolute !important;
  top: 280px !important;
  left: 24px !important;
  right: auto !important;
  width: 310px !important;
  height: max-content !important;
  z-index: 999 !important;
  pointer-events: none !important;
}

.cesium-infoBox {
  display: block !important;
  position: relative !important;
  width: 100% !important;
  max-height: 380px !important;
  background: var(--panel-bg) !important;
  border: 1px solid var(--panel-line) !important;
  border-radius: 12px !important;
  box-shadow: var(--panel-shadow) !important;
  overflow: hidden !important;
  visibility: visible !important;
  pointer-events: none !important;
}

.cesium-infoBox.cesium-infoBox-visible {
  pointer-events: auto !important;
}

.cesium-infoBox-iframe {
  width: 100% !important;
  height: 240px !important;
  border: none !important;
  background: transparent !important;
  display: block !important;
}

.cesium-infoBox-title {
  background: var(--accent-soft) !important;
  color: var(--accent-hover) !important;
  font-family: "Roboto", sans-serif !important;
  font-weight: 700 !important;
  font-size: 0.88rem !important;
  padding: 8px 12px !important;
}

.cesium-infoBox-close {
  top: 6px !important;
  right: 8px !important;
  color: var(--text) !important;
}

/* Depth Readout Card Overlay (left-aligned with Controls panel) */
.depth-readout {
  position: absolute;
  bottom: 24px;
  left: 24px;
  z-index: 90;
  display: none;
  min-width: 170px;
  width: 210px;
  padding: 10px 14px;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  pointer-events: none;
}

.loading-overlay {
  position: absolute;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(238, 241, 243, 0.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 240ms ease, visibility 240ms ease;
}

.loading-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-card {
  width: min(340px, calc(100vw - 40px));
  padding: 18px 18px 16px;
  border-radius: 18px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  box-shadow: var(--panel-shadow);
}

.loading-title {
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.loading-bar {
  margin-top: 12px;
  height: 8px;
  border-radius: 999px;
  background: #eceff1;
  overflow: hidden;
}

.loading-bar-fill {
  width: 12%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1a73e8, #12b5cb);
  transition: width 180ms ease;
}

.loading-label {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text);
}

.control-panel {
  border-radius: var(--radius);
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  box-shadow: var(--panel-shadow);
}

/* --- LAYER TOOLBAR (icon row, directly below the search bar) --- */
.toolbar-row-wrap {
  position: absolute;
  top: calc(var(--header-h) + 66px);
  left: 250px;
  z-index: 110;
  max-width: calc(100vw - 250px - 24px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  box-shadow: var(--panel-shadow);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.toolbar-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f3f4;
  border: 1px solid var(--panel-line);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toolbar-btn:hover {
  background: var(--accent-soft);
  border-color: rgba(26, 115, 232, 0.3);
  color: var(--accent-hover);
}

.toolbar-btn.layer-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.toolbar-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.toolbar-divider {
  flex: 0 0 auto;
  width: 1px;
  height: 22px;
  background: var(--panel-line);
  margin: 0 2px;
}

/* Active-layer opacity chips — built/removed in JS as layers toggle on/off.
   Flows naturally below the toolbar row rather than using a fixed pixel
   offset, so it stays correctly positioned regardless of toolbar height
   (which varies between desktop and the taller mobile touch targets). */
.active-layers-strip {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
}

.active-layers-strip.has-items {
  display: flex;
}

.active-layer-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  padding: 4px 10px;
  box-shadow: var(--panel-shadow);
}

.active-layer-chip-label {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.active-layer-chip .alpha-slider {
  width: 70px;
}

/* Floating precise-zoom widget (right side, freed up by the sidebar removal) */
.zoom-float-widget {
  position: absolute;
  top: 50%;
  right: 20px;
  transform: translateY(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  padding: 10px 8px;
}

.alpha-slider {
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

.alpha-slider::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: var(--panel-line);
}

.alpha-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -4.5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel-bg);
  box-shadow: 0 0 0 1px rgba(26, 115, 232, 0.3);
  cursor: pointer;
}

.alpha-slider::-moz-range-track {
  height: 3px;
  border-radius: 999px;
  background: var(--panel-line);
}

.alpha-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel-bg);
  box-shadow: 0 0 0 1px rgba(26, 115, 232, 0.3);
  cursor: pointer;
}

/* --- VERTICAL ZOOM SLIDER (minimalist, ghost-style controls) --- */
.zoom-btn {
  width: 22px;
  height: 22px;
  background: transparent;
  border: none;
  color: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.zoom-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.slider-wrapper {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2px 0;
}

.zoom-slider {
  writing-mode: vertical-lr;
  direction: rtl;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  width: 16px;
  height: 88px;
  cursor: pointer;
}

.zoom-slider::-webkit-slider-runnable-track {
  width: 3px;
  height: 100%;
  border-radius: 999px;
  background: var(--panel-line);
}

.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  margin-left: -4px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel-bg);
  box-shadow: 0 0 0 1px rgba(26, 115, 232, 0.3);
  cursor: pointer;
}

.zoom-slider::-moz-range-track {
  width: 3px;
  height: 100%;
  border-radius: 999px;
  background: var(--panel-line);
}

.zoom-slider::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel-bg);
  box-shadow: 0 0 0 1px rgba(26, 115, 232, 0.3);
  cursor: pointer;
}

/* --- CONTROL PANEL --- */
.control-panel {
  position: absolute;
  left: 24px;
  bottom: 24px;
  z-index: 200;
  min-width: 170px;
  width: 210px;
  height: auto;
  padding: 12px 14px;
}

.control-panel-top {
  display: block;
  top: calc(var(--header-h) + 16px);
  left: 24px;
  right: auto;
  bottom: unset;
  height: fit-content;
  padding: 10px 14px 14px;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.control-panel-top.is-collapsed {
  display: none;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--panel-line);
}

.panel-header-title {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
}

.panel-close-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.panel-close-btn:hover {
  background: #f1f3f4;
  color: var(--text);
}

.controls-reopen-btn {
  display: none;
  align-items: center;
  gap: 8px;
  position: absolute;
  top: calc(var(--header-h) + 16px);
  left: 24px;
  z-index: 210;
  padding: 9px 16px 9px 14px;
  border-radius: 999px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  box-shadow: var(--panel-shadow);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
}

.controls-reopen-btn.is-visible {
  display: flex;
}

.controls-reopen-btn:hover {
  color: var(--accent-hover);
}

.slider-label {
  display: block;
  margin-bottom: 0;
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.slider-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 12px;
}

.slider-inline-value {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
}

.control-panel input[type="range"] {
  width: 100%;
  height: 16px;
  accent-color: var(--accent);
}

.status {
  display: none;
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.72rem;
}

.status.error {
  color: var(--danger);
}

@media (max-width: 900px) {
  .cesium-viewer-infoBoxContainer {
    top: auto !important;
    bottom: 24px !important;
    left: 16px !important;
    width: calc(100vw - 32px) !important;
  }

  .depth-readout {
    left: 16px;
    bottom: 16px;
  }

  .control-panel-top {
    top: calc(var(--header-h) + 76px);
    left: 16px;
    width: min(220px, calc(100vw - 32px));
  }

  .controls-reopen-btn {
    top: calc(var(--header-h) + 76px);
    left: 16px;
  }

  .app-header-inner {
    padding: 0 max(12px, var(--safe-right)) 0 max(12px, var(--safe-left));
  }

  .app-badge {
    display: none;
  }
}

/* --- MOBILE BACKDROP (dims map behind an open drawer on small screens) --- */
.mobile-backdrop {
  position: absolute;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
  transition: background 0.2s ease;
}

.toolbar-btn:active,
.zoom-btn:active,
.search-input-wrap button:active,
.controls-reopen-btn:active,
.panel-close-btn:active {
  transform: scale(0.96);
}

@media (max-width: 640px) {
  .mobile-backdrop.is-active {
    background: rgba(15, 23, 32, 0.45);
    pointer-events: auto;
  }

  .app-header-inner {
    padding: 0 max(14px, var(--safe-right)) 0 max(14px, var(--safe-left));
  }

  .app-title {
    font-size: 0.94rem;
  }

  .app-logo {
    width: 24px;
    height: 24px;
  }

  .coord-pill {
    font-size: 0.66rem;
    padding: 5px 9px;
  }

  .search-panel {
    left: 16px;
    width: calc(100vw - 32px);
  }

  .toolbar-row-wrap {
    left: 16px;
    max-width: calc(100vw - 32px);
  }

  .toolbar-btn {
    width: 40px;
    height: 40px;
  }

  .zoom-float-widget {
    right: 12px;
  }

  .zoom-float-widget .zoom-btn {
    width: 40px;
    height: 40px;
  }

  .depth-readout {
    left: 16px;
    bottom: calc(76px + var(--safe-bottom));
    width: auto;
    max-width: calc(100vw - 32px);
  }

  /* Controls becomes a full-width bottom sheet that slides up over the map */
  .control-panel-top {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 62vh;
    border-radius: 20px 20px 0 0;
    padding-bottom: calc(16px + var(--safe-bottom));
    box-shadow: 0 -4px 24px rgba(60, 64, 67, 0.22);
    transform: translateY(0);
    transition: transform 0.25s ease;
  }

  .control-panel-top.is-collapsed {
    display: block;
    transform: translateY(100%);
    pointer-events: none;
  }

  /* Reopen pill moves to a safe thumb-reach corner at the bottom */
  .controls-reopen-btn {
    top: auto;
    bottom: calc(16px + var(--safe-bottom));
    left: 16px;
  }

  .cesium-viewer-infoBoxContainer {
    top: auto !important;
    bottom: calc(16px + var(--safe-bottom)) !important;
    left: 16px !important;
    width: calc(100vw - 32px) !important;
  }

  .panel-close-btn {
    width: 32px;
    height: 32px;
  }

  .search-input-wrap {
    padding: 6px 8px 6px 14px;
  }

  .search-input-wrap button {
    width: 34px;
    height: 34px;
  }
}

/* Flood Status Badges */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 4px;
  text-transform: uppercase;
  color: #ffffff;
}
.status-normal { background-color: #1a73e8; }
.status-action { background-color: #188038; }
.status-minor { background-color: #f9ab00; color: #202124; }
.status-moderate { background-color: #e8710a; }
.status-major { background-color: #d93025; }
