:root {
  font-family: 'Avenir Next', Avenir, Arial, sans-serif;
  color: #173b48;
  background: #c2dce2;
  font-size: 13px;
  --navy: #173b48;
  --teal: #157c8a;
  --paper: #f5fafbf7;
  --line: #cbdde1;
  --muted: #55717c;
  --red: #b73743;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select,
summary {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  color: var(--navy);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  line-height: 1.25;
}

button:hover:not(:disabled):not(.active) {
  background: #e2f0f2;
  border-color: #80a8b1;
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

button.active {
  color: white;
  background: var(--navy);
  border-color: var(--navy);
}

:focus-visible {
  outline: 3px solid #20a4bd;
  outline-offset: 3px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h2 {
  font-size: 15px;
  font-weight: 650;
}

h3 {
  font-size: 13px;
}

a {
  color: var(--teal);
  text-underline-offset: 3px;
}

input[type=checkbox] {
  accent-color: var(--teal);
}

input[type=range] {
  width: 100%;
  accent-color: var(--teal);
  min-height: 24px;
}

select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  max-width: 100%;
  color: var(--navy);
  background: white;
}

[hidden] {
  display: none !important;
}

/* Viewport */
#viewport,
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#scene {
  touch-action: none;
}

#scene.rendering {
  object-fit: contain;
  background: #000;
}

/* Topbar */
.topbar {
  position: absolute;
  top: 18px;
  left: 20px;
  right: 20px;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--paper);
  border: 1px solid #fffc;
  border-radius: 14px;
  padding: 10px 15px;
  box-shadow: 0 8px 28px #13344012;
  gap: 15px;
}

.identity {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  background: var(--navy);
  color: #a0e2e5;
  font: 500 26px/42px Georgia, serif;
  width: 42px;
  height: 42px;
  text-align: center;
  border-radius: 10px;
}

.identity h1 {
  font-size: 21px;
  letter-spacing: -.6px;
  line-height: 1.2;
}

.identity h1 span {
  font-size: 14px;
  color: var(--teal);
  font-weight: 500;
}

.identity p {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.modes {
  display: flex;
  background: #dce9ed;
  padding: 4px;
  border-radius: 10px;
  gap: 3px;
}

.modes button {
  border: 0;
  background: none;
  padding: 10px 17px;
  font-weight: 600;
}

.modes button.active {
  background: var(--navy);
}

.top-actions {
  display: flex;
  gap: 8px;
}

#planner-open {
  background: #ffefd4;
  border-color: #d9bc8d;
}

.record {
  display: flex;
  gap: 9px;
  align-items: center;
  background: #fff;
}

.record i {
  display: block;
  background: var(--red);
  height: 10px;
  width: 10px;
  border-radius: 50%;
}

.record.recording {
  background: var(--red);
  color: white;
  border-color: var(--red);
}

.record.recording i {
  border-radius: 2px;
  background: white;
}

/* Panels */
.panel {
  position: absolute;
  background: var(--paper);
  border: 1px solid #fffc;
  border-radius: 14px;
  padding: 17px;
  box-shadow: 0 10px 36px #13344014;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-heading > span {
  font-size: 11px;
  color: var(--muted);
}

.subtle {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
  margin: 6px 0 12px;
}

.wide {
  width: 100%;
  font-size: 12px;
}

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  margin: 11px 0;
}

/* Territory sidebar */
.territory {
  left: 20px;
  top: 102px;
  width: 272px;
  max-height: calc(100dvh - 192px);
  overflow: auto;
  scrollbar-width: thin;
}

.marine-controls {
  border-block: 1px solid var(--line);
  padding: 12px 0 4px;
  margin-top: 12px;
}

.marine-controls h3 {
  margin-bottom: 10px;
}

.marine-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  flex-wrap: wrap;
  margin: 10px 0;
  cursor: pointer;
}

.marine-controls small {
  color: var(--muted);
  font-size: 9px;
  margin-left: 25px;
}

.marine-controls .subtle {
  margin-bottom: 4px;
  font-size: 10px;
}

.swatch {
  display: inline-block;
  width: 13px;
  height: 9px;
  border-radius: 2px;
  border: 1px solid #173b4840;
  flex: none;
}

.swatch.lagoon { background: #22baa9; }
.swatch.reef { background: #c8d99a; }
.swatch.territorial { background: #4a91db; }
.swatch.park { background: #97efbd; }

.marine-views {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  gap: 4px;
  margin-top: 12px;
}

.marine-views button {
  padding: 8px 3px;
  font-size: 10px;
}

.coast-controls {
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
}

.coast-controls h3 {
  margin-bottom: 12px;
}

.coast-choice {
  display: block;
  margin: 12px 0 6px;
  font-size: 11px;
}

.coast-controls select {
  width: 100%;
  min-width: 0;
  padding: 8px 5px;
}

.coast-controls .wide {
  margin-top: 7px;
}

.tide-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 12px 0;
}

.tide-presets button {
  font-size: 11px;
  padding: 8px 4px;
}

.coast-controls label[for=tide-level],
.coast-controls label[for=hour] {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}

.coast-controls input[type=range] {
  margin: 10px 0;
}

.coast-controls .subtle {
  font-size: 10px;
  margin: 9px 0 0;
}

.coast-controls output {
  font-variant-numeric: tabular-nums;
}

.light-title {
  margin-top: 14px;
}

.search {
  display: block;
  margin-top: 16px;
}

.search span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff8;
  color: var(--navy);
}

.selection-actions {
  display: flex;
  gap: 8px;
  margin: 10px 0;
}

.selection-actions button {
  font-size: 11px;
  flex: 1;
  padding: 7px;
}

.communes {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 10px;
}

.commune-row {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 32px;
  border-radius: 7px;
  padding: 0 6px;
}

.commune-row:hover {
  background: #dcecee;
}

.commune-row input {
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.commune-row button {
  flex: 1;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 7px 0;
  font-size: 12px;
}

.commune-row .area {
  font-size: 10px;
  color: #66828a;
  font-variant-numeric: tabular-nums;
  min-width: 35px;
  text-align: right;
}

.layers {
  border-top: 1px solid var(--line);
  margin-top: 15px;
  padding-top: 12px;
}

.layers summary,
details#takes summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.layers label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  margin-top: 12px;
}

.layers select {
  font-size: 10px;
}

.layers small {
  color: var(--muted);
  font-size: 10px;
}

/* Studio sidebar */
.studio {
  right: 20px;
  top: 102px;
  width: 264px;
  max-height: calc(100dvh - 192px);
  overflow: auto;
  scrollbar-width: thin;
}

#toggle-studio {
  padding: 2px 8px;
  font-size: 19px;
  border: 0;
  background: none;
}

.transport {
  display: flex;
  gap: 7px;
  margin: 13px 0;
}

.transport button {
  flex: 1;
  font-size: 11px;
}

.record-settings {
  border-top: 1px solid var(--line);
  padding-top: 13px;
  margin-top: 15px;
}

.record-settings > label:first-child {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.speed {
  display: block;
  margin: 15px 0 12px;
  font-size: 12px;
}

.speed output {
  float: right;
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}

.speed input {
  display: block;
  margin: 8px 0;
}

/* Keyboard-accessible visually-hidden file inputs */
.import-route {
  position: relative;
  display: inline-block;
  cursor: pointer;
  margin-top: 13px;
  font-size: 11px;
  text-decoration: underline;
  text-underline-offset: 3px;
  border-radius: 4px;
}

.import-route:focus-within {
  outline: 3px solid #20a4bd;
  outline-offset: 3px;
}

.import-route input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.cinema-settings {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.cinema-settings summary {
  font-weight: 650;
  cursor: pointer;
}

.cinema-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin: 8px 0;
}

.cinema-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  font-size: 11px;
  color: var(--muted);
}

.cinema-grid select {
  width: 100%;
  min-width: 0;
  border-radius: 8px;
  padding: 7px 5px;
}

#takes {
  border-top: 1px solid var(--line);
  padding-top: 13px;
}

#take-count {
  color: var(--teal);
  margin-left: 8px;
}

.take {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}

.take a {
  display: block;
  margin: 5px 0;
}

.take-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.take-actions button {
  font-size: 11px;
  padding: 6px 8px;
}

#timeline-section {
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

/* Flight planner */
.planner {
  right: 20px;
  top: 102px;
  width: 344px;
  max-height: calc(100dvh - 192px);
  overflow: auto;
  scrollbar-width: thin;
}

.plan-actions {
  display: flex;
  gap: 6px;
  margin: 10px 0;
}

.plan-actions button {
  flex: 1;
  font-size: 11px;
  padding: 9px 7px;
}

.plan-list-heading {
  margin-top: 18px;
}

.plan-points {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 125px;
  overflow: auto;
  margin: 10px 0;
}

.plan-point {
  font-size: 11px;
  padding: 7px 9px;
}

.planner fieldset {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px;
  margin: 13px 0;
}

.planner legend {
  padding: 0 5px;
  font-weight: 600;
}

.plan-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.plan-grid label,
.plan-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  line-height: 1.4;
}

.planner input[type=number],
.planner select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--navy);
  padding: 8px;
}

.planner details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 12px;
}

.planner summary {
  cursor: pointer;
  font-size: 12px;
  margin-bottom: 10px;
}

.plan-summary {
  margin-top: 15px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.planner .subtle {
  margin-bottom: 8px;
}

/* Overlays & HUD */
#labels,
#waypoint-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.map-label {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 4px #102d3c, 0 0 10px #102d3c;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  padding: 2px 4px;
  letter-spacing: .02em;
}

.map-label::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #d7f7f6;
  margin-right: 5px;
  vertical-align: middle;
}

.map-label.commune-name {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: #ffe9b8;
  border: 1px solid #ffe9b866;
  border-radius: 4px;
  background: #102d3c55;
}

.map-label.commune-name::before {
  display: none;
}

.map-label.village {
  transform: translate(-3px, -50%);
  font-weight: 500;
}

.map-label.village::before {
  width: 5px;
  height: 5px;
  background: #fff;
}

.map-label.chef-lieu {
  font-size: 12px;
  font-weight: 750;
}

.map-label.chef-lieu::before {
  width: 8px;
  height: 8px;
  background: #ffcf5a;
  box-shadow: 0 0 0 2px #102d3c;
}

.waypoint-marker {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  background: #e29b34;
  color: #172e37;
  border-radius: 50%;
  width: 29px;
  height: 29px;
  padding: 0;
  font-weight: 700;
  pointer-events: auto;
  box-shadow: 0 2px 7px #102d3c66;
}

.telemetry {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 30px;
  background: #173b48eb;
  color: #e8f7f9;
  padding: 13px 24px;
  border: 1px solid #ffffff20;
  border-radius: 12px;
  pointer-events: none;
  min-width: 620px;
  box-shadow: 0 6px 25px #14374015;
}

.telemetry > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.telemetry span {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #add0d8;
  white-space: nowrap;
}

.telemetry strong {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.telemetry > div:first-child {
  margin-right: auto;
  max-width: 200px;
}

.telemetry > div:first-child strong {
  font-family: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quality {
  text-align: right;
}

.compass {
  position: absolute;
  bottom: 30px;
  left: 30px;
  width: 42px;
  height: 42px;
  border: 1px solid #fff8;
  border-radius: 50%;
  background: #173b48bc;
  color: #e4f8ff;
  text-align: center;
  font: 10px monospace;
}

.compass span {
  position: absolute;
  top: 2px;
  left: 17px;
}

.compass i {
  display: block;
  position: absolute;
  left: 17px;
  top: 16px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 16px solid #b8eef2;
  transform-origin: 50% 6px;
}

#crosshair {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 40px;
  width: 60px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 1px 2px #123);
}

#crosshair span {
  position: absolute;
  top: 20px;
  left: 0;
  width: 60px;
  border-top: 1px solid #fff9;
}

#crosshair i {
  position: absolute;
  top: 17px;
  left: 27px;
  width: 6px;
  height: 6px;
  border: 1px solid #fff;
  border-radius: 50%;
}

/* Loading, toast, modals */
.loading {
  position: absolute;
  inset: 0;
  background: #d1e5eade;
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  z-index: 50;
}

.loading-box {
  width: 320px;
  background: #f5fafb;
  padding: 32px;
  border: 1px solid #fff;
  border-radius: 18px;
  box-shadow: 0 20px 80px #173b4820;
}

.loading h2 {
  margin: 22px 0 8px;
  font-size: 20px;
}

.loading p {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

progress {
  width: 100%;
  height: 5px;
  margin-top: 22px;
  accent-color: var(--teal);
}

#toast {
  position: absolute;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(540px, 90vw);
  background: #173b48f2;
  color: white;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 12px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 80;
}

#toast.show {
  opacity: 1;
}

.cinema-overlay {
  position: fixed;
  inset: auto 20px 24px auto;
  z-index: 50;
  width: min(360px, calc(100vw - 40px));
}

.cinema-box {
  background: var(--paper);
  border: 1px solid #fffc;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 10px 36px #13344033;
}

.cinema-box h2 {
  margin-bottom: 6px;
}

.cinema-box progress {
  width: 100%;
  margin: 10px 0 4px;
}

.cinema-box button {
  margin-top: 4px;
}

dialog {
  width: min(680px, 94vw);
  max-height: 85dvh;
  overflow: auto;
  border: 0;
  border-radius: 16px;
  padding: 30px;
  color: var(--navy);
  background: #f5fafb;
  box-shadow: 0 30px 100px #102d3c66;
}

dialog::backdrop {
  background: #102d3c70;
  backdrop-filter: blur(3px);
}

dialog h2 {
  font-size: 24px;
  margin: 18px 0;
}

dialog h3 {
  margin: 20px 0 6px;
}

dialog p {
  font-size: 13px;
  line-height: 1.7;
  margin-bottom: 10px;
}

.dialog-close {
  float: right;
}

.mobile-toggle,
.mobile-help {
  display: none;
}

.mobile-help {
  margin-top: 12px;
}

/* P3 Studio UX additions */
.heading-right,
.plan-history {
  display: flex;
  align-items: center;
  gap: 6px;
}

.heading-right > span {
  font-size: 11px;
  color: var(--muted);
}

.icon-btn {
  padding: 2px 8px;
  font-size: 15px;
  line-height: 1.2;
  border: 0;
  background: transparent;
}

.reopen-territory {
  position: absolute;
  left: 20px;
  top: 102px;
  z-index: 12;
  background: var(--paper);
  box-shadow: 0 6px 20px #13344018;
}

.zen-exit {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 60;
  background: #173b48eb;
  color: #e8f7f9;
  border: 1px solid #ffffff30;
  font-size: 11px;
  padding: 7px 12px;
}

.zen-exit:hover {
  background: var(--navy);
  border-color: #ffffff66;
}

body.zen-mode .topbar,
body.zen-mode .panel,
body.zen-mode .telemetry,
body.zen-mode .compass,
body.zen-mode .mobile-toggle,
body.zen-mode .reopen-territory {
  display: none !important;
}

.sun-presets,
.studio-tools,
.plan-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin: 8px 0;
}

.sun-presets button,
.studio-tools button,
.plan-presets button {
  font-size: 10px;
  padding: 6px 4px;
}

.search-results {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
  max-height: 170px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 4px;
}

.search-results button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px 8px;
  font-size: 11px;
  border-radius: 6px;
}

.search-results button small {
  color: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
  flex: none;
}

.measure-panel {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 10px;
}

.measure-profile {
  display: block;
  width: 100%;
  height: 64px;
  background: #fff8;
  border: 1px solid var(--line);
  border-radius: 7px;
  margin: 6px 0 8px;
}

.waypoint-marker {
  cursor: grab;
}

.waypoint-marker:active {
  cursor: grabbing;
}

.waypoint-marker.selected {
  background: #173b48;
  color: #ffcf5a;
  border-color: #ffcf5a;
}

.waypoint-marker.poi-marker {
  display: grid;
  place-items: center;
  background: #157c8a;
  color: #fff;
  border-color: #a0f7f2;
  font-size: 15px;
  pointer-events: none;
}

@media (max-width: 1100px) {
  .territory { width: 230px; }
  .studio { width: 235px; }
  .identity p { display: none; }
  .telemetry { min-width: 550px; gap: 20px; }
}

@media (max-width: 760px) {
  .topbar {
    left: 10px;
    right: 10px;
    top: 10px;
    height: 58px;
    padding: 7px;
    gap: 5px;
    z-index: 25;
  }
  .identity { gap: 5px; }
  .identity h1 { font-size: 16px; }
  .brand-mark { width: 30px; height: 32px; line-height: 32px; font-size: 22px; border-radius: 7px; }
  .modes button { padding: 9px 10px; font-size: 11px; }
  .top-actions { gap: 4px; }
  .top-actions #fullscreen,
  .top-actions #help,
  .top-actions #zen-toggle,
  #collapse-territory,
  .reopen-territory { display: none; }
  .top-actions #planner-open {
    position: fixed;
    left: 100px;
    top: 70px;
    font-size: 11px;
    white-space: nowrap;
  }
  .record { font-size: 10px; padding: 10px 7px; gap: 5px; }
  .record i { width: 7px; height: 7px; }
  .mobile-toggle {
    display: block;
    position: absolute;
    left: 10px;
    top: 80px;
    background: var(--paper);
  }
  .mobile-help { display: block; }
  .territory {
    display: none;
    top: 120px;
    left: 10px;
    width: 235px;
    max-height: calc(100dvh - 205px);
    z-index: 15;
  }
  .territory.open { display: block; }
  .studio {
    top: 122px;
    right: 10px;
    width: 210px;
    max-height: calc(100dvh - 205px);
    padding: 12px;
  }
  .studio h2 { font-size: 12px; }
  .planner {
    right: 10px;
    top: 120px;
    width: min(320px, calc(100vw - 20px));
    max-height: calc(100dvh - 205px);
    z-index: 16;
  }
  .planner .plan-grid { gap: 7px; }
  .telemetry {
    bottom: 10px;
    min-width: 0;
    width: calc(100% - 20px);
    padding: 12px;
    gap: 12px;
  }
  .telemetry .quality { display: none; }
  .telemetry > div:first-child { max-width: 115px; }
  .telemetry span { font-size: 8px; }
  .telemetry strong { font-size: 10px; }
  .compass { bottom: 90px; left: 14px; }
  .map-label { font-size: 10px; }
  #toast { bottom: 90px; }
  .layers select { max-width: 145px; }
}
