:root {
  --bg: #eef1ee;
  --surface: #ffffff;
  --text: #17201b;
  --muted: #5c6a62;
  --border: #d6ddd8;
  --accent: #1f7a5c;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --warn-bg: #fbeee0;
  --warn-text: #8a4b00;
  --target: #e0452b;
  --user: #2a6fdb;
  --user-cone: rgba(42, 111, 219, 0.22);
  --map-corridor: #d9e2dc;
  --map-node: #9aa8a0;
  --map-product: #c08a1a;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111513;
    --surface: #1b211e;
    --text: #e8eee9;
    --muted: #9aa8a0;
    --border: #2e3833;
    --accent: #3fb68b;
    --accent-text: #06140e;
    --danger: #f2766d;
    --warn-bg: #3a2a12;
    --warn-text: #f2b866;
    --target: #ff6b4f;
    --user: #6ea1ff;
    --user-cone: rgba(110, 161, 255, 0.25);
    --map-corridor: #2b3530;
    --map-node: #56645c;
    --map-product: #e0b04a;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body[data-mode="ar"] { background: #000; }

.hidden { display: none !important; }

/* Kamera i Three.js — struktura jak w przykładzie Immersal */
#container {
  position: fixed; inset: 0;
  overflow: hidden;
  line-height: 0;
  display: none;
}
body[data-mode="ar"] #container { display: block; }
#container > * {
  position: absolute; top: 0; left: 0;
  /* immersal.js i Three.js ustawiają rozmiar inline w px — nadpisujemy, obie warstwy mają te same proporcje */
  width: 100% !important; height: 100% !important;
  object-fit: cover;
  user-select: none;
}

/* Mapa */
#mapWrap {
  position: fixed; inset: 0;
  padding: 76px 16px 200px;
}
body[data-mode="demo"].has-sheet #mapWrap { padding-bottom: 380px; }
body[data-mode="start"] #mapWrap { opacity: 0.35; pointer-events: none; }
body[data-mode="ar"] #mapWrap {
  inset: auto auto calc(16px + env(safe-area-inset-bottom)) 16px;
  width: 140px; height: 140px;
  padding: 6px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 3;
}
body[data-mode="ar"].has-sheet #mapWrap { bottom: auto; top: 76px; }
#map { width: 100%; height: 100%; display: block; touch-action: manipulation; }

/* Arkusze */
.sheet {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(560px, calc(100% - 32px));
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  z-index: 5;
}

.start { top: 50%; bottom: auto; transform: translate(-50%, -50%); display: flex; flex-direction: column; gap: 12px; }
.start h1 { font-size: 26px; letter-spacing: -0.02em; }
.lead { color: var(--muted); margin-bottom: 4px; }
body:not([data-mode="start"]) .start { display: none; }

details summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
details label { display: block; font-size: 14px; color: var(--muted); margin-top: 10px; }
input[type="password"], input[type="number"], input[type="search"], input[type="text"], select {
  display: block; width: 100%;
  margin-top: 4px;
  font: inherit; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.hint { font-size: 13px; color: var(--muted); margin-top: 8px; }

.btn {
  font: inherit; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 42px; font-size: 14px; padding: 0 12px; }
.btn.wide { width: 100%; margin-top: 12px; }
.btn:active { transform: scale(0.98); }

/* Wyszukiwarka */
#searchBar {
  position: fixed; z-index: 6;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  display: flex; gap: 8px;
}
#search {
  margin: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  border-color: transparent;
  padding: 14px 16px;
  border-radius: 14px;
}
.icon-btn {
  flex: none; width: 52px;
  font-size: 20px;
  border: 0; border-radius: 14px;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.icon-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
#results {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  list-style: none;
  max-height: 50vh; overflow-y: auto;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
#results li {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
#results li:last-child { border-bottom: 0; }
#results li small { display: block; color: var(--muted); }
#results li.empty { color: var(--muted); cursor: default; }

/* Gdzie jestem */
.where {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 15px; font-weight: 600;
  margin-bottom: 8px;
}
.icon-btn.small { width: 40px; height: 40px; flex: none; font-size: 18px; box-shadow: none; border: 1px solid var(--border); }

/* Panel trasy */
#status { font-size: 15px; color: var(--muted); }
#status:empty { display: none; }
#status:not(:empty) + #routeInfo:not(.hidden) { margin-top: 10px; }
.route-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.route-name { font-size: 18px; font-weight: 700; }
.route-meta { color: var(--muted); font-size: 14px; }
.route-dist { font-size: 26px; font-weight: 700; color: var(--accent); white-space: nowrap; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row .btn { flex: 1; }
body[data-mode="ar"] #simulate { display: none; }
body[data-mode="ar"] #panel { left: calc(16px + 140px + 12px); transform: none; width: auto; right: 16px; }
body[data-mode="ar"].has-sheet #panel { left: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 32px)); right: auto; }

/* Edytor */
.editor-title { font-weight: 700; }
#editStats { font-weight: 400; color: var(--muted); font-size: 14px; }
.dist { font-variant-numeric: tabular-nums; }
.dist.far { color: var(--danger); font-weight: 600; }
.warning {
  margin-top: 8px; padding: 8px 10px;
  background: var(--warn-bg); color: var(--warn-text);
  border-radius: 10px; font-size: 13px; font-weight: 600;
}
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

/* Strzałka kierunku w AR */
#compass {
  position: fixed; z-index: 4;
  top: calc(84px + env(safe-area-inset-top));
  left: 50%; transform: translateX(-50%);
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid; place-items: center;
  box-shadow: var(--shadow);
}
#compass .arrow { font-size: 34px; line-height: 1; transition: transform 0.15s linear; }
#compass.arrived { background: var(--target); }

#toast {
  position: fixed; z-index: 10;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  max-width: calc(100% - 32px);
  background: rgba(20, 24, 22, 0.9); color: #fff;
  padding: 12px 18px; border-radius: 12px;
  font-size: 15px; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
#toast.show { opacity: 1; }

#badge {
  position: fixed; z-index: 4;
  right: 12px; bottom: calc(8px + env(safe-area-inset-bottom));
  font-size: 11px; color: #fff; opacity: 0.75;
  text-shadow: 0 1px 2px #000;
}
body.has-sheet #badge { display: none; }
