/*
Theme Name: TutorPress
Theme URI: https://example.com/tutorpress
Author: TutorPress Team
Author URI: https://example.com
Description: A W3Schools-inspired tutorial theme with TOC, left/right sidebars, and SILO structure for tutorials.
Version: 2.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: tutorpress
Tags: tutorial, education, sidebar, table-of-contents, silo
*/

/* ==========================================
   CSS VARIABLES & RESET
   ========================================== */
:root {
  --primary: #04AA6D;
  --primary-dark: #038a57;
  --primary-light: #d4edda;
  --accent: #f1c40f;
  --dark: #282A35;
  --dark-mid: #3d3f4e;
  --sidebar-bg: #282A35;
  --sidebar-text: #d4d4d4;
  --sidebar-hover: #04AA6D;
  --sidebar-active: #04AA6D;
  --body-bg: #ffffff;
  --content-bg: #ffffff;
  --border: #e0e0e0;
  --text: #333333;
  --text-muted: #666666;
  --code-bg: #f1f1f1;
  --code-border: #04AA6D;
  --note-bg: #ffffcc;
  --tip-bg: #e7f3fe;
  --warning-bg: #fff3cd;
  --toc-bg: #f9f9f9;
  --toc-border: #04AA6D;
  --font-body: 'Source Sans 3', 'Segoe UI', sans-serif;
  --font-heading: 'Nunito', 'Trebuchet MS', sans-serif;
  --font-mono: 'Fira Code', 'Courier New', monospace;
  --left-sidebar-width: 270px;
  --right-sidebar-width: 260px;
  --header-height: 56px;
  --transition: 0.2s ease;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--body-bg);
  overflow-x: hidden;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--primary); }

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

/* ==========================================
   GOOGLE FONTS IMPORT
   ========================================== */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&family=Source+Sans+3:wght@300;400;600&family=Fira+Code:wght@400;500&display=swap');

/* ==========================================
   HEADER / TOPBAR
   ========================================== */
#site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--dark);
  display: flex;
  align-items: center;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 0 16px;
  line-height: var(--header-height);
}

#site-header .logo {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  padding: 0 20px;
  white-space: nowrap;
}
#site-header .logo span { color: var(--primary); }

#header-search {
  flex: 1;
  max-width: 420px;
  margin: 0 16px;
  position: relative;
}
#header-search input {
  width: 100%;
  padding: 7px 36px 7px 14px;
  border-radius: 4px;
  border: none;
  background: #3d3f4e;
  color: #fff;
  font-size: 14px;
  outline: none;
  transition: background var(--transition);
}
#header-search input::placeholder { color: #aaa; }
#header-search input:focus { background: #52546a; }
#header-search .search-icon {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: #aaa; pointer-events: none;
}

#header-nav { margin-left: auto; display: flex; align-items: center; gap: 4px; padding-right: 16px; }
#header-nav a {
  color: #ccc; font-size: 13px; padding: 6px 12px;
  border-radius: 4px; transition: all var(--transition);
}
#header-nav a:hover { background: var(--primary); color: #fff; text-decoration: none; }
#header-nav a.active { background: var(--primary); color: #fff; }

/* ==========================================
   PAGE LAYOUT - THREE COLUMNS
   ========================================== */
#page-wrapper {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* ==========================================
   LEFT SIDEBAR (Navigation)
   ========================================== */
#left-sidebar {
  width: var(--left-sidebar-width);
  min-width: var(--left-sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 900;
  transition: transform var(--transition);
  scrollbar-width: thin;
  scrollbar-color: #555 var(--sidebar-bg);
}
#left-sidebar::-webkit-scrollbar { width: 4px; }
#left-sidebar::-webkit-scrollbar-thumb { background: #555; border-radius: 2px; }

.sidebar-nav { padding: 12px 0 60px; }

/* ── Series header: full-width link row ── */
.silo-group { margin-bottom: 1px; }

.silo-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8a90a0;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}
.silo-group-header:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
  text-decoration: none;
}
/* Active / current series */
.silo-group-header.series-active {
  color: var(--primary);
  border-left-color: var(--primary);
  background: rgba(4,170,109,0.13);
  padding-left: 17px;
}
.silo-group-header.series-active:hover { color: var(--primary); text-decoration: none; }
.silo-group-header .toggle-icon {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.6;
  flex-shrink: 0;
}

/* Active series header — distinct highlight */
.silo-group-header.is-active-series {
  color: var(--primary);
  background: rgba(4,170,109,0.1);
  border-left-color: var(--primary);
}
.silo-group-header.is-active-series .series-label { color: var(--primary); }

.series-label { flex: 1; }
.series-count {
  font-size: 11px;
  font-weight: 600;
  background: rgba(255,255,255,0.08);
  color: #888;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 22px;
  text-align: center;
}
.is-active-series .series-count {
  background: rgba(4,170,109,0.2);
  color: var(--primary);
}

/* ── Posts panel (shown only for active series) ── */
.silo-posts-panel {
  background: rgba(0,0,0,0.15);
  border-top: 1px solid rgba(255,255,255,0.04);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

/* ── Chapter accordion inside posts panel ── */
.silo-chapter { }

.silo-chapter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px 8px 24px;
  font-size: 12.5px;
  font-weight: 600;
  color: #7a8499;
  cursor: pointer;
  user-select: none;
  transition: color var(--transition), background var(--transition);
  letter-spacing: 0.02em;
}
.silo-chapter-header:hover { color: #bbb; background: rgba(255,255,255,0.03); }
.silo-chapter--open .silo-chapter-header { color: #ccc; }
.sub-toggle { font-size: 10px; }

/* ── Individual post links ── */
.silo-links a {
  display: block;
  padding: 6px 16px 6px 36px;
  font-size: 13.5px;
  color: #b8c0d0;
  border-left: 3px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1.4;
}
.silo-links a:hover {
  color: #fff;
  background: rgba(4,170,109,0.08);
  border-left-color: rgba(4,170,109,0.5);
  text-decoration: none;
}
.silo-links a.active {
  color: var(--primary);
  background: rgba(4,170,109,0.13);
  border-left-color: var(--primary);
  font-weight: 600;
}

/* Top-level posts (no chapter) are slightly less indented */
.silo-links--top a { padding-left: 24px; }

.silo-links.hidden { display: none; }

/* Left sidebar overlay on mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 850;
}

/* ==========================================
   MAIN CONTENT AREA
   ========================================== */
#main-content {
  flex: 1;
  margin-left: var(--left-sidebar-width);
  margin-right: var(--right-sidebar-width);
  min-width: 0;
}

.content-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 36px 40px 60px;
}

/* ==========================================
   RIGHT SIDEBAR (TOC + Ads/Quick Refs)
   ========================================== */
#right-sidebar {
  width: var(--right-sidebar-width);
  min-width: var(--right-sidebar-width);
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  background: #fafafa;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 24px 16px 40px;
  scrollbar-width: thin;
  scrollbar-color: #ccc #fafafa;
}
#right-sidebar::-webkit-scrollbar { width: 4px; }
#right-sidebar::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* ==========================================
   TABLE OF CONTENTS (Right Sidebar)
   ========================================== */
.toc-widget {
  background: var(--toc-bg);
  border: 1px solid var(--border);
  border-top: 3px solid var(--toc-border);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 24px;
}
.toc-widget h3 {
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dark);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.toc-widget h3::before {
  content: '☰';
  font-size: 14px;
  color: var(--primary);
}
.toc-list { list-style: none; }
.toc-list li { margin-bottom: 2px; }
.toc-list a {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  padding: 3px 6px;
  border-radius: 3px;
  transition: all var(--transition);
  text-decoration: none;
}
.toc-list a:hover { color: var(--primary-dark); background: var(--primary-light); }
.toc-list a.active { color: var(--primary-dark); font-weight: 600; background: var(--primary-light); }
.toc-list .toc-h3 { padding-left: 18px; font-size: 12.5px; }
.toc-list .toc-h4 { padding-left: 32px; font-size: 12px; }

/* Progress bar */
.reading-progress-bar {
  position: fixed;
  top: var(--header-height);
  left: var(--left-sidebar-width);
  right: var(--right-sidebar-width);
  height: 3px;
  background: var(--border);
  z-index: 800;
}
.reading-progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.1s linear;
}

/* Right sidebar quick ref box */
.quick-ref-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 14px;
  margin-bottom: 16px;
}
.quick-ref-box h4 {
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.quick-ref-box a {
  display: block;
  font-size: 13px;
  padding: 4px 0;
  color: var(--primary-dark);
  border-bottom: 1px solid #f0f0f0;
}
.quick-ref-box a:last-child { border-bottom: none; }
.quick-ref-box a:hover { text-decoration: underline; }

/* ==========================================
   POST / PAGE CONTENT STYLES
   ========================================== */
.entry-header { margin-bottom: 28px; padding-bottom: 20px; border-bottom: 2px solid var(--border); }

.breadcrumb {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--primary-dark); font-size: 12.5px; }
.breadcrumb span { color: #bbb; }

.entry-title {
  font-family: var(--font-heading);
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--dark);
  line-height: 1.2;
  margin-bottom: 10px;
}

.entry-meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.entry-meta .meta-item { display: flex; align-items: center; gap: 4px; }
.entry-meta .difficulty-badge {
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-beginner { background: #d4edda; color: #155724; }
.badge-intermediate { background: #fff3cd; color: #856404; }
.badge-advanced { background: #f8d7da; color: #721c24; }

/* INLINE TOC (appears in post before content) */
.inline-toc {
  background: var(--toc-bg);
  border: 1px solid #ddd;
  border-left: 4px solid var(--primary);
  border-radius: 0 4px 4px 0;
  padding: 20px 24px;
  margin: 0 0 32px;
}
.inline-toc-title {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.inline-toc-list {
  list-style: decimal;
  padding-left: 22px;
}
.inline-toc-list li { margin-bottom: 4px; }
.inline-toc-list a { font-size: 14px; color: var(--primary-dark); }
.inline-toc-list a:hover { text-decoration: underline; }
.inline-toc-list ol { list-style: lower-alpha; padding-left: 20px; margin-top: 4px; }

/* Headings */
.entry-content h1, .entry-content h2, .entry-content h3,
.entry-content h4, .entry-content h5 {
  font-family: var(--font-heading);
  color: var(--dark);
  margin: 36px 0 14px;
  line-height: 1.3;
  scroll-margin-top: calc(var(--header-height) + 12px);
}
.entry-content h2 { font-size: 1.7rem; font-weight: 800; border-bottom: 2px solid var(--border); padding-bottom: 8px; }
.entry-content h3 { font-size: 1.3rem; font-weight: 700; }
.entry-content h4 { font-size: 1.1rem; font-weight: 600; }

/* Heading anchor links */
.heading-anchor {
  opacity: 0;
  color: var(--primary);
  margin-left: 8px;
  font-size: 0.8em;
  transition: opacity var(--transition);
  text-decoration: none;
}
h2:hover .heading-anchor,
h3:hover .heading-anchor,
h4:hover .heading-anchor { opacity: 1; }

/* Paragraphs */
.entry-content p { margin-bottom: 18px; }
.entry-content ul, .entry-content ol { margin-bottom: 18px; padding-left: 26px; }
.entry-content li { margin-bottom: 6px; }

/* CODE BLOCKS */
.entry-content pre {
  background: var(--dark);
  color: #f8f8f2;
  border-radius: 6px;
  padding: 20px;
  overflow-x: auto;
  margin: 20px 0;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.6;
  position: relative;
}
.entry-content pre::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px; right: 12px;
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-body);
}
.copy-btn {
  position: absolute;
  top: 8px; right: 50px;
  background: #444;
  border: none;
  color: #ccc;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 3px;
  cursor: pointer;
  transition: all var(--transition);
}
.copy-btn:hover { background: var(--primary); color: #fff; }

.entry-content code {
  font-family: var(--font-mono);
  background: var(--code-bg);
  color: #c0392b;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.88em;
}
.entry-content pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

/* TRY IT YOURSELF button */
.try-it-btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 7px 18px;
  border-radius: 4px;
  font-size: 13.5px;
  font-weight: 600;
  margin-top: -8px;
  margin-bottom: 20px;
  transition: background var(--transition);
  cursor: pointer;
  border: none;
  text-decoration: none;
}
.try-it-btn:hover { background: var(--primary-dark); color: #fff; text-decoration: none; }

/* NOTE / TIP / WARNING boxes */
.note-box, .tip-box, .warning-box, .example-box {
  border-radius: 4px;
  padding: 16px 20px;
  margin: 20px 0;
  border-left: 4px solid;
}
.note-box   { background: var(--note-bg); border-color: #e6cc00; }
.tip-box    { background: var(--tip-bg); border-color: #0d6efd; }
.warning-box { background: var(--warning-bg); border-color: #ffc107; }
.example-box { background: #f5fff8; border-color: var(--primary); }

.note-box strong, .tip-box strong, .warning-box strong, .example-box strong {
  display: block;
  font-family: var(--font-heading);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
  color: var(--dark);
}

/* QUIZ / EXERCISE box */
.exercise-box {
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 6px;
  padding: 20px 24px;
  margin: 28px 0;
}
.exercise-box h4 {
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--primary-dark);
}
.exercise-form .quiz-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: background var(--transition);
}
.exercise-form .quiz-option:hover { background: var(--primary-light); }
.exercise-form .quiz-option input { cursor: pointer; }
.quiz-submit {
  margin-top: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 22px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.quiz-submit:hover { background: var(--primary-dark); }
.quiz-result { margin-top: 12px; font-size: 14px; font-weight: 600; }
.quiz-result.correct { color: var(--primary); }
.quiz-result.wrong { color: #dc3545; }

/* PREV / NEXT navigation */
.post-navigation {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 16px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 2px solid var(--border);
}
.nav-prev, .nav-next {
  flex: 1;
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 18px;
  transition: all var(--transition);
  text-decoration: none;
  color: var(--text);
}
.nav-prev:hover, .nav-next:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  text-decoration: none;
  color: var(--text);
}
.nav-next { text-align: right; }
.nav-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.nav-title { font-size: 15px; font-weight: 600; font-family: var(--font-heading); color: var(--primary-dark); }

/* ==========================================
   HOMEPAGE / ARCHIVE CARDS
   ========================================== */
.tutorials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin: 28px 0;
}
.tutorial-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.tutorial-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--primary);
}
.tutorial-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}
.tutorial-card h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 8px;
}
.tutorial-card p { font-size: 13.5px; color: var(--text-muted); margin-bottom: 16px; }
.tutorial-card .card-link {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition);
}
.tutorial-card .card-link:hover { background: var(--primary-dark); text-decoration: none; }

/* Hero section */
.site-hero {
  background: var(--dark);
  color: #fff;
  text-align: center;
  padding: 60px 40px;
  margin-bottom: 40px;
}
.site-hero h1 {
  font-family: var(--font-heading);
  font-size: 2.8rem;
  font-weight: 800;
  margin-bottom: 16px;
}
.site-hero h1 span { color: var(--primary); }
.site-hero p { font-size: 17px; color: #ccc; max-width: 560px; margin: 0 auto 24px; }
.hero-search {
  display: flex;
  max-width: 500px;
  margin: 0 auto;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.hero-search input {
  flex: 1;
  padding: 13px 18px;
  border: none;
  font-size: 15px;
  outline: none;
}
.hero-search button {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}
.hero-search button:hover { background: var(--primary-dark); }

/* ==========================================
   FOOTER
   ========================================== */
#site-footer {
  background: var(--dark);
  color: #999;
  text-align: center;
  padding: 24px;
  font-size: 13px;
  margin-left: var(--left-sidebar-width);
}
#site-footer a { color: var(--primary); }

/* ==========================================
   RESPONSIVE DESIGN
   ========================================== */
@media (max-width: 1200px) {
  :root { --right-sidebar-width: 220px; }
}

@media (max-width: 960px) {
  #right-sidebar { display: none; }
  #main-content { margin-right: 0; }
  .reading-progress-bar { right: 0; }
}

@media (max-width: 768px) {
  #hamburger-btn { display: block; }
  #header-nav { display: none; }

  #left-sidebar {
    transform: translateX(-100%);
  }
  #left-sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.active { display: block; }

  #main-content {
    margin-left: 0;
    margin-right: 0;
  }
  .reading-progress-bar { left: 0; }

  .content-inner { padding: 20px 18px 40px; }
  .entry-title { font-size: 1.65rem; }
  .post-navigation { flex-direction: column; }
  #site-footer { margin-left: 0; }
}

/* ==========================================
   SYNTAX HIGHLIGHTING (basic)
   ========================================== */
.token.comment { color: #6a9955; }
.token.keyword { color: #569cd6; }
.token.string { color: #ce9178; }
.token.number { color: #b5cea8; }
.token.function { color: #dcdcaa; }
.token.class-name { color: #4ec9b0; }
.token.operator { color: #d4d4d4; }
.token.tag { color: #569cd6; }
.token.attr-name { color: #9cdcfe; }
.token.attr-value { color: #ce9178; }
.token.punctuation { color: #d4d4d4; }

/* ==========================================
   UTILITIES
   ========================================== */
.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.w-green { color: var(--primary); }
.text-center { text-align: center; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
