:root {
  --bg: #11151c;
  --bg-raised: #1a202a;
  --bg-input: #121821;
  --line: #2c3542;
  --ink: #e6ebf2;
  --ink-dim: #96a2b3;
  --accent: #d8a33a;
  --accent-ink: #1a1206;
  --danger: #d4634f;
  --radius: 10px;
  --sidebar-w: 360px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}

#app {
  display: flex;
  height: 100%;
}

/* ------------------------------------------------------------- Sidebar - */

#sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-raised);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: margin-left .2s ease;
}

#app.sidebar-hidden #sidebar { margin-left: calc(var(--sidebar-w) * -1); }

.brand {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.brand h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: .04em;
  color: var(--accent);
}
.brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-dim);
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 1;
  padding: 10px 4px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.panel {
  display: none;
  padding: 14px 16px 24px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.panel.is-active { display: block; }

/* ------------------------------------------------------------ Controls - */

.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 4px;
}
input[type="text"], input[type="search"], input[type="password"],
input[type="number"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); }
.check input { width: auto; }

.row { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.row > * { flex: 1; }

.btn {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { filter: brightness(1.1); }
.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
  font-weight: 500;
}
.btn-ghost:hover { border-color: var(--ink-dim); }
.btn.is-active { background: var(--danger); border-color: var(--danger); color: #fff; }

.icon-btn {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
#sidebar-toggle { position: absolute; top: 12px; right: 12px; }
.floating {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 500;
  display: none;
}
#app.sidebar-hidden .floating { display: block; }

.hint {
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.5;
  margin: 6px 0;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 14px; }

/* ----------------------------------------------------------- Wegpunkte - */

.waypoints { list-style: none; margin: 0 0 6px; padding: 0; }
.waypoints li {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.wp-dot {
  width: 22px;
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--line);
  color: var(--ink);
}
.wp-dot.start { background: #4e9a5a; color: #061007; }
.wp-dot.end { background: var(--danger); color: #1a0604; }
.waypoints select { flex: 1; min-width: 0; }
.wp-remove {
  flex: 0 0 26px;
  background: none;
  border: 0;
  color: var(--ink-dim);
  font-size: 17px;
  cursor: pointer;
}
.wp-remove:hover { color: var(--danger); }

/* -------------------------------------------------------------- Result - */

.result:empty { display: none; }
.result {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 12px;
}
.result .totals {
  display: flex;
  gap: 16px;
  align-items: baseline;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.result .big { font-size: 24px; font-weight: 700; color: var(--accent); }
.result .sub { font-size: 12px; color: var(--ink-dim); }
.result ol { margin: 10px 0 0; padding-left: 0; list-style: none; }
.result .stage-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-dim);
  margin: 10px 0 4px;
}
.leg {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 3px 0;
}
.leg .swatch {
  width: 14px;
  flex: 0 0 14px;
  height: 4px;
  border-radius: 2px;
}
.leg .leg-name { flex: 1; }
.leg .leg-val { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.warn { color: var(--danger); font-size: 12px; margin-top: 8px; }

/* --------------------------------------------------------------- Listen - */

.list { list-style: none; margin: 10px 0 0; padding: 0; }
.list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.list li:hover { background: #20283380; }
.list .name { flex: 1; cursor: pointer; min-width: 0; }
.list .name small { display: block; color: var(--ink-dim); font-size: 11px; }
.list .mini {
  background: none;
  border: 0;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
}
.list .mini:hover { color: var(--accent); }
.list .mini.del:hover { color: var(--danger); }
.empty { color: var(--ink-dim); font-size: 13px; padding: 10px 0; }

.saved { margin-top: 14px; }
.saved h3 { font-size: 13px; color: var(--ink-dim); margin: 0; }

.legend { list-style: none; margin: 0; padding: 0; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0; }
.legend .swatch { width: 24px; flex: 0 0 24px; height: 4px; border-radius: 2px; }

.speeds { width: 100%; border-collapse: collapse; font-size: 12px; }
.speeds th, .speeds td { text-align: left; padding: 3px 6px 3px 0; }
.speeds th { color: var(--ink-dim); font-weight: 500; }
.speeds td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- Map - */

#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #607baa; }

.readout {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 500;
  background: #11151cd0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 900;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 20px #0008;
}
.toast.err { background: var(--danger); color: #fff; }

.place-label {
  background: none;
  border: 0;
  box-shadow: none;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 0 4px #000, 0 0 8px #000, 0 1px 2px #000;
  white-space: nowrap;
  pointer-events: none;
}
.place-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #11151c;
  box-shadow: 0 0 0 1px #d8a33a80;
}
.place-dot.hauptstadt { background: #e8584f; width: 14px; height: 14px; }
.place-dot.dorf { background: #9fb0c4; width: 8px; height: 8px; }
.place-dot.ruine { background: #8a6fc4; }
.place-dot.dungeon { background: #c45f9c; }
.place-dot.hafen { background: #4ea3d8; }

.leaflet-container { background: #607baa; font-family: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-raised);
  color: var(--ink);
}
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.leaflet-popup-content h4 { margin: 0 0 4px; font-size: 14px; color: var(--accent); }
.leaflet-popup-content .pop-row { display: flex; gap: 6px; margin-top: 8px; }
.leaflet-popup-content .pop-row .btn { flex: 1; padding: 5px 8px; font-size: 12px; }
.leaflet-bar a { background: var(--bg-raised); color: var(--ink); border-color: var(--line); }
.leaflet-bar a:hover { background: #26303c; color: var(--ink); }

.vertex-handle {
  width: 9px;
  height: 9px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  cursor: move;
}

/* ---------------------------------------------------------------- Mobil - */

body:not(.can-edit) .edit-only { display: none !important; }

@media (max-width: 760px) {
  :root { --sidebar-w: 100%; }
  #app { flex-direction: column; }
  #sidebar {
    position: absolute;
    inset: 0;
    /* ueber den Leaflet-Controls, die selbst bei z-index 1000 liegen */
    z-index: 1200;
    width: 100%;
    flex: 1 1 auto;
  }
  .floating { top: auto; bottom: 16px; left: 16px; width: 44px; height: 44px; font-size: 20px; }
  #app.sidebar-hidden #sidebar { margin-left: -100%; }
  #map-wrap { position: absolute; inset: 0; }
}
