:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --panel: rgba(255, 255, 255, 0.78);
  --panel-strong: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --blue: #0071e3;
  --blue-soft: #e8f2ff;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: rgba(245, 245, 247, 0.86);
  border-right: 1px solid var(--line);
  overflow: auto;
  backdrop-filter: blur(28px);
}

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

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: #1d1d1f;
  color: #fff;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  letter-spacing: 0;
}

.brand p,
.result-head p,
.detail-kicker {
  color: var(--muted);
  font-size: 13px;
}

.side-section {
  margin-top: 24px;
}

.section-label {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

.intent-list,
.module-list,
.subcategory-list,
.prompt-list,
.tag-list,
.chip-row,
.active-filters,
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.intent-button,
.module-button,
.subcategory-button,
.prompt-button,
.tag-button,
.filter-pill,
.chip {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 6px 11px;
  font-size: 13px;
  line-height: 1.2;
}

.module-button,
.subcategory-button,
.prompt-button,
.intent-button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  border-radius: 8px;
  padding: 10px 11px;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.module-button {
  align-items: center;
  min-height: 44px;
}

.subcategory-list {
  max-height: 330px;
  overflow: auto;
  padding-right: 2px;
}

.subcategory-cluster {
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.subcategory-cluster summary {
  align-items: center;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  font-size: 13px;
  font-weight: 700;
  justify-content: space-between;
  list-style: none;
  min-height: 34px;
  padding: 0 4px;
}

.subcategory-cluster summary::-webkit-details-marker {
  display: none;
}

.subcategory-cluster summary::before {
  content: "+";
  font-size: 16px;
  margin-right: 8px;
}

.subcategory-cluster[open] summary::before {
  content: "−";
}

.subcategory-cluster summary span {
  flex: 1;
}

.subcategory-cluster summary small {
  font-weight: 500;
}

.subcategory-cluster-items {
  display: grid;
  gap: 6px;
  padding-top: 4px;
}

.subcategory-button {
  align-items: center;
  min-height: 38px;
  background: rgba(255, 255, 255, 0.72);
}

.subcategory-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subcategory-button small {
  color: var(--muted);
}

.prompt-button {
  align-items: flex-start;
  flex-direction: column;
  gap: 4px;
  min-height: 54px;
  text-align: left;
}

.prompt-button span {
  font-weight: 680;
}

.prompt-button small {
  color: var(--muted);
  line-height: 1.35;
}

.module-button small,
.intent-button small {
  color: var(--muted);
}

.module-button:hover,
.subcategory-button:hover,
.prompt-button:hover,
.intent-button:hover,
.tag-button:hover,
.metric:hover,
.card:hover {
  transform: translateY(-1px);
}

.intent-button.is-active,
.module-button.is-active,
.subcategory-button.is-active,
.prompt-button.is-active,
.tag-button.is-active,
.filter-pill,
.chip.is-primary {
  border-color: rgba(0, 113, 227, 0.24);
  background: var(--blue-soft);
  color: #005bb5;
}

.workspace {
  min-width: 0;
  padding: 24px 32px 44px;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 0 0 18px;
  background: linear-gradient(180deg, var(--bg) 78%, rgba(245, 245, 247, 0));
}

.search-wrap {
  position: relative;
  flex: 1;
}

.search-wrap input,
.tag-browser input,
select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  outline: none;
}

.search-wrap input {
  padding: 0 44px;
  font-size: 16px;
}

.search-wrap input:focus,
.tag-browser input:focus,
select:focus {
  border-color: rgba(0, 113, 227, 0.5);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
}

.search-icon,
.icon-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.search-icon {
  left: 16px;
  color: var(--muted);
}

.icon-button {
  right: 8px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
}

select {
  width: 132px;
  padding: 0 10px;
}

.text-button,
.load-more {
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: #1d1d1f;
  color: #fff;
  padding: 0 16px;
  font-weight: 650;
}

.danger-button {
  background: #d70015;
}

.insight-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 15px 16px;
  text-align: left;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.metric span {
  display: block;
  font-size: 26px;
  font-weight: 750;
}

.metric small {
  color: var(--muted);
}

.metric.is-active {
  border-color: rgba(0, 113, 227, 0.26);
  background: var(--blue-soft);
}

.active-filters {
  min-height: 38px;
  align-items: center;
}

.tag-browser {
  margin: 10px 0 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.tag-browser-head,
.result-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.tag-browser h2,
.result-head h2 {
  font-size: 22px;
}

.tag-browser input {
  max-width: 260px;
  padding: 0 12px;
}

.tag-cloud {
  margin-top: 14px;
  max-height: 240px;
  overflow: auto;
}

.personal-uploader {
  display: grid;
  grid-template-columns: minmax(220px, 0.7fr) minmax(0, 1.3fr);
  gap: 18px;
  margin: 8px 0 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  padding: 18px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
}

.upload-copy h2 {
  font-size: 22px;
}

.upload-copy p,
.upload-status {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.upload-form {
  display: grid;
  gap: 12px;
}

.file-drop {
  display: grid;
  min-height: 96px;
  place-items: center;
  border: 1px dashed rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  background: #f7f7f9;
  color: var(--text);
  text-align: center;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.file-drop:hover,
.file-drop.is-dragging {
  border-color: rgba(0, 113, 227, 0.54);
  background: #eef6ff;
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.1);
  transform: translateY(-1px);
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop span {
  font-weight: 700;
}

.file-drop small {
  color: var(--muted);
}

.upload-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.upload-fields input,
.upload-fields textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  outline: none;
  padding: 0 12px;
}

.upload-fields input {
  height: 42px;
}

.upload-fields textarea {
  grid-column: 1 / -1;
  min-height: 92px;
  padding-top: 10px;
  resize: vertical;
}

.upload-fields input:focus,
.upload-fields textarea:focus {
  border-color: rgba(0, 113, 227, 0.5);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.12);
}

.result-head {
  margin: 14px 0 16px;
}

.density-control {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.density {
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 0 10px;
  color: var(--muted);
}

.density.is-active {
  background: #1d1d1f;
  color: #fff;
}

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

.grid.is-compact {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  opacity: 0;
  transform: translateY(8px);
  animation: cardIn 360ms ease forwards;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.card:hover {
  border-color: rgba(0, 0, 0, 0.14);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.09);
}

.thumb {
  position: relative;
  aspect-ratio: 16 / 11;
  background: linear-gradient(135deg, #ececf0, #fafafa);
  overflow: hidden;
}

.thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.01);
  transition: opacity 260ms ease, transform 420ms ease;
}

.thumb video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #111;
}

.thumb img.is-loaded {
  opacity: 1;
  transform: scale(1);
}

.fav {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.86);
  color: #1d1d1f;
}

.fav.is-on {
  color: #d70015;
}

.card-body {
  padding: 12px;
}

.card-title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.mini-tags {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  overflow: hidden;
}

.mini-tag {
  max-width: 100%;
  overflow: hidden;
  border-radius: 999px;
  background: #f2f2f4;
  padding: 4px 8px;
  color: #515154;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.term-card .thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 11;
  padding: 0;
  background: radial-gradient(circle at top left, #ffffff, #f0f2f5 58%, #e5e8ed);
}

.term-card .thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  background: #f4f4f5;
}

.term-initial {
  color: #1d1d1f;
  font-size: 42px;
  font-weight: 760;
}

.term-card .card-title {
  white-space: normal;
  line-height: 1.3;
}

.term-note {
  display: -webkit-box;
  min-height: 42px;
  margin-top: 8px;
  overflow: hidden;
  color: #424245;
  font-size: 13px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.prompt-line {
  margin-top: 10px;
  border-left: 2px solid rgba(0, 113, 227, 0.35);
  padding-left: 9px;
  color: #005bb5;
  font-size: 12px;
  line-height: 1.45;
}

.load-more {
  display: block;
  margin: 24px auto 0;
  min-width: 160px;
}

dialog {
  width: min(980px, calc(100vw - 28px));
  border: 0;
  border-radius: 12px;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
}

.detail-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  overflow: hidden;
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
  animation: dialogIn 220ms ease;
}

.detail-close {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(245, 245, 247, 0.9);
  font-size: 22px;
}

.detail-media {
  min-height: 420px;
  background: #111;
}

.detail-media img {
  width: 100%;
  height: 100%;
  max-height: 78vh;
  display: block;
  object-fit: contain;
}

.detail-media video {
  width: 100%;
  height: 100%;
  max-height: 78vh;
  display: block;
  object-fit: contain;
}

dialog.term-mode .detail-shell {
  grid-template-columns: 1fr;
}

dialog.term-mode .detail-media {
  display: none;
}

.detail-info {
  padding: 34px 28px;
  overflow: auto;
}

.detail-info h2 {
  margin-top: 5px;
  font-size: 28px;
}

.detail-info p {
  margin-top: 12px;
  color: #424245;
  line-height: 1.55;
}

.detail-block {
  margin-top: 22px;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 26px;
}

.subtle .chip {
  background: #f5f5f7;
  color: #515154;
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding-bottom: 12px;
  }

  .intent-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    padding: 18px 16px 34px;
  }

  .toolbar,
  .tag-browser-head,
  .result-head {
    align-items: stretch;
    flex-direction: column;
  }

  .personal-uploader,
  .upload-fields {
    grid-template-columns: 1fr;
  }

  .toolbar-actions,
  .insight-strip {
    grid-template-columns: 1fr;
    display: grid;
  }

  select {
    width: 100%;
  }

  .detail-shell {
    grid-template-columns: 1fr;
  }

  .detail-media {
    min-height: 260px;
  }
}

@keyframes cardIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dialogIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
