/* 介面樣式：顏色一律使用 theme.css 的變數 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Noto Sans TC", system-ui, -apple-system, "PingFang TC", sans-serif;
  color: var(--ui-text);
  background: linear-gradient(180deg, var(--c-bg-top) 0%, var(--c-bg-bottom) 70%);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#app {
  position: fixed;
  inset: 0;
}

/* ---------- 3D 舞台 ---------- */
#stage {
  position: absolute;
  inset: 0;
  z-index: 0; /* 獨立堆疊層：CSS2DRenderer 會替標籤設 z-index，避免蓋到面板與清單 */
}

#stage canvas {
  display: block;
  outline: none;
}

#labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.label {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: opacity 0.3s, transform 0.2s;
}

.label:hover,
.label.is-selected {
  transform: translateY(-2px);
}

.label.is-selected {
  background: var(--ui-accent);
  color: var(--ui-on-accent);
  border-color: transparent;
}

.label.is-dim {
  opacity: 0.35;
}

.label.is-rising,
.label.is-out {
  opacity: 0;
  pointer-events: none;
}

.label-no {
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--ui-accent);
  color: var(--ui-on-accent);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.label.is-selected .label-no {
  background: var(--ui-on-accent);
  color: var(--ui-accent);
}

.dots {
  display: inline-flex;
  gap: 3px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dot);
}

/* ---------- 上方標題列 ---------- */
.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 0;
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--ui-accent);
  color: var(--ui-on-accent);
  font-size: 20px;
}

.brand-kicker {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--ui-accent);
}

.brand h1 {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.modes {
  display: flex;
  padding: 4px;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
}

.mode {
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: none;
  font-size: 14px;
  font-weight: 700;
}

.mode.is-on {
  background: var(--ui-accent);
  color: var(--ui-on-accent);
}

.mode:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- 工具列 ---------- */
.toolbar {
  position: absolute;
  top: 76px;
  left: 20px;
  right: 20px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toolbar > * {
  pointer-events: auto;
}

.search input {
  width: 220px;
  padding: 8px 14px;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-surface);
  color: var(--ui-text);
  font: inherit;
  font-size: 14px;
  box-shadow: var(--ui-shadow);
}

.search input:focus {
  outline: 2px solid var(--ui-accent);
  outline-offset: 1px;
}

.tags,
.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tools {
  margin-left: auto;
}

.tag,
.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-surface);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--ui-shadow);
}

.tag-letter {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--dot);
  color: #fff;
  font-size: 11px;
}

.tag[aria-pressed="true"] {
  border-color: var(--dot);
  box-shadow: inset 0 0 0 1px var(--dot), var(--ui-shadow);
}

.tool[aria-pressed="true"] {
  background: var(--ui-accent);
  color: var(--ui-on-accent);
  border-color: transparent;
}

.tag:focus-visible,
.tool:focus-visible,
.mode:focus-visible,
.label:focus-visible,
.panel button:focus-visible,
.card:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

/* ---------- 底部提示 ---------- */
.hint,
.count {
  position: absolute;
  bottom: 18px;
  z-index: 4;
  margin: 0;
  font-size: 13px;
  color: var(--ui-muted);
  pointer-events: none;
}

.hint {
  left: 20px;
  max-width: 60%;
}

.hint #lead {
  display: block;
  margin-bottom: 2px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ui-text);
}

.count {
  right: 20px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 右側詳情面板 ---------- */
.panel {
  position: absolute;
  top: 128px;
  right: 20px;
  bottom: 20px;
  z-index: 6;
  width: min(380px, calc(100% - 40px));
  overflow-y: auto;
  padding: 24px 22px;
  border: 1px solid var(--ui-line);
  border-radius: 20px;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  backdrop-filter: blur(8px);
  animation: panel-in 0.3s ease-out;
}

.panel[hidden] {
  display: none;
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
}

.panel-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--ui-line);
}

.panel-kicker {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--ui-accent);
}

.panel h2 {
  margin: 4px 40px 10px 0;
  font-size: 26px;
  font-weight: 900;
}

.panel h3 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 22px 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--ui-muted);
}

.panel h3 span {
  font-variant-numeric: tabular-nums;
}

.panel-summary {
  margin: 12px 0 0;
  font-size: 15px;
  line-height: 1.7;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--dot) 16%, transparent);
  font-size: 12px;
  font-weight: 700;
}

.items,
.relations {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.items button,
.relations button {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--ui-line);
  border-radius: 12px;
  background: none;
  text-align: left;
}

.items button:hover,
.relations button:hover {
  border-color: var(--ui-accent);
}

.items strong,
.relations strong {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
}

.items span,
.relations span {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ui-muted);
}

.items li {
  display: grid;
  gap: 4px;
}

.items .item-role {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ui-accent);
}

.item-link {
  justify-self: end;
  font-size: 12px;
  font-weight: 700;
  color: var(--ui-accent);
  text-decoration: none;
}

.item-link:hover {
  text-decoration: underline;
}

.relations strong::before {
  content: "→";
  color: var(--ui-accent);
}

.empty {
  margin: 0;
  font-size: 13px;
  color: var(--ui-muted);
}

/* ---------- 清單模式 ---------- */
.list {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow-y: auto;
  padding: 140px 20px 40px;
  background: color-mix(in srgb, var(--c-bg-top) 88%, transparent);
  backdrop-filter: blur(6px);
}

.list[hidden] {
  display: none;
}

.list-inner {
  max-width: 1080px;
  margin: 0 auto;
}

.list-kicker {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--ui-accent);
}

.list h2 {
  margin: 4px 0 6px;
  font-size: 28px;
  font-weight: 900;
}

.list-note {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--ui-muted);
}

.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.card {
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 18px;
  border: 1px solid var(--ui-line);
  border-radius: 18px;
  background: var(--ui-surface);
  box-shadow: var(--ui-shadow);
  text-align: left;
  transition: transform 0.2s, border-color 0.2s;
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--ui-accent);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-no {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--ui-accent);
}

.card strong {
  font-size: 18px;
}

.card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ui-muted);
}

/* ---------- 載入畫面 ---------- */
.loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: var(--c-bg-top);
  transition: opacity 0.6s;
}

.loading.is-done {
  opacity: 0;
  pointer-events: none;
}

.loading-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--ui-accent);
  color: var(--ui-on-accent);
  font-size: 24px;
  animation: spin 2.4s linear infinite;
}

.loading p {
  margin: 0;
  font-weight: 700;
  color: var(--ui-muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- 手機 ---------- */
@media (max-width: 800px) {
  .topbar {
    padding: 12px 16px 0;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .brand {
    min-width: 0;
  }

  .brand > div {
    min-width: 0;
  }

  .brand h1 {
    overflow: hidden;
    font-size: 16px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .modes {
    flex-shrink: 0;
  }

  .mode {
    padding: 6px 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .mode span {
    display: none;
  }

  .toolbar {
    top: 62px;
    left: 16px;
    right: 16px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toolbar::-webkit-scrollbar {
    display: none;
  }

  .search input {
    width: 150px;
  }

  .tags,
  .tools {
    flex-wrap: nowrap;
  }

  .tag,
  .tool {
    white-space: nowrap;
  }

  .tag-name {
    display: none;
  }

  .label {
    font-size: 11px;
    padding: 3px 8px 3px 3px;
  }

  .label-no {
    min-width: 20px;
    height: 20px;
    font-size: 10px;
  }

  .label .dots {
    display: none;
  }

  .hint {
    left: 16px;
    bottom: 14px;
    max-width: calc(100% - 32px);
  }

  .hint-how,
  .count {
    display: none;
  }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 58%;
    border-radius: 20px 20px 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    animation-name: sheet-in;
  }

  @keyframes sheet-in {
    from {
      opacity: 0;
      transform: translateY(24px);
    }
  }

  .list {
    padding: 112px 16px 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
