* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #08090e;
  color: #f2f3f7;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

#fullscreenApp {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #08090e;
}

.fullscreen-map {
  position: absolute;
  inset: 0;
  background: #0b0c12;
}

#mapCanvas {
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
  cursor: grab;
}

#mapCanvas:active {
  cursor: grabbing;
}

.map-title {
  position: absolute;
  left: 22px;
  top: 14px;
  max-width: min(700px, calc(100vw - 44px));
  pointer-events: none;
  z-index: 3;
  text-shadow: 0 2px 18px rgba(0,0,0,0.55);
}

.map-title h1 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.map-title p {
  margin: 0;
  color: rgba(242,243,247,0.74);
  line-height: 1.45;
}

.overlay-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.floating-panel {
  position: absolute;
  width: 390px;
  max-width: min(390px, calc(100vw - 32px));
  max-height: calc(100vh - 36px);
  overflow: auto;
  pointer-events: auto;
  background: rgba(18, 20, 30, 0.84);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 18px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 80px rgba(0,0,0,0.38);
}

.settings-panel {
  width: 320px;
  z-index: 30;
}

.history-panel {
  width: min(760px, calc(100vw - 36px));
  transform: translateX(-50%);
  max-height: 340px;
  overflow: hidden;
}

.history-header {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  color: #f2f3f7;
  font-size: 15px;
  font-weight: 650;
  cursor: move;
  user-select: none;
}

.history-frame {
  margin-top: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 10px;
  width: 100%;
  min-width: 0;
}

#historyCanvas {
  width: 100%;
  height: 230px;
  display: block;
  border-radius: 12px;
  background: #0b0c12;
}

.panel {
  background: rgba(18, 20, 30, 0.84);
}

.panel.collapsible {
  padding: 0;
  overflow: auto;
}

.panel-toggle {
  width: 100%;
  appearance: none;
  border: 0;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  background: transparent;
  color: #f2f3f7;
  padding: 13px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  font-size: 15px;
  font-weight: 650;
  border-radius: 0;
  cursor: move;
  user-select: none;
}

.panel-toggle:hover {
  background: rgba(255,255,255,0.045);
}

.panel-toggle .chevron {
  color: #aeb5c8;
  transition: transform 0.18s ease;
}

.panel.collapsed .panel-toggle .chevron {
  transform: rotate(-90deg);
}

.panel-content {
  padding: 16px;
}

.panel.collapsed .panel-content {
  display: none;
}

.panel-hidden {
  display: none !important;
}

h1 {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 14px;
  font-size: 16px;
}

h3 {
  margin: 16px 0 8px;
  font-size: 14px;
  color: #d8dbe6;
}

p {
  color: #b9bdc9;
  line-height: 1.55;
  margin: 0;
}

.field {
  display: grid;
  grid-template-columns: 1fr 74px;
  grid-template-areas:
    "label output"
    "input input";
  gap: 7px 12px;
  margin: 14px 0;
}

.field.compact {
  grid-template-columns: 1fr;
  grid-template-areas:
    "label"
    "input";
}

.field span {
  grid-area: label;
  color: #d8dbe6;
  font-size: 14px;
}

.field output {
  grid-area: output;
  text-align: right;
  color: #aeb5c8;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.field input,
.field select {
  grid-area: input;
}

select,
button,
input[type="number"] {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  background: #191b25;
  color: #f2f3f7;
  padding: 10px 12px;
  font-size: 14px;
}

input[type="range"] {
  width: 100%;
}

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.buttons.one-col {
  grid-template-columns: 1fr;
}

button {
  cursor: pointer;
}

button:hover {
  background: #222533;
}

.metric-options {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: #d8dbe6;
  font-size: 14px;
}

.metric-options.two-col {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

.metric-options.i-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.visibility-list {
  display: grid;
  gap: 9px;
  color: #d8dbe6;
  font-size: 14px;
}

.status {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  color: #aeb5c8;
  font-size: 14px;
}

.status strong {
  color: #f2f3f7;
}

.motion-block {
  margin-top: 8px;
}

.hidden {
  display: none !important;
}

.coordinate-grid {
  display: grid;
  grid-template-columns: 64px 1fr 1fr;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
}

.coord-head {
  color: #aeb5c8;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.coord-label {
  color: #d8dbe6;
  font-size: 14px;
}

.readout {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

th,
td {
  padding: 7px 5px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  color: #aeb5c8;
  font-weight: 600;
}

.metrics {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.metrics div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  background: rgba(0,0,0,0.18);
  border-radius: 10px;
}

.metrics span {
  color: #aeb5c8;
}

.metrics strong {
  font-variant-numeric: tabular-nums;
}

code {
  color: #dce2ff;
}

.about-overlay {
  position: absolute;
  inset: 0;
  z-index: 80;
  background: rgba(0,0,0,0.50);
  display: grid;
  place-items: center;
  padding: 28px;
}

.about-modal {
  width: min(1180px, calc(100vw - 56px));
  max-height: calc(100vh - 56px);
  overflow: auto;
  background: rgba(18, 20, 30, 0.96);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 22px;
  box-shadow: 0 30px 120px rgba(0,0,0,0.55);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.about-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(18, 20, 30, 0.98);
  border-bottom: 1px solid rgba(255,255,255,0.12);
  padding: 18px 22px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

.about-header h2 {
  margin: 0;
}

.about-header button {
  width: auto;
  padding: 8px 14px;
}

.about-content {
  padding: 22px;
}

.about-content > h2 {
  display: none;
}

.explanation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 18px;
}

.explanation-grid article {
  background: rgba(0,0,0,0.16);
  border: 1px solid rgba(255,255,255,0.075);
  border-radius: 16px;
  padding: 16px;
}

.explanation-grid article h3 {
  margin-top: 0;
  font-size: 15px;
}

.explanation-grid article p + p {
  margin-top: 10px;
}

@media (max-width: 980px) {
  .floating-panel {
    width: min(360px, calc(100vw - 24px));
  }

  .map-title {
    display: none;
  }

  .history-panel {
    width: calc(100vw - 24px);
  }

  .explanation-grid {
    grid-template-columns: 1fr;
  }
}


/* v10 fixed interaction patches */
.floating-panel {
  z-index: 10;
}

.settings-panel {
  z-index: 40;
}

.panel-hidden {
  display: none !important;
}

.drag-handle {
  touch-action: none;
}

.panel-content {
  cursor: default;
}

.panel-content button,
.panel-content input,
.panel-content select,
.panel-content label {
  touch-action: auto;
}


/* v12: edge-based panel resizing, no visible resize mark */
.floating-panel {
  min-width: 220px;
  min-height: 54px;
  max-width: none;
  max-height: none;
}

.history-panel {
  min-width: 320px;
  min-height: 180px;
  width: min(900px, calc(100vw - 36px));
  height: 320px;
  overflow: hidden;
}

.history-panel .history-frame {
  height: calc(100% - 42px);
}

.history-panel #historyCanvas {
  width: 100%;
  height: 100%;
  min-height: 120px;
}

.floating-panel.resizing,
.floating-panel.dragging {
  user-select: none;
}

.floating-panel.resize-n,
.floating-panel.resize-s {
  cursor: ns-resize;
}

.floating-panel.resize-e,
.floating-panel.resize-w {
  cursor: ew-resize;
}

.floating-panel.resize-ne,
.floating-panel.resize-sw {
  cursor: nesw-resize;
}

.floating-panel.resize-nw,
.floating-panel.resize-se {
  cursor: nwse-resize;
}


/* v13: active panel stacking */
.floating-panel {
  z-index: 10;
}

.floating-panel.active-panel {
  z-index: 60;
}

.settings-panel {
  z-index: 70;
}

#mapCanvas.move-triangle {
  cursor: move;
}


/* v16: map panning cursor */
#mapCanvas.pan-map {
  cursor: grab;
}

#mapCanvas.panning-map {
  cursor: grabbing;
}


/* v17: custom profile expression editor */
.custom-profile {
  margin: 8px 0 12px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  background: rgba(0,0,0,0.16);
}

.field.text-field {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "label"
    "input";
}

textarea {
  grid-area: input;
  width: 100%;
  resize: vertical;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  background: #191b25;
  color: #f2f3f7;
  padding: 10px 12px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  line-height: 1.45;
}

.help-text {
  font-size: 12px;
  color: #aeb5c8;
}


/* v18: custom profile apply workflow */
.profile-param-control.hidden {
  display: none;
}

#applyCustomProfile {
  margin: 8px 0 4px;
}
