:root {
  color-scheme: dark;

  --primary: #ff9000;
  --primary-hover: #ffa733;
  --primary-soft: rgba(255, 144, 0, 0.12);

  --bg: #0b0b0c;
  --bg-elevated: #141416;
  --card: #17171a;
  --card-hover: #1e1e22;

  --text: #f2f2f4;
  --text-muted: #9a9aa3;

  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);

  --danger: #ff7b7b;
  --danger-bg: rgba(255, 80, 80, 0.12);
  --danger-border: rgba(255, 80, 80, 0.35);

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow: 0 18px 45px rgba(0, 0, 0, 0.45);
  --focus-ring: 0 0 0 3px rgba(255, 144, 0, 0.3);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 15% -10%, rgba(255, 144, 0, 0.12), transparent 45%),
    radial-gradient(circle at 90% 0%, rgba(255, 144, 0, 0.06), transparent 40%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

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

.skip-link {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #1b1200;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-150%);
  transition: transform 0.2s ease;
}

.skip-link:focus {
  transform: translateY(0);
}

/* Header */
.site-header {
  padding: 2.25rem 1rem 1.5rem;
  text-align: center;
}

.header-inner h1 {
  margin: 0;
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  letter-spacing: 0.02em;
  color: var(--primary);
}

.tagline {
  margin: 0.4rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Navigation */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(13, 13, 14, 0.86);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.site-nav ul {
  display: flex;
  gap: 0.25rem;
  width: fit-content;
  max-width: min(1200px, 100%);
  margin: 0 auto;
  padding: 0.5rem 1rem;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
}

.site-nav ul::-webkit-scrollbar {
  display: none;
}

.site-nav li {
  flex: 0 0 auto;
}

.site-nav a {
  display: block;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.site-nav a:hover {
  color: var(--text);
  background-color: rgba(255, 255, 255, 0.06);
}

.site-nav a.active {
  background-color: var(--primary);
  color: #1b1200;
}

/* Main content */
main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem 5rem;
}

main > section {
  scroll-margin-top: 4.5rem;
}

main > section[hidden] {
  display: none;
}

.category-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 2.25rem 0 1rem;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

.category-title::before {
  content: "";
  width: 4px;
  height: 1.1em;
  border-radius: 999px;
  background: var(--primary);
}

/* Link grid */
.link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.75rem, 1fr));
  gap: 0.75rem;
}

.link-card {
  position: relative;
  background-color: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: transform 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

.link-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 6.75rem;
  padding: 1.1rem 0.65rem;
  border-radius: inherit;
  text-decoration: none;
  color: inherit;
}

.link-icon {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
}

.link-icon i {
  font-size: 1.15rem;
  color: var(--primary);
}

.link-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
}

@media (hover: hover) {
  .link-card:hover {
    transform: translateY(-3px);
    background-color: var(--card-hover);
    border-color: rgba(255, 144, 0, 0.35);
  }
}

/* Card actions (edit mode) */
.card-actions {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  display: none;
  gap: 0.25rem;
}

body.is-editing .card-actions {
  display: flex;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background-color: rgba(10, 10, 12, 0.9);
  color: var(--text-muted);
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.icon-btn:hover {
  color: var(--primary);
  border-color: rgba(255, 144, 0, 0.45);
}

.card-actions .icon-btn:last-child:hover {
  color: var(--danger);
  border-color: var(--danger-border);
}

/* Status */
.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin: 1.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.status.is-error {
  color: var(--danger);
}

.status:not(.is-loading) .spinner {
  display: none;
}

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

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

.btn-primary {
  background-color: var(--primary);
  color: #1b1200;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
}

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

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

.btn-danger {
  background-color: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background-color: rgba(255, 80, 80, 0.2);
}

.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}

/* Floating actions */
.float-stack {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + var(--safe-bottom));
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

.float-btn {
  box-shadow: var(--shadow);
}

.float-toggle {
  background-color: var(--card);
  border-color: var(--border-strong);
  color: var(--text);
}

.float-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.float-toggle[aria-pressed="true"] {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #1b1200;
}

.float-add {
  display: none;
}

body.is-editing .float-add {
  display: inline-flex;
}

/* Dialog */
dialog {
  width: min(27rem, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background-color: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow-y: auto;
}

dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
}

dialog[open] {
  animation: dialog-in 0.16s ease-out;
}

@keyframes dialog-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.dialog-summary {
  margin: 0 0 1rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-sm);
  background-color: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: #ffc4c4;
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.field {
  display: block;
  margin-bottom: 0.85rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.field > span {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: #0e0e10;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.field input::placeholder {
  color: #5f5f68;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.hint {
  display: block;
  margin-top: 0.3rem;
  color: #71717a;
  font-size: 0.75rem;
  font-weight: 400;
}

.form-message {
  min-height: 1.2rem;
  margin: 0 0 0.5rem;
  color: var(--danger);
  font-size: 0.8rem;
}

.form-message:empty {
  min-height: 0;
  margin-bottom: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.dialog-actions .btn-danger {
  margin-right: auto;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(4.75rem + var(--safe-bottom));
  z-index: 40;
  max-width: calc(100vw - 2rem);
  padding: 0.65rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background-color: #1e1e23;
  color: var(--text);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 0.75rem);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* Footer */
footer {
  padding: 1.5rem 1rem calc(1.5rem + var(--safe-bottom));
  border-top: 1px solid var(--border);
  color: #71717a;
  text-align: center;
  font-size: 0.78rem;
}

footer p {
  margin: 0;
}

/* Responsive */
@media (max-width: 768px) {
  .site-header {
    padding: 1.75rem 1rem 1.25rem;
  }

  .link-grid {
    grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
    gap: 0.6rem;
  }

  .link-main {
    min-height: 6.25rem;
    padding: 1rem 0.5rem;
  }
}

@media (max-width: 480px) {
  .link-grid {
    grid-template-columns: repeat(auto-fill, minmax(6.25rem, 1fr));
  }

  .link-icon {
    width: 2.25rem;
    height: 2.25rem;
  }

  .link-title {
    font-size: 0.8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
