:root {
  color-scheme: light;
  --navy: #082f49;
  --navy-deep: #041f31;
  --sea: #0e7490;
  --cyan: #22d3ee;
  --sky: #bae6fd;
  --paper: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --orange: #f97316;
  --warning: #facc15;
  --critical: #ef4444;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.map-page {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #dceff1;
  color: var(--ink);
  touch-action: none;
}

#map { position: absolute; inset: 0; background: #e7f4f4; }
.offline-tile { image-rendering: auto; }

.top-bar {
  position: absolute;
  z-index: 800;
  top: 0;
  left: 0;
  right: 0;
  height: calc(64px + var(--safe-top));
  padding: calc(8px + var(--safe-top)) 12px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(4, 31, 49, .92), rgba(4, 31, 49, .76) 70%, transparent);
}

.app-title { display: flex; align-items: center; gap: 9px; color: white; pointer-events: auto; text-shadow: 0 1px 2px #0008; }
.app-title-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; font-weight: 900; background: linear-gradient(145deg, #0891b2, #0e7490); box-shadow: 0 8px 24px #001b; border: 1px solid #ffffff40; }
.app-title strong { display: block; font-size: 18px; letter-spacing: -.02em; }
.app-title small { display: block; margin-top: 1px; color: #d8f3fa; font-size: 11px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }

.icon-button, .map-action {
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: white;
  background: rgba(4, 31, 49, .86);
  box-shadow: 0 6px 20px rgba(2, 21, 32, .25);
  cursor: pointer;
  pointer-events: auto;
  font-size: 22px;
  font-weight: 800;
}
.icon-button:active, .map-action:active { transform: scale(.94); }
.icon-button.dark { background: #e2e8f0; color: var(--ink); border-color: #cbd5e1; box-shadow: none; font-size: 28px; }

.status-pill {
  position: absolute;
  z-index: 790;
  top: calc(70px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 108px);
  min-height: 32px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  background: rgba(255,255,255,.94);
  color: #334155;
  box-shadow: 0 4px 18px rgba(15, 23, 42, .18);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #94a3b8; }
.status-loading .status-dot { background: #0ea5e9; animation: statusPulse 1.2s infinite; }
.status-ready .status-dot { background: #22c55e; }
.status-error .status-dot { background: var(--critical); }
@keyframes statusPulse { 50% { transform: scale(1.55); opacity: .55; } }

.alert-banner {
  position: absolute;
  z-index: 900;
  top: calc(108px + var(--safe-top));
  left: 10px;
  right: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  color: #1c1917;
  background: rgba(250, 204, 21, .97);
  border: 2px solid #a16207;
  box-shadow: 0 8px 32px rgba(15,23,42,.35);
  animation: alertIn .22s ease-out;
}
.alert-banner.critical { color: white; background: rgba(220, 38, 38, .97); border-color: #7f1d1d; animation: criticalPulse .85s infinite alternate; }
.alert-banner strong { display: block; font-size: 16px; line-height: 1.15; }
.alert-banner span { display: block; margin-top: 3px; font-size: 13px; font-weight: 650; }
@keyframes alertIn { from { transform: translateY(-12px); opacity: 0; } }
@keyframes criticalPulse { to { box-shadow: 0 8px 42px rgba(239,68,68,.75); transform: scale(1.012); } }

.locate-button { position: absolute; z-index: 770; right: 12px; bottom: calc(168px + var(--safe-bottom)); font-size: 26px; }

.instrument-panel {
  position: absolute;
  z-index: 800;
  left: 8px;
  right: 8px;
  bottom: calc(8px + var(--safe-bottom));
  min-height: 116px;
  padding: 10px 8px 21px;
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 4px;
  border-radius: 22px;
  color: white;
  background: linear-gradient(150deg, rgba(4,31,49,.96), rgba(8,47,73,.93));
  border: 1px solid rgba(255,255,255,.22);
  box-shadow: 0 12px 40px rgba(2,21,32,.38);
  backdrop-filter: blur(15px);
}
.instrument { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; border-left: 1px solid rgba(186,230,253,.18); }
.instrument:first-child { border-left: 0; }
.instrument-value { font-variant-numeric: tabular-nums; font-size: 42px; line-height: .98; font-weight: 840; letter-spacing: -.055em; }
.instrument-value.small-value { font-size: 28px; letter-spacing: -.03em; }
.instrument-label { margin-top: 5px; color: #d8f3fa; font-size: 11px; font-weight: 760; letter-spacing: .09em; text-transform: uppercase; }
.instrument-label small { color: #7dd3fc; font-size: 9px; }
.accuracy-label { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; color: #a5d8e7; font-size: 10px; font-weight: 650; }
.accuracy-label.poor { color: #fcd34d; }

.leaflet-control-zoom { margin-bottom: calc(224px + var(--safe-bottom)) !important; border: 0 !important; box-shadow: 0 6px 20px rgba(2,21,32,.25) !important; }
.leaflet-control-zoom a { width: 44px !important; height: 44px !important; line-height: 42px !important; color: white !important; background: rgba(4,31,49,.88) !important; border-color: #ffffff2b !important; font-size: 24px !important; }
.leaflet-control-scale { margin-bottom: calc(141px + var(--safe-bottom)) !important; }
.leaflet-control-scale-line { background: rgba(255,255,255,.82); border-color: #0f172a; color: #0f172a; font-weight: 650; }
.boat-position { fill: #0ea5e9; fill-opacity: 1; stroke: white; stroke-width: 4; filter: drop-shadow(0 2px 4px #001a); }
.accuracy-circle { fill: #38bdf8; fill-opacity: .10; stroke: #0284c7; stroke-opacity: .55; stroke-width: 1.5; }
.course-line { fill: none; stroke: #0284c7; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 10 8; filter: drop-shadow(0 1px 1px white); animation: courseMove 1.2s linear infinite; }
@keyframes courseMove { to { stroke-dashoffset: -18; } }
.danger-marker { fill: #facc15; fill-opacity: .5; stroke: #a16207; stroke-width: 4; }
.danger-marker.critical { fill: #ef4444; stroke: #7f1d1d; animation: markerPulse .7s infinite alternate; }
.danger-line { stroke: #ca8a04; stroke-width: 4; stroke-dasharray: 6 5; }
.danger-line.critical { stroke: #dc2626; stroke-width: 6; }
@keyframes markerPulse { to { fill-opacity: .95; stroke-width: 8; } }

.side-panel {
  position: absolute;
  z-index: 1000;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(90vw, 390px);
  padding: calc(18px + var(--safe-top)) 18px calc(20px + var(--safe-bottom));
  overflow-y: auto;
  color: var(--ink);
  background: rgba(248,250,252,.98);
  box-shadow: -16px 0 50px rgba(2,21,32,.3);
  touch-action: pan-y;
  animation: panelIn .22s ease-out;
}
@keyframes panelIn { from { transform: translateX(100%); } }
.side-panel-head { display: flex; justify-content: space-between; align-items: center; }
.side-panel h2 { margin: 0; font-size: 26px; letter-spacing: -.04em; }
.eyebrow { margin: 0 0 3px; color: var(--sea); font-size: 11px; font-weight: 850; text-transform: uppercase; letter-spacing: .14em; }
.panel-section { margin-top: 18px; padding: 16px; border-radius: 18px; background: white; border: 1px solid #e2e8f0; box-shadow: 0 6px 22px rgba(15,23,42,.06); }
.panel-section h3 { margin: 0 0 7px; font-size: 15px; }
.panel-section p { margin: 0; font-size: 13px; line-height: 1.45; }
.panel-section .muted { margin-top: 8px; color: var(--muted); }
.download-meter { height: 8px; margin-top: 13px; overflow: hidden; border-radius: 999px; background: #e2e8f0; }
.download-meter span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #0891b2, #22c55e); transition: width .25s; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; font-weight: 650; }
.switch-row input { width: 48px; height: 28px; accent-color: var(--sea); }
.safety-copy { border-color: #fdba74; background: #fff7ed; }
.secondary-button, .primary-button { width: 100%; min-height: 50px; border: 0; border-radius: 14px; font-weight: 800; cursor: pointer; }
.primary-button { color: white; background: linear-gradient(135deg, #0e7490, #075985); box-shadow: 0 9px 24px rgba(8,47,73,.24); }
.secondary-button { margin-top: 18px; color: #991b1b; background: #fee2e2; border: 1px solid #fecaca; }
.version-line { margin: 14px 0 0; color: #94a3b8; text-align: center; font-size: 11px; }

.first-run-backdrop { position: absolute; z-index: 1200; inset: 0; padding: calc(18px + var(--safe-top)) 16px calc(18px + var(--safe-bottom)); display: grid; align-items: end; background: linear-gradient(180deg, rgba(2,21,32,.38), rgba(2,21,32,.82)); backdrop-filter: blur(7px); touch-action: pan-y; overflow-y: auto; }
.first-run-card { width: min(100%, 430px); margin: auto; padding: 24px 20px 18px; border-radius: 28px; background: rgba(255,255,255,.98); box-shadow: 0 22px 70px rgba(0,0,0,.42); }
.first-run-icon { width: 54px; height: 54px; margin-bottom: 15px; display: grid; place-items: center; border-radius: 17px; color: white; background: linear-gradient(145deg, #0e7490, #082f49); font-size: 28px; }
.first-run-card h1 { margin: 0; color: var(--navy-deep); font-size: 29px; line-height: 1.05; letter-spacing: -.045em; }
.first-run-card > p:not(.eyebrow):not(.permission-note) { margin: 13px 0; color: #475569; line-height: 1.5; font-size: 15px; }
.safety-note { margin: 17px 0; padding: 14px; border-radius: 16px; background: #fff7ed; border: 1px solid #fdba74; }
.safety-note strong, .safety-note span { display: block; }
.safety-note strong { color: #9a3412; font-size: 14px; }
.safety-note span { margin-top: 4px; color: #7c2d12; font-size: 13px; line-height: 1.4; }
.start-button { min-height: 58px; font-size: 16px; }
.permission-note { margin: 10px 0 0; color: #94a3b8; text-align: center; font-size: 11px; }

.login-page { min-height: 100dvh; padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); display: grid; place-items: center; color: white; background: radial-gradient(circle at 70% 10%, #0e7490 0, transparent 38%), linear-gradient(145deg, #041f31, #082f49 62%, #0e7490); }
.login-card { width: min(100%, 390px); padding: 28px 22px; border-radius: 28px; color: var(--ink); background: rgba(255,255,255,.98); box-shadow: 0 28px 80px rgba(0,0,0,.35); }
.brand-mark { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 18px; color: white; background: linear-gradient(145deg, #0891b2, #082f49); font-size: 25px; font-weight: 900; }
.login-card .eyebrow { margin-top: 20px; }
.login-card h1 { margin: 0; color: var(--navy-deep); font-size: 38px; letter-spacing: -.06em; }
.login-intro { margin: 7px 0 20px; color: var(--muted); font-size: 14px; }
.login-form { display: grid; gap: 8px; }
.login-form label { margin-top: 6px; color: #334155; font-size: 12px; font-weight: 750; }
.login-form input { width: 100%; height: 50px; padding: 0 14px; border: 1px solid #cbd5e1; border-radius: 13px; background: white; color: var(--ink); font-size: 16px; outline: none; }
.login-form input:focus { border-color: #0891b2; box-shadow: 0 0 0 3px #22d3ee30; }
.login-form .primary-button { margin-top: 10px; }
.form-message { padding: 10px 12px; border-radius: 12px; font-size: 13px; }
.form-message.error { color: #991b1b; background: #fee2e2; border: 1px solid #fecaca; }
.login-footnote { margin: 18px 0 0; color: #94a3b8; text-align: center; font-size: 11px; }

@media (min-width: 700px) {
  .top-bar { padding-left: 22px; padding-right: 22px; }
  .instrument-panel { left: 50%; right: auto; width: 480px; transform: translateX(-50%); }
  .alert-banner { left: 50%; right: auto; width: min(520px, calc(100vw - 24px)); transform: translateX(-50%); }
  .locate-button { right: 24px; }
  .first-run-backdrop { align-items: center; }
}

@media (max-height: 650px) and (orientation: landscape) {
  .instrument-panel { left: 8px; right: auto; width: 390px; min-height: 86px; grid-template-columns: repeat(3, 1fr); }
  .instrument-value { font-size: 32px; }
  .instrument-value.small-value { font-size: 24px; }
  .locate-button { bottom: 104px; }
  .leaflet-control-zoom { margin-bottom: 104px !important; }
  .first-run-backdrop { align-items: start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
