/* --- General Styles --- */
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f4f6f9; margin: 0; color: #333; transition: background-color 0.3s, color 0.3s; }
.page-wrapper { max-width: 100vw; width: 100%; margin: 0 auto; padding: 20px; box-sizing: border-box; }
.header { text-align: center; margin-bottom: 30px; padding: 20px; border-radius: 12px; background-size: cover; background-position: center; position: relative; overflow: hidden; }
.header::before { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.4); z-index: 1; transition: background-color 0.3s; }
.header > * { position: relative; z-index: 2; }
.header-banner { font-size: 1.2rem; font-weight: bold; background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%); color: white; padding: 10px 20px; border-radius: 50px; margin-bottom: 25px; display: inline-block; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.search-container { max-width: 600px; margin: 20px auto 10px auto; position: relative; }
.search-container input { width: 100%; padding: 16px 50px 16px 25px; border-radius: 50px; border: none; font-size: 16px; box-sizing: border-box; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,0.1); transition: background-color 0.3s, color 0.3s; }
.search-container input:focus { outline: none; box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.5); }
.search-container button { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; padding: 10px; }
.search-container form { position: relative; }
.search-submit-btn { display: inline-flex; align-items: center; justify-content: center; }
.search-container svg { width: 22px; height: 22px; fill: #4285f4; }
.content-layout { display: grid; grid-template-columns: 1fr 280px; gap: 20px; }
.main-content, .sidebar { display: flex; flex-direction: column; gap: 20px; }
#sidebar-container { display: flex; flex-direction: column; gap: 20px; }
.card { background: #fff; padding: 20px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); position: relative; transition: background-color 0.3s, box-shadow 0.3s; }
.delete-card-btn { position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; background: #e0e0e0; color: #888; border-radius: 50%; border: none; display: flex; justify-content: center; align-items: center; cursor: pointer; font-size: 16px; font-weight: bold; opacity: 0; transition: opacity 0.2s ease; z-index: 10; }
.card:hover .delete-card-btn { opacity: 1; }
.delete-card-btn:hover { background: #dc3545; color: white; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)); gap: 15px; }
.sidebar .icon-grid { grid-template-columns: repeat(2, 1fr); gap: 20px; }
.card h3 { margin-top: 0; font-size: 14px; color: #555; text-align: center; border-bottom: 1px solid #eee; padding-bottom: 10px; margin-bottom: 15px; display: flex; justify-content: center; align-items: center; transition: color 0.3s, border-color 0.3s; }
.edit-title-btn { margin-left: 8px; cursor: pointer; font-size: 12px; color: #aaa; }
.icon-item, .add-new-btn { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-decoration: none; color: #555; font-size: 13px; transition: transform 0.2s, color 0.3s; position: relative; text-align: center; height: 90px; box-sizing: border-box; padding-top: 10px; }
.icon-item span { word-break: break-all; }
.icon-item:hover { transform: translateY(-3px); }
.icon-item img, .fallback-icon { width: 48px; height: 48px; margin-bottom: 8px; border-radius: 12px; object-fit: contain; }
.fallback-icon { display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 500; color: white; }
.add-new-btn { justify-content: center; border: 2px dashed #e0e0e0; border-radius: 12px; color: #888; font-size: 24px; cursor: pointer; transition: border-color 0.3s, color 0.3s; }
.delete-btn { position: absolute; top: 0px; right: 0px; width: 22px; height: 22px; background: #dc3545; color: white; border-radius: 50%; border: 2px solid white; display: none; justify-content: center; align-items: center; cursor: pointer; font-size: 14px; font-weight: bold; z-index: 10; }
.sortable-ghost { opacity: 0.4; }
.categories-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.category-card h3 { text-align: left; justify-content: flex-start; }
.category-card ul { list-style: none; padding: 0; margin: 0; }
.category-link { display: flex; align-items: center; padding: 8px 5px; text-decoration: none; color: #333; border-radius: 6px; transition: background-color 0.2s ease, color 0.3s; font-size: 14px; position: relative; }
.category-link:hover { background-color: #f4f6f9; }
.category-link .delete-btn { right: 0; top: 50%; transform: translateY(-50%); }
.category-link img, .category-link .fallback-icon-small { width: 20px; height: 20px; margin-right: 12px; border-radius: 4px; flex-shrink: 0; }
.category-link .link-label { display: inline-block; min-width: 0; }
.add-new-category-item { padding: 8px 5px; color: #007bff; cursor: pointer; text-align: center; font-size: 13px; }
.add-new-category-card { align-items: center; justify-content: center; border: 2px dashed #e0e0e0; color: #888; font-size: 18px; cursor: pointer; transition: border-color 0.3s, color 0.3s; }
.modal{display:none;position:fixed;z-index:1001;left:0;top:0;width:100%;height:100%;background-color:rgba(0,0,0,0.5);justify-content:center;align-items:center}.modal-content{background-color:#fff;padding:30px;border-radius:8px;width:90%;max-width:400px; transition: background-color 0.3s;}.modal-content h2{margin-top:0}.modal-content input{width:100%;padding:12px;margin-bottom:15px;border:1px solid #ddd;border-radius:5px;box-sizing:border-box; background-color: #f9f9f9; color: #333; transition: background-color 0.3s, color 0.3s, border-color 0.3s;}.modal-buttons{display:flex;justify-content:flex-end;gap:10px}.modal-buttons button{padding:10px 20px;border:none;border-radius:5px;cursor:pointer}.btn-save{background-color:#007bff;color:white}.btn-cancel{background-color:#f1f3f4}
.settings-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.settings-button { background: #6c757d; color: white; border: none; padding: 10px; width: 100%; border-radius: 8px; cursor: pointer; font-size: 14px; text-align: center; transition: background-color 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; box-sizing: border-box; }
.settings-button.full-width { grid-column: 1 / -1; }
.settings-button.edit-mode-btn.active { background-color: #28a745; }
.edit-controls, .add-new-btn, .add-new-category-item, .add-new-category-card { display: none; }
body.edit-mode .edit-controls, body.edit-mode .add-new-btn, body.edit-mode .add-new-category-item, body.edit-mode .add-new-category-card { display: flex; }
.icon-item:hover .delete-btn, .category-link:hover .delete-btn { display: none; }
body.edit-mode .icon-item:hover .delete-btn, body.edit-mode .category-link:hover .delete-btn { display: flex; }
.delete-card-btn, .edit-title-btn { opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
body.edit-mode .card:hover .delete-card-btn, body.edit-mode .edit-title-btn { opacity: 1; pointer-events: auto; }
body.dark-mode { background-color: #121212; color: #e0e0e0; }
.dark-mode .card { background-color: #1e1e1e; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.dark-mode .header::before { background: rgba(0, 0, 0, 0.7); }
.dark-mode .search-container input { background: #2c2c2c; color: #e0e0e0; border: 1px solid #444; }
.dark-mode .search-container input:focus { box-shadow: 0 0 0 4px rgba(70, 70, 70, 0.5); }
.dark-mode .search-container svg { fill: #8ab4f8; }
.dark-mode .search-container .settings-menu-toggle { color: #fff; }
.dark-mode .card h3 { color: #ccc; border-bottom: 1px solid #333; }
.dark-mode .icon-item, .dark-mode .category-link { color: #ccc; }
.dark-mode .add-new-btn, .dark-mode .add-new-category-card { border-color: #444; color: #aaa; }
.dark-mode .category-link:hover { background-color: #2a2a2a; }
.dark-mode .modal-content { background-color: #2c2c2c; color: #e0e0e0; }
.dark-mode .modal-content input { background-color: #383838; color: #e0e0e0; border: 1px solid #555; }
.dark-mode .btn-cancel { background-color: #383838; color: #e0e0e0; }
.dark-mode .settings-button { background-color: #444; }
.dark-mode .settings-button.edit-mode-btn.active { background-color: #218838; }
.dark-mode .sun-icon { display: block; }
.dark-mode .moon-icon { display: none; }
.sun-icon { display: none; }
.moon-icon { display: block; }
@media (max-width: 1024px) { .content-layout { grid-template-columns: 1fr; } }
.custom-section { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin-top: 20px; }
.custom-card { background: #fff; padding: 20px; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); transition: background-color 0.3s, box-shadow 0.3s, transform 0.2s ease; }
.custom-card:hover { transform: translateY(-3px); }
.custom-card h3 { margin-top: 0; font-size: 16px; color: #555; border-bottom: 1px solid #eee; padding-bottom: 10px; margin-bottom: 15px; text-align: left; justify-content: flex-start; }
.custom-card p, .custom-card li { font-size: 14px; line-height: 1.6; margin-bottom: 8px; }
.custom-card ul { list-style: none; padding: 0; margin: 0; }
.custom-card a { color: #333; text-decoration: none; transition: color 0.2s; }
.custom-card a:hover { color: #007bff; }
.social-grid { display: flex; gap: 15px; margin-top: 10px; flex-wrap: wrap; }
.social-grid a { width: 38px; height: 38px; background: #f0f2f5; display: flex; align-items: center; justify-content: center; border-radius: 50%; font-size: 18px; color: #555; transition: background-color 0.3s, color 0.3s; }
.social-grid a:hover { background: #007bff; color: #fff; }
.dark-mode .custom-card { background-color: #1e1e1e; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.dark-mode .custom-card h3 { color: #ccc; border-bottom-color: #333; }
.dark-mode .custom-card, .dark-mode .custom-card p, .dark-mode .custom-card li, .dark-mode .custom-card a { color: #ccc; }
.dark-mode .custom-card a:hover { color: #8ab4f8; }
.dark-mode .social-grid a { background: #2c2c2c; color: #ccc; }
.dark-mode .social-grid a:hover { background: #8ab4f8; color: #121212; }
#welcome-box { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,0.8); color: #fff; font-size: 32px; font-weight: bold; padding: 30px 60px; border-radius: 15px; text-align: center; z-index: 9999; animation: fadeIn 1s ease-in-out; }
@keyframes fadeIn { from {opacity: 0; transform: translate(-50%, -60%);} to {opacity: 1; transform: translate(-50%, -50%);} }

.settings-card { overflow: visible; }
.settings-menu-wrap { display: none; position: relative; }
.settings-menu-toggle {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: #6c757d;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}
.settings-menu-toggle i { font-size: 18px; }
.settings-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(260px, 78vw);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.16);
  padding: 10px;
  display: none;
  grid-template-columns: 1fr;
  gap: 8px;
  z-index: 50;
}
.settings-dropdown.open { display: grid; }
.settings-dropdown .settings-button,
.settings-dropdown .settings-button.full-width {
  grid-column: auto;
  justify-content: flex-start;
  padding: 12px 14px;
}
.search-container .settings-dropdown .settings-button {
  position: static;
  top: auto;
  right: auto;
  transform: none;
  width: 100%;
}
.dark-mode .settings-menu-toggle { background: #444; }
.dark-mode .settings-dropdown { background: #1e1e1e; border: 1px solid #333; }

@media (max-width: 767px) {
  .page-wrapper { padding: 14px; }
  .header { padding: 16px; margin-bottom: 20px; overflow: visible; }
  .sidebar { display: none; }
  .card, .custom-card { padding: 16px; }
  .icon-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 12px; }
  .icon-item, .add-new-btn { min-height: 94px; height: auto; }
  .icon-item span {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    word-break: break-word;
    line-height: 1.25;
    max-width: 100%;
  }
  .categories-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }
  .category-card,
  .custom-card { min-width: 0; }
  .category-card h3,
  .custom-card h3 {
    font-size: 13px;
    line-height: 1.35;
  }
  .category-card h3 {
    justify-content: center;
    text-align: center;
  }
  .category-card ul {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .category-link {
    width: 100%;
    min-height: 54px;
    margin: 0;
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    font-size: 13px;
    padding: 10px 12px;
    justify-content: stretch;
    text-align: left;
    border-radius: 10px;
  }
  .category-link img,
  .category-link .fallback-icon-small {
    margin-right: 0;
    justify-self: center;
  }
  .category-link .link-label {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    line-height: 1.22;
    min-height: calc(1.22em * 2);
    max-height: calc(1.22em * 2);
    text-align: left;
    word-break: break-word;
  }

  .custom-section {
    display: block;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    padding: 16px;
    margin-top: 0;
    text-align: center;
  }
  .custom-card {
    background: transparent;
    box-shadow: none;
    padding: 0;
    border-radius: 0;
  }
  .custom-card + .custom-card {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #eceff3;
  }
  .custom-card h3 {
    justify-content: center;
    text-align: center;
    margin-bottom: 12px;
  }
  .info-card {
    align-items: center;
  }
  .custom-card p,
  .custom-card ul,
  .custom-card li {
    text-align: center;
  }
  .social-grid {
    gap: 10px;
    justify-content: center;
  }

  .settings-buttons.desktop-settings { display: none; }
  .settings-card {
    display: none;
    background: transparent;
    box-shadow: none;
    padding: 0;
    margin: 0;
    border-radius: 0;
  }
  .settings-menu-wrap {
    display: inline-flex;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 60;
  }
  .search-submit-btn {
    display: none;
  }
  .search-container input {
    padding-right: 52px;
  }
  .settings-menu-toggle {
    position: static;
    transform: none;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    background: transparent;
    box-shadow: none;
    color: #4285f4;
  }
  .settings-dropdown {
    top: calc(100% + 10px);
    right: 0;
    left: auto;
    width: min(260px, calc(100vw - 28px));
    z-index: 70;
  }
  .search-container .settings-dropdown .settings-button,
  .search-container .settings-dropdown .settings-button.full-width {
    position: static;
    top: auto;
    right: auto;
    transform: none;
    width: 100%;
    border: none;
    background: #6c757d;
    color: #fff;
    box-shadow: none;
  }
  .search-container .settings-dropdown .settings-button:hover,
  .search-container .settings-dropdown .settings-button.full-width:hover {
    background: #5c6670;
  }
  .search-container .settings-dropdown .settings-button.edit-mode-btn.active {
    background-color: #28a745;
  }

  .dark-mode .custom-section {
    background: #1e1e1e;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  }
  .dark-mode .custom-card + .custom-card {
    border-top-color: #333;
  }
}


html { scroll-behavior: smooth; }


.info-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.info-card .info-links {
  display: grid;
  width: min(100%, 360px);
  max-width: 360px;
}

.info-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  column-gap: clamp(34px, 8vw, 88px);
  row-gap: 6px;
  align-items: start;
  justify-content: center;
  width: min(100%, 360px);
  margin: 0 auto;
}

.info-links li {
  margin: 0;
  min-width: 0;
  width: 100%;
  display: flex;
}

.info-links li:nth-child(odd) {
  justify-content: flex-start;
}

.info-links li:nth-child(even) {
  justify-content: flex-end;
}

.info-link-btn {
  width: auto;
  border: none;
  background: none;
  color: #334155;
  border-radius: 0;
  padding: 2px 0;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: color 0.2s ease, opacity 0.2s ease;
  box-shadow: none;
  white-space: nowrap;
}

.info-link-btn:hover {
  transform: none;
  border-color: transparent;
  box-shadow: none;
  color: #2563eb;
  text-decoration: underline;
}

.info-modal {
  padding: 18px;
  box-sizing: border-box;
}

.info-modal-content {
  width: min(760px, 100%);
  max-width: 760px;
  max-height: min(86vh, 900px);
  overflow-y: auto;
  border-radius: 24px;
  padding: 28px;
  position: relative;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.28);
}

.info-modal-head {
  margin-bottom: 20px;
  padding-right: 36px;
}

.info-modal-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: #eef4ff;
  color: #2457d6;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 14px;
}

.info-modal-content h2 {
  font-size: clamp(24px, 3vw, 32px);
  line-height: 1.15;
  margin-bottom: 10px;
}

.info-modal-summary {
  margin: 0;
  font-size: 15px;
  line-height: 1.7;
  color: #4b5563;
}

.info-modal-body {
  display: grid;
  gap: 16px;
}

.info-section {
  background: #f8fafc;
  border: 1px solid #e9eef5;
  border-radius: 18px;
  padding: 18px 20px;
}

.info-section h4 {
  margin: 0 0 10px;
  font-size: 16px;
  color: #1f2937;
}

.info-section p,
.info-section li,
.info-note {
  font-size: 14px;
  line-height: 1.75;
}

.info-section ul {
  margin: 0;
  padding-left: 18px;
}

.info-note {
  border-radius: 18px;
  padding: 16px 18px;
  background: linear-gradient(135deg, #eef4ff 0%, #f8fbff 100%);
  border: 1px solid #d9e5ff;
  color: #1f3c88;
}

.info-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: #eef2f7;
  color: #334155;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.info-modal-close:hover {
  background: #dfe7f2;
  transform: rotate(90deg);
}

.back-to-top {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 100%);
  color: #fff;
  box-shadow: 0 16px 34px rgba(29, 78, 216, 0.28);
  cursor: pointer;
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(0.92);
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.back-to-top:hover {
  box-shadow: 0 20px 40px rgba(29, 78, 216, 0.34);
}

.dark-mode .info-link-btn {
  background: none;
  color: #d7e0ee;
}

.dark-mode .info-link-btn:hover {
  color: #8ab4f8;
  text-decoration: underline;
}

.dark-mode .info-modal-content {
  background: #1b1f27;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.dark-mode .info-modal-badge {
  background: #22314e;
  color: #bfd5ff;
}

.dark-mode .info-modal-summary {
  color: #c9d3e2;
}

.dark-mode .info-section {
  background: #232934;
  border-color: #333b48;
}

.dark-mode .info-section h4 {
  color: #f8fafc;
}

.dark-mode .info-note {
  background: linear-gradient(135deg, #1d2a42 0%, #182131 100%);
  border-color: #31476d;
  color: #d8e7ff;
}

.dark-mode .info-modal-close {
  background: #2a3140;
  color: #e2e8f0;
}

.dark-mode .info-modal-close:hover {
  background: #374151;
}

.dark-mode .back-to-top {
  background: linear-gradient(135deg, #2563eb 0%, #60a5fa 100%);
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.3);
}

@media (max-width: 767px) {
  .info-link-btn {
    width: auto;
    text-align: left;
    padding: 2px 0;
    font-size: 13px;
  }

  .info-links {
    width: min(100%, 320px);
    max-width: 320px;
    grid-template-columns: repeat(2, minmax(116px, 1fr));
    column-gap: 26px;
    row-gap: 5px;
    justify-content: center;
    margin-left: auto;
    margin-right: auto;
  }

  .info-modal {
    padding: 12px;
  }

  .info-modal-content {
    padding: 20px 16px 18px;
    border-radius: 20px;
    max-height: 88vh;
  }

  .info-modal-head {
    margin-bottom: 16px;
    padding-right: 28px;
  }

  .info-modal-close {
    top: 12px;
    right: 12px;
    width: 38px;
    height: 38px;
    font-size: 24px;
  }

  .info-section {
    padding: 15px 14px;
    border-radius: 15px;
  }

  .info-note {
    padding: 14px;
    border-radius: 15px;
  }

  .back-to-top {
    width: 42px;
    height: 42px;
    right: 14px;
    bottom: 14px;
  }
}

/* ── Performance Optimizations ── */

/* Skip rendering of off-screen category cards */
.category-card {
  content-visibility: auto;
  contain-intrinsic-size: 0 280px;
}

/* GPU-accelerated layers for elements that animate */
.back-to-top {
  will-change: opacity, transform;
}

/* Avoid expensive repaints on hover transitions */
.icon-item { contain: layout style; }
.custom-card { contain: layout style; }

/* Smooth font rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeSpeed;
}

/* Prevent FOUC on lazy-loaded FA icons */
.fab, .fas, .fa-solid, .fa-brands { display: inline-block; }
