:root {
  --bg: #f3f3f2;
  --panel: rgba(255, 255, 255, 0.86);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --active: #1d1d1f;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --r: 12px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px;
  --t-xs: 11px; --t-s: 13px; --t-m: 15px; --t-l: 17px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg);
  font-family: var(--font); color: var(--text);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
#app, #app canvas { position: fixed; inset: 0; display: block; touch-action: none; }
#app canvas { width: 100%; height: 100%; outline: none; }
.labels { position: fixed !important; inset: 0; pointer-events: none; }
a { color: #0066cc; }

.panel {
  background: var(--panel);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.title {
  position: fixed; top: calc(var(--s4) + var(--safe-t)); left: var(--s4);
  font-size: var(--t-l); font-weight: 600; letter-spacing: -0.01em;
  pointer-events: none;
}

/* toolbar */
#toolbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--s4) + var(--safe-b));
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s1); border-radius: 16px;
  max-width: calc(100vw - 2 * var(--s3));
}
#toolbar .row { display: flex; align-items: center; gap: var(--s1); }
button, select {
  font: inherit; font-size: var(--t-s); color: var(--text);
  border: 0; background: transparent; cursor: pointer;
  height: 36px; border-radius: 10px; padding: 0 var(--s3);
}
button:focus-visible, select:focus-visible { outline: 2px solid #0066cc; outline-offset: 2px; }
.seg { display: flex; background: rgba(0, 0, 0, 0.05); border-radius: 12px; padding: 2px; }
.seg button { height: 32px; font-weight: 500; color: var(--muted); }
.seg button[aria-pressed="true"] { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }
.toggle { color: var(--muted); }
.toggle[aria-pressed="true"] { color: var(--text); background: rgba(0, 0, 0, 0.06); }
.select { position: relative; display: block; }
.select select {
  -webkit-appearance: none; appearance: none; padding-right: 26px; max-width: 168px;
  background: rgba(0, 0, 0, 0.05);
}
.select::after {
  content: ""; position: absolute; right: 11px; top: 50%; width: 6px; height: 6px; margin-top: -5px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg); pointer-events: none;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (hover: hover) { button:hover { color: var(--text); } }

/* room labels */
.room-label {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 3px 8px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.82); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  font-size: var(--t-xs); line-height: 1.25; white-space: nowrap;
}
.room-label b { font-weight: 600; }
.room-label span { color: var(--muted); }

/* captions / pills / hints */
#caption, #roompill, #hint {
  position: fixed; left: 50%; transform: translate(-50%, -6px);
  opacity: 0; transition: opacity .35s ease, transform .35s ease; pointer-events: none;
  border-radius: 999px; white-space: nowrap;
}
#caption { top: calc(56px + var(--safe-t)); padding: var(--s2) var(--s4); font-size: var(--t-m); display: flex; gap: var(--s3); align-items: baseline; }
#caption span { font-size: var(--t-s); color: var(--muted); }
#caption b { font-weight: 600; }
#roompill { top: calc(56px + var(--safe-t)); padding: 6px var(--s3); font-size: var(--t-s); font-weight: 600; }
#hint { bottom: calc(76px + var(--safe-b)); padding: var(--s2) var(--s4); font-size: var(--t-s); color: var(--muted); white-space: normal; text-align: center; max-width: calc(100vw - 32px); width: max-content; }
.show { opacity: 1 !important; transform: translate(-50%, 0) !important; }

/* joystick (walk mode on touch screens) */
#joystick {
  position: fixed; left: var(--s5); bottom: calc(96px + var(--safe-b));
  width: 112px; height: 112px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.55); border: 1px solid var(--line); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  display: none; touch-action: none;
}
#joystick .knob {
  position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
@media (pointer: coarse) { body[data-mode="walk"] #joystick { display: block; } }

#loading {
  position: fixed; inset: 0; display: grid; place-items: center;
  font-size: var(--t-m); color: var(--muted); background: var(--bg); text-align: center; padding: var(--s5);
}

/* narrow screens: two-row toolbar */
@media (max-width: 560px) {
  #toolbar { flex-direction: column; align-items: stretch; gap: var(--s1); width: calc(100vw - 2 * var(--s3)); }
  .seg button { flex: 1; }
  #toolbar .row { justify-content: space-between; }
  .select { flex: 1; }
  .select select { max-width: none; width: 100%; }
  #hint { bottom: calc(124px + var(--safe-b)); }
  #joystick { bottom: calc(132px + var(--safe-b)); }
  .title { font-size: var(--t-m); }
  .room-label { font-size: 10px; padding: 2px 6px; border-radius: 6px; }
}
@media (prefers-reduced-motion: reduce) { #caption, #roompill, #hint { transition: none; } }
