@import "./tokens.css";

:root {
  --ui-bg: var(--bg);
  --ui-surface: var(--surface);
  --ui-ink: var(--text);
  --ui-accent: var(--accent);
  --domain-embedded: #2f6f5e;
  --domain-skill: #3a8370;
  --domain-reverse: #c93a32;
  --domain-design: #27594c;
  --domain-writing: #8a5a3a;
  --domain-visual: #4a6b8a;
  --domain-agent: #5a4f7a;
  --domain-other: #6b665c;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

* { box-sizing: border-box; }

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color-scheme: light;
  scrollbar-width: thin;
  scrollbar-color: var(--chip) transparent;
}

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  line-height: 1.47;
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--glow-a), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, var(--glow-b), transparent 45%),
    var(--bg);
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

.shell { min-height: 100dvh; }
.sidebar { display: none; }
.desktop-only { display: none !important; }
.mobile-only { display: revert; }

.page {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
}

.nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 8px;
  position: sticky;
  top: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  box-shadow: inset 0 1px 0 0 var(--glass-hi), 0 1px 0 0 var(--separator);
  z-index: 10;
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
}

.nav-side {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.nav-side:last-child { justify-self: end; }

main { padding: 4px 16px 24px; }

.large-title {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin: 8px 0 4px;
  color: var(--text);
  text-wrap: pretty;
}

.subtitle {
  margin: 0 0 16px;
  color: var(--text-tertiary);
  font-size: 15px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.toolbar {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  grid-template-columns: 1fr auto;
}
#ai-search-btn {
  width: auto;
  min-width: 72px;
  padding: 10px 14px;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  box-shadow: var(--shadow-sm);
  min-height: 44px;
}
.search input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  min-width: 0;
}
.search input::placeholder { color: var(--text-tertiary); }

.sort {
  border: 1px solid var(--separator);
  background: var(--surface);
  border-radius: var(--radius-sm);
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--separator);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  padding: 8px 12px;
  min-height: 36px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chip.is-on {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: rgba(47, 111, 94, 0.22);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 160ms var(--ease-out), filter 160ms var(--ease-out), background 160ms var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost {
  background: var(--surface);
  color: var(--accent-text);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-sm);
}
.btn:disabled { opacity: 0.55; cursor: wait; }

.stat-row {
  display: flex;
  gap: 16px;
  margin: 0 0 16px;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-tertiary);
}
.stat-row b { color: var(--accent-text); font-weight: 700; }

.card-grid {
  display: grid;
  gap: 10px;
}

.hw-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-sm);
  transition: transform 180ms var(--ease-out), box-shadow 180ms var(--ease-out);
  min-height: 148px;
}
.hw-card:hover { text-decoration: none; }

.hw-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hw-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-text);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.code-pill {
  flex-shrink: 0;
  min-width: 36px;
  height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--mono);
}
.code-pill[data-cat="embedded"] { background: rgba(47,111,94,.12); color: var(--domain-embedded); }
.code-pill[data-cat="skill"] { background: rgba(58,131,112,.12); color: var(--domain-skill); }
.code-pill[data-cat="reverse"] { background: rgba(201,58,50,.12); color: var(--domain-reverse); }
.code-pill[data-cat="design"] { background: rgba(39,89,76,.12); color: var(--domain-design); }
.code-pill[data-cat="writing"] { background: rgba(138,90,58,.12); color: var(--domain-writing); }
.code-pill[data-cat="visual"] { background: rgba(74,107,138,.12); color: var(--domain-visual); }
.code-pill[data-cat="agent"] { background: rgba(90,79,122,.12); color: var(--domain-agent); }
.code-pill[data-cat="other"] { background: var(--chip); color: var(--domain-other); }

.hw-title {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.2px;
  line-height: 1.3;
  color: var(--text);
  text-wrap: pretty;
}
.hw-note {
  font-size: 13px;
  color: var(--text-tertiary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hw-why {
  font-size: 12px;
  color: var(--accent-text);
  line-height: 1.4;
}
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.card-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 7px;
}
.hw-foot {
  margin-top: auto;
  padding-top: 8px;
  font-size: 13px;
  color: var(--text-tertiary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.hw-foot span { color: var(--accent); font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12px; }
.tag {
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--chip);
  border-radius: 6px;
  padding: 2px 6px;
}

.empty {
  color: var(--text-tertiary);
  padding: 36px 8px;
  text-align: center;
}

.banner {
  background: var(--accent-soft);
  color: var(--accent-text);
  border: 1px solid rgba(47, 111, 94, 0.18);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12.5px;
  margin-bottom: 10px;
}
.banner.warn { color: var(--red); background: rgba(201,58,50,.08); border-color: rgba(201,58,50,.18); }

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  display: grid;
  gap: 6px;
  width: min(320px, calc(100vw - 32px));
}
.toast {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--separator);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
.toast.is-out { opacity: 0; transform: translateY(8px); }
.toast.ok { color: var(--accent); }
.toast.error { color: var(--red); }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(35, 33, 28, 0.28);
  z-index: 30;
  display: none;
  place-items: end center;
}
.modal-back.is-open { display: grid; }
.modal {
  width: min(520px, 100%);
  max-height: min(88dvh, 760px);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-lg);
  padding: 18px 18px 24px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.icon-close {
  width: 44px;
  height: 44px;
  border: 0;
  background: var(--chip);
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}
.icon-close:active { transform: scale(0.97); }
.modal h2 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 0 0 6px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--separator);
  font-size: 13px;
  color: var(--text-tertiary);
}
.field input,
.field select {
  border: 0;
  outline: none;
  background: transparent;
  font-size: 17px;
  color: var(--text);
  font-family: inherit;
}
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  font-size: 15px;
  color: var(--text);
}
.check input { width: 18px; height: 18px; }
.hint { font-size: 12px; color: var(--text-tertiary); margin: 10px 0 0; line-height: 1.45; }

.side-link {
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  background: none;
  border: 0;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 44px;
  width: 100%;
  transition: background 150ms var(--ease-out), color 150ms var(--ease-out);
}
.side-link .n {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
}
.side-link.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--separator);
}

@media (hover: hover) and (pointer: fine) {
  .hw-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
  .btn.primary:hover { filter: brightness(1.06); background: var(--accent-hover); }
  .btn.ghost:hover { background: var(--surface-2); }
  .side-link:hover { background: var(--chip); }
  .chip:hover { background: var(--surface-2); }
}

@media (min-width: 900px) {
  .mobile-only { display: none !important; }
  .desktop-only { display: revert !important; }

  .shell {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    max-width: 1180px;
    margin: 28px auto;
    min-height: calc(100dvh - 56px);
    background: rgba(253, 251, 244, 0.72);
    border: 1px solid var(--separator);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    backdrop-filter: blur(18px) saturate(160%);
    -webkit-backdrop-filter: blur(18px) saturate(160%);
  }

  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 28px 20px;
    background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
    border-right: 1px solid var(--separator);
  }

  .brand { display: flex; gap: 12px; align-items: center; padding: 0 6px; }
  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: linear-gradient(145deg, #2f6f5e, #3a8370);
    color: #fff;
    font-weight: 700;
    display: grid;
    place-items: center;
    box-shadow: 0 8px 18px rgba(47, 111, 94, 0.28);
    font-family: var(--serif);
  }
  .brand-title {
    font-size: 16px;
    font-weight: 700;
    font-family: var(--serif);
    color: var(--text);
  }
  .brand-sub { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

  .side-nav { display: flex; flex-direction: column; gap: 4px; }
  .side-foot {
    margin-top: auto;
    font-size: 12px;
    color: var(--text-tertiary);
    padding: 0 8px;
    line-height: 1.45;
  }

  .page {
    max-width: none;
    margin: 0;
    min-height: auto;
    padding-bottom: 40px;
  }

  main { padding: 28px 36px 40px; }
  .large-title { font-size: 36px; margin-top: 0; }
  .toolbar { grid-template-columns: 1fr auto 180px; }
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .modal-back { place-items: center; }
  .modal { border-radius: var(--radius-lg); padding: 22px 24px; }
}

@media (min-width: 1200px) {
  .shell { max-width: 1280px; grid-template-columns: 260px minmax(0, 1fr); }
  .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.hw-card {
  opacity: 1;
  transform: translateY(0);
}
.hw-card.is-enter {
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  animation: cardIn 220ms var(--ease-out) forwards;
}
.hw-card.is-enter:nth-child(1) { animation-delay: 0ms; }
.hw-card.is-enter:nth-child(2) { animation-delay: 30ms; }
.hw-card.is-enter:nth-child(3) { animation-delay: 60ms; }
.hw-card.is-enter:nth-child(4) { animation-delay: 90ms; }
.hw-card.is-enter:nth-child(5) { animation-delay: 120ms; }
.hw-card.is-enter:nth-child(6) { animation-delay: 150ms; }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .hw-card.is-enter { opacity: 1; transform: none; }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.module-switch {
  display: inline-flex;
  gap: 4px;
  margin: 10px 16px 4px;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--chip);
  border: 1px solid var(--separator);
}
.module-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.module-button.is-active {
  background: var(--surface);
  color: var(--accent-text);
  box-shadow: var(--shadow-sm);
}
.module-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  background: rgba(60, 52, 38, 0.08);
  border-radius: var(--radius-pill);
  padding: 2px 7px;
}
.module-button.is-active .module-badge {
  color: var(--accent-text);
  background: var(--accent-soft);
}

.dev-side-note {
  margin-top: auto;
  padding: 14px 16px 18px;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.5;
  border-top: 1px solid var(--separator);
}
.dev-side-note p { margin: 0 0 6px; }
.dev-side-note p:first-child {
  color: var(--accent-text);
  font-weight: 700;
  font-size: 13px;
}

.dev-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.dev-eyebrow {
  margin: 8px 0 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  font-weight: 700;
}
.dev-root { margin-bottom: 8px; }
.dev-intro {
  margin: 0 0 12px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}
.dev-toolbar {
  display: grid;
  gap: 8px;
  margin: 12px 0 10px;
}
.dev-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}
.dev-filter {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 600;
}
.dev-review-hint { margin: 0 0 10px; }
.dev-result-count {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.dev-card .dev-path {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dev-classification {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.dev-evidence {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.45;
}
.dev-card.needs-review {
  box-shadow: inset 0 0 0 1px rgba(201, 58, 50, 0.18), var(--shadow-sm);
}
.dev-kind-pill[data-kind="reparse"],
.dev-kind-pill[data-kind="error"] {
  color: var(--red);
  background: rgba(201, 58, 50, 0.08);
}
.copy-path {
  appearance: none;
  border: 0;
  background: var(--accent-soft);
  color: var(--accent-text);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  min-height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.copy-path:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
body.is-dev-mode .brand-sub::after {
  content: " · 开发库";
}

@media (min-width: 900px) {
  .module-switch { margin: 0 0 14px; }
  .dev-toolbar {
    grid-template-columns: minmax(0, 1fr) 180px;
    align-items: center;
  }
  .dev-filters { gap: 12px; }
}
