:root {
  color-scheme: dark;
  --text: #ebf7ff;
  --muted: rgba(222, 239, 248, 0.72);
  --accent: #8fdcff;
  --danger: #ffb1a6;
  --glass-bg: rgba(10, 20, 30, 0.28);
  --glass-line: rgba(210, 235, 255, 0.16);
  --glass-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Space Grotesk", "Noto Sans JP", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(0, 144, 255, 0.22), transparent 28%),
    radial-gradient(circle at top right, rgba(0, 214, 201, 0.18), transparent 24%),
    linear-gradient(180deg, #02131f 0%, #041b2a 50%, #021018 100%);
  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;
  inset: 0;
}

/* --- COMMAND CENTER UI PANEL (TOP-LEFT FLOATING CARD) --- */
#ui-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 120;
  background: rgba(8, 14, 26, 0.92);
  border: 1px solid rgba(0, 180, 255, 0.25);
  border-radius: 12px;
  padding: 16px;
  width: 340px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.status-badge {
  display: inline-block;
  font-size: 9px;
  font-family: monospace;
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(255, 170, 0, 0.15);
  color: #ffaa00;
  border: 1px solid #ffaa00;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.title { font-size: 15px; font-weight: 700; color: #fff; margin-bottom: 2px; }
.subtitle { font-size: 10px; color: #64748b; margin-bottom: 14px; }

.section-label {
  font-size: 9px;
  font-family: monospace;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 12px 0 6px 0;
}

.btn-group { display: flex; gap: 6px; }

.btn {
  flex: 1;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  padding: 8px 10px;
  font-size: 11px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  text-align: left;
}

.btn:hover {
  background: rgba(0, 180, 255, 0.15);
  color: #00e5ff;
  border-color: rgba(0, 180, 255, 0.4);
}

.btn.active {
  background: #0284c7;
  color: #fff;
  border-color: #38bdf8;
  font-weight: 600;
  box-shadow: 0 0 12px rgba(2, 132, 199, 0.5);
}

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.btn-stack { display: flex; flex-direction: column; gap: 5px; }
.count-tag { font-family: monospace; font-size: 10px; opacity: 0.8; }

#vessel-card {
  margin: 10px 0;
  background: rgba(2, 132, 199, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 6px;
  padding: 10px;
  font-size: 11px;
  display: none;
}

#vessel-card .v-header {
  font-weight: bold;
  color: #00e5ff;
  margin-bottom: 6px;
  font-family: monospace;
  word-break: break-all;
}

#vessel-card .v-row {
  display: flex;
  justify-content: space-between;
  color: #94a3b8;
  margin-bottom: 4px;
  font-size: 10px;
}

#vessel-card .v-val { color: #fff; font-family: monospace; }

.btn-deselect {
  width: 100%;
  margin-top: 8px;
  background: rgba(239, 68, 68, 0.2);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #f87171;
  padding: 6px;
  font-size: 10px;
  font-family: monospace;
  border-radius: 4px;
  cursor: pointer;
  text-align: center;
}

.btn-deselect:hover { background: rgba(239, 68, 68, 0.4); color: #fff; }

/* --- SEARCH BAR PANEL (OFFSET TO CLEAR UI-PANEL) --- */
.search-panel {
  position: absolute;
  top: 16px;
  left: 372px;
  z-index: 100;
  width: min(320px, calc(100vw - 480px));
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: rgba(10, 20, 30, 0.85);
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  padding: 4px 6px 4px 12px;
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--glass-shadow);
  transition: border-color 0.2s ease;
}

.search-input-wrap:focus-within {
  border-color: #00f0ff;
}

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

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

.search-input-wrap button {
  background: rgba(0, 240, 255, 0.1);
  border: 1px solid rgba(0, 240, 255, 0.3);
  color: #00f0ff;
  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: rgba(0, 240, 255, 0.25);
  color: #ffffff;
}

.search-results {
  display: none;
  margin-top: 6px;
  background: rgba(10, 20, 30, 0.92);
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--glass-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: rgba(0, 240, 255, 0.15);
  color: #00f0ff;
}

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

/* --- CESIUM INFOBOX OVERRIDE --- */
.cesium-viewer-infoBoxContainer {
  position: absolute !important;
  top: 195px !important;
  left: 372px !important;
  right: auto !important;
  width: 310px !important;
  height: max-content !important;
  z-index: 999 !important;
  pointer-events: auto !important;
}

.cesium-infoBox {
  display: block !important;
  position: relative !important;
  width: 100% !important;
  max-height: 380px !important;
  background: rgba(10, 20, 30, 0.95) !important;
  border: 1px solid rgba(0, 240, 255, 0.3) !important;
  border-radius: 12px !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5) !important;
  overflow: hidden !important;
  visibility: visible !important;
}

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

.cesium-infoBox-title {
  background: rgba(0, 240, 255, 0.15) !important;
  color: #00f0ff !important;
  font-family: "Space Grotesk", 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: #ebf7ff !important;
}

/* Depth Readout Card Overlay */
.depth-readout {
  position: absolute;
  bottom: 24px;
  left: 140px;
  z-index: 99;
  display: none;
  padding: 8px 12px;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--glass-bg);
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--glass-shadow);
  pointer-events: none;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 14, 22, 0.24);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  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: rgba(10, 20, 30, 0.72);
  border: 1px solid rgba(210, 235, 255, 0.16);
  box-shadow: var(--glass-shadow);
}

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

.loading-bar {
  margin-top: 12px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

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

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

.navigator-panel,
.legend-panel,
.control-panel {
  border-radius: 18px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--glass-shadow);
}

.legend-panel {
  position: absolute;
  left: 24px;
  bottom: 24px;
  z-index: 10;
  width: 96px;
  padding: 12px 10px 10px;
}

.legend-title {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.legend-ramp-wrap {
  position: relative;
  margin-top: 8px;
  width: 18px;
  height: 180px;
}

.legend-ramp {
  width: 18px;
  height: 180px;
  border-radius: 0;
  background-color: rgba(255, 255, 255, 0.08);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.legend-sea-level {
  position: absolute;
  left: -4px;
  right: -4px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.42);
  transform: translateY(-50%);
  pointer-events: none;
}

.legend-scale {
  position: absolute;
  top: 32px;
  left: 40px;
  right: 8px;
  height: 180px;
  font-size: 0.62rem;
  color: var(--text);
}

.legend-marker {
  position: absolute;
  left: 0;
  transform: translateY(-50%);
  white-space: nowrap;
}

.legend-marker-sea-level {
  color: #ffffff;
  font-weight: 700;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.28);
}

/* --- NAVIGATOR PANEL (RIGHT SIDE MODIFIED FOR WATER QUALITY) --- */
.navigator-panel {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 99;
  width: 108px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: rgba(10, 20, 30, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  user-select: none;
}

.nav-section-title {
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.nav-grid {
  display: flex;
  gap: 4px;
  width: 100%;
  justify-content: center;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.3);
}

.nav-divider {
  width: 80%;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 2px 0;
}

.layer-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.layer-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 600;
  border-radius: 6px;
  padding: 6px 4px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  word-break: break-word;
}

.layer-btn:hover {
  background: rgba(0, 240, 255, 0.15);
  border-color: #00f0ff;
  color: #ffffff;
}

.layer-btn.layer-active {
  border-color: #00f0ff !important;
  background: rgba(0, 240, 255, 0.3) !important;
  color: #ffffff !important;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

.ship-switch-btn {
  width: 100%;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #00f0ff;
  background: rgba(0, 240, 255, 0.08);
  border: 1px solid rgba(0, 240, 255, 0.3);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ship-switch-btn:hover {
  background: rgba(0, 240, 255, 0.25);
  border-color: #00f0ff;
  color: #ffffff;
}

/* --- VERTICAL ZOOM SLIDER --- */
.nav-zoom-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.zoom-btn {
  width: 100%;
  height: 24px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text);
  border-radius: 6px;
  font-weight: bold;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zoom-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

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

.zoom-slider {
  writing-mode: bt-lr;
  writing-mode: vertical-lr;
  direction: rtl;
  appearance: slider-vertical;
  width: 12px;
  height: 90px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* --- CONTROL PANEL (EXTENDED SLIDERS BOTTOM LEFT) --- */
.control-panel {
  position: absolute;
  left: 24px;
  bottom: 24px;
  z-index: 10;
  min-width: 170px;
  width: 210px;
  height: auto;
  padding: 12px 14px;
}

.control-panel-top {
  display: block;
  top: 16px;
  left: 372px;
  right: auto;
  bottom: unset;
  height: fit-content;
}

.slider-label {
  display: block;
  margin-bottom: 0;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  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;
}

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

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

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

/* --- RESPONSIVE MOBILE OVERRIDES --- */
@media (max-width: 900px) {
  #ui-panel {
    width: calc(100vw - 32px);
    max-height: 260px;
    top: 16px;
    left: 16px;
  }

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

  .navigator-panel {
    top: 16px;
    right: 16px;
    width: 88px;
  }

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

  .legend-panel {
    left: 16px;
    bottom: 16px;
  }

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

  .control-panel-top {
    top: 335px;
    left: 16px;
    width: min(220px, calc(100vw - 32px));
  }
}