:root {
  --ink: #1f2933;
  --muted: #6b7785;
  --card: rgba(255, 255, 255, 0.9);
  --line: rgba(31, 41, 51, 0.1);
  --accent: #d97757;
  --idle: #9aa5b1;
  --working: #3fa9f5;
  --blocked: #e5484d;
  --review: #f5b942;
  --done: #46c06e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Microsoft JhengHei', 'PingFang TC', 'Noto Sans TC', sans-serif;
  color: var(--ink);
  background: #cfe8f5;
}

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }
.label-layer { position: absolute; top: 0; left: 0; pointer-events: none; }

/* 左側面板 */
#panel {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--card);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(31, 41, 51, 0.15);
  overflow: hidden;
}
#panel h1 { margin: 0; font-size: 20px; }
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.collapse-btn {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
/* 收起後只留標題、整體進度與請示按鈕，把畫面讓給 3D 辦公室；手機版面板貼底，只有桌機要放掉 bottom */
@media (min-width: 701px) {
  #panel.collapsed { bottom: auto; }
}
#panel.collapsed .sub,
#panel.collapsed #member-list,
#panel.collapsed #faceid-btn,
#panel.collapsed #conn { display: none; }
#panel .sub { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

.overall-row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.bar { height: 8px; background: rgba(31, 41, 51, 0.08); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width 0.6s; }

.revit-line { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* Claude 用量：5 小時工作階段、每週 */
.claude-usage { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.claude-usage .overall-row { font-size: 12px; margin-bottom: 4px; }
.claude-usage small { display: block; margin-top: 3px; font-size: 11px; color: var(--muted); }

/* 3D 場景裡 Revit 跑步機的看板 */
.station-tag {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  max-width: 220px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--idle);
  border-radius: 10px;
  font-size: 12px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(31, 41, 51, 0.15);
}
.station-tag.busy { border-color: #1d4f91; }
.station-tag small { color: var(--muted); }
.revit-line b { color: var(--ink); }

/* 右上角音樂、音效開關 */
#sound-ctrl {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  display: flex;
  gap: 6px;
}
#sound-ctrl button {
  border: 0;
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(31, 41, 51, 0.15);
  cursor: pointer;
}
#sound-ctrl button.off { color: var(--muted); background: rgba(255, 255, 255, 0.6); }

.ask-btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  animation: pulse 1.6s ease-in-out infinite;
}

#member-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#member-list li {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 4px 8px;
  align-items: center;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
}
#member-list li:hover, #member-list li.active { background: rgba(31, 41, 51, 0.06); }
#member-list .dot { width: 12px; height: 12px; border-radius: 50%; }
#member-list .name { font-weight: 700; font-size: 14px; }
#member-list .task { grid-column: 2 / 4; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#member-list .bar { grid-column: 2 / 4; height: 4px; }
#member-list .bar i { background: var(--c, var(--accent)); }

.chip {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--idle);
  white-space: nowrap;
}
.chip.working { background: var(--working); }
.chip.blocked { background: var(--blocked); }
.chip.review { background: var(--review); }
.chip.done { background: var(--done); }

.faceid-btn {
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.faceid-btn[hidden] { display: none; }
.conn { margin: 0; font-size: 11px; color: var(--muted); }
.conn.err { color: var(--blocked); }

/* 3D 場景上的名牌與對話框 */
.tag {
  pointer-events: auto;
  cursor: pointer;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  border-left: 4px solid var(--c);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(31, 41, 51, 0.15);
}
.tag small { font-weight: 400; color: var(--muted); margin-left: 4px; }
.tag .flag { color: var(--blocked); margin-left: 4px; }

.zzz {
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 36px;
  font-weight: 800;
  color: #dbe6ff;
  text-shadow: 0 1px 3px rgba(20, 30, 80, 0.7);
}
.zzz[hidden] { display: none; }
.zzz span { animation: zzz-float 2.4s ease-in-out infinite; opacity: 0; }
.zzz span:nth-child(1) { font-size: 12px; }
.zzz span:nth-child(2) { font-size: 16px; animation-delay: 0.6s; }
.zzz span:nth-child(3) { font-size: 20px; animation-delay: 1.2s; }
@keyframes zzz-float {
  0% { opacity: 0; transform: translateY(8px); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-12px); }
}

.bubble {
  pointer-events: auto;
  cursor: pointer;
  position: relative;
  max-width: 220px;
  padding: 10px 12px;
  background: #fff;
  border: 3px solid var(--accent);
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 6px 16px rgba(31, 41, 51, 0.25);
  animation: bob 1.4s ease-in-out infinite;
}
.bubble b { color: var(--accent); display: block; margin-bottom: 2px; }
.bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -12px;
  margin-left: -10px;
  border: 10px solid transparent;
  border-top-color: var(--accent);
  border-bottom: 0;
}
.bubble.thinking { border-color: var(--muted); animation: none; font-size: 12px; color: var(--muted); }
.bubble.thinking::after { border-top-color: var(--muted); }

@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes pulse { 50% { filter: brightness(1.12); transform: scale(1.02); } }

/* 請示事項視窗 */
#modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 41, 51, 0.35);
  padding: 16px;
}
#modal[hidden] { display: none; }
.modal-box {
  width: min(560px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(31, 41, 51, 0.3);
}
.modal-box header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-box h2 { margin: 0; font-size: 18px; }
.icon-btn { border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--muted); }

.q-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.q-meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.q-text { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.q-context { font-size: 13px; color: var(--muted); white-space: pre-wrap; margin-bottom: 10px; }
.q-options { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.q-options button {
  text-align: left;
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.q-options button.selected { border-color: var(--accent); background: #fdf1ec; }
.q-card textarea {
  width: 100%;
  min-height: 60px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  font: inherit;
  font-size: 14px;
  resize: vertical;
}
.q-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.q-actions .err { color: var(--blocked); font-size: 12px; }
.q-actions button {
  border: 0;
  border-radius: 10px;
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.q-actions button:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 700px) {
  /* 加到主畫面全螢幕後，避開底部橫條 */
  #panel { top: auto; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); width: auto; max-height: 40vh; }
  #modal { padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}

/* 訪客版：在線人數與累計瀏覽 */
.visitors {
  position: fixed;
  right: 10px;
  bottom: 10px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(31, 41, 51, 0.15);
  pointer-events: none;
}
.visitors[hidden] { display: none; }
.visitors .sep { color: var(--muted); font-weight: 400; }
.visitors .live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #46c06e;
  animation: live-pulse 1.6s ease-in-out infinite;
}
@keyframes live-pulse { 50% { opacity: 0.35; } }
@media (max-width: 700px) {
  .visitors { bottom: auto; top: 56px; }
}
