/* Modern light theme inspired by Medium and top longform platforms */
:root { 
  --maxw: 1280px; 
  --bg: #ffffff; 
  --text: #1a1a1a; 
  --muted: #6b7280; 
  --accent: #3b82f6;
  --border: #e5e7eb;
  --card-bg: #f9fafb;
  --reading-bg: #fafafa;
}

* { box-sizing: border-box; }

body { 
  margin: 0; 
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; 
  background: var(--reading-bg); 
  color: var(--text); 
  line-height: 1.7;
  font-size: 18px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

header { 
  position: sticky; 
  top: 0; 
  background: rgba(255,255,255,0.95); 
  border-bottom: 1px solid var(--border); 
  backdrop-filter: blur(20px);
  z-index: 100;
}

.nav { 
  max-width: var(--maxw); 
  margin: 0 auto; 
  padding: 1rem 2rem; 
  display: flex; 
  gap: 0.75rem; 
  align-items: center; 
}

.nav a { 
  color: var(--muted); 
  text-decoration: none; 
  padding: 0.5rem 1rem; 
  border-radius: 8px; 
  font-weight: 500;
  transition: all 0.2s ease;
}

.nav a:hover { 
  background: var(--card-bg); 
  color: var(--text); 
}

/* Brand + Logo */
.brand { 
  display: inline-flex; 
  align-items: center; 
  padding: 0; 
}

.logo { 
  height: 28px; 
  width: auto; 
  display: block; 
}

/* No hover frame/border for logo link */
.brand:hover { 
  background: transparent; 
  border-bottom: none;
}

/* Link pills container */
.nav-links { 
  display: flex; 
  flex-wrap: wrap; 
  gap: 0; 
  margin-left: 0; 
  align-items: center;
}

/* Pill style */
.pill { 
  background: transparent; 
  border: 0; 
  color: var(--text); 
  border-radius: 0; 
  padding: 0 0.25rem; 
  font-size: 0.8rem;
  line-height: 1;
  margin: 0;
}

.nav-links .pill + .pill {
  border-left: none;
}

.pill:hover { 
  background: transparent; 
  color: var(--text); 
  text-decoration: underline;
}

.pill.active { 
  background: var(--text); 
  color: #fff; 
  border-radius: 999px; 
  margin: 0 2px; 
  padding: 0 0.5rem;
}

.container { 
  max-width: var(--maxw); 
  margin: 0 auto; 
  padding: 2rem 2rem 4rem; 
}

main article { 
  background: var(--bg); 
  border: 1px solid var(--border); 
  border-radius: 16px; 
  padding: 3rem; 
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 2rem;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* Alla bilder i artiklar */
main article img {
  max-width: 100% !important;
  width: auto !important;
  height: auto !important;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.2s ease;
  /* Säkerställ att bilden inte går utanför artikelbredden */
  display: block !important;
  margin: 2rem auto !important;
  /* Tvinga bilden att respektera containern */
  box-sizing: border-box;
  overflow: hidden;
}

/* Specifika klasser för bilder */
.article-image {
  max-width: 100% !important;
  width: auto !important;
  height: auto !important;
  display: block !important;
  margin: 2rem auto !important;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.2s ease;
}

.image-container {
  text-align: center;
  overflow: hidden;
  max-width: 100%;
  margin: 2rem 0;
}

/* Bildtexter */
.image-caption {
  text-align: center;
  margin: 0.5rem 0 2rem 0;
  color: var(--muted);
  font-size: 1.9rem;
  line-height: 1.4;
  font-style: italic;
  max-width: 100%;
}

.image-caption em {
  font-style: italic;
  color: var(--muted);
}

/* Automatisk styling för markdown-bilder med bildtexter */
main article img + p em,
main article img + em {
  display: block;
  text-align: center;
  margin: 0.5rem 0 2rem 0;
  color: var(--muted);
  font-size: 1.9rem;
  line-height: 1.4;
  font-style: italic;
  max-width: 100%;
}

/* Hantera fall där bilden inte är i en p-tag */
main article img + em {
  display: block;
  text-align: center;
  margin: 0.5rem 0 2rem 0;
  color: var(--muted);
  font-size: 1.9rem;
  line-height: 1.4;
  font-style: italic;
  max-width: 100%;
}

/* Styling för bildtexter som ligger i samma p-tag som bilden */
.image-container em {
  display: block;
  text-align: center;
  margin: 0.5rem 0 2rem 0;
  color: var(--muted);
  font-size: 1.9rem;
  line-height: 1.4;
  font-style: italic;
  max-width: 100%;
}

/* Alternativ styling för bildtexter i image-container */
p.image-container em {
  display: block;
  text-align: center;
  margin: 0.5rem 0 2rem 0;
  color: var(--muted);
  font-size: 1.9rem;
  line-height: 1.4;
  font-style: italic;
  max-width: 100%;
}

/* Mer specifik styling för bildtexter i image-container */
.image-container > em {
  display: block !important;
  text-align: center !important;
  margin: 0.5rem 0 2rem 0 !important;
  color: var(--muted) !important;
  font-size: 1.9rem !important;
  line-height: 1.4 !important;
  font-style: italic !important;
  max-width: 100% !important;
}

main article img:hover,
.article-image:hover {
  transform: scale(1.02);
}

/* Hantera paragraf som innehåller bilder */
main article p:has(img) {
  text-align: center;
  overflow: hidden;
  max-width: 100%;
}

/* Alternativ för webbläsare som inte stöder :has() */
main article p img {
  /* Säkerställ att bilden inte går utanför paragrafen */
  max-width: 100% !important;
  width: auto !important;
  height: auto !important;
}

/* Behåll figure-stilarna för kompatibilitet */
figure { 
  margin: 2.5rem 0; 
  text-align: center;
  /* Begränsa figure till artikelbredden */
  max-width: 100%;
  overflow: hidden;
}

figure img {
  max-width: 100%;
  width: auto;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.2s ease;
  /* Säkerställ att bilden inte går utanför figure */
  display: block;
  margin: 0 auto;
}

figure img:hover {
  transform: scale(1.02);
}

/* Bildvisar-overlay */
.image-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}

.image-overlay.active {
  display: flex;
}

.overlay-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  text-align: center;
}

.overlay-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.overlay-caption {
  color: white;
  margin-top: 1rem;
  font-size: 1rem;
  font-style: italic;
}

/* Navigeringsknappar */
.overlay-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 2rem;
  padding: 1rem 0.5rem;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.overlay-nav:hover {
  background: rgba(255, 255, 255, 0.3);
}

.overlay-nav.prev {
  left: -60px;
}

.overlay-nav.next {
  right: -60px;
}

.overlay-close {
  position: absolute;
  top: -50px;
  right: -50px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.5rem;
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  transition: background 0.2s ease;
}

.overlay-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Tumnaglar */
.overlay-thumbnails {
  position: absolute;
  bottom: -80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.5rem;
  max-width: 80vw;
  overflow-x: auto;
  padding: 1rem;
}

.thumbnail {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  border: 2px solid transparent;
}

.thumbnail:hover,
.thumbnail.active {
  opacity: 1;
  border-color: var(--accent);
}

figcaption { 
  color: var(--muted); 
  font-size: 0.95rem; 
  text-align: center;
  margin-top: 1rem;
  font-style: italic;
}

a { 
  color: var(--accent); 
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

a:hover {
  border-bottom-color: var(--accent);
}

/* Hero section */
.hero {
  position: relative;
  text-align: center;
  margin-bottom: 4rem;
  padding: 6rem 1rem;
  background: var(--bg);
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  overflow: hidden;
}

.hero h1 {
  font-size: 3.2rem;
  margin-bottom: 1.5rem;
  color: #fff;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.ingress {
  font-size: 1.4rem;
  color: #e5e7eb;
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.6;
  font-weight: 400;
}

/* Hero with background image and dark gradient overlay */
.hero-has-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--hero-image);
  background-size: cover;
  background-position: center;
  filter: saturate(0.9) contrast(1.05);
}

.hero-has-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.55), rgba(0,0,0,0.35) 40%, rgba(0,0,0,0.6));
}

.hero-has-bg > * {
  position: relative;
  z-index: 1;
}

/* Articles grid */
.articles-grid h2 {
  text-align: center;
  margin-bottom: 3rem;
  color: var(--text);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.cards-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2rem;
  margin-top: 2rem;
}

/* Responsive grid columns for cards */
@media (max-width: 1200px) {
  .cards-container {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .cards-container {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Card styles */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.3s ease;
  height: 100%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 20px 25px rgba(0,0,0,0.1);
}

/* Make the whole card clickable without default underline */
.card-link-block {
  display: block;
  color: inherit;
  text-decoration: none;
  border: none;
}

.card-link-block:hover {
  text-decoration: none;
  border: none;
}

.card-image {
  height: 200px;
  overflow: hidden;
  background: var(--card-bg);
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.card:hover .card-image img {
  transform: scale(1.05);
}

.placeholder-image {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
}

.placeholder-image .icon {
  font-size: 3rem;
  opacity: 0.4;
  color: var(--muted);
}

.card-content {
  padding: 1.5rem;
}

.card-title {
  font-size: 1.4rem;
  margin-bottom: 1rem;
  color: var(--text);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.025em;
}

.card-excerpt {
  color: var(--muted);
  margin-bottom: 1.5rem;
  line-height: 1.6;
  font-size: 0.95rem;
}

.card-link {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;
  padding: 0.5rem 0;
  border-bottom: 1px solid transparent;
}

.card-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Article typography for optimal readability */
main article h1 {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.025em;
  margin: 0 0 2rem 0;
  color: var(--text);
}

main article h2 {
  font-size: 1.8rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 3rem 0 1.5rem 0;
  color: var(--text);
}

main article h3 {
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.4;
  margin: 2.5rem 0 1rem 0;
  color: var(--text);
}

main article p {
  margin: 0 0 1.5rem 0;
  line-height: 1.8;
  color: var(--text);
}

main article strong {
  font-weight: 600;
  color: var(--text);
}

main article em {
  font-style: italic;
  color: var(--muted);
}

main article ul, main article ol {
  margin: 1.5rem 0;
  padding-left: 1.5rem;
}

main article li {
  margin: 0.5rem 0;
  line-height: 1.6;
}

main article blockquote {
  margin: 2rem 0;
  padding: 1.5rem 2rem;
  border-left: 4px solid var(--accent);
  background: var(--card-bg);
  border-radius: 8px;
  font-style: italic;
  color: var(--muted);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .hero h1 {
    font-size: 2.5rem;
  }
  
  .hero {
    padding: 2rem 1rem;
  }
  
  .cards-container {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  
  .card-content {
    padding: 1.2rem;
  }
  
  main article {
    padding: 2rem 1.5rem;
  }
  
  .container {
    padding: 1rem 1rem 2rem;
  }
  
  .nav {
    padding: 1rem 1rem;
  }

  .logo {
    height: 24px;
  }
}
