:root {
  --bg: #03070d;
  --panel: rgba(10, 18, 30, 0.62);
  --panel-solid: rgba(9, 15, 25, 0.95);
  --line: rgba(160, 200, 255, 0.16);
  --fg: #e6f0fb;
  --muted: #8ba0b8;
  --accent: #5cd0ff;
  --warn: #ffb454;
  --top: calc(max(12px, env(safe-area-inset-top)) + 34px);
  --bottom: calc(max(16px, env(safe-area-inset-bottom)) + 44px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
#video { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.glass { background: var(--panel); border: 1px solid var(--line); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }

/* status */
#hud {
  position: fixed; z-index: 30; top: var(--top); left: 12px; max-width: calc(100vw - 84px);
  display: flex; align-items: center; gap: 8px; text-align: left;
  font-size: 13px; color: var(--fg); padding: 8px 13px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  transition: opacity 0.4s;
}
#hud.quiet { opacity: 0.55; }
#hud .live { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
#hud.search .live { background: var(--warn); box-shadow: 0 0 10px var(--warn); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* akcje z boku */
#actions { position: fixed; z-index: 14; top: var(--top); right: 12px; display: flex; flex-direction: column; gap: 10px; }
.fab {
  position: relative; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; padding: 0;
  background: var(--panel); border: 1px solid var(--line); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.fab:active { background: rgba(40, 62, 92, 0.8); }
.fab svg, .field svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.fab.text { font-weight: 700; font-size: 16px; }
.fab.small { width: 40px; height: 40px; flex: none; }
.badge { position: absolute; top: 3px; right: 3px; min-width: 10px; height: 10px; border-radius: 50%; background: var(--warn); border: 2px solid #0a1220; }

/* warstwy */
#toolbar { position: fixed; z-index: 12; left: 0; right: 0; bottom: var(--bottom); }
#layers { display: flex; gap: 8px; overflow-x: auto; padding: 4px 12px; scrollbar-width: none; scroll-snap-type: x proximity; }
#layers::-webkit-scrollbar { display: none; }
/* wygaszona krawędź: po tej stronie są jeszcze warstwy */
#layers.more-r { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 48px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 48px), transparent); }
#layers.more-l { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent); }
#layers.more-l.more-r { -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 48px), transparent); mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 48px), transparent); }
#layers .chip { padding: 8px 12px; font-size: 13px; gap: 7px; }
body.sheet-open #toolbar, body.sheet-open #actions { visibility: hidden; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; scroll-snap-align: center;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  padding: 10px 15px; border-radius: 999px; font-size: 14px; font-weight: 500; white-space: nowrap;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.chip i { width: 10px; height: 10px; border-radius: 50%; opacity: 0.3; transition: opacity 0.2s; }
.chip.on { color: var(--fg); border-color: rgba(160, 200, 255, 0.42); background: rgba(24, 40, 62, 0.82); }
.chip.on i { opacity: 1; }

/* dymek z nazwami, przypięty wybór, komunikaty */
#tip, #pin, #toast {
  position: fixed; z-index: 15; background: rgba(8, 14, 24, 0.88); border: 1px solid var(--line); border-radius: 14px;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); font-size: 14px;
}
#tip { padding: 4px; max-width: 88vw; }
#tip button { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: none; padding: 7px 9px; border-radius: 10px; text-align: left; }
#tip button:active { background: rgba(60, 90, 130, 0.5); }
#tip i, #pin i, #results i { flex: none; width: 10px; height: 10px; border-radius: 50%; }
#tip b, #pin b, #results b { font-weight: 600; }
#tip span { color: var(--muted); font-size: 12px; margin-left: auto; padding-left: 12px; white-space: nowrap; }
/* „schemat”: część odtworzona, nie z bazy anatomicznej */
.tag { flex: none; font-style: normal; font-size: 10.5px; font-weight: 600; letter-spacing: 0.04em; color: var(--warn); border: 1px solid rgba(255, 180, 84, 0.45); border-radius: 6px; padding: 1px 5px; line-height: 1.3; }
#pin { top: calc(var(--top) + 52px); left: 12px; right: 70px; padding: 0 0 6px 13px; display: flex; flex-direction: column; }
#pin .row { display: flex; align-items: center; gap: 9px; min-height: 44px; }
#pin b { flex: 0 1 auto; min-width: 0; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-height: 1.3; max-height: 2.6em; margin: 4px 0; }
#pin .x { margin-left: auto; flex: none; width: 44px; height: 44px; background: none; border: none; color: var(--muted); font-size: 16px; padding: 0; }
#pin .acts { display: flex; gap: 8px; padding-right: 10px; }
#pin .acts button { min-height: 36px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(22, 36, 56, 0.72); color: var(--fg); font-size: 13px; font-weight: 500; }
#pin .acts button[aria-pressed="true"], #pin .acts button[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
#pin .desc { margin: 8px 12px 2px 0; font-size: 13.5px; line-height: 1.5; color: var(--fg); max-height: 30vh; overflow-y: auto; }
#pin .desc .none { color: var(--muted); }
#pin .desc .note { display: block; margin-top: 6px; color: var(--warn); font-size: 12.5px; }
#toast { left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom) + 66px); padding: 10px 16px; max-width: 86vw; text-align: center; color: var(--fg); animation: rise 0.25s ease-out; pointer-events: none; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* panel */
#scrim { position: fixed; inset: 0; z-index: 24; background: rgba(0, 4, 10, 0.45); }
#sheet {
  position: fixed; z-index: 25; left: 0; right: 0; bottom: 0; max-height: 78vh; display: flex; flex-direction: column;
  background: var(--panel-solid); border-top: 1px solid var(--line); border-radius: 22px 22px 0 0;
  padding: 8px 14px calc(max(14px, env(safe-area-inset-bottom)) + 8px); animation: up 0.22s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.handle { width: 42px; height: 4px; border-radius: 2px; background: rgba(160, 200, 255, 0.3); margin: 2px auto 12px; }
.sheet-head { display: flex; gap: 8px; align-items: center; }
.field { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; background: rgba(22, 36, 56, 0.72); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px 0 14px; color: var(--muted); }
.field:focus-within { border-color: var(--accent); }
#q { flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--fg); background: none; border: none; padding: 11px 0; outline: none; -webkit-user-select: text; user-select: text; }
#q::-webkit-search-cancel-button { display: none; }
#qClear { flex: none; width: 44px; height: 44px; background: none; border: none; color: var(--muted); padding: 0; }
.sheet-label { display: flex; align-items: center; gap: 10px; margin: 16px 2px 9px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.link { background: none; border: none; color: var(--accent); font-size: 12px; text-transform: none; letter-spacing: 0; padding: 0; margin-left: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 16px 2px 4px; }
#found { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#results { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 90px; }
#results li { display: flex; align-items: center; gap: 9px; padding: 12px 4px; border-bottom: 1px solid rgba(160, 200, 255, 0.08); }
#results li:active { background: rgba(40, 62, 92, 0.5); }
#results li.grp { position: sticky; top: 0; z-index: 1; padding: 0; background: var(--panel-solid); border-bottom: 1px solid var(--line); }
#results li.grp button { display: flex; align-items: center; gap: 9px; width: 100%; min-height: 44px; padding: 8px 4px; background: none; border: none; text-align: left; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
#results li.grp button[aria-pressed="true"] { color: var(--accent); }
#results li.grp span { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--accent); }
#results li.more { padding: 0; }
#results li.more button { width: 100%; min-height: 44px; background: none; border: none; color: var(--accent); font-size: 14px; text-align: left; padding: 8px 23px; }
#results mark { background: none; color: var(--accent); }

/* ekran startowy i podpowiedzi */
#start, #tips, #about { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 24px; }
#start { background: radial-gradient(120% 80% at 50% 30%, #0c2238 0%, var(--bg) 70%); }
#tips, #about { background: rgba(0, 4, 10, 0.7); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.card { max-width: 420px; text-align: center; }
#tips .card, #about .card { text-align: left; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 20px; padding: 22px; }
#tips h2 { margin: 0 0 12px; font-size: 19px; }
#tips ul { margin: 0 0 18px; padding-left: 20px; color: var(--muted); line-height: 1.55; font-size: 14.5px; }
#tips li { margin-bottom: 8px; }
#tips b { color: var(--fg); }
#start h1 { font-size: clamp(30px, 10vw, 46px); font-weight: 700; letter-spacing: 0.08em; margin: 0 0 14px; }
#start h1 span { color: var(--accent); text-shadow: 0 0 24px rgba(92, 208, 255, 0.6); }
#start p { color: var(--muted); line-height: 1.6; font-size: 15px; margin: 0 0 24px; }
#go, #tipsOk, #aboutOk {
  font-size: 17px; font-weight: 600; padding: 15px 34px; border-radius: 999px; border: none;
  background: linear-gradient(180deg, #7bdcff, #3fb6f0); color: #03121d; box-shadow: 0 10px 40px rgba(63, 182, 240, 0.35);
}
#tipsOk, #aboutOk { width: 100%; font-size: 16px; padding: 13px; }
#go:disabled { display: none; }
#load { margin-top: 6px; color: var(--muted); font-size: 13px; }
.bar { height: 5px; border-radius: 3px; background: rgba(160, 200, 255, 0.14); overflow: hidden; margin-bottom: 10px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.3s; }
#err { color: var(--warn) !important; background: rgba(255, 180, 84, 0.08); border: 1px solid rgba(255, 180, 84, 0.3); border-radius: 12px; padding: 12px; margin-top: 16px !important; font-size: 14px !important; }
#start small { display: block; margin-top: 18px; color: var(--muted); font-size: 12px; line-height: 1.5; }
#demoLink { display: inline-block; margin-top: 14px; padding: 12px 8px; color: var(--accent); font-size: 15px; text-decoration: underline; text-underline-offset: 3px; }
#tips .tag { vertical-align: 1px; }

/* „Informacje, prywatność i licencje” */
#about { z-index: 50; }
#about .card { max-height: calc(100dvh - 48px); overflow-y: auto; font-size: 14px; line-height: 1.5; color: var(--muted); }
#about h2 { margin: 0 0 10px; font-size: 19px; color: var(--fg); }
#about h3 { margin: 16px 0 6px; font-size: 15px; color: var(--fg); }
#about p { margin: 0 0 8px; }
#about ul { margin: 0 0 16px; padding-left: 18px; }
#about b { color: var(--fg); }
#about a { color: #8ecbff; }
.about-link { display: block; margin: 10px 0; font-size: 13px; color: var(--muted); }
#tips .about-link { margin: 0 0 14px; }
