* { box-sizing: border-box; }
:root {
  --wood-dark: #1f1109;
  --wood-mid: #331c10;
  --wood-warm: #5c341d;
  --gold: #f59e0b;
  --gold-bright: #fde047;
  --parchment: #fdf6e3;
  --parchment-deep: #f5e6c4;
  --terracotta: #c2410c;
  --ink: #291d12;
}
body {
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: #1f1109;
  color: var(--ink);
  overflow: hidden;
  user-select: none;
}

/* Top Tribal Navigation Bar */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: linear-gradient(180deg, rgba(31, 17, 9, 0.96) 0%, rgba(48, 26, 14, 0.92) 100%);
  border-bottom: 2px solid #b45309;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  color: #fef3c7;
  z-index: 30;
  gap: 8px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.5px;
  color: #fef08a;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.65);
}
.brand-sub {
  font-size: 12px;
  font-weight: 600;
  color: #fed7aa;
  background: rgba(180, 83, 9, 0.45);
  border: 1px solid rgba(251, 191, 36, 0.45);
  padding: 2px 8px;
  border-radius: 999px;
}
nav {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 7px 12px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.15s ease;
}
button:hover {
  filter: brightness(1.1);
}
nav button {
  background: rgba(92, 52, 29, 0.78);
  color: #fef3c7;
  border: 1px solid rgba(217, 119, 6, 0.55);
  font-weight: 700;
  font-size: 13.5px;
}
nav button.active-view {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  color: #fffbeb;
  border-color: #fde047;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.55);
}
nav button.accent-btn {
  background: linear-gradient(135deg, #7c2d12 0%, #9a3412 100%);
  border-color: #fb923c;
}

/* 3D Canvas & Floating Carved Wood-Plaque Labels */
#scene {
  position: fixed;
  inset: 0;
}
#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8;
}
.lbl {
  position: absolute;
  transform: translate(-50%, -100%);
  background: linear-gradient(135deg, rgba(43, 24, 14, 0.95) 0%, rgba(64, 35, 20, 0.95) 100%);
  color: #fef3c7;
  padding: 5px 11px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  border: 1.5px solid rgba(245, 158, 11, 0.65);
  border-left: 5px solid var(--c, #f59e0b);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
  letter-spacing: 0.3px;
}
.lbl:hover {
  z-index: 60 !important;
  transform: translate(-50%, -100%) scale(1.09);
  background: linear-gradient(135deg, #451a03 0%, #78350f 100%);
  border-color: #fde047;
  box-shadow: 0 8px 22px rgba(245, 158, 11, 0.45);
}
.lbl.hub {
  background: linear-gradient(135deg, #9a3412 0%, #d97706 100%);
  color: #fffbeb;
  font-size: 13.5px;
  border: 2px solid #fde047;
  box-shadow: 0 4px 18px rgba(245, 158, 11, 0.6);
}

/* Left Sidebar: Tribal Roster (#dir) */
#dir {
  position: fixed;
  left: 12px;
  top: 68px;
  bottom: 44px;
  width: 285px;
  background: linear-gradient(180deg, rgba(36, 20, 11, 0.94) 0%, rgba(28, 15, 8, 0.94) 100%);
  border: 1.5px solid #92400e;
  border-radius: 16px;
  padding: 12px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  color: #fef3c7;
}
.dir-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 800;
  font-size: 14px;
  color: #fde047;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(217, 119, 6, 0.35);
}
#dir input, #dir select {
  padding: 8px 10px;
  border: 1px solid #78350f;
  border-radius: 9px;
  background: rgba(253, 246, 227, 0.95);
  color: #291d12;
  font: inherit;
  font-size: 13px;
}
#tribeList {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 1;
}
#tribeList li {
  padding: 9px 10px;
  border-radius: 11px;
  cursor: pointer;
  background: rgba(62, 35, 20, 0.82);
  border: 1px solid rgba(180, 83, 9, 0.45);
  border-left: 5px solid var(--c, #f59e0b);
  transition: background 0.15s ease, transform 0.12s ease;
}
#tribeList li:hover, #tribeList li.active {
  background: rgba(120, 53, 15, 0.92);
  border-color: #fbbf24;
  transform: translateX(2px);
}
.li-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 3px;
}
.li-badge {
  font-size: 12px;
  font-weight: 800;
  color: #fde047;
}
.li-cat {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 99px;
  background: rgba(245, 158, 11, 0.22);
  color: #fed7aa;
}
#tribeList b {
  display: block;
  font-size: 13px;
  color: #fffbeb;
  line-height: 1.35;
}
#tribeList small {
  display: block;
  color: #fdba74;
  font-size: 11.5px;
  margin-top: 3px;
}
.li-actions {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}
.mini-btn {
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: #d97706;
  color: #fffbeb;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.mini-btn.sec {
  background: rgba(255, 255, 255, 0.14);
  color: #fef3c7;
}

/* Right Detail Scroll Panel (#panel) */
#panel {
  position: fixed;
  right: 12px;
  top: 68px;
  bottom: 44px;
  width: min(530px, 94vw);
  background: var(--parchment);
  border: 2px solid #92400e;
  border-radius: 16px;
  z-index: 25;
  display: flex;
  flex-direction: column;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  color: var(--ink);
}
.panel-top {
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, #3b1f10 0%, #2b160b 100%);
  color: #fef3c7;
  z-index: 5;
  border-bottom: 2px solid #d97706;
  padding: 12px 140px 10px 16px;
}
.panel-top h2 {
  margin: 6px 0 4px;
  font-size: 18.5px;
  line-height: 1.35;
  color: #fef08a;
}
.close {
  position: absolute;
  right: 10px;
  top: 10px;
  background: linear-gradient(135deg, #78350f, #451a03);
  color: #fef3c7;
  border: 1px solid #fbbf24;
  font-weight: 800;
  font-size: 12.5px;
  padding: 7px 12px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 10;
}
.close:hover {
  background: linear-gradient(135deg, #dc2626, #991b1b);
  border-color: #fca5a5;
}
#panelBody {
  overflow-y: auto;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.68;
  flex: 1;
  user-select: text;
}
.preview-box {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid #b45309;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  margin-bottom: 12px;
  background: #1c1917;
}
.preview-box img {
  width: 100%;
  height: 215px;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}
.preview-box:hover img {
  transform: scale(1.03);
}
.preview-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 6px 10px;
  background: linear-gradient(0deg, rgba(15, 10, 5, 0.88), transparent);
  color: #fde047;
  font-size: 12.5px;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.cta-row {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 8px;
  margin: 10px 0 12px;
}
.cta-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 10px 10px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 13.5px;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  border: 0;
}
.cta-primary {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  color: #fffbeb;
  box-shadow: 0 4px 12px rgba(180, 83, 9, 0.4);
}
.cta-secondary {
  background: #3b1f10;
  color: #fef3c7;
  border: 1px solid #d97706;
}
.cta-qr {
  background: linear-gradient(135deg, #15803d 0%, #166534 100%);
  color: #f0fdf4;
}
.chief-quote {
  background: var(--parchment-deep);
  border-left: 4px solid #d97706;
  padding: 9px 12px;
  border-radius: 10px;
  margin: 10px 0;
  font-size: 13.5px;
}
.tag {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  background: rgba(217, 119, 6, 0.2);
  color: #78350f;
  border: 1px solid rgba(180, 83, 9, 0.4);
  padding: 2px 8px;
  border-radius: 999px;
  margin: 0 5px 5px 0;
}
.panel-top .tag {
  background: rgba(245, 158, 11, 0.25);
  color: #fde047;
  border-color: rgba(253, 224, 71, 0.5);
}
.panel-foot {
  padding: 9px 14px;
  border-top: 1px solid #d6c7a9;
  background: #f5e6c4;
}
.back-arch-btn {
  width: 100%;
  padding: 10px 14px;
  font-weight: 800;
  font-size: 14.5px;
  border-radius: 999px;
  background: linear-gradient(135deg, #78350f, #b45309);
  color: #fffbeb;
}

/* Full-Screen Totem Overview Wall (#wallView) */
#wallView {
  position: fixed;
  top: 58px;
  left: 0;
  right: 0;
  bottom: 34px;
  background:
    radial-gradient(circle at 50% 15%, rgba(180, 83, 9, 0.28), transparent 65%),
    linear-gradient(180deg, #1c1008 0%, #2a170c 100%);
  z-index: 22;
  overflow-y: auto;
  padding: 14px 22px 24px;
  color: #fef3c7;
}
.wall-container {
  max-width: 1280px;
  margin: 0 auto;
}
.wall-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(135deg, rgba(67, 36, 17, 0.92), rgba(43, 22, 10, 0.92));
  border: 1.5px solid #d97706;
  border-radius: 16px;
  padding: 16px 20px;
  margin-bottom: 18px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
.wall-hero h1 {
  margin: 0 0 4px;
  font-size: 22px;
  color: #fde047;
}
.wall-hero p {
  margin: 0;
  font-size: 13.5px;
  color: #fed7aa;
}
.wall-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
}
.pill-btn {
  background: rgba(67, 36, 17, 0.85);
  color: #fef3c7;
  border: 1px solid #92400e;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 700;
}
.pill-btn.on {
  background: linear-gradient(135deg, #d97706, #b45309);
  color: #fffbeb;
  border-color: #fde047;
}
#wallSearch {
  margin-left: auto;
  min-width: 240px;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1.5px solid #b45309;
  background: #fdf6e3;
  color: #291d12;
  font: inherit;
  font-size: 13.5px;
}
.totem-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.totem-card {
  background: linear-gradient(180deg, #fdf6e3 0%, #f5e6c4 100%);
  color: #291d12;
  border-radius: 16px;
  border: 2px solid #92400e;
  border-top: 6px solid var(--c, #d97706);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.totem-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 14px 34px rgba(245, 158, 11, 0.32);
}
.card-thumb {
  position: relative;
  height: 156px;
  background: #1c1917;
  overflow: hidden;
  border-bottom: 2px solid #d97706;
}
.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(31, 17, 9, 0.9);
  color: #fde047;
  border: 1.5px solid #f59e0b;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.card-cat {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--c, #d97706);
  color: #fff;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 800;
}
.card-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
}
.card-body h3 {
  margin: 0 0 6px;
  font-size: 17px;
  color: #451a03;
  line-height: 1.35;
}
.card-stats {
  font-size: 12.5px;
  font-weight: 800;
  color: #b45309;
  margin-bottom: 8px;
}
.card-desc {
  margin: 0 0 10px;
  font-size: 13.5px;
  line-height: 1.6;
  color: #3f2e21;
  flex: 1;
}
.card-actions {
  display: grid;
  grid-template-columns: 1.3fr 1fr 0.9fr 0.9fr;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #d6c7a9;
}
.card-actions a, .card-actions button {
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 800;
  border-radius: 8px;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

/* Modals (#qrModal, #addModal) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 6, 3, 0.82);
  backdrop-filter: blur(5px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.mbox {
  position: relative;
  background: var(--parchment);
  color: var(--ink);
  border: 2.5px solid #d97706;
  border-radius: 18px;
  width: min(680px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.75);
  user-select: text;
}
.qr-box {
  width: min(460px, 94vw);
  text-align: center;
}
.qr-canvas-wrap {
  background: #fffdf7;
  display: inline-block;
  padding: 12px;
  border-radius: 16px;
  border: 2px solid #d97706;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  margin: 10px auto;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 10px 0;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 700;
}
.form-grid input, .form-grid select, .form-grid textarea {
  padding: 8px 10px;
  border: 1px solid #b45309;
  border-radius: 8px;
  font: inherit;
  background: #fffdf7;
}
pre.code-snip {
  background: #1c1917;
  color: #fde047;
  padding: 12px;
  border-radius: 10px;
  font-size: 12px;
  overflow-x: auto;
}

/* Toast Notification */
#toast {
  position: fixed;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #15803d, #166534);
  color: #fff;
  padding: 9px 18px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  z-index: 80;
}

.hidden { display: none !important; }

footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 34px;
  line-height: 34px;
  text-align: center;
  background: rgba(24, 12, 6, 0.94);
  border-top: 1px solid #78350f;
  color: #fed7aa;
  font-size: 12.5px;
  z-index: 30;
}
footer a { color: #fde047; text-decoration: none; }

@media (max-width: 820px) {
  #topbar { padding: 6px 10px; }
  .brand { font-size: 14.5px; width: 100%; }
  .brand-sub { display: none; }
  nav button { padding: 5px 9px; font-size: 12px; }
  #dir {
    top: auto;
    bottom: 38px;
    height: 27vh;
    width: auto;
    left: 8px;
    right: 8px;
    padding: 8px;
  }
  body.panel-open #dir { display: none !important; }
  #panel {
    left: 8px;
    right: 8px;
    width: auto;
    top: 94px;
    bottom: 40px;
  }
  .cta-row { grid-template-columns: 1fr; }
  .totem-grid { grid-template-columns: 1fr; }
  .card-actions { grid-template-columns: 1fr 1fr; }
  .lbl { font-size: 11px; padding: 4px 8px; }
}
