:root {
  --bg: #e9e6e0;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --line: rgba(40, 36, 30, 0.12);
  --text: #23211e;
  --muted: #6d6860;
  --accent: #2f5f7a;
  --accent-soft: rgba(47, 95, 122, 0.12);
  --accent-text: #ffffff;
  --shadow: 0 6px 24px rgba(30, 26, 20, 0.12), 0 1px 3px rgba(30, 26, 20, 0.08);
  --label-bg: rgba(255, 255, 255, 0.92);
  --label-text: #2a2723;
  --radius: 14px;
  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "맑은 고딕", "Noto Sans KR", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --panel: rgba(28, 30, 34, 0.86);
    --panel-solid: #1c1e22;
    --line: rgba(255, 255, 255, 0.1);
    --text: #ecebe8;
    --muted: #a3a09a;
    --accent: #7fb3cf;
    --accent-soft: rgba(127, 179, 207, 0.16);
    --accent-text: #0f1a20;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
    --label-bg: rgba(28, 30, 34, 0.9);
    --label-text: #ecebe8;
  }
}

:root[data-theme="dark"] {
  --bg: #15171a;
  --panel: rgba(28, 30, 34, 0.86);
  --panel-solid: #1c1e22;
  --line: rgba(255, 255, 255, 0.1);
  --text: #ecebe8;
  --muted: #a3a09a;
  --accent: #7fb3cf;
  --accent-soft: rgba(127, 179, 207, 0.16);
  --accent-text: #0f1a20;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --label-bg: rgba(28, 30, 34, 0.9);
  --label-text: #ecebe8;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: fixed;
  inset: 0;
}

#viewport {
  position: absolute;
  inset: 0;
  touch-action: none;
}

#viewport canvas {
  display: block;
  outline: none;
}

button {
  font: inherit;
  color: inherit;
}

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
}

/* ── 상단 ── */
.brand {
  top: 16px;
  left: 16px;
  padding: 12px 16px;
  max-width: 260px;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand p {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.modes {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  display: flex;
  gap: 2px;
  padding: 4px;
}

.modes button {
  white-space: nowrap;
  border: 0;
  background: transparent;
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}

.modes button:hover {
  color: var(--text);
}

.modes button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.toolbar {
  top: 16px;
  right: 16px;
  display: flex;
  gap: 2px;
  padding: 4px;
}

.tool {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
}

.tool:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.tool[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.tool:disabled {
  opacity: 0.4;
  cursor: default;
}

.tool svg,
.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ── 공간 목록 ── */
.rooms {
  top: 96px;
  left: 16px;
  width: 196px;
  max-height: calc(100% - 112px);
  overflow: auto;
  padding: 10px 6px 8px;
}

.rooms h2 {
  margin: 2px 10px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.rooms ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rooms li button {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 7px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 14px;
}

.rooms li button:hover {
  background: var(--accent-soft);
}

.rooms li button[aria-current="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.rooms li button[aria-current="true"] .area {
  color: inherit;
  opacity: 0.8;
}

.rooms .name small {
  font-size: 11.5px;
  color: var(--muted);
  margin-left: 4px;
}

.rooms li button[aria-current="true"] .name small {
  color: inherit;
  opacity: 0.8;
}

.rooms .area {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── 정보 카드 ── */
.info {
  right: 16px;
  bottom: 16px;
  width: 300px;
  padding: 14px 16px;
}

.info-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.info h3 {
  margin: 0;
  font-size: 16px;
}

#info-size {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#info-note {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.55;
}

.icon-btn {
  border: 0;
  background: transparent;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--text);
}

/* ── 이름표 ── */
.room-label {
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--label-bg);
  color: var(--label-text);
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
  transition: transform 0.12s;
}

.room-label:hover {
  transform: scale(1.06);
}

.room-label .a {
  font-weight: 500;
  color: var(--muted);
  margin-left: 4px;
  font-size: 11.5px;
}

.room-label.minor {
  font-size: 11px;
  padding: 3px 7px;
  opacity: 0.88;
}

.labels-off .room-label {
  display: none;
}

/* ── 걷기 안내·조이스틱 ── */
.hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(20, 20, 22, 0.66);
  color: #fff;
  font-size: 12.5px;
  white-space: nowrap;
  pointer-events: none;
}

.joystick {
  position: absolute;
  left: 22px;
  bottom: 90px;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(20, 20, 22, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.35);
  touch-action: none;
}

.joystick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* ── 로딩 ── */
.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: var(--bg);
  color: var(--muted);
  font-size: 14px;
  transition: opacity 0.4s;
}

.loading.done {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 개발용 사진 비교 화면(?photo=) */
.photo-frame .panel,
.photo-frame .hint,
.photo-frame .loading,
.photo-frame .room-label {
  display: none !important;
}

.noscript {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
}

/* ── 좁은 화면 ── */
@media (max-width: 1080px) {
  .tool span {
    display: none;
  }

  .tool {
    padding: 8px;
  }
}

@media (max-width: 760px) {
  .brand {
    top: 12px;
    left: 12px;
    padding: 8px 12px;
    max-width: calc(100% - 200px);
  }

  .brand h1 {
    font-size: 15px;
  }

  .brand p {
    font-size: 11.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .toolbar {
    top: 12px;
    right: 12px;
  }

  .modes {
    top: 70px;
  }

  .modes button {
    padding: 7px 16px;
    font-size: 13.5px;
  }

  .rooms {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-height: none;
    padding: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .rooms::-webkit-scrollbar {
    display: none;
  }

  .rooms h2 {
    display: none;
  }

  .rooms ul {
    display: flex;
    gap: 4px;
  }

  .rooms li button {
    width: auto;
    padding: 8px 12px;
    font-size: 13.5px;
    white-space: nowrap;
  }

  .rooms .area {
    display: none;
  }

  .info {
    left: 12px;
    right: 12px;
    bottom: 70px;
    width: auto;
    padding: 12px 14px;
  }

  #info-note {
    display: none;
  }

  .hint {
    top: 122px;
    bottom: auto;
    font-size: 11.5px;
    white-space: normal;
    width: max-content;
    max-width: calc(100% - 24px);
    text-align: center;
  }

  .joystick {
    left: 16px;
    bottom: 80px;
  }

  body.walking .info {
    display: none;
  }

  .room-label.minor {
    display: none;
  }

  .room-label {
    font-size: 11.5px;
    padding: 3px 8px;
  }
}
