/* ===========================================
   Unofficial Tutorials - Clean Reading Theme
   =========================================== */

:root {
  /* Light mode */
  --bg: #ffffff;
  --bg-alt: #f7f8fa;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #d71920;
  --accent-hover: #b31418;
  --accent-text: #ffffff;
  --card-bg: #ffffff;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.08);
  --code-bg: #f3f4f6;
  --code-text: #1f2937;
  --max-width: 800px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
}

/* Dark mode (system preference) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --bg-alt: #1a1b26;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #2d2f3e;
    --accent: #ef4444;
    --accent-hover: #dc2626;
    --accent-text: #ffffff;
    --card-bg: #1a1b26;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
    --code-bg: #1e1e2e;
    --code-text: #cdd6f4;
  }
}

/* Manual dark mode override (class-based, takes precedence) */
html.dark-mode {
  --bg: #0f1117;
  --bg-alt: #1a1b26;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #2d2f3e;
  --accent: #ef4444;
  --accent-hover: #dc2626;
  --accent-text: #ffffff;
  --card-bg: #1a1b26;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
  --code-bg: #1e1e2e;
  --code-text: #cdd6f4;
}

/* Manual light mode override (class-based, takes precedence) */
html.light-mode {
  --bg: #ffffff;
  --bg-alt: #f7f8fa;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #d71920;
  --accent-hover: #b31418;
  --accent-text: #ffffff;
  --card-bg: #ffffff;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.08);
  --code-bg: #f3f4f6;
  --code-text: #1f2937;
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  overflow-x: hidden;
  word-wrap: break-word;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s;
}
a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

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

/* Layout */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Theme toggle button */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 6px 10px;
  line-height: 1;
  transition: border-color 0.15s;
}
.theme-toggle:hover {
  border-color: var(--accent);
}

/* Site header */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  background: var(--bg);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.site-brand {
  font-size: 1.3rem;
  font-weight: 700;
}
.site-brand a {
  color: var(--text);
  text-decoration: none;
}
.site-brand a:hover {
  color: var(--accent);
  text-decoration: none;
}
.site-brand .tagline {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
  display: block;
  margin-top: -2px;
}

.main-nav {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
}
.main-nav a {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.main-nav a:hover {
  color: var(--accent);
  text-decoration: none;
}

/* Search form */
.search-form {
  display: flex;
  gap: 0;
}
.search-form input[type="text"] {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 6px 0 0 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  width: 140px;
  outline: none;
}
.search-form input[type="text"]:focus {
  border-color: var(--accent);
}
.search-form button {
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid var(--accent);
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s;
}
.search-form button:hover {
  background: var(--accent-hover);
}

/* Main content area */
.main-content {
  padding: 40px 0;
  min-height: 60vh;
}

.content-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 40px;
  max-width: 100%;
}

@media (max-width: 900px) {
  .content-layout {
    grid-template-columns: 1fr 260px;
    gap: 24px;
  }
}

@media (max-width: 768px) {
  .content-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  html, body {
    overflow-x: hidden;
    width: 100%;
  }
  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .main-nav {
    justify-content: space-between;
    gap: 8px;
  }
  .search-form input[type="text"] {
    width: 100px;
  }
  .article-header h1 {
    font-size: 1.5rem;
  }
  .article-body {
    font-size: 1rem;
  }
  .article-body pre {
    font-size: 0.8rem;
    padding: 12px 14px;
    -webkit-overflow-scrolling: touch;
  }
  .page-heading {
    font-size: 1.35rem;
  }
  .container {
    padding: 0 14px;
    max-width: 100%;
    overflow: hidden;
  }
  .sidebar {
    overflow: hidden !important;
    max-width: 100% !important;
  }
  .sidebar-section {
    padding: 14px;
    overflow: hidden !important;
    max-width: 100% !important;
  }
  .adsense-container,
  .ad-inline {
    overflow: hidden !important;
    max-width: 100% !important;
    min-width: 0 !important;
    width: 100% !important;
  }
  .adsense-container ins.adsbygoogle,
  .ad-inline ins.adsbygoogle,
  .adsense-container iframe,
  .ad-inline iframe {
    max-width: 100% !important;
    min-width: 0 !important;
    width: 100% !important;
    overflow: hidden !important;
  }
}

@media (max-width: 400px) {
  .main-nav {
    flex-wrap: wrap;
  }
  .search-form {
    flex: 1;
    min-width: 0;
  }
  .search-form input[type="text"] {
    width: 0;
    flex: 1;
    min-width: 60px;
  }
  .article-card {
    padding: 16px;
  }
  .article-card h2 {
    font-size: 1.1rem;
  }
  .article-body pre {
    font-size: 0.75rem;
    padding: 10px 12px;
  }
  .sidebar {
    width: 100%;
  }
  .sidebar-section {
    padding: 12px;
  }
}

.content-area {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

/* Article layout */
article {
  max-width: 100%;
  overflow: hidden;
}

/* Article list (homepage + category) */
.article-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.article-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--card-shadow);
  transition: border-color 0.15s;
}
.article-card:hover {
  border-color: var(--accent);
}

.article-card .category-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.article-card .category-tag:hover {
  text-decoration: none;
}

.article-card h2 {
  font-size: 1.25rem;
  line-height: 1.4;
  margin-bottom: 8px;
}
.article-card h2 a {
  color: var(--text);
}
.article-card h2 a:hover {
  color: var(--accent);
  text-decoration: none;
}

.article-card .excerpt {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.article-card .meta {
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  gap: 16px;
  align-items: center;
}

/* Single article page */
.article-header {
  margin-bottom: 32px;
}

.article-header .category-tag {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.article-header h1 {
  font-size: 2rem;
  line-height: 1.3;
  margin-bottom: 12px;
}

.article-header .meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.article-body {
  font-size: 1.05rem;
  line-height: 1.8;
  max-width: 100%;
  overflow-wrap: break-word;
}

.article-body h2 {
  font-size: 1.5rem;
  margin: 32px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.article-body h3 {
  font-size: 1.2rem;
  margin: 24px 0 10px;
}

.article-body p {
  margin-bottom: 16px;
}

.article-body ul, .article-body ol {
  margin: 0 0 16px 24px;
}
.article-body li {
  margin-bottom: 6px;
}

.article-body strong {
  font-weight: 600;
}

.article-body code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  color: var(--code-text);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
}

.article-body pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 16px 20px;
  border-radius: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0 20px;
  border: 1px solid var(--border);
  font-size: 0.88rem;
  line-height: 1.5;
  word-break: break-word;
  max-width: 100%;
}
.article-body pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

.article-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 10px 16px;
  margin: 16px 0;
  background: var(--bg-alt);
  border-radius: 0 6px 6px 0;
  color: var(--text-muted);
}

.article-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

.article-body a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.article-body img {
  border-radius: 8px;
  margin: 16px 0;
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  overflow: hidden;
}

.sidebar-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  overflow: hidden;
}

.sidebar-section h3 {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.category-list {
  list-style: none;
}
.category-list li {
  margin-bottom: 6px;
}
.category-list a {
  display: block;
  padding: 6px 0;
  font-size: 0.9rem;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.category-list a:hover {
  color: var(--accent);
  text-decoration: none;
}
.category-list .count {
  float: right;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Ad block */
.ad-block {
  text-align: center;
  margin: 24px 0;
}
.ad-block ins {
  display: inline-block;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--text-muted);
}

/* Page title */
.page-title {
  font-size: 1.5rem;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h2 {
  font-size: 1.3rem;
  margin-bottom: 8px;
  color: var(--text);
}

/* Page heading */
.page-heading {
  font-size: 1.75rem;
  margin-bottom: 8px;
}

/* Cheat Sheet Sections */
.cheat-sheet-sections {
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.cheat-sheet-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cheat-sheet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.cs-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.cs-card:hover {
  border-color: var(--accent);
  background: var(--bg-alt);
  transform: translateY(-2px);
  text-decoration: none;
  color: var(--text);
}

.cs-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.cs-info {
  flex: 1;
  min-width: 0;
}
.cs-title {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 2px;
  line-height: 1.3;
}
.cs-desc {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.cs-card:hover .cs-title {
  color: var(--accent);
}

@media (max-width: 600px) {
  .cheat-sheet-grid {
    grid-template-columns: 1fr;
  }
  .cs-card {
    padding: 14px;
  }
}

/* Cheat sheet body - more compact than article body */
.cheat-sheet-body {
  max-width: 100%;
  overflow: hidden;
}
.cheat-sheet-body h2 {
  font-size: 1.25rem;
  margin: 24px 0 8px;
}
.cheat-sheet-body h3 {
  font-size: 1.05rem;
  margin: 16px 0 6px;
}
.cheat-sheet-body pre {
  margin: 8px 0 12px;
  font-size: 0.82rem;
}
.cheat-sheet-body p {
  margin-bottom: 8px;
}
.page-subhead {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 0.95rem;
}

/* AdSense containers - prevent iframe overflow */
.adsense-container {
  text-align: center;
  margin: 24px 0;
  min-height: 90px;
  overflow: hidden !important;
  max-width: 100%;
}
.adsense-container iframe,
.adsense-container ins {
  max-width: 100% !important;
  overflow: hidden !important;
}

.ad-inline {
  margin: 24px 0;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
  overflow: hidden !important;
  max-width: 100%;
}
.ad-inline iframe,
.ad-inline ins {
  max-width: 100% !important;
  overflow: hidden !important;
}
