* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: #dfe8f2;
}

canvas.three { display: block; }
body.picking canvas.three { cursor: crosshair; }

/* ---------- side panel ---------- */
#panel {
  position: fixed;
  top: 14px;
  left: 14px;
  width: 340px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  z-index: 10;
  background: rgba(15, 22, 36, 0.90);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 16px;
  padding: 16px;
  color: #e7edf5;
  box-shadow: 0 12px 40px rgba(10, 18, 34, 0.35);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.2) transparent;
}

#panel header h1 {
  margin: 0 0 4px;
  font-size: 19px;
  letter-spacing: .2px;
}
#panel .sub {
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.45;
  color: #9fb1c8;
}
#panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #8fa3bc;
  margin: 0;
}

/* ---------- inputs ---------- */
.fields { position: relative; }

.field {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  padding: 0 6px 0 10px;
  margin-bottom: 8px;
  transition: border-color .15s;
}
.field:focus-within { border-color: #4aa8ff; }
.field.picking { border-color: #ffd166; box-shadow: 0 0 0 2px rgba(255,209,102,.25); }

.field input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: #eef4fb;
  font-size: 13.5px;
  padding: 10px 0;
}
.field input::placeholder { color: #6d8098; }

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-start { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,.8); }
.dot-end   { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.8); }

.pick {
  background: transparent;
  border: none;
  color: #7f93ac;
  font-size: 17px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.pick:hover { color: #ffd166; background: rgba(255,255,255,.06); }
.field.picking .pick { color: #ffd166; }

#swap {
  position: absolute;
  right: 40px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.15);
  background: #1c2942;
  color: #b9c8dc;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
#swap:hover { color: #fff; border-color: #4aa8ff; }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  z-index: 30;
  margin: 0; padding: 4px;
  list-style: none;
  background: #16233c;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  max-height: 220px;
  overflow-y: auto;
}
.suggestions li {
  padding: 8px 10px;
  font-size: 12.5px;
  border-radius: 6px;
  cursor: pointer;
  color: #d5e0ee;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggestions li:hover, .suggestions li.active { background: rgba(74,168,255,.18); }
.suggestions li small { color: #7f93ac; margin-left: 6px; }

/* ---------- row / buttons ---------- */
.row { display: flex; gap: 8px; margin-top: 2px; }

select#profile {
  flex: 1;
  background: rgba(255,255,255,0.06);
  color: #dfe8f3;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 9px 8px;
  font-size: 12.5px;
  outline: none;
}
select#profile option { background: #16233c; }

button.primary {
  background: linear-gradient(135deg, #2f9ff0, #2563eb);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: filter .15s, transform .05s;
}
button.primary:hover { filter: brightness(1.12); }
button.primary:active { transform: scale(.98); }
button.primary:disabled { filter: grayscale(.6) brightness(.8); cursor: wait; }

.hint {
  font-size: 11px;
  color: #74879f;
  margin: 8px 0 0;
  line-height: 1.4;
}

#status[hidden] { display: none; }
#status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: #ffd166;
  margin: 10px 0 0;
}
#status::before {
  content: "";
  width: 12px; height: 12px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid rgba(255,209,102,.3);
  border-top-color: #ffd166;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- route cards ---------- */
#routes { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.route-card {
  position: relative;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 12px;
  padding: 10px 12px 10px 18px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  overflow: hidden;
}
.route-card:hover { background: rgba(255,255,255,0.09); }
.route-card.selected {
  border-color: var(--rc, #4aa8ff);
  background: rgba(255,255,255,0.10);
}
.route-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 6px;
  background: var(--rc, #4aa8ff);
}

.route-card .rc-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.route-card .rc-name { font-weight: 600; font-size: 13px; white-space: nowrap; }
.badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(255,255,255,.10);
  color: #cfe0f2;
  white-space: nowrap;
}
.badge.good { background: rgba(34,197,94,.18); color: #7fe0a7; }
.badge.warn { background: rgba(239,68,68,.16); color: #f5a3a3; }

.rc-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.rc-stats div { font-size: 12.5px; font-weight: 600; }
.rc-stats span {
  display: block;
  font-size: 9.5px;
  font-weight: 400;
  color: #7f93ac;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ---------- chart ---------- */
#chart-box { margin-top: 14px; }
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
#chart-tip { font-size: 11px; color: #ffd166; font-variant-numeric: tabular-nums; }
#chart {
  width: 100%;
  height: 110px;
  display: block;
  background: rgba(0,0,0,.28);
  border-radius: 10px;
  cursor: crosshair;
}

/* ---------- bottom controls ---------- */
.controls {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.slider-row { display: block; font-size: 12px; color: #a9bad0; }
.slider-row b { color: #e7edf5; }
.slider-row input {
  width: 100%;
  margin: 6px 0 2px;
  accent-color: #2f9ff0;
}
.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: #c4d2e3;
  margin: 8px 0;
  cursor: pointer;
}
.check input { accent-color: #2f9ff0; }

#slope-legend[hidden] { display: none; }
#slope-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 10.5px;
  color: #9fb1c8;
  margin: 2px 0 8px;
}
#slope-legend i {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 3px;
  margin-right: 4px;
  vertical-align: -1px;
}

.btn-row { display: flex; gap: 7px; margin-top: 8px; }
.btn-row button {
  flex: 1;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.12);
  color: #c4d2e3;
  font-size: 11.5px;
  padding: 7px 4px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-row button:hover { background: rgba(255,255,255,.13); color: #fff; }
.btn-row button.on { border-color: #2f9ff0; color: #7cc4ff; }

/* ---------- attribution & toast ---------- */
#attribution {
  position: fixed;
  right: 8px;
  bottom: 6px;
  z-index: 5;
  font-size: 10px;
  color: #47586d;
  background: rgba(255,255,255,.72);
  padding: 2px 8px;
  border-radius: 10px;
}
#attribution a { color: #33475e; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 50;
  background: #16233c;
  color: #eef4fb;
  border: 1px solid rgba(255,255,255,.15);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
  transition: opacity .3s;
}
#toast.error { border-color: rgba(239,68,68,.6); color: #ffc9c9; }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  #panel {
    top: auto;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 55vh;
    border-radius: 16px 16px 0 0;
  }
  #attribution { bottom: auto; top: 6px; }
}
