/* CSS Reset & Variables */
:root {
  --primary-color: #E60023;
  --bg-color: #ffffff;
  --text-dark: #111111;
  --text-light: #767676;
  --hover-gray: #e9e9e9;
  --search-bg: #e1e1e1;
  --search-hover: #d1d1d1;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 20px 0 rgba(0,0,0,0.1);
  --shadow-md: 0 4px 14px 0 rgba(0,0,0,0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Helvetica, "ヒラギノ角ゴ Pro W3", "Hiragino Kaku Gothic Pro", メイリオ, Meiryo, "ＭＳ Ｐゴシック", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

body {
  background-color: var(--bg-color);
  color: var(--text-dark);
  overflow-y: scroll; /* Always show scrollbar to prevent horizontal layout shift */
  -webkit-font-smoothing: antialiased;
}

/* Typography */
button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
}

/* ================== Navbar ================== */
.navbar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background-color: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  z-index: 1000;
  height: 80px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.05);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.logo:hover {
  background-color: var(--hover-gray);
}

.nav-btn {
  padding: 12px 16px;
  border-radius: var(--radius-full);
  transition: background-color 0.2s ease;
  color: var(--text-dark);
}

.nav-btn.active {
  background-color: var(--text-dark);
  color: white;
}

.nav-btn:not(.active):hover {
  background-color: var(--hover-gray);
}

.search-container {
  flex-grow: 1;
  margin: 0 16px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 16px;
  color: var(--text-light);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 14px 16px 14px 48px;
  border-radius: var(--radius-full);
  border: none;
  background-color: var(--search-bg);
  font-size: 16px;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}

.search-input:hover {
  background-color: var(--search-hover);
}

.search-input:focus {
  background-color: transparent;
  box-shadow: 0 0 0 4px rgba(0, 132, 255, 0.5);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  color: var(--text-light);
  transition: background-color 0.2s ease;
}

.icon-btn.small {
  width: 24px;
  height: 24px;
}

.icon-btn:hover {
  background-color: var(--hover-gray);
}

.profile-pic {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  overflow: hidden;
  cursor: pointer;
  margin: 0 8px;
}

.profile-pic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ================== Main Content & Grid ================== */
.main-content {
  margin-top: 80px;
  padding: 16px;
  min-height: 100vh;
}

/* CSS Grid Masonry Layout (Both Row and Column placement) */
.masonry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(236px, 1fr));
  grid-auto-rows: 10px; /* Small row height for granular spanning */
  justify-content: center;
  gap: 0 16px; /* Column gap only, rows handled by grid logic */
  max-width: 2000px;
  margin: 0 auto;
}

/* ================== Pin Card Component ================== */
.pin {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: zoom-in;
  background-color: #f0f0f0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  transform: translateZ(0);
  /* The row span will be calculated and applied inline by JS */
  margin-bottom: 16px; /* Creates the visual gap between cards */
}

.pin:hover {
  box-shadow: var(--shadow-sm);
}

.pin img {
  width: 100%;
  display: block;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s ease-in-out;
}

.pin img.loaded {
  opacity: 1;
}

/* Hover Overlay */
.pin-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px;
  pointer-events: none;
}

.pin:hover .pin-overlay {
  opacity: 1;
}

.pin-overlay button, 
.pin-overlay a {
  pointer-events: auto;
}

.pin-save-btn {
  align-self: flex-end;
  background-color: var(--primary-color);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius-full);
  font-size: 16px;
  font-weight: 700;
  transform: translateY(-10px);
  opacity: 0;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pin:hover .pin-save-btn {
  transform: translateY(0);
  opacity: 1;
}

.pin-save-btn:hover {
  background-color: #ad081b;
}

.pin-bottom-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  transform: translateY(10px);
  opacity: 0;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pin:hover .pin-bottom-actions {
  transform: translateY(0);
  opacity: 1;
}

.link-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background-color: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(4px);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  text-decoration: none;
  color: var(--text-dark);
  font-size: 14px;
  font-weight: 600;
  max-width: 60%;
}

.link-btn:hover {
  background-color: rgba(255, 255, 255, 1);
}

.link-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-action-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background-color: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dark);
}

.icon-action-btn:hover {
  background-color: rgba(255, 255, 255, 1);
}

.icon-action-btn .material-icons-round {
  font-size: 18px;
}

/* ================== Loading Spinner ================== */
.loader-container {
  display: flex;
  justify-content: center;
  padding: 32px;
  width: 100%;
  grid-column: 1 / -1; /* Loader spans all columns */
}

.spinner {
  width: 32px;
  height: 32px;
  border: 4px solid var(--hover-gray);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* ================== Media Queries ================== */
@media (max-width: 768px) {
  .nav-btn:not(.active), .nav-actions .icon-btn[title="Notifications"], .nav-actions .icon-btn[title="Messages"] {
    display: none;
  }
  .search-container {
    margin: 0 8px;
  }
}
