:root {
  --radius-xs: 4px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 28px;
  --radius-pill: 9999px;

  --accent: #9c413a;
  --accent-h: #ffdad6;
  --accent-soft: #9c413a99;
  --border-c: #9c413a4d;
  --red: #ba1a1a;
  --panel-bkdrop: blur(20px);
  --gray-mid: #e7e0df88;
  --text: #201a19;
  --bg: #fff8f6;
  --overlay: #201a191a;
  --shadow-o: 0 4px 8px 3px rgba(0, 0, 0, .05);
  --shadow-h: inset 0 0 0 1px #9c413a;
  --alert-bg: #fff8f6ee;
  --alert-heading-bg: #ffdad6;
  --alert-heading: #3b0906;
  --border: #d3c1be;
  --white: #fff;
}

body.dark-theme {
  --accent: #ffb4ab;
  --accent-h: #72342e;
  --accent-soft: #ffb4ab99;
  --text: #ede0de;
  --bg: #1a1110;
  --overlay: #00000066;
  --border: #534341;
  --border-c: #ffb4ab4d;
  --shadow-o: 0 4px 12px 4px rgba(0, 0, 0, .4);
  --alert-bg: #201a19ee;
  --alert-heading-bg: #3b0906;
  --alert-heading: #ffdad6;
  --gray-mid: #53434188;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 10px;
  min-width: 300px;
  overflow: hidden;
}

::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
  margin-block: 5px;
}

::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: var(--radius-pill);
  cursor: grab;
}

::-webkit-scrollbar-thumb:active {
  background: var(--accent-h);
  cursor: grabbing;
}

.cal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  margin-bottom: 10px;
}

#cal-search-bar {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  outline: none;
}

#cal-search-bar:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-h);
}


#cal-theme-toggle {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 5px;
  border-radius: 50%;
  margin-left: 10px;
}

#cal-theme-toggle:hover {
  background: var(--gray-mid);
}

.cal-link-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
  max-width: inherit;
  justify-items: center;
  max-height: 80vh;
  overflow: auto;
  padding: 5px;
}

.card {
  width: 80px;
  height: 80px;
  background: transparent;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.2s ease, transform 0.2s ease;
  animation: fade3 0.5s ease-in-out;
  border: 1px solid transparent;
  cursor: grab;
}

.card.dragging {
  opacity: 0.5;
  transform: scale(0.95);
}

.card:hover {
  background: var(--accent-h);
  border-color: var(--border-c);
}

.card.pinned::before {
  content: '📌';
  position: absolute;
  top: -5px;
  left: -5px;
  font-size: 16px;
}


.card .icon {
  width: 50px;
  height: 50px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  margin: auto;
  font-weight: bold;
}

.card .icon img {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  object-fit: cover;
}

.card .name {
  width: 100%;
  margin: auto;
  margin-top: 5px;
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

@keyframes fade3 {
  0% {
    transform: translateY(-20%);
    opacity: 0;
  }

  100% {
    transform: translateY(0%);
    opacity: 1;
  }
}

.menu-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background: transparent;
  border: none;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  padding: 0 5px;
  border-radius: var(--radius-xs);
}

.menu-btn:hover {
  background: var(--gray-mid);
}

.context-menu {
  display: none;
  flex-direction: column;
  position: absolute;
  background: var(--alert-bg);
  backdrop-filter: var(--panel-bkdrop);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-o);
  z-index: 101;
  width: 160px;
  animation: fade5 0.3s ease-in-out;
  padding: 5px 0;
}

.context-menu button {
  background: none;
  border: none;
  text-align: start;
  padding: 10px 15px;
  width: 100%;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

@keyframes fade5 {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.context-menu button:hover {
  background: var(--gray-mid);
}

.cal-controls {
  display: flex;
  justify-content: center;
  position: sticky;
  bottom: 10px;
  gap: 10px;
  margin: auto;
  padding: 20px 0 0 0;
  flex-wrap: nowrap;
  flex-direction: row;
}

.cal-controls button {
  padding: 5px 12px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  font-weight: bold;
}

.cal-controls button:hover {
  background: var(--accent-h);
  color: var(--text);
}

.cal-controls button:active {
  background: var(--accent-soft);
}

.add-link-box,
.info-dialog {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.add-link-box-content,
.info-dialog-content {
  background: var(--alert-bg);
  backdrop-filter: var(--panel-bkdrop);
  text-align: center;
  padding-bottom: 20px;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow-o);
  animation: fade4 0.4s ease-in-out;
  border: 1px solid var(--border);
}

@keyframes fade4 {
  0% {
    opacity: 0.2;
    transform: translateY(-30%);
  }

  100% {
    opacity: 1;
    transform: translateY(0%);
  }
}

.add-link-box-content h2,
.info-dialog-heading {
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  padding: 15px;
  margin: 0 0 20px 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--alert-heading);
  background: var(--alert-heading-bg);
}

.add-link-box-content input[type="text"] {
  width: calc(100% - 40px);
  padding: 10px;
  font-size: 16px;
  border: 1px solid var(--border);
  outline: none;
  border-radius: var(--radius-sm);
  margin-bottom: 15px;
  background: var(--bg);
  color: var(--text);
}

.add-link-box-content .icon-uploader {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
  font-size: 14px;
}

#cal-link-Icon-File {
  margin-left: 10px;
  max-width: 200px;
  color: var(--text);
}

#cal-link-Icon-File::file-selector-button {
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--accent);
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
  margin-right: 10px;
}

.add-link-box-buttons {
  display: flex;
  flex-direction: row-reverse;
  margin-top: 20px;
  padding: 0 20px;
}

.add-link-box-buttons button {
  flex-grow: 1;
  padding: 10px 12px;
  margin: 0 5px;
  font-size: 14px;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-weight: bold;
}

.add-link-box-buttons .cancel {
  background: var(--gray-mid);
  color: var(--text);
}

.add-link-box-buttons .cancel:hover {
  opacity: 0.8;
}

.add-link-box-buttons .add {
  background: var(--accent);
  color: var(--bg);
}

.add-link-box-buttons .add:hover {
  background: var(--accent-h);
  color: var(--text);
}

.delete-box {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: none;
  background: var(--alert-bg);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-o);
  z-index: 1001;
  padding-bottom: 20px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  animation: fade2 0.3s ease-out;
  display: none;
}


@keyframes fade2 {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }

  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.alert-box-heading {
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  margin: 0;
  padding: 15px;
  font-size: 20px;
  font-weight: 700;
  background: var(--alert-heading-bg);
  color: var(--alert-heading);
}

.delete-box-content p {
  margin: 20px;
  font-size: 1.1em;
  line-height: 1.5;
  color: var(--text);
}

.delete-box-action {
  display: flex;
  flex-direction: row-reverse;
  justify-content: center;
  padding: 0 20px;
}

.delete-box-action button {
  width: 100%;
  background: var(--gray-mid);
  color: var(--text);
  padding: 10px 24px;
  margin: 0 5px;
  font-size: 14px;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-weight: bold;
}

.delete-box-action button:hover {
  opacity: 0.8;
}

.delete-box-action .danger {
  background: var(--red);
  color: var(--white);
}

.info-dialog-content {
  text-align: left;
  padding: 0 20px 20px 20px;
}

.info-dialog-content h3 {
  margin-top: 20px;
}

.info-dialog-content ul {
  padding-left: 20px;
}

#cal-info-close-btn {
  display: block;
  margin: 20px auto 0 auto;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
  font-weight: bold;
}

#cal-info-close-btn:hover {
  background: var(--accent-h);
  color: var(--text);
}

@media (max-width: 768px) {
  .cal-link-grid {
    max-height: 70vh;
  }
}

@media (max-width: 480px) {

  .cal-link-grid {
    gap: 5px;
    max-height: 75vh;
  }

  .card {
    width: 75px;
    height: 75px;
  }

  .card .icon {
    width: 45px;
    height: 45px;
    font-size: 1rem;
  }

  .card .name {
    font-size: 0.8rem;
  }
}