/* ---------------------------------------------------------- tokens */
:root {
  --paper: #efe9df;
  --card: #fffdf9;
  --ink: #2f2a26;
  --muted: #857c72;
  --line: #e2dbcf;
  --accent: #5b7f66;
  --accent-soft: #e9efe9;
  --warm-soft: #f6ecdc;
  --radius: 14px;
  --shadow: 0 2px 6px rgba(50, 40, 30, 0.08), 0 12px 32px rgba(50, 40, 30, 0.10);
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", Helvetica, Arial, sans-serif;
  --panel-w: 380px;
}

/* ---------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  overflow: hidden;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.3; }
ul, ol { margin: 0; padding-left: 20px; }
li { margin: 4px 0; }
p { margin: 6px 0; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------- 3D viewport */
.viewport { position: fixed; inset: 0; }
.viewport canvas { display: block; touch-action: none; }
.labels { position: absolute; top: 0; left: 0; pointer-events: none; overflow: hidden; }
.room-label {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--muted);
  background: rgba(255, 253, 249, 0.75);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  transform: translateY(14px);
}
.hotspot {
  pointer-events: auto;
  position: relative;
  display: block;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  font-family: inherit;
  transform: translateY(-10px);
}
.hs-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  transition: transform 0.15s, border-color 0.15s;
}
.hs-title {
  display: none;
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(calc(-50% + var(--label-dy, 0px)));
  margin-left: 6px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  line-height: 1.5;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  text-align: left;
}
.hotspot.flip .hs-title { left: auto; right: 100%; margin-left: 0; margin-right: 6px; }
.hs-desc, .hs-close { display: none; }
/* Selected pin with a description: the label opens into a small card. */
.hotspot.active .hs-title:has(.hs-desc) {
  white-space: normal;
  width: max-content;
  max-width: min(240px, 70vw);
  padding: 7px 26px 8px 11px;
  border-radius: 12px;
}
.hotspot.active .hs-desc {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(255, 253, 249, 0.82);
  max-height: 40vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.hs-desc > span { display: block; }
.hs-desc > span + span { margin-top: 3px; }
.hotspot.active .hs-close {
  display: block;
  position: absolute;
  top: 3px;
  right: 7px;
  font-size: 17px;
  line-height: 1;
  color: rgba(255, 253, 249, 0.7);
  cursor: pointer;
  padding: 2px 3px;
}
.hotspot.active .hs-close:hover { color: var(--paper); }
.hotspot:hover .hs-icon, .hotspot.active .hs-icon { transform: scale(1.12); border-color: var(--ink); }
.hotspot.tag .hs-icon { border-color: var(--ink); background: var(--paper); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.hotspot.tag .hs-icon::before { content: "📍"; transform: rotate(45deg); }
.hotspot.tag .hs-icon { font-size: 0; }
.hotspot.tag .hs-icon::before { font-size: 18px; }
.hotspot.tag:hover .hs-icon, .hotspot.tag.active .hs-icon { transform: rotate(-45deg) scale(1.12); background: var(--warm-soft); }
.hotspot.tag.draft .hs-icon { border-style: dashed; background: var(--warm-soft); }
.hotspot.tag.draft .hs-title { display: block; }
.hotspot.tag.occluded { opacity: 0.22; }
.hotspot.tag.occluded .hs-icon { box-shadow: none; }
.hotspot.tag.draggable { cursor: grab; touch-action: none; }
.hotspot.tag.dragging { cursor: grabbing; }
.hotspot.tag.dragging .hs-icon { transform: rotate(-45deg) scale(1.3); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3); }
.hotspot:hover .hs-title, .hotspot.active .hs-title { display: block; }

/* ---------------------------------------------------------- top bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 17px;
  background: rgba(255, 253, 249, 0.85);
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  background: rgba(255, 253, 249, 0.9);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 16px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.3;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.icon-btn:hover { background: var(--card); }

/* ---------------------------------------------------------- panel */
.panel {
  position: fixed;
  z-index: 15;
  background: var(--card);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  top: calc(60px + env(safe-area-inset-top));
  right: 16px;
  bottom: 16px;
  width: var(--panel-w);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { flex: 1; margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-head .icon-btn { box-shadow: none; background: none; border: 0; font-size: 15px; padding: 4px 6px; }
.list-item.active .li-icon { transform: scale(1.15); }
#btn-close { font-size: 22px; line-height: 1; }
.panel-search { padding: 10px 14px 0; }
.panel-search input {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
}
.li-snippet { display: block; color: var(--muted); font-size: 12px; line-height: 1.4; }
.panel-body { flex: 1; overflow-y: auto; padding: 14px 16px 20px; -webkit-overflow-scrolling: touch; }
.panel-body h3 { font-size: 16px; margin: 18px 0 6px; }
.panel-body h3:first-child { margin-top: 0; }
.where { margin: 0 0 8px; }

@media (max-width: 899px) {
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 45vh;
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .icon-btn .label { display: none; }
  .hs-icon { width: 34px; height: 34px; font-size: 17px; }

  /* Folded list: only the head bar stays, as a handle to unfold it. */
  .panel.collapsed { max-height: none; }
  .panel.collapsed .panel-search, .panel.collapsed .panel-body { display: none; }
  .panel.collapsed .panel-head { cursor: pointer; border-bottom: 0; }
  .panel.collapsed .panel-head h2::after { content: " ▴"; color: var(--muted); font-size: 13px; }
}

/* list */
.list-group { margin-bottom: 12px; }
.list-group .list-group { margin: 2px 0 6px 14px; padding-left: 10px; border-left: 2px solid var(--line); }
.list-room {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 6px 4px;
  margin: 4px 0 2px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.list-room:hover { background: var(--accent-soft); }
.depth-0 > .list-room { font-size: 14px; color: var(--ink); }
.list-room .chev { display: inline-block; width: 12px; transition: transform 0.15s; transform: rotate(90deg); color: var(--muted); font-weight: 400; }
.list-group.collapsed > .list-room .chev { transform: rotate(0deg); }
.list-room .count { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.list-group.collapsed > .group-body { display: none; }
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 8px 6px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.list-item:hover, .list-item.active { background: var(--accent-soft); }
.li-icon { width: 28px; text-align: center; font-size: 18px; }

/* detail blocks */
.kv { margin: 6px 0 0; display: grid; gap: 6px; }
.kv > div { display: grid; grid-template-columns: 5.5em 1fr; gap: 10px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.routine { margin: 0; display: grid; gap: 8px; }
.routine > div { display: grid; grid-template-columns: 3em 1fr; gap: 10px; font-size: 15px; }
.routine dt { font-family: var(--serif); font-weight: 600; }
.routine dd { margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 15px; }
ul.ticks, ul.crosses, ul.notes { list-style: none; padding: 0; }
ul.ticks li::before { content: "✓ "; color: var(--accent); font-weight: 700; }
ul.crosses li::before { content: "✗ "; color: var(--muted); font-weight: 700; }
ul.notes li { padding-left: 14px; position: relative; }
ul.notes li::before { content: "·"; position: absolute; left: 2px; font-weight: 700; color: var(--muted); }
ol.steps li { margin: 5px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 14px; padding: 3px 11px; border-radius: 999px; background: var(--warm-soft); }
.feed { display: flex; gap: 12px; padding: 6px 0; font-size: 15px; }
.feed-time { font-family: var(--serif); font-weight: 600; min-width: 6.5em; }
.feed small { display: block; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.vet .btn { margin: 4px 0; }
.zoomable { width: 100%; border-radius: 10px; margin: 0 0 10px; cursor: zoom-in; }

/* ---------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}
.btn-small { padding: 5px 10px; font-size: 14px; }
.copy {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--accent);
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  vertical-align: middle;
}

/* ---------------------------------------------------------- overlays */
.welcome {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(40, 32, 24, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.welcome-box {
  width: 100%;
  max-width: 520px;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: 0 18px 60px rgba(30, 20, 10, 0.35);
  padding: 22px 24px 24px;
}
.welcome .kicker { color: var(--muted); font-size: 13px; letter-spacing: 0.12em; margin: 0 0 6px; }
.welcome h1 { font-size: 26px; margin: 0 0 8px; }
.welcome-text p { font-size: 16px; line-height: 1.7; }
.wifi-card {
  display: flex;
  gap: 18px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 16px 0 14px;
  box-shadow: var(--shadow);
}
.wifi-info { flex: 1; min-width: 0; }
.wifi-card h2 { font-size: 18px; margin: 0 0 6px; }
.wifi-card .kv { margin: 0 0 6px; }
.wifi-card .kv > div { grid-template-columns: 3em 1fr; }
.wifi-card code { font-size: 16px; background: var(--paper); padding: 1px 6px; border-radius: 6px; }
.wifi-qr { width: 150px; flex-shrink: 0; }
.wifi-qr svg { width: 100%; height: auto; display: block; border-radius: 8px; background: #fff; }
@media (max-width: 480px) {
  .wifi-card { flex-direction: column; align-items: stretch; }
  .wifi-qr { width: 180px; align-self: center; }
}
.welcome .btn-primary { display: block; margin: 8px auto 0; min-width: 8em; }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); padding: 10px 22px; font-size: 16px; }

.dev-box {
  position: fixed;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 12;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  box-shadow: var(--shadow);
  max-width: min(440px, calc(100% - 32px));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dev-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dev-box code { font-size: 13px; }
.dev-readout:empty { display: none; }
.tag-form { display: flex; flex-direction: column; gap: 6px; }
.tag-form input, .tag-form textarea {
  font: inherit;
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
}
.tag-form .dev-row input { flex: 1; }
.dev-toggle { font-size: 13px; color: var(--muted); }
.dev-toggle.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.list-row { display: flex; align-items: center; gap: 4px; }
.list-row .list-item { flex: 1; }
.mini {
  border: 1px solid var(--line);
  background: none;
  color: var(--muted);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
}
.mini:hover { color: var(--ink); }

.lightbox { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.92); display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 50;
  white-space: nowrap;
}
.loading {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 18px;
  background: var(--paper);
}
