/* ============================================================ tokens */
:root {
  --paper: #f3f3f1;
  --paper-2: #e6e6e3;
  --card: #ffffff;
  --ink: #131313;
  --ink-soft: #3d3d3b;
  --muted: #8a8a86;
  --line: #e3e3df;
  --line-soft: #eeeeeb;
  --accent: #131313;
  --accent-deep: #000000;
  --ring: rgba(0, 0, 0, 0.18);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 5px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 18px 38px -14px rgba(0, 0, 0, 0.24), 0 6px 14px -8px rgba(0, 0, 0, 0.12);

  --radius: 16px;
  --radius-sm: 11px;

  --display: "Fraunces", ui-serif, Georgia, "Times New Roman", serif;
  --sans: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(120% 80% at 12% -8%, #ffffff 0%, transparent 55%),
    radial-gradient(120% 90% at 100% 0%, #e8e8e5 0%, transparent 50%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ============================================================ masthead */
.masthead {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(2.2rem, 5vw, 3.6rem) clamp(1.2rem, 4vw, 2.4rem) clamp(1.4rem, 3vw, 2rem);
}

.masthead__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand__mark {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 4px;
  background: var(--accent);
  transform: rotate(45deg);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.08);
}

.brand__title {
  margin: 0;
  font-family: var(--display);
  font-optical-sizing: auto;
  font-weight: 580;
  font-size: clamp(2.1rem, 5.5vw, 3.4rem);
  line-height: 0.96;
  letter-spacing: -0.018em;
}

.brand__count {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.brand__tag {
  margin: 0.85rem 0 0;
  max-width: 46ch;
  font-size: clamp(0.98rem, 2vw, 1.1rem);
  font-style: italic;
  font-family: var(--display);
  color: var(--ink-soft);
}

/* ============================================================ dropbar */
.dropbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: clamp(1.4rem, 3vw, 2rem);
  padding: 0.45rem 0.45rem 0.45rem 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: inset 0 1px 1px rgba(46, 33, 16, 0.03), var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.dropbar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring), var(--shadow-sm);
}

.dropbar__icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  color: var(--muted);
}
.dropbar__icon svg {
  width: 100%;
  height: 100%;
}

#url-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-family: var(--sans);
  font-size: 1.02rem;
  color: var(--ink);
  padding: 0.55rem 0.4rem;
}
#url-input::placeholder {
  color: var(--muted);
}
#url-input:focus {
  outline: none;
}

.dropbar__btn {
  position: relative;
  flex: none;
  border: 0;
  cursor: pointer;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.95rem;
  color: #fafafa;
  background: var(--accent);
  padding: 0.66rem 1.3rem;
  border-radius: 999px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 4px 12px -4px rgba(0, 0, 0, 0.45);
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}
.dropbar__btn:hover {
  background: var(--accent-deep);
}
.dropbar__btn:active {
  transform: translateY(1px);
}
.dropbar__btn:disabled {
  cursor: default;
  opacity: 0.85;
}
.dropbar__btn.is-loading .dropbar__btn-label {
  opacity: 0;
}
.dropbar__spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  opacity: 0;
}
.dropbar__btn.is-loading .dropbar__spinner {
  opacity: 1;
  animation: spin 0.7s linear infinite;
}

/* ============================================================ page + grid */
.page {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.5rem clamp(1.2rem, 4vw, 2.4rem) 4rem;
}

.grid {
  position: relative; /* makes grid the offsetParent for drag hit-testing */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: clamp(1rem, 2vw, 1.5rem);
}

/* ============================================================ card */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.26s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.26s ease,
    border-color 0.26s ease, opacity 0.26s ease;
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--line-soft);
}

/* drag-to-reorder (pointer-based) */
.card {
  cursor: grab;
  touch-action: pan-y;
}
/* the lifted card floating under the cursor */
.card.dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-lg);
  border-color: var(--line-soft);
  animation: none;
  will-change: transform;
}
/* the empty slot the card will drop into */
.card--placeholder {
  pointer-events: none;
  background: transparent;
  border: 1.5px dashed var(--line);
  box-shadow: none;
  animation: none;
}
body.is-reordering {
  cursor: grabbing;
  user-select: none;
  -webkit-user-select: none;
}
/* Freeze hover reactions on the resting cards mid-drag so nothing flickers,
   and hand transform control entirely to GSAP (no CSS transition fighting it). */
.grid.is-dragging .card {
  cursor: grabbing;
  transition: none;
}
.grid.is-dragging .card:not(.dragging):hover {
  transform: none;
  box-shadow: var(--shadow-sm);
  border-color: var(--line);
}
.grid.is-dragging .card:not(.dragging):hover .card__media img {
  transform: none;
}
.grid.is-dragging .card:not(.dragging):hover .card__del {
  opacity: 0;
}

.card__media {
  position: relative;
  display: block;
  aspect-ratio: 16 / 10;
  background: var(--paper-2);
  overflow: hidden;
}
.card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.card:hover .card__media img {
  transform: scale(1.045);
}

/* image-less fallback */
.card__media--fallback {
  display: grid;
  place-items: center;
}
.fallback {
  --tint: 28deg;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 0.2rem;
  background:
    radial-gradient(120% 120% at 30% 18%, hsl(var(--tint) 0% 94%), transparent 60%),
    linear-gradient(150deg, hsl(var(--tint) 0% 88%), hsl(var(--tint) 0% 78%));
}
.fallback__letter {
  font-family: var(--display);
  font-weight: 600;
  font-size: 2.6rem;
  line-height: 1;
  color: hsl(var(--tint) 0% 22%);
}
.fallback__domain {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: hsl(var(--tint) 0% 34%);
  max-width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* delete */
.card__del {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
  background: rgba(252, 251, 246, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 2px 8px rgba(46, 33, 16, 0.18);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.18s ease, transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}
.card__del svg {
  width: 16px;
  height: 16px;
}
.card:hover .card__del,
.card__del:focus-visible {
  opacity: 1;
  transform: scale(1);
}
.card__del:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.card__body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem 1.05rem 0.55rem;
  flex: 1;
}
.card__title {
  font-family: var(--display);
  font-optical-sizing: auto;
  font-weight: 560;
  font-size: 1.07rem;
  line-height: 1.25;
  letter-spacing: -0.006em;
  color: var(--ink);
  text-decoration: none;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__title:hover {
  color: var(--accent-deep);
}
.card__desc {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__foot {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
  padding: 0.7rem 1.05rem 0.95rem;
  text-decoration: none;
  color: var(--muted);
  border-top: 1px solid var(--line-soft);
}
.card__fav {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 4px;
  object-fit: cover;
  background: var(--paper-2);
}
.card__site {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: lowercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================ skeleton */
.card--skeleton {
  pointer-events: none;
}
.card--skeleton .card__media {
  aspect-ratio: 16 / 10;
}
.skel {
  position: relative;
  overflow: hidden;
  background: var(--line-soft);
}
.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  animation: shimmer 1.25s infinite;
}
.skel--line {
  height: 0.85rem;
  border-radius: 5px;
  margin: 0.55rem 1.05rem 0;
}
.skel--chip {
  height: 0.8rem;
  width: 45%;
  border-radius: 5px;
  margin: 0.85rem 1.05rem 1.1rem;
}

/* ============================================================ card exit */
.card--out {
  opacity: 0;
  transform: scale(0.94) translateY(6px);
  pointer-events: none;
}

/* ============================================================ empty */
.empty {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  text-align: center;
  gap: 0.5rem;
  margin: 2rem auto;
  padding: clamp(2.5rem, 7vw, 4.5rem) 1.5rem;
  max-width: 460px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(252, 251, 246, 0.4);
}
.empty__mark {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--paper-2);
  border: 1.5px solid var(--line);
  transform: rotate(45deg);
  margin-bottom: 0.5rem;
}
.empty__title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.3rem;
  font-weight: 560;
  color: var(--ink);
}
.empty__hint {
  margin: 0;
  max-width: 36ch;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--muted);
}

/* ============================================================ toast */
.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 1.5rem;
  transform: translate(-50%, 150%);
  max-width: min(90vw, 420px);
  padding: 0.8rem 1.2rem;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.32s ease;
}
.toast--show {
  transform: translate(-50%, 0);
  opacity: 1;
}

/* ============================================================ motion */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes shimmer {
  100% {
    transform: translateX(100%);
  }
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
