/* ===== Theme tokens ===== */
:root {
  color-scheme: light dark;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #141922;
  --muted: #5c6472;
  --faint: #8a919e;
  --border: #e3e7ee;
  --accent: #2f6bff;
  --accent-text: #1d4ed8;
  --accent-soft: #ecf2ff;
  --ring: rgba(47, 107, 255, 0.28);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 1px 2px rgba(15, 23, 42, 0.04), 0 18px 40px -24px rgba(15, 23, 42, 0.28);

  --radius-lg: 18px;
  --radius-md: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0f14;
    --surface: #131820;
    --text: #e9edf5;
    --muted: #9aa4b5;
    --faint: #6f7a8c;
    --border: #232b38;
    --accent: #6d9bff;
    --accent-text: #9dbcff;
    --accent-soft: rgba(109, 155, 255, 0.12);
    --ring: rgba(109, 155, 255, 0.32);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.35), 0 24px 48px -28px rgba(0, 0, 0, 0.75);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* Soft ambient glow behind the content */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(600px 300px at 15% -5%, rgba(47, 107, 255, 0.12), transparent 70%),
    radial-gradient(520px 260px at 95% 0%, rgba(124, 58, 237, 0.1), transparent 70%);
}

@media (prefers-color-scheme: dark) {
  body::before {
    background:
      radial-gradient(600px 300px at 15% -5%, rgba(47, 107, 255, 0.16), transparent 70%),
      radial-gradient(520px 260px at 95% 0%, rgba(124, 58, 237, 0.14), transparent 70%);
  }
}

::selection {
  background: var(--accent);
  color: #ffffff;
}

a {
  color: var(--accent-text);
  text-underline-offset: 3px;
}

/* ===== Layout ===== */
.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(40px, 8vw, 72px) 24px 44px;
}

/* ===== Hero ===== */
.hero {
  display: flex;
  align-items: center;
  gap: 20px;
  animation: rise 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: linear-gradient(135deg, #2f6bff, #7c3aed);
  box-shadow: 0 12px 26px -12px rgba(47, 107, 255, 0.65);
  color: #ffffff;
  font-size: 30px;
  font-weight: 700;
}

h1 {
  margin: 0 0 4px;
  font-size: clamp(26px, 4vw, 32px);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h1 .handle {
  color: var(--faint);
  font-size: 0.55em;
  font-weight: 500;
  letter-spacing: 0;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.16);
}

/* ===== Sections ===== */
.section {
  margin-top: 44px;
  animation: rise 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.section:nth-of-type(1) {
  animation-delay: 0.08s;
}

.section:nth-of-type(2) {
  animation-delay: 0.16s;
}

.section:nth-of-type(3) {
  animation-delay: 0.24s;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.section-title .num {
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.card {
  padding: clamp(20px, 4vw, 28px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.card p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.85;
}

.card p:last-of-type {
  margin-bottom: 0;
}

.card strong {
  color: var(--text);
  font-weight: 600;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.tags li {
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12.5px;
  font-weight: 500;
}

/* ===== GitHub link cards ===== */
.links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.link-card {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: inherit;
  text-decoration: none;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.link-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.link-card:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.icon svg {
  width: 19px;
  height: 19px;
}

.link-body {
  min-width: 0;
}

.link-body strong {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.link-body span {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.arrow {
  display: flex;
  flex: none;
  margin-left: auto;
  color: var(--faint);
  transition: transform 0.18s ease, color 0.18s ease;
}

.arrow svg {
  width: 16px;
  height: 16px;
}

.link-card:hover .arrow {
  transform: translateX(3px);
  color: var(--accent-text);
}

/* ===== Footer ===== */
.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: 52px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--faint);
  font-size: 12.5px;
  animation: rise 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) 0.32s both;
}

.footer a {
  color: var(--muted);
  text-decoration: none;
}

.footer a:hover {
  color: var(--accent-text);
}

/* ===== Motion & responsive ===== */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

@media (max-width: 520px) {
  .hero {
    align-items: flex-start;
    gap: 16px;
  }

  .avatar {
    width: 60px;
    height: 60px;
    border-radius: 18px;
    font-size: 24px;
  }

  .links {
    grid-template-columns: 1fr;
  }

  .wrap {
    padding-right: 18px;
    padding-left: 18px;
  }
}

/* ===== Library entry on the homepage ===== */
.library-entry {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: inherit;
  text-decoration: none;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.library-entry:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.library-entry:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.library-entry .entry-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.library-entry .entry-body strong {
  font-size: 14.5px;
  font-weight: 600;
}

.library-entry .entry-body span {
  color: var(--muted);
  font-size: 12.5px;
}

/* ===== Subpages (library / admin) ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.subpage .wrap {
  max-width: 920px;
  padding-top: clamp(32px, 6vw, 56px);
}

.page-head {
  margin-bottom: 28px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.back-link:hover {
  color: var(--accent-text);
}

.page-title-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title-row h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 32px);
  letter-spacing: -0.02em;
}

.count-pill {
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.page-sub {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  color: #ffffff;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-danger {
  border-color: rgba(220, 38, 38, 0.35);
  background: transparent;
  color: #dc2626;
}

.btn-danger:hover:not(:disabled) {
  border-color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
  color: #dc2626;
}

.btn-sm {
  padding: 6px 11px;
  border-radius: 9px;
  font-size: 12.5px;
}

/* ===== Toolbar & filters ===== */
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.search {
  position: relative;
  flex: 1 1 260px;
}

.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  color: var(--faint);
  pointer-events: none;
}

.search input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.search input:focus {
  outline: 3px solid var(--ring);
  border-color: var(--accent);
}

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

.chip {
  flex: 0 0 auto;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent-text);
}

.chip[aria-pressed="true"] {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

/* ===== States ===== */
.state {
  padding: 28px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.state.is-error {
  border-color: rgba(220, 38, 38, 0.4);
  color: #dc2626;
}

/* ===== Resource grid ===== */
.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.resource-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.resource-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.resource-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.resource-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.resource-icon svg {
  width: 18px;
  height: 18px;
}

.cat-badge {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11.5px;
}

.resource-title {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.resource-meta {
  margin: 0;
  color: var(--faint);
  font-size: 12px;
}

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

.resource-tags span {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.1);
  color: var(--muted);
  font-size: 11.5px;
}

.resource-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 6px;
}

/* ===== Admin ===== */
.admin-page .wrap {
  max-width: 960px;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.usage-card {
  margin-bottom: 14px;
}

.usage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.usage-head #usage-text {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.usage-bar {
  height: 8px;
  margin: 14px 0 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.14);
}

.usage-fill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2f6bff, #7c3aed);
  transition: width 0.4s ease;
}

.usage-fill.is-warn {
  background: linear-gradient(90deg, #f59e0b, #ef4444);
}

.hint {
  margin: 0;
  color: var(--faint);
  font-size: 12.5px;
}

.hint.is-error {
  color: #dc2626;
}

.upload-card {
  margin-bottom: 34px;
}

.upload-card .card-title {
  margin-bottom: 16px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 18px;
  border: 1.5px dashed var(--border);
  border-radius: 14px;
  background: rgba(127, 127, 127, 0.03);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone strong {
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.dropzone-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent-text);
}

.dropzone-icon svg {
  width: 20px;
  height: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  margin-top: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12.5px;
}

.field input,
.field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
}

.field input:focus,
.field select:focus {
  outline: 3px solid var(--ring);
  border-color: var(--accent);
}

.segmented {
  display: inline-flex;
  width: fit-content;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  padding: 6px 14px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.segmented input:checked + span {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--ring);
}

.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.items-section {
  margin-top: 8px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.row-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent-text);
}

.row-icon svg {
  width: 18px;
  height: 18px;
}

.item-main {
  flex: 1;
  min-width: 0;
}

.item-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

.item-title > span:first-child {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vis-badge {
  flex: none;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}

.vis-badge.is-public {
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
}

.vis-badge.is-private {
  background: rgba(127, 127, 127, 0.1);
  color: var(--muted);
}

.item-meta {
  margin-top: 3px;
  overflow: hidden;
  color: var(--faint);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.item-tags span {
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(127, 127, 127, 0.1);
  color: var(--muted);
  font-size: 11px;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 50;
  padding: 10px 16px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: #141922;
  color: #ffffff;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.5);
  font-size: 13px;
}

@media (prefers-color-scheme: dark) {
  .btn-danger {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.4);
  }

  .btn-danger:hover:not(:disabled) {
    color: #f87171;
    border-color: #f87171;
  }

  .vis-badge.is-public {
    color: #4ade80;
  }

  .toast {
    background: #e9edf5;
    color: #141922;
  }
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .resource-grid {
    grid-template-columns: 1fr;
  }

  .item-row {
    flex-wrap: wrap;
  }

  .item-actions {
    width: 100%;
    justify-content: flex-start;
    padding-left: 52px;
  }

  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
  }
}
