:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-1-soft: rgba(42, 120, 214, 0.14);
  --status-good: #0ca30c;
  --status-good-soft: rgba(12, 163, 12, 0.12);
  --status-warning: #a66a00;
  --status-warning-soft: rgba(250, 178, 25, 0.22);
  --status-critical: #d03b3b;
  --status-critical-soft: rgba(208, 59, 59, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-1-soft: rgba(57, 135, 229, 0.18);
    --status-good: #0ca30c;
    --status-good-soft: rgba(12, 163, 12, 0.16);
    --status-warning: #fab219;
    --status-warning-soft: rgba(250, 178, 25, 0.16);
    --status-critical: #e66767;
    --status-critical-soft: rgba(230, 103, 103, 0.16);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --series-1-soft: rgba(57, 135, 229, 0.18);
  --status-good: #0ca30c;
  --status-good-soft: rgba(12, 163, 12, 0.16);
  --status-warning: #fab219;
  --status-warning-soft: rgba(250, 178, 25, 0.16);
  --status-critical: #e66767;
  --status-critical-soft: rgba(230, 103, 103, 0.16);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.app-header .title-block h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 700;
}
.app-header .title-block p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--status-good);
  background: var(--status-good-soft);
  border-radius: 999px;
  padding: 5px 10px 5px 8px;
  white-space: nowrap;
}
.live-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-good);
  animation: pulse 2s infinite;
}
.live-badge.is-stale {
  color: var(--status-warning);
  background: var(--status-warning-soft);
}
.live-badge.is-stale .dot { background: var(--status-warning); animation: none; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
}

@media (min-width: 900px) {
  .app-body { flex-direction: row; }
}

.map-pane {
  position: relative;
  height: 58vh;
  min-height: 320px;
  background: var(--surface-1);
}
@media (min-width: 900px) {
  .map-pane { height: auto; flex: 1 1 auto; }
}

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

.recenter-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 500;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
.recenter-btn:hover { background: var(--series-1-soft); }

.sidebar {
  background: var(--page-plane);
  padding: 14px;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 900px) {
  .sidebar {
    width: 320px;
    flex: 0 0 320px;
    grid-template-columns: 1fr;
    overflow-y: auto;
    border-left: 1px solid var(--border);
  }
}
@media (min-width: 560px) and (max-width: 899px) {
  .sidebar { grid-template-columns: repeat(3, 1fr); }
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  grid-column: span 1;
}
.stat-tile.span-2 { grid-column: span 2; }
@media (min-width: 900px) {
  .stat-tile.span-2 { grid-column: span 1; }
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  margin: 0 0 4px;
}
.stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.stat-value .unit {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 3px;
}
.stat-sub {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.meter-track {
  margin-top: 8px;
  height: 6px;
  border-radius: 999px;
  background: var(--gridline);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  background: var(--series-1);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 9px;
}
.status-pill.good { color: var(--status-good); background: var(--status-good-soft); }
.status-pill.warning { color: var(--status-warning); background: var(--status-warning-soft); }
.status-pill.critical { color: var(--status-critical); background: var(--status-critical-soft); }
.status-pill.neutral { color: var(--text-secondary); background: var(--gridline); }

.boat-marker {
  width: 26px;
  height: 26px;
  transform-origin: 50% 50%;
}

.leaflet-popup-content { font-size: 0.85rem; }

.sponsors {
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  padding: 14px 16px 20px;
  text-align: center;
}
.sponsors p {
  margin: 0 0 10px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.sponsors .logos {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 22px;
}
.sponsors img {
  height: 34px;
  max-width: 120px;
  object-fit: contain;
  opacity: 0.85;
  filter: grayscale(15%);
}
.sponsors img:hover { opacity: 1; filter: none; }

.data-banner {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--status-warning-soft);
  color: var(--status-warning);
  font-size: 0.8rem;
  display: none;
}
.data-banner.visible { display: block; }
