/* ============================================================
   FlipMag – Polished Magazine UI
   ============================================================ */

:root {
  --tile-radius: 16px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Navigation */
.nav-link {
  @apply px-3.5 py-2 rounded-xl text-sm font-medium text-slate-600 dark:text-slate-400
         hover:text-slate-900 dark:hover:text-white hover:bg-slate-100 dark:hover:bg-slate-800
         transition-colors;
}
.nav-link.active {
  @apply text-indigo-600 dark:text-indigo-400 bg-indigo-50 dark:bg-indigo-500/10;
}
.nav-link-mobile {
  @apply block px-3 py-2.5 rounded-xl text-sm font-medium text-slate-700 dark:text-slate-300
         hover:bg-slate-100 dark:hover:bg-slate-800;
}
.nav-link-mobile.active {
  @apply text-indigo-600 dark:text-indigo-400 bg-indigo-50 dark:bg-indigo-500/10;
}

/* Magazine masonry grid — denser, more tiles on screen */
.magazine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.9rem;
  grid-auto-rows: 10px;
}

@media (min-width: 640px) {
  .magazine-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
  }
}

@media (min-width: 1024px) {
  .magazine-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 1.1rem;
  }
}

@media (min-width: 1280px) {
  .magazine-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (min-width: 1536px) {
  .magazine-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* Tile sizes via span */
.tile {
  border-radius: var(--tile-radius);
  overflow: hidden;
  background: white;
  box-shadow: 0 4px 24px -4px rgba(0,0,0,0.08), 0 2px 8px -2px rgba(0,0,0,0.04);
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease);
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
}

.dark .tile {
  background: #1e293b;
  box-shadow: 0 4px 24px -4px rgba(0,0,0,0.4);
}

.tile:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 20px 40px -12px rgba(0,0,0,0.18), 0 8px 16px -8px rgba(0,0,0,0.1);
}

.dark .tile:hover {
  box-shadow: 0 20px 40px -12px rgba(0,0,0,0.5);
}

/* Size variants — compact so more tiles fit */
.tile-small   { grid-row: span 12; }
.tile-medium  { grid-row: span 15; }
.tile-large   { grid-row: span 19; }
.tile-wide    { grid-column: span 2; grid-row: span 13; }
.tile-hero    { grid-column: span 2; grid-row: span 22; }

@media (min-width: 1280px) {
  .tile-hero { grid-column: span 2; grid-row: span 24; }
}

@media (max-width: 639px) {
  .tile-wide, .tile-hero { grid-column: span 1; }
  .tile-small   { grid-row: span 14; }
  .tile-medium  { grid-row: span 16; }
  .tile-large   { grid-row: span 18; }
  .tile-hero    { grid-row: span 20; }
}

/* Title hierarchy by tile size */
.tile-small  .tile-title { font-size: 0.88rem; -webkit-line-clamp: 2; }
.tile-medium .tile-title { font-size: 0.98rem; }
.tile-large  .tile-title { font-size: 1.1rem;  -webkit-line-clamp: 3; }
.tile-wide   .tile-title { font-size: 1.05rem; -webkit-line-clamp: 2; }
.tile-hero   .tile-title { font-size: 1.3rem;  -webkit-line-clamp: 3; line-height: 1.25; }

.tile-hero .tile-source { font-size: 0.75rem; margin-bottom: 0.35rem; }
.tile-small .tile-meta  { padding: 0.45rem 0.75rem; font-size: 0.7rem; }
.tile-medium .tile-meta { padding: 0.55rem 0.85rem; }

/* Image area */
.tile-image {
  position: relative;
  flex: 1;
  min-height: 120px;
  background: linear-gradient(145deg, #e2e8f0 0%, #cbd5e1 50%, #94a3b8 100%);
  overflow: hidden;
}

.tile-small  .tile-image { min-height: 95px; }
.tile-medium .tile-image { min-height: 120px; }
.tile-large  .tile-image { min-height: 150px; }
.tile-wide   .tile-image { min-height: 130px; }
.tile-hero   .tile-image { min-height: 190px; }

.dark .tile-image {
  background: linear-gradient(145deg, #334155 0%, #1e293b 60%, #0f172a 100%);
}

/* Attractive fallback when no image (or image failed) */
.tile-image.no-image {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(99,102,241,0.18), transparent 55%),
    radial-gradient(ellipse at 70% 80%, rgba(139,92,246,0.12), transparent 50%),
    linear-gradient(145deg, #e2e8f0 0%, #cbd5e1 50%, #94a3b8 100%);
}
.dark .tile-image.no-image {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(99,102,241,0.25), transparent 55%),
    radial-gradient(ellipse at 70% 80%, rgba(139,92,246,0.18), transparent 50%),
    linear-gradient(145deg, #334155 0%, #1e293b 60%, #0f172a 100%);
}

.tile-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
}

.tile-image img.img-failed {
  display: none;
}

.tile-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.3) 45%, transparent 70%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 1rem 1.1rem 1.1rem;
}

.tile-source {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.85);
  margin-bottom: 0.25rem;
}

.tile-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
  color: white;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  font-size: 0.75rem;
  color: #64748b;
  background: white;
  border-top: 1px solid #f1f5f9;
}

.dark .tile-meta {
  background: #1e293b;
  border-top-color: #334155;
  color: #94a3b8;
}

/* Context menu */
.ctx-menu {
  position: absolute;
  z-index: 60;
  min-width: 180px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.05);
  padding: 0.35rem;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95) translateY(-4px);
  transition: all 0.15s var(--ease);
}

.dark .ctx-menu {
  background: #1e293b;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.06);
}

.ctx-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

.ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.85rem;
  font-size: 0.875rem;
  border-radius: 8px;
  color: #334155;
  transition: background 0.1s;
}

.dark .ctx-item { color: #e2e8f0; }
.ctx-item:hover { background: #f1f5f9; }
.dark .ctx-item:hover { background: #334155; }
.ctx-sep { height: 1px; background: #e2e8f0; margin: 0.3rem 0.5rem; }
.dark .ctx-sep { background: #334155; }

/* Cards for lists / settings */
.card {
  background: white;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  padding: 1.25rem 1.5rem;
  transition: border-color 0.2s;
}

.dark .card {
  background: #1e293b;
  border-color: #334155;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 12px;
  transition: all 0.2s;
}
.btn-primary {
  background: #0f172a;
  color: white;
}
.dark .btn-primary {
  background: white;
  color: #0f172a;
}
.btn-primary:hover { opacity: 0.9; }
.btn-ghost {
  background: transparent;
  color: #64748b;
}
.btn-ghost:hover { background: #f1f5f9; color: #0f172a; }
.dark .btn-ghost:hover { background: #334155; color: white; }
.btn-accent {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  box-shadow: 0 4px 14px -3px rgba(99,102,241,0.4);
}
.btn-accent:hover { opacity: 0.95; transform: translateY(-1px); }

/* Form controls */
.input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: white;
  font-size: 0.9rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
  outline: none;
  border-color: #818cf8;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}
.dark .input {
  background: #0f172a;
  border-color: #334155;
  color: #f1f5f9;
}
.dark .input:focus {
  border-color: #818cf8;
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 12px;
}
.dark .skeleton {
  background: linear-gradient(90deg, #1e293b 25%, #334155 50%, #1e293b 75%);
  background-size: 200% 100%;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 1.5rem;
  text-align: center;
  color: #64748b;
}

/* Smooth page transitions */
.page-enter {
  animation: fadeUp 0.35s var(--ease);
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Prose for reader */
.prose p { margin-bottom: 1em; }
.prose a { color: #6366f1; text-decoration: underline; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.dark ::-webkit-scrollbar-thumb { background: #475569; }

/* ============================================================
   Live / motion effects
   ============================================================ */

/* Continuous Ken Burns on tile images – more visible scale */
.tile-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  transform-origin: center center;
  animation: kenburns 22s ease-in-out infinite alternate;
  will-change: transform;
  backface-visibility: hidden;
}

/* Stagger direction & speed so the grid feels alive */
.tile:nth-child(3n) .tile-image img {
  animation-duration: 28s;
  animation-direction: alternate-reverse;
  transform-origin: 30% 40%;
}
.tile:nth-child(3n+1) .tile-image img {
  animation-duration: 18s;
  transform-origin: 70% 60%;
}
.tile:nth-child(4n) .tile-image img {
  animation-delay: -6s;
  transform-origin: 40% 70%;
}
.tile:nth-child(5n) .tile-image img {
  animation-duration: 26s;
  animation-direction: alternate-reverse;
}

@keyframes kenburns {
  0%   { transform: scale(1) translate(0, 0); }
  100% { transform: scale(1.18) translate(-2.5%, -2%); }
}

/* ---------- Story-swap effects (randomly chosen) ---------- */

/* 1. Classic crossfade */
.tile.swap-fade.is-swapping .tile-image,
.tile.swap-fade.is-swapping .tile-meta {
  animation: tileFade 0.72s var(--ease);
}
.tile.swap-fade.is-swapping .tile-title {
  animation: titleSlide 0.75s var(--ease);
}

@keyframes tileFade {
  0%   { opacity: 1; }
  40%  { opacity: 0.12; }
  100% { opacity: 1; }
}
@keyframes titleSlide {
  0%   { opacity: 1; transform: translateY(0); }
  35%  { opacity: 0; transform: translateY(10px); }
  36%  { opacity: 0; transform: translateY(-8px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* 2. Scale + fade (zoom through) */
.tile.swap-scale.is-swapping {
  animation: tileScale 0.75s var(--ease);
}
.tile.swap-scale.is-swapping .tile-image,
.tile.swap-scale.is-swapping .tile-meta {
  animation: tileFade 0.72s var(--ease);
}

@keyframes tileScale {
  0%   { transform: scale(1); }
  40%  { transform: scale(0.94); }
  100% { transform: scale(1); }
}

/* 3. Vertical slide */
.tile.swap-slide.is-swapping .tile-image {
  animation: tileSlideImg 0.75s var(--ease);
}
.tile.swap-slide.is-swapping .tile-title {
  animation: titleSlide 0.75s var(--ease);
}
.tile.swap-slide.is-swapping .tile-meta {
  animation: tileFade 0.7s var(--ease);
}

@keyframes tileSlideImg {
  0%   { opacity: 1; transform: translateY(0); }
  38%  { opacity: 0; transform: translateY(18px); }
  39%  { opacity: 0; transform: translateY(-14px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* 4. Card flip (Y-axis) */
.tile.swap-flip.is-swapping {
  animation: tileFlip 0.78s var(--ease);
  transform-style: preserve-3d;
  perspective: 900px;
}

@keyframes tileFlip {
  0%   { transform: rotateY(0deg); }
  45%  { transform: rotateY(90deg); }
  55%  { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

/* Live indicator pulse */
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
  animation: livePulse 2s ease-out infinite;
}
@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45); }
  70%  { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .tile-image img,
  .tile.is-swapping,
  .tile.is-swapping .tile-image,
  .tile.is-swapping .tile-meta,
  .tile.is-swapping .tile-title,
  .live-dot {
    animation: none !important;
  }
}
