:root {
  --bg: #0a0a0a;
  --bg-elevated: #141414;
  --text: #f5f5f5;
  --text-muted: #888888;
  --accent: #ffffff;
  --border: rgba(255, 255, 255, 0.1);
  --dot-color: rgba(255, 255, 255, 0.08);
  --max-width: 720px;
  --card-glow: rgba(255, 255, 255, 0.08);
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-elevated: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666666;
  --accent: #000000;
  --border: rgba(0, 0, 0, 0.1);
  --dot-color: rgba(0, 0, 0, 0.06);
  --card-glow: rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.5s ease, color 0.5s ease;
  overflow-x: hidden;
}

body {
  transition: background-color 0.5s ease;
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: radial-gradient(var(--dot-color) 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.5;
  pointer-events: none;
  z-index: -1;
  transition: opacity 0.5s ease;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  height: auto;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
header {
  padding: 32px 0;
  border-bottom: 1px solid var(--border);
}

header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

.logo {
  font-weight: 600;
  font-size: 1.1rem;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.nav-main {
  display: flex;
  gap: 24px;
  font-size: 0.9rem;
  margin-left: auto;
}

.nav-main a {
  color: var(--text-muted);
  transition: color 0.2s;
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 4px;
}

.nav-main a:hover,
.nav-main a.active {
  color: var(--text);
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  touch-action: manipulation;
  flex-shrink: 0;
}

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

.theme-icon {
  width: 20px;
  height: 20px;
}

/* Main Content */
main {
  padding: 48px 0;
}

.section {
  margin-bottom: 64px;
}

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* Cards */
.card {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 32px;
  margin-bottom: 24px;
  transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.5s ease;
  box-shadow: 0 0 0 1px var(--border);
  display: block;
}

.card:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 8px 32px var(--card-glow), 0 0 0 1px var(--border);
}

.card-featured {
  box-shadow: -3px 0 0 0 var(--accent), 0 0 0 1px var(--border);
}

.card-featured:hover {
  box-shadow: -3px 0 0 0 var(--accent), 0 8px 32px var(--card-glow), 0 0 0 1px var(--border);
}

.card h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.card h3 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.card p {
  color: var(--text-muted);
  margin-bottom: 16px;
}

.meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.tag {
  font-size: 0.875rem;
  padding: 6px 12px;
  background: var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Lists */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.item-list a {
  display: block;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  min-height: 44px;
}

.item-list a:hover h3 {
  color: var(--accent);
}

.item-list h3 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.item-list .meta {
  font-size: 0.9rem;
}

/* Empty State */
.empty-state {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 12px;
}

/* Article Styles */
article {
  max-width: 65ch;
  overflow-wrap: break-word;
  word-wrap: break-word;
  hyphens: auto;
}

article h1 {
  font-size: 2.5rem;
  line-height: 1.2;
  margin-bottom: 16px;
}

article h2 {
  font-size: 1.5rem;
  margin: 48px 0 16px;
}

article h3 {
  font-size: 1.25rem;
  margin: 32px 0 12px;
}

article p {
  margin-bottom: 20px;
  color: var(--text-muted);
}

article p:first-of-type {
  font-size: 1.125rem;
  color: var(--text);
  margin-bottom: 32px;
}

/* Breadcrumb */
.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.breadcrumb a:hover {
  color: var(--text);
}

/* Chapter Navigation */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  padding: 32px 0;
  border-top: 1px solid var(--border);
  margin-top: 48px;
  gap: 16px;
}

.chapter-nav a {
  color: var(--text-muted);
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 8px 0;
}

.chapter-nav a:hover {
  color: var(--text);
}

/* Related Section */
.related {
  margin-top: 48px;
  padding: 24px;
  background: var(--bg-elevated);
  border-radius: 8px;
}

.related h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Footer */
footer {
  padding: 32px 0;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--text-muted);
}

footer .container {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.footer-links {
  display: flex;
  gap: 24px;
}

.footer-links a {
  min-height: 44px;
  display: flex;
  align-items: center;
}

.footer-links a:hover {
  color: var(--text);
}

/* Menu Toggle Button (for mobile) */
.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--text);
  touch-action: manipulation;
  flex-shrink: 0;
}

.menu-toggle:hover {
  border-color: var(--text);
}

.menu-icon {
  width: 24px;
  height: 24px;
}

/* Responsive */
@media (max-width: 640px) {
  header .container {
    flex-wrap: nowrap;
    gap: 16px;
  }
  
  .nav-main {
    order: 2;
    width: auto;
    justify-content: flex-end;
    gap: 16px;
    margin-left: auto;
  }
  
  .theme-toggle {
    order: 3;
    margin-left: 0;
  }
  
  article h1 {
    font-size: 1.75rem;
  }
  
  .card {
    padding: 24px;
  }
}

@media (max-width: 480px) {
  .nav-main {
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    width: 100%;
    order: 4;
    margin-top: 8px;
    margin-left: 0;
  }
  
  .nav-main a {
    font-size: 0.85rem;
    min-height: 36px;
    padding: 0 8px;
  }
  
  .logo {
    font-size: 1rem;
  }
  
  header .container {
    flex-wrap: wrap;
  }
  
  .section-title {
    font-size: 0.75rem;
  }
  
  .tag {
    font-size: 0.8rem;
    padding: 6px 10px;
    min-height: 36px;
  }
}

@media (max-width: 360px) {
  .container {
    padding: 0 16px;
  }
  
  .nav-main {
    display: none;
  }
  
  .nav-main.active {
    display: flex;
    width: 100%;
    order: 4;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
  }
  
  .menu-toggle {
    display: flex;
    order: 2;
    margin-left: auto;
  }
  
  .theme-toggle {
    order: 3;
    margin-left: 12px;
  }
  
  .chapter-nav {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    gap: 8px;
  }
  
  footer .container {
    justify-content: center;
    text-align: center;
  }
  
  .footer-links {
    justify-content: center;
    width: 100%;
    gap: 16px;
  }
}

/* Disable hover effects on touch devices */
@media (hover: none) {
  .card:hover {
    transform: none;
    box-shadow: 0 0 0 1px var(--border);
  }
  
  .card-featured:hover {
    box-shadow: -3px 0 0 0 var(--accent), 0 0 0 1px var(--border);
  }
}

/* Utilities */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
