/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { display: flex; flex-direction: column; min-height: 100%; }

:root {
  --purple: #6e38cc;
  --purple-light: #8b5cf6;
  --purple-dark: #5b2ea8;

  /* Light theme (default) */
  --bg: #ffffff;
  --bg-secondary: #f8f7fc;
  --text: #1a1a2e;
  --text-secondary: #555;
  --border: #e5e5e5;
  --code-bg: #f4f0fb;
  --card-bg: #ffffff;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.08);
  --card-shadow-hover: 0 4px 12px rgba(110,56,204,0.15);

  font-family: 'Mulish', sans-serif;
  font-size: 16px;
  line-height: 1.8;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Dark theme */
[data-theme="dark"] {
  --bg: #0f0e17;
  --bg-secondary: #1a1929;
  --text: #e8e6f0;
  --text-secondary: #a09cb5;
  --border: #2a2940;
  --code-bg: #1e1d2f;
  --card-bg: #1a1929;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
  --card-shadow-hover: 0 4px 12px rgba(110,56,204,0.3);
  --purple: #a78bfa;
  --purple-light: #c4b5fd;
  --purple-dark: #8b5cf6;
}

/* Auto = follow system */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg: #0f0e17;
    --bg-secondary: #1a1929;
    --text: #e8e6f0;
    --text-secondary: #a09cb5;
    --border: #2a2940;
    --code-bg: #1e1d2f;
    --card-bg: #1a1929;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
    --card-shadow-hover: 0 4px 12px rgba(110,56,204,0.3);
    --purple: #a78bfa;
    --purple-light: #c4b5fd;
    --purple-dark: #8b5cf6;
  }
}

/* === Skip Link === */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--purple);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 0 0 6px 6px;
  font-weight: 700;
  font-size: 0.85rem;
  z-index: 200;
  text-decoration: none;
}

.skip-link:focus {
  top: 0;
}

/* === Layout === */
.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* === Header === */
.site-header {
  border-bottom: 2px solid var(--purple);
  padding: 1.25rem 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}

.site-header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-name {
  font-weight: 900;
  font-size: 1.25rem;
  color: var(--purple);
  text-decoration: none;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.nav-right a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.nav-right a:hover {
  color: var(--purple);
}

/* === Theme Toggle === */
.theme-toggle {
  background: none;
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 2.25rem;
  height: 2.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s;
}

.theme-toggle:hover {
  border-color: var(--purple);
}

.theme-icon::before {
  content: "\25D1";
  font-size: 1.1rem;
  color: var(--text);
}

[data-theme="light"] .theme-icon::before { content: "\2600"; }
[data-theme="dark"] .theme-icon::before { content: "\263E"; }

/* === Main Content === */
main {
  flex: 1;
  padding: 3.5rem 0 4rem;
}

/* === Homepage Hero === */
.hero {
  margin-bottom: 4rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.hero h1 {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.2;
  margin-bottom: 1rem;
}

.hero h1 .accent {
  color: var(--purple);
}

.hero p {
  color: var(--text-secondary);
  font-size: 1.1rem;
  line-height: 1.8;
  max-width: 540px;
}

/* === Article List === */
.articles-list {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.article-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: block;
  transition: box-shadow 0.2s, transform 0.15s;
  box-shadow: var(--card-shadow);
}

.article-card > a {
  text-decoration: none;
  color: inherit;
  display: block;
}

.article-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

.article-card img {
  width: 100%;
  height: auto;
  display: block;
}

.article-card .card-body {
  padding: 1.5rem;
}

.article-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  line-height: 1.35;
}

.article-card .meta {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.article-card .excerpt {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* === Back Link === */
.back-link {
  display: inline-block;
  color: var(--purple);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 2rem;
  transition: opacity 0.2s;
}

.back-link:hover {
  opacity: 0.7;
}

article + .back-link {
  margin-top: 3rem;
  margin-bottom: 0;
}

/* === Article Detail === */
.article-header {
  margin-bottom: 2.5rem;
}

.article-header h1 {
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.2;
  margin-bottom: 0.75rem;
}

.article-header .meta {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

picture.article-hero {
  display: block;
  margin-bottom: 2.5rem;
}

picture.article-hero img,
.article-hero {
  width: 100%;
  height: auto;
  border-radius: 12px;
}

.article-card picture {
  display: block;
}

.article-card picture img {
  width: 100%;
  height: auto;
  display: block;
}

/* === Article Prose === */
.prose h2 { font-size: 1.5rem; font-weight: 800; margin: 2.5rem 0 1rem; }
.prose h3 { font-size: 1.25rem; font-weight: 700; margin: 2rem 0 0.75rem; }
.prose p { margin-bottom: 1.5rem; text-align: justify; }

.prose a {
  color: var(--purple);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose img {
  max-width: 100%;
  border-radius: 8px;
  margin: 2rem 0;
  display: block;
}

.prose picture {
  display: block;
  margin: 2rem 0;
}

.prose picture img {
  width: 100%;
  height: auto;
  margin: 0;
}

.prose blockquote {
  border-left: 4px solid var(--purple);
  padding: 1rem 1.5rem;
  margin: 2rem 0;
  background: var(--bg-secondary);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}

.prose code {
  background: var(--code-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.9em;
}

.prose pre {
  background: var(--code-bg);
  padding: 1.25rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 2rem 0;
}

.prose pre code {
  background: none;
  padding: 0;
}

.prose ul, .prose ol {
  margin: 1.25rem 0 1.5rem 1.5rem;
}

.prose li {
  margin-bottom: 0.5rem;
  text-align: justify;
}

.prose hr {
  border: none;
  border-top: 2px solid var(--border);
  margin: 2.5rem 0;
}

/* === Error Page === */
.error-page {
  text-align: center;
  padding: 4rem 0;
}

.error-code {
  font-size: 6rem;
  font-weight: 900;
  color: var(--purple);
  line-height: 1;
  margin-bottom: 0.5rem;
  opacity: 0.3;
}

.error-page h1 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 1rem;
}

.error-message {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 2.5rem;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.7;
}

.error-home {
  display: inline-block;
  color: var(--purple);
  text-decoration: none;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.6rem 1.5rem;
  border: 2px solid var(--purple);
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
}

.error-home:hover {
  background: var(--purple);
  color: #fff;
}

/* === Footer === */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  margin-top: 2rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.site-footer .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.social-links {
  display: flex;
  gap: 1.25rem;
}

.social-links a {
  color: var(--purple);
  text-decoration: none;
  font-weight: 600;
}

.social-links a:hover {
  text-decoration: underline;
}

/* === Responsive (tablet+) === */
@media (min-width: 640px) {
  .hero h1 { font-size: 2.5rem; }
  .article-header h1 { font-size: 2.5rem; }
}

@media (min-width: 1024px) {
  .container { max-width: 760px; }
  .hero h1 { font-size: 3rem; }
}

/* === Article Perex === */
.article-perex {
  font-size: 1.15rem;
  line-height: 1.8;
  color: var(--text);
  text-align: justify;
  margin-bottom: 0;
}

.article-perex p {
  margin-bottom: 0.75rem;
}

.article-perex p:last-child {
  margin-bottom: 0;
}

.article-perex + hr {
  margin: 2.5rem 0;
}
