:root {
  --bg-900: #2f2f2f;
  --bg-850: #3a3a3a;
  --bg-800: #4d4d4d;
  --bg-700: #5c5c5c;
  --bg-600: #6b6b6b;
  --ink-100: #f2f2f2;
  --ink-200: #d9d9d9;
  --ink-300: #bdbdbd;
  --ink-700: #2a2a2a;
  --accent-100: #ffffff;
  --transition: all 0.3s ease;
  --btn-radius-round: 50%;
  --bg-surface: var(--bg-850);
  --text-primary: var(--ink-200);
  --border-color: var(--bg-600);
  --accent-danger: #e74c3c;
  --link-height: 40px;
}

body {
  font-family:
    "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
    "Source Han Sans SC", "Noto Sans CJK SC", "Helvetica Neue", Arial,
    sans-serif;
  background-color: var(--bg-800);
  background-image:
    radial-gradient(
      circle at 20% 20%,
      rgba(255, 255, 255, 0.06),
      transparent 40%
    ),
    radial-gradient(circle at 80% 10%, rgba(0, 0, 0, 0.25), transparent 45%),
    linear-gradient(180deg, #3f3f3f 0%, #4d4d4d 100%);
  color: var(--ink-200);
  margin: 0;
  background-attachment: fixed;
  overflow-x: hidden;
}

.container {
  max-width: 1500px;
  margin: 50px auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 20px;
}

h3 {
  text-align: left;
  grid-column: 1 / -1;
  color: #d9d9d9;
  padding: 0px 10px;
}

ul {
  list-style-type: none;
  padding: 10px;
  margin: 0;
  color: var(--ink-200);
}

.category {
  display: flex;
  align-items: center;
  font-weight: 600;
  margin-bottom: 12px;
  font-size: 18px;
  padding: 8px 6px; /* Consistent padding */
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-100);
  cursor: default;
  transition: background 0.2s;
  border-radius: 4px;
}

/* Edit Mode Overlay - Fixed to not affect layout */
.edit-mode::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.1);
  z-index: 1000;
  pointer-events: none;
  animation: fadeIn 0.3s ease forwards;
  box-shadow:
    inset 0 0 100px rgba(0, 100, 159, 0.4),
    inset 0 0 20px rgba(0, 100, 159, 0.6);
}

.edit-mode body::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 4px solid #00649f;
  pointer-events: none;
  z-index: 10000;
  opacity: 0.5;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes wiggle {
  0% {
    transform: rotate(-0.3deg);
  }
  50% {
    transform: rotate(0.3deg);
  }
  100% {
    transform: rotate(-0.3deg);
  }
}

.edit-mode .link,
.edit-mode .main-section-group,
.edit-mode .category,
.edit-mode .main-category-group {
  z-index: 1001;
  position: relative;
  /* Use after for dashed borders to avoid element 'squeezing' */
}

.edit-mode .link::after,
.edit-mode .title-div::after,
.edit-mode .category::after,
.edit-mode .main-section-group::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px dashed rgba(255, 255, 255, 0.4);
  border-radius: inherit;
  pointer-events: none;
}

.edit-mode .category {
  animation: wiggle 0.3s infinite ease-in-out;
}

.edit-mode .category {
  animation-duration: 0.4s;
}
.edit-mode .title-div {
  animation-duration: 0.35s;
}

.edit-mode .link:hover,
.edit-mode .title-div:hover,
.edit-mode .category:hover {
  animation: none;
  transform: scale(1.05);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.drag-handle {
  cursor: grab;
  margin-right: 8px;
  opacity: 0.5;
  font-weight: normal;
  user-select: none;
}

.add-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 8px;
  margin-top: 10px;
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
  background: transparent;
}

.edit-mode .add-btn {
  display: flex;
}

body.is-dragging .add-btn {
  opacity: 0.5;
  border-style: dashed;
  border-color: rgba(52, 152, 219, 0.5);
  pointer-events: auto; /* Re-enable to allow drop */
}

body.dragging-section .add-link-trigger,
body.dragging-link .add-link-trigger,
body.dragging-section .add-section-trigger {
  border-color: #3498db;
  background: rgba(52, 152, 219, 0.1);
}

.add-btn.drag-external-over {
  border-color: #3498db !important;
  background-color: rgba(52, 152, 219, 0.2) !important;
  opacity: 1 !important;
}

.add-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: #3498db;
}

/* Drop Indicator Styling */
@keyframes pulse-blue {
  0%,
  100% {
    box-shadow:
      0 0 8px #00d2ff,
      0 0 15px rgba(0, 210, 255, 0.6);
  }
  50% {
    box-shadow:
      0 0 15px #00d2ff,
      0 0 30px rgba(0, 210, 255, 0.8);
  }
}

.drag-target-before::before,
.drag-target-before::before,
.drag-target-left::before,
.drag-target-right::after {
  content: "";
  position: absolute;
  background-color: #00d2ff;
  z-index: 10000;
  pointer-events: none;
  animation: pulse-blue 1.5s infinite ease-in-out;
}

.drag-target-before::before {
  top: -5px;
  left: -15px;
  right: -15px;
  height: 8px;
  border-radius: 4px;
}

.drag-target-left::before {
  top: -10px;
  bottom: -10px;
  left: -3px;
  width: 6px;
  border-radius: 3px;
}

.drag-target-right::after {
  top: -10px;
  bottom: -10px;
  right: -3px;
  width: 6px;
  border-radius: 3px;
}

/* In Edit mode, we don't change padding to avoid jitter */
.edit-mode .link,
.edit-mode .main-section-group,
.edit-mode .category,
.edit-mode .add-btn {
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
  position: relative;
}

.delete-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: #e74c3c;
  color: white;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  z-index: 1005;
  border: 2px solid var(--bg-800);
  transition: all 0.3s ease;
}

.delete-btn svg {
  width: 12px;
  height: 12px;
  stroke: white;
  stroke-width: 3;
}

.delete-btn:hover {
  transform: rotate(90deg) scale(1.1);
  background: #ff0000;
}

.edit-mode .link:hover > .delete-btn,
.edit-mode .title-div:hover > .delete-btn,
.edit-mode .category:hover > .delete-btn {
  display: flex;
}

/* Edit Modal (The Popup) */
#edit-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}

#edit-modal-overlay.show {
  display: flex;
}

#link-editor-popup {
  background: var(--bg-surface);
  width: 320px;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--bg-600);
  display: flex;
  flex-direction: column;
  gap: 15px;
}

#link-editor-popup h4 {
  margin: 0;
  font-size: 16px;
  color: #fff;
}

.input-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.input-field label {
  font-size: 11px;
  color: var(--ink-300);
  text-transform: uppercase;
}
.input-field input {
  background: var(--bg-800);
  border: 1px solid var(--bg-600);
  color: #fff;
  padding: 8px;
  border-radius: 6px;
  font-size: 13px;
}

#edit-toolbar {
  position: fixed;
  bottom: 100px;
  right: 30px;
  background: var(--bg-surface);
  padding: 15px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  display: none;
  flex-direction: column;
  gap: 12px;
  z-index: 1002;
  border: 1px solid var(--bg-600);
  width: 280px;
}

.edit-mode #edit-toolbar {
  display: flex;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toolbar-section {
  padding-bottom: 0px;
  border-bottom: 1px solid var(--bg-600);
}
.toolbar-section:last-child {
  border-bottom: none;
}
.toolbar-label {
  font-size: 12px;
  font-weight: bold;
  color: var(--ink-300);
  margin-bottom: 8px;
  display: block;
}

#layout-toggle-container {
  position: fixed;
  bottom: 30px;
  right: 100px;
  cursor: pointer;
  z-index: 1002;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #2d2d2d;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.2s;
  color: var(--ink-200);
}

#layout-toggle-container.active {
  background-color: #00649f;
  color: #fff;
  transform: scale(1.1);
}

a {
  display: flex;
  padding: 10px 12px; /* Fixed padding */
  background-color: #b3b3b3;
  color: #333333;
  text-decoration: none;
  border-radius: 10px;
  border: 1px solid #737373;
  transition:
    background-color 0.2s,
    box-shadow 0.2s,
    transform 0.2s;
  height: var(--link-height);
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

a:hover {
  background-color: #f2f2f2;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
  transform: translateY(-1px);
}

.title-div {
  text-align: center;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.1em;
  background-color: #1a5c8a;
  cursor: default;
  user-select: none;
  border: 1px solid transparent;
  margin: 2px 0 1px 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  padding: 0 12px;
  height: var(--link-height);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.link {
  font-size: 14px;
  color: #2f2f2f;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin: 2px 0 0 0;
}

.favicon {
  width: 16px;
  height: 16px;
  margin-right: 8px;
  border-radius: 2px;
  filter: grayscale(0.5);
  opacity: 0.9;
  flex-shrink: 0;
}

.searchingbox {
  font-size: 14px;
  color: #2f2f2f;
  background-color: #ffffff;
  border: 1px solid #737373;
  border-radius: 10px;
  padding: 0 12px;
  height: var(--link-height);
  width: 100%;
  box-sizing: border-box;
  margin: 2px 0 0 0;
  outline: none;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}

#note-icon-container {
  position: fixed;
  bottom: 30px;
  right: 30px;
  cursor: pointer;
  z-index: 1001;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #2d2d2d;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.2s;
  color: var(--ink-200);
}

#note-modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 999;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#note-modal-overlay.show {
  display: block;
}

#quick-note-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  width: 80vw;
  max-width: 1000px;
  height: 70vh;
  background-color: var(--bg-850);
  z-index: 1000;
  display: none;
  flex-direction: column;
  border-radius: 12px;
  overflow: hidden;
  opacity: 0;
  transition:
    opacity 0.2s ease,
    transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

#quick-note-modal.show {
  display: flex;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#note-header {
  height: 50px;
  padding: 0 20px;
  background-color: #00649f;
  color: #ffffff;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#note-header-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

#note-textarea {
  width: 100%;
  height: 100%;
  padding: 20px;
  box-sizing: border-box;
  border: none;
  resize: none;
  font-size: 16px;
  line-height: 1.6;
  outline: none;
  background-color: #b3b3b3;
  color: #333;
  font-family: inherit;
}

.mode-selector-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
}

select,
input[type="text"] {
  background: var(--bg-800);
  border: 1px solid var(--bg-600);
  color: #fff;
  padding: 8px 12px;
  border-radius: 4px;
}

.btn {
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  border: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: filter 0.2s;
}

svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary {
  background: #3498db;
  color: #fff;
}
.btn-danger {
  background: var(--accent-danger);
  color: #fff;
}
.btn-success {
  background: #27ae60;
  color: #fff;
}

.std-close-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}

.std-close-btn:hover {
  background: var(--accent-danger);
  transform: rotate(90deg) scale(1.1);
}

@media (max-width: 1200px) {
  .container {
    grid-template-columns: repeat(3, 1fr);
  }
}
@media (max-width: 600px) {
  .container {
    grid-template-columns: 1fr;
  }
}

.edit-detail-trigger {
  margin-left: auto;
  font-size: 18px;
  color: #00649f;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}
.edit-detail-trigger:hover {
  background: #88c0d0;
  color: #2f2f2f;
}
