:root {
  --accent: #111111;                 /* black and white: black for selected and primary, white panels */
  --accent-ink: #ffffff;
  --accent-soft: rgba(17, 17, 17, 0.07);
  --ink: #111111;
  --ink-2: #444444;
  --ink-3: #8c8c8c;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --line: rgba(0, 0, 0, 0.10);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.14), 0 1px 2px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --gap: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --toolbar-h: 64px;
  --hud-top: calc(var(--gap) + var(--safe-t));
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #ececec;
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.labels-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

/* ---------- panels and buttons ---------- */
.panel {
  background: var(--panel);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.icon-btn {
  width: 44px; height: 44px;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 10px; background: transparent;
  cursor: pointer; color: var(--ink);
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn.small { width: 44px; height: 44px; }
.icon-btn svg, .tool svg { width: 22px; height: 22px; }
button:focus-visible, canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; z-index: 20;
  top: calc(var(--gap) + var(--safe-t));
  left: calc(var(--gap) + var(--safe-l));
  right: calc(var(--gap) + var(--safe-r));
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brandbox {
  display: flex; align-items: center; gap: 6px; overflow: hidden;
  padding: 4px 14px 4px 4px; min-height: 52px; min-width: 0;
}
.brand-logo { height: 22px; width: auto; flex: none; margin: 0 4px 0 2px; }
.titles { min-width: 0; padding-left: 10px; border-left: 1px solid var(--line); }
.title { font-size: 15px; font-weight: 600; letter-spacing: 0.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brandbox .icon-btn { flex: none; }
.studio { overflow: hidden; text-overflow: ellipsis; font-size: 11px; font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-2); margin-top: 1px; white-space: nowrap; }

.top-right { display: flex; gap: 8px; align-items: flex-start; flex-shrink: 0; }
.seg { display: inline-flex; padding: 4px; gap: 2px; }
.seg button {
  min-width: 44px; height: 44px; padding: 0 12px;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer;
  font-weight: 500; white-space: nowrap; color: var(--ink);
}
.seg button:hover:not([aria-pressed="true"]):not(:disabled) { background: var(--accent-soft); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg button:disabled { opacity: 0.35; cursor: default; }
.seg .short { display: none; }

.lang { position: relative; z-index: 2; } /* the menu opens over the chips below */
.lang-btn {
  width: 52px; height: 52px; border-radius: var(--radius);
  font-weight: 600; font-size: 13px; letter-spacing: 0.04em; cursor: pointer;
}
.lang-menu {
  position: absolute; right: 0; top: 58px; padding: 4px; min-width: 150px;
  display: flex; flex-direction: column;
}
.lang-menu button {
  height: 44px; border: 0; background: transparent; border-radius: 10px;
  text-align: left; padding: 0 12px; cursor: pointer;
}
.lang-menu button:hover { background: var(--accent-soft); }
.lang-menu button[aria-checked="true"] { color: var(--accent); font-weight: 600; }

.chip {
  position: absolute; right: 52px; top: 62px;
  height: 44px; padding: 0 14px 0 10px; border-radius: 12px;
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500;
}
.chip svg { width: 20px; height: 20px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
#app:not([data-mode="doll"]) .chip { display: none; }
.help-btn { position: absolute; right: 0; top: 62px; border-radius: 12px; background: var(--panel); }
.help-btn:hover { background: var(--panel-solid); }
.help-btn svg { width: 21px; height: 21px; }

/* ---------- rooms panel ---------- */
.rooms {
  position: fixed; z-index: 15;
  left: calc(var(--gap) + var(--safe-l));
  top: calc(76px + var(--safe-t));
  width: 280px;
  max-height: calc(100% - 76px - var(--toolbar-h) - 40px - var(--safe-t) - var(--safe-b));
  display: flex; flex-direction: column;
  transition: transform 0.28s cubic-bezier(.2,.8,.2,1), opacity 0.2s;
}
.rooms:not(.open) { transform: translateX(calc(-100% - 24px)); opacity: 0; pointer-events: none; }
.rooms-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 6px 4px 16px; }
.rooms-head h2 { font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-2); margin: 0; }
.rooms-list { overflow-y: auto; padding: 0 6px 8px; overscroll-behavior: contain; }
.level-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 12px 10px 4px; font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.level-head .a { font-weight: 500; color: var(--ink-2); }
.room-item {
  width: 100%; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 0; background: transparent; border-radius: 10px; padding: 8px 10px; cursor: pointer; text-align: left;
}
.room-item:hover { background: var(--accent-soft); }
.room-item .n { font-weight: 500; }
.room-item .a { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.room-item[aria-current="true"] { background: var(--accent); color: var(--accent-ink); }
.room-item[aria-current="true"] .a { color: rgba(255,255,255,0.8); }
.sheet-handle { display: none; }

/* ---------- toolbar ---------- */
.toolbar {
  position: fixed; z-index: 20;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--gap) + var(--safe-b));
  display: flex; align-items: center; gap: 2px; padding: 5px;
  border-radius: 18px;
}
.tool {
  min-width: 68px; height: 54px; padding: 4px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: transparent; border-radius: 13px; cursor: pointer; color: var(--ink);
}
.tool .lbl { font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.tool:hover:not([aria-pressed="true"]) { background: var(--accent-soft); }
.tool[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.tool-sep { width: 1px; height: 30px; background: var(--line); margin: 0 4px; }

/* ---------- walk HUD, minimap, joystick ---------- */
.hud {
  position: fixed; z-index: 12; left: 50%; transform: translateX(-50%);
  top: var(--hud-top);
  padding: 9px 16px; border-radius: 999px; font-weight: 500; white-space: nowrap;
  display: flex; gap: 8px; align-items: baseline;
}
.hud .lv { color: var(--ink-2); font-size: 12px; }
.minimap {
  position: fixed; z-index: 12;
  right: calc(var(--gap) + var(--safe-r));
  bottom: calc(var(--toolbar-h) + 2 * var(--gap) + 8px + var(--safe-b));
  width: 188px; height: 188px; padding: 6px; overflow: hidden;
}
.minimap canvas { width: 100%; height: 100%; display: block; border-radius: 9px; cursor: crosshair; touch-action: none; }

.joystick { position: fixed; inset: 0; z-index: 11; pointer-events: none; }
.joy-base {
  position: absolute; width: 116px; height: 116px; margin: -58px 0 0 -58px; border-radius: 50%;
  background: rgba(250, 250, 246, 0.28); border: 1.5px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: opacity 0.2s;
}
.joystick:not(.active) .joy-base { opacity: 0.55; }
.joy-knob {
  position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255,255,255,0.85);
}

/* ---------- labels ---------- */
.room-label {
  pointer-events: none;
  display: flex; flex-direction: column; align-items: center;
  min-height: 40px; padding: 6px 12px; border-radius: 12px;
  background: rgba(252, 252, 249, 0.9);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--line); box-shadow: 0 3px 12px rgba(0, 0, 0, 0.14);
  font-family: var(--font); color: var(--ink); line-height: 1.2; white-space: nowrap;
  transition: opacity 0.2s, background 0.15s, color 0.15s;
}
.room-label .n { font-size: 12.5px; font-weight: 600; }
.room-label .a { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.room-label.hover, .room-label.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.room-label.hover .a, .room-label.active .a { color: rgba(255,255,255,0.82); }
.room-label.occluded { opacity: 0; }
.walk-marker { pointer-events: none; }

/* ---------- hint, toast, sheet ---------- */
.hint {
  position: fixed; z-index: 25; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--toolbar-h) + 2 * var(--gap) + 8px + var(--safe-b));
  width: min(420px, calc(100% - 2 * var(--gap)));
  padding: 14px 14px 14px 18px; display: flex; gap: 14px; align-items: center;
  animation: rise 0.3s cubic-bezier(.2,.8,.2,1);
  pointer-events: none; /* gestures on the card reach the canvas; only its button is live */
}
.hint .btn { pointer-events: auto; }
/* touch Walk: keep the card off the joystick and the minimap */
#app[data-mode="walk"] .hint.touch { top: calc(var(--hud-top) + 56px); bottom: auto; }
.hint ul { margin: 0; padding: 0; list-style: none; flex: 1; display: grid; gap: 6px; font-size: 13.5px; line-height: 1.35; }
.hint li { display: flex; gap: 10px; align-items: flex-start; }
.hint li::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-top: 6px; }
.btn {
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; white-space: nowrap;
}
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid rgba(17,17,17,0.30); }
.toast {
  position: fixed; z-index: 40; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--toolbar-h) + 2 * var(--gap) + 16px + var(--safe-b));
  background: rgba(29, 36, 33, 0.92); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-weight: 500; box-shadow: var(--shadow); animation: rise 0.25s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.sheet { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(18, 26, 22, 0.32); }
.sheet-card {
  position: relative; width: min(420px, calc(100% - 32px)); padding: 10px 18px 20px;
  background: rgba(250, 250, 246, 0.94);
}
.sheet-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-top h2 { font-size: 17px; font-weight: 600; margin: 8px 0; }
.sheet-body p { margin: 8px 0; line-height: 1.45; color: var(--ink-2); }
.ar-choice {
  width: 100%; min-height: 64px; margin-top: 10px; display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line); background: #fff;
  text-decoration: none; color: var(--ink);
}
.ar-choice:hover { border-color: var(--accent); }
.ar-choice .t { font-weight: 600; display: block; }
.ar-choice .s { font-size: 12.5px; color: var(--ink-2); display: block; margin-top: 2px; }
.ar-choice .ico { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.ar-choice .ico svg { width: 22px; height: 22px; }
.qr { display: grid; place-items: center; margin: 12px auto 6px; width: 212px; height: 212px; background: #fff; border-radius: 14px; border: 1px solid var(--line); }
.qr svg, .qr img { width: 188px; height: 188px; display: block; }
.note { font-size: 12.5px; padding: 10px 12px; border-radius: 10px; background: #f3efe4; color: #6b5a2e; margin-top: 12px; line-height: 1.4; }
.url-field {
  width: 100%; min-height: 44px; margin-top: 8px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); font: inherit; font-size: 13px; background: #fff; color: var(--ink);
}
.sheet-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- loading ---------- */
.loading {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: radial-gradient(120% 90% at 50% 20%, #ffffff 0%, #ececec 60%, #dedede 100%);
  transition: opacity 0.5s ease, visibility 0.5s;
}
.loading.done { opacity: 0; visibility: hidden; }
.loading-inner { text-align: center; width: min(320px, 80vw); }
.loading-mark {
  width: 46px; height: 46px; margin: 0 auto 18px; border-radius: 12px; background: var(--accent);
  position: relative;
}
.loading-mark::after {
  content: ""; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 23V14l8-6 8 6v9z' fill='none' stroke='white' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat;
}
.loading-logo { display: block; height: 44px; width: auto; margin: 0 auto 16px; }
.loading-title { font-size: 24px; font-weight: 600; letter-spacing: 0.005em; }
.loading-studio { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2); margin-top: 4px; }
.loading-bar { height: 3px; border-radius: 3px; background: rgba(29,36,33,0.1); margin: 26px 0 12px; overflow: hidden; }
.loading-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.loading.indeterminate .loading-bar span { width: 30%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.loading-text { font-size: 13px; color: var(--ink-2); min-height: 18px; }
.loading.error .loading-text { color: #8a2f20; }

/* ---------- mode-specific ---------- */
#app[data-mode="walk"] #stage canvas { cursor: pointer; }
#app[data-mode="walk"] #stage canvas.dragging { cursor: grabbing; }
#app[data-mode="plan"] #stage canvas { cursor: move; }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  :root { --gap: 10px; --toolbar-h: 58px; }
  .brandbox { padding-right: 10px; min-height: 48px; }
  .title {
    font-size: 14px; line-height: 1.15; white-space: normal; overflow-wrap: anywhere;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  }
  .studio { text-transform: none; letter-spacing: 0.02em; }
  .seg button { padding: 0 8px; }
  .top-right { gap: 6px; }
  .seg .full { display: none; }
  .seg .short { display: inline; }
  .lang-btn { width: 48px; height: 52px; }
  .chip, .help-btn { top: 60px; }
  .toolbar { left: calc(var(--gap) + var(--safe-l)); right: calc(var(--gap) + var(--safe-r)); transform: none; justify-content: space-between; padding: 4px; }
  .tool { min-width: 0; flex: 1; height: 50px; padding: 4px 2px; }
  .tool .lbl { font-size: 10.5px; }
  .tool-sep { margin: 0 1px; }
  :root { --hud-top: calc(70px + var(--safe-t)); }
  .hud { font-size: 13px; padding: 8px 14px; }
  .minimap { width: 128px; height: 128px; padding: 4px; }
  .room-label { min-height: 30px; padding: 5px 10px; border-radius: 10px; }
  .room-label::after { inset: -7px -4px; }
  .room-label .n { font-size: 11.5px; }
  .room-label .a { display: none; }
  .room-label.active .a { display: block; }
  .sheet { place-items: end center; }
  .sheet-card { width: 100%; border-radius: 20px 20px 0 0; padding-bottom: calc(20px + var(--safe-b)); }
}
/* rooms list as a bottom sheet: phones, also held sideways (keep in sync with rooms-panel.js) */
@media (max-width: 640px), (pointer: coarse) and (max-height: 500px) {
  .rooms {
    left: 0; right: 0; top: auto; bottom: 0; width: auto;
    max-height: 64%; border-radius: 20px 20px 0 0; z-index: 30;
    padding-bottom: var(--safe-b);
  }
  .rooms:not(.open) { transform: translateY(105%); }
  .sheet-handle { display: block; width: 40px; height: 4px; border-radius: 4px; background: rgba(29,36,33,0.2); margin: 8px auto 0; }
}
@media (max-height: 500px) {
  .minimap { width: 128px; height: 128px; padding: 4px; }
}
@media (max-width: 380px) {
  .brandbox { gap: 2px; padding-right: 8px; }
  .lang-btn { width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
