:root {
  color-scheme: dark;
  --ink: #f1eee8;
  --dim: #b5b2ab;
  --panel: rgba(20, 22, 26, 0.72);
  --line: rgba(255, 255, 255, 0.13);
  --accent: #c9d6bf;
  --gap: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --plan-frei: 195px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #14161a; overflow: hidden; font: 14px/1.4 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif; color: var(--ink); -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
#app { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
canvas { display: block; touch-action: none; }
[hidden] { display: none !important; }
button, select, input { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 8px 12px; border-radius: 8px; min-height: 36px; white-space: nowrap; user-select: none; -webkit-user-select: none; transition: background-color .15s ease, color .15s ease; }
@media (hover: hover) { button:hover { background: rgba(255, 255, 255, 0.1); } }
button.on { background: var(--accent); color: #17191c; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: default; }

#fade { position: fixed; inset: 0; background: #0d0e10; opacity: 0; pointer-events: none; transition: opacity .18s ease; z-index: 5; }
#fade.on { opacity: 1; }

#load { position: fixed; inset: 0; display: grid; place-items: center; background: #14161a; z-index: 20; transition: opacity .45s ease; }
#load.gone { opacity: 0; pointer-events: none; }
#load .inner { width: min(320px, 80vw); }
#load h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
#load p { color: var(--dim); margin: 0 0 14px; }
.track { height: 3px; background: rgba(255, 255, 255, 0.14); border-radius: 2px; overflow: hidden; }
#loadBar { height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }

#top { position: fixed; left: var(--gap); right: var(--gap); top: calc(var(--gap) + var(--safe-t)); display: flex; justify-content: space-between; align-items: flex-start; gap: var(--gap); pointer-events: none; z-index: 6; }
#title, #modes, #timePanel, #roofBtn, #tourbar, #hint { background: var(--panel); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 12px; }
#title { padding: 8px 12px; font-weight: 600; min-height: 38px; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#modes { display: flex; gap: 2px; padding: 3px; pointer-events: auto; }

/* Grundriss: ohne Weichzeichner, damit die Karte auf dem Handy keine Bildrate kostet */
#plan { position: fixed; left: var(--gap); top: calc(var(--gap) + 46px + var(--safe-t)); width: clamp(200px, 26vw, 340px); padding: 6px; background: rgba(20, 22, 26, 0.9); border: 1px solid var(--line); border-radius: 12px; z-index: 6; display: block; min-width: 0; min-height: 0; cursor: zoom-in; transition: width .2s ease, background-color .15s ease; }
#plan.gross { width: min(760px, calc(100vw - 2 * var(--gap)), calc((100vh - 90px) * 2.2)); width: min(760px, calc(100vw - 2 * var(--gap)), calc((100dvh - 90px) * 2.2)); cursor: zoom-out; }
body[data-mode=tour] #plan.gross { width: min(760px, calc(100vw - 2 * var(--gap)), calc((100vh - var(--plan-frei)) * 2.2)); width: min(760px, calc(100vw - 2 * var(--gap)), calc((100dvh - var(--plan-frei)) * 2.2)); }
@media (hover: hover) { #plan:hover { background: rgba(30, 33, 38, 0.94); } }
#planView { position: relative; display: block; overflow: hidden; border-radius: 7px; }
#planView > svg { display: block; width: 100%; height: auto; }
#planView .platte { fill: rgba(255, 255, 255, 0.07); }
#planView .terrasse { fill: rgba(255, 255, 255, 0.04); }
#planView .r { fill: transparent; transition: fill .2s ease; }
#planView .r.on { fill: rgba(201, 214, 191, 0.46); }
#planView .r.ziel { fill: rgba(201, 214, 191, 0.24); }
#planView .r.on.ziel { fill: rgba(201, 214, 191, 0.58); }
/* Kopfzeile der grossen Karte: Hinweis und Minus zum Verkleinern */
#planKopf { display: none; align-items: center; justify-content: space-between; gap: 10px; padding: 0 0 6px 6px; }
#plan.gross #planKopf { display: flex; }
#planHint { font-size: 12px; color: var(--dim); text-align: left; white-space: normal; }
#planZu { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); color: var(--ink); cursor: pointer; transition: background-color .15s ease, transform .12s ease; }
#planZu svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
#planZu:active { transform: scale(.92); }
@media (hover: hover) { #planZu:hover { background: rgba(255, 255, 255, 0.2); } }
@media (pointer: coarse) { #planZu { width: 36px; height: 36px; } }
#planView .moebel { fill: rgba(255, 255, 255, 0.11); }
#planView .stufen, #planView .aufzug, #planView .gelaender, #planView .fenster, #planView .tueren { fill: none; vector-effect: non-scaling-stroke; stroke-width: 1px; }
#planView .stufen, #planView .aufzug { stroke: rgba(241, 238, 232, 0.42); }
#planView .gelaender { stroke: rgba(241, 238, 232, 0.5); stroke-dasharray: 3 2; }
#planView .fenster { stroke: #9fc3d6; }
#planView .waende { fill: var(--ink); }
#planView .tueren { stroke: rgba(241, 238, 232, 0.55); display: none; }
#planView text { text-rendering: geometricPrecision; }
#planView .legende { display: none; fill: var(--dim); }
#planView .legende path { fill: none; stroke: var(--dim); stroke-width: 1px; vector-effect: non-scaling-stroke; }
#planView .namen { display: none; fill: var(--ink); text-anchor: middle; paint-order: stroke; stroke: rgba(20, 22, 26, 0.75); stroke-width: 0.14em; stroke-linejoin: round; }
#planView .namen .klein { font-size: 0.86em; }
#plan.gross .tueren, #plan.gross .namen, #plan.gross .legende { display: inline; }
#plan.eng .namen .klein, #plan.eng .namen .lang { display: none; }
#planMarker { position: absolute; left: -44px; top: -44px; width: 88px; height: 88px; will-change: transform; pointer-events: none; }
#planMarker svg { display: block; width: 100%; height: 100%; overflow: visible; }
#planMarker .punkt { fill: #fff; stroke: #17191c; stroke-width: 2.5px; }
#planMarker.aussen .punkt { fill: #17191c; stroke: #fff; }
@media (max-height: 620px) and (min-width: 721px) { body[data-mode=model] #plan { display: none; } }

#timePanel { position: fixed; right: var(--gap); top: calc(var(--gap) + 58px + var(--safe-t)); width: 270px; padding: 12px; z-index: 6; }
#timePanel label { display: flex; justify-content: space-between; color: var(--dim); margin-bottom: 4px; }
#timePanel output { color: var(--ink); font-variant-numeric: tabular-nums; }
#timePanel input[type=range] { width: 100%; margin: 0 0 12px; accent-color: var(--accent); height: 28px; }
#timePanel select { width: 100%; padding: 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); }
#timePanel option { background: #1c1e22; }
#timePanel .note { color: var(--dim); font-size: 12px; margin: 8px 0 0; }

/* Dach abnehmen: ein einzelner Schalter unten in der Mitte, das Dach im Symbol hebt sich mit */
#roofBtn { position: fixed; left: 50%; bottom: calc(var(--gap) + 8px + var(--safe-b)); transform: translateX(-50%); z-index: 6; display: flex; align-items: center; gap: 9px; padding: 10px 20px 10px 15px; border-radius: 999px; font-weight: 600; letter-spacing: .01em; box-shadow: 0 8px 28px rgba(0, 0, 0, .28); transition: background-color .2s ease, color .2s ease, transform .16s ease; }
#roofBtn svg { width: 21px; height: 21px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
#roofBtn .dach { transition: transform .45s cubic-bezier(.3, .7, .2, 1); }
#roofBtn[aria-pressed=true] { background: var(--accent); color: #17191c; }
#roofBtn[aria-pressed=true] .dach { transform: translate(2.5px, -4px) rotate(8deg); transform-origin: 12px 8px; }
#roofBtn:active { transform: translateX(-50%) scale(.96); }
@media (hover: hover) { #roofBtn:hover { background: rgba(40, 43, 49, 0.86); } #roofBtn[aria-pressed=true]:hover { background: #d6e1cd; } }

#tourbar { position: fixed; left: 50%; bottom: calc(var(--gap) + var(--safe-b)); transform: translateX(-50%); width: min(960px, calc(100vw - 2 * var(--gap))); padding: 8px; z-index: 6; }
#chips { display: flex; gap: 2px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; scrollbar-width: none; border-bottom: 1px solid var(--line); }
#chips::-webkit-scrollbar { display: none; }
#chips button { flex: 0 0 auto; white-space: nowrap; font-size: 13px; color: var(--dim); min-height: 30px; padding: 4px 10px; }
#chips button.on { color: #17191c; }
#tourbar .row { display: flex; align-items: center; gap: 4px; }
#tourSlider { flex: 1; min-width: 40px; accent-color: var(--accent); height: 30px; }
#tourTime { color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; padding: 0 6px; font-size: 13px; }
#tourPlay { min-width: 66px; }

#joy { position: fixed; left: 26px; bottom: calc(30px + var(--safe-b)); width: 128px; height: 128px; border-radius: 50%; background: rgba(20, 22, 26, 0.42); border: 1px solid var(--line); z-index: 6; touch-action: none; display: grid; place-items: center; }
#knob { width: 54px; height: 54px; border-radius: 50%; background: rgba(241, 238, 232, 0.86); box-shadow: 0 2px 10px rgba(0, 0, 0, .35); pointer-events: none; }

#hint { position: fixed; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%); padding: 8px 14px; z-index: 6; max-width: calc(100vw - 2 * var(--gap)); text-align: center; pointer-events: none; }
body[data-mode=walk] #hint { bottom: calc(26px + var(--safe-b)); }
#hud { position: fixed; left: 12px; bottom: 10px; opacity: .7; pointer-events: none; font-size: 12px; z-index: 6; }

body[data-mode=shot] #plan, body[data-mode=load] #plan, body[data-mode=shot] #top, body[data-mode=shot] #timePanel, body[data-mode=shot] #roofBtn, body[data-mode=shot] #tourbar, body[data-mode=shot] #joy, body[data-mode=shot] #hint, body[data-mode=load] #top { display: none; }

@media (max-width: 720px) {
  #title { max-width: 40vw; font-size: 13px; padding: 8px 10px; }
  #modes button { padding: 8px 9px; }
  #timePanel { left: var(--gap); right: var(--gap); width: auto; }
  #tourbar .row { flex-wrap: wrap; }
  #tourSlider { order: -1; flex-basis: 100%; }
  #tourBack, #tourFwd { display: none; }
  #tourClose { margin-left: auto; }
  body[data-mode=walk] #hint { bottom: calc(170px + var(--safe-b)); }
}
@media (pointer: coarse) {
  button { min-height: 44px; min-width: 44px; }
  :root { --plan-frei: 215px; }
  #plan { top: calc(var(--gap) + 58px + var(--safe-t)); min-height: 0; min-width: 0; }
  input[type=range] { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) { #fade, #load, button, #plan, #planView .r, #roofBtn .dach { transition: none; } }
