/* =========================================================
   CSS Custom Properties — 4 theme × mode combos
   ========================================================= */

/* Default: dark-tech dark */
:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #c9d1d9;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --green: #3fb950;
  --purple: #bc8cff;
  --font-sans: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Courier New', Courier, monospace;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,.5);
  --tag-cloud-bg: #1f3460; --tag-cloud-text: #58a6ff;
  --tag-ai-bg: #2d1f52;   --tag-ai-text: #bc8cff;
  --tag-infra-bg: #1a3326; --tag-infra-text: #3fb950;
  --code-bg: #0d1117;
}

/* Dark-tech light */
html[data-mode="light"] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --green: #1a7f37;
  --purple: #7c3aed;
  --shadow: 0 1px 4px rgba(0,0,0,.1);
  --tag-cloud-bg: #ddf4ff;  --tag-cloud-text: #0969da;
  --tag-ai-bg: #fbefff;     --tag-ai-text: #7c3aed;
  --tag-infra-bg: #dafbe1;  --tag-infra-text: #1a7f37;
  --code-bg: #f6f8fa;
}

/* Terminal dark */
html[data-theme="terminal"] {
  --bg: #0a0a0a;
  --surface: #0f0f0f;
  --border: #003b10;
  --text: #00ff41;
  --muted: #00b32d;
  --accent: #00ff41;
  --accent-hover: #33ff66;
  --green: #00ff41;
  --purple: #55cc55;
  --font-sans: 'Courier New', Courier, monospace;
  --radius: 2px;
  --shadow: none;
  --tag-cloud-bg: #001a08;  --tag-cloud-text: #00b32d;
  --tag-ai-bg: #001a08;     --tag-ai-text: #00ff41;
  --tag-infra-bg: #001a08;  --tag-infra-text: #55cc55;
  --code-bg: #050505;
}

/* Terminal light */
html[data-theme="terminal"][data-mode="light"] {
  --bg: #f0f4e8;
  --surface: #e8eed8;
  --border: #8ab060;
  --text: #1a3010;
  --muted: #3a5020;
  --accent: #2a6010;
  --accent-hover: #1a4008;
  --green: #2a6010;
  --purple: #2a6010;
  --code-bg: #e0e8d0;
  --tag-cloud-bg: #d0e0b0;  --tag-cloud-text: #1a4008;
  --tag-ai-bg: #d0e0b0;     --tag-ai-text: #2a6010;
  --tag-infra-bg: #d0e0b0;  --tag-infra-text: #3a5020;
}

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

html { font-size: 16px; background: var(--bg); } /* no-JS background fallback */

body {
  font-family: var(--font-sans);
  background: transparent; /* bg-canvas owns the background */
  color: var(--text);
  line-height: 1.7;
  transition: color .2s ease;
  min-height: 100vh;
}

#bg-canvas {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

/* Terminal scanline overlay */
html[data-theme="terminal"] body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0,255,65,.012) 2px, rgba(0,255,65,.012) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
html[data-theme="terminal"] a:hover { text-shadow: 0 0 6px var(--accent); text-decoration: none; }

img { max-width: 100%; display: block; }

/* =========================================================
   Terminal Window Chrome
   ========================================================= */
.term-chrome {
  display: none;
  align-items: center;
  gap: 1rem;
  padding: .6rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

html[data-theme="terminal"] .term-chrome { display: flex; }

.term-dots { display: flex; gap: .45rem; }
.term-dots .dot { width: 11px; height: 11px; border-radius: 50%; background: #2a2a2a; }
.term-dots .dot-r { background: #ff5f57; }
.term-dots .dot-y { background: #febc2e; }
.term-dots .dot-g { background: #28c840; }

.term-bar-title {
  flex: 1;
  text-align: center;
  font-size: .78rem;
  color: var(--muted);
  font-family: var(--font-mono);
}

/* =========================================================
   Navigation
   ========================================================= */
.site-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }

.brand-prompt {
  color: var(--green);
  font-family: var(--font-mono);
  font-size: .9rem;
}
.brand-name { color: var(--text); }

/* Terminal: swap brand prefix */
html[data-theme="terminal"] .brand-prompt { display: none; }
html[data-theme="terminal"] .brand::before {
  content: 'user@blog:~$ ';
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .82rem;
}

.nav-links {
  list-style: none;
  display: flex;
  gap: .25rem;
  flex-wrap: wrap;
  margin-right: auto;
}

.nav-links a {
  font-size: .85rem;
  color: var(--muted);
  padding: .3rem .6rem;
  border-radius: var(--radius);
  transition: background .15s, color .15s;
  text-decoration: none;
}
.nav-links a:hover {
  background: var(--border);
  color: var(--text);
}

html[data-theme="terminal"] .nav-links a { border-radius: 0; }
html[data-theme="terminal"] .nav-links a:hover { background: transparent; color: var(--accent); }
html[data-theme="terminal"] .nav-links a::before { content: './'; font-size: .75rem; opacity: .5; }

.nav-controls { display: flex; gap: .5rem; align-items: center; }

.ctrl-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .78rem;
  padding: .3rem .75rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: border-color .15s, color .15s;
  white-space: nowrap;
}
.ctrl-btn:hover { border-color: var(--accent); color: var(--text); }

html[data-theme="terminal"] .ctrl-btn { border-color: var(--muted); border-radius: 0; font-family: var(--font-mono); }

/* =========================================================
   Hero (home page)
   ========================================================= */
.hero {
  background: linear-gradient(135deg, var(--bg) 0%, var(--surface) 60%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
  padding: 3.5rem 1.5rem;
  text-align: center;
}

.hero-inner { max-width: 680px; margin: 0 auto; }

.hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -.03em;
  color: var(--text);
  line-height: 1.2;
}
.hero-accent { color: var(--accent); }

.hero p {
  color: var(--muted);
  margin-top: .75rem;
  font-size: 1rem;
}

/* Terminal hero style */
html[data-theme="terminal"] .hero { text-align: left; padding: 2rem 1.5rem; }
html[data-theme="terminal"] .hero-inner { max-width: 900px; }
html[data-theme="terminal"] .hero::before {
  content: '$ cat welcome.txt';
  display: block;
  font-family: var(--font-mono);
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: .75rem;
}

.category-pills {
  display: flex;
  justify-content: center;
  gap: .75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
html[data-theme="terminal"] .category-pills { justify-content: flex-start; }

.pill {
  padding: .3rem 1rem;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 600;
  border: 1px solid;
  text-decoration: none;
}
.pill:hover { text-decoration: none; opacity: .85; }
.pill-blue  { color: var(--accent); border-color: var(--accent); }
.pill-green { color: var(--green);  border-color: var(--green); }
.pill-purple{ color: var(--purple); border-color: var(--purple); }

html[data-theme="terminal"] .pill { border-radius: 0; }

/* =========================================================
   Content Grid
   ========================================================= */
.content-area { max-width: 1140px; margin: 2.5rem auto; padding: 0 1.5rem; }

.content-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 800px) {
  .content-grid { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}

/* =========================================================
   Post Cards
   ========================================================= */
.post-list { display: flex; flex-direction: column; gap: 1.25rem; }

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: border-color .15s;
}
.post-card:hover { border-color: var(--accent); }

/* Terminal: command-output style */
html[data-theme="terminal"] .post-card { border-radius: 0; position: relative; }
html[data-theme="terminal"] .post-card::before {
  content: '-rw-r--r--';
  display: block;
  font-size: .72rem;
  color: var(--muted);
  margin-bottom: .25rem;
  font-family: var(--font-mono);
}

.card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: .6rem;
}
.meta-sep { color: var(--border); }

.card-tag {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 600;
}
.tag-cloud { background: var(--tag-cloud-bg); color: var(--tag-cloud-text); }
.tag-ai    { background: var(--tag-ai-bg);    color: var(--tag-ai-text); }
.tag-infra { background: var(--tag-infra-bg); color: var(--tag-infra-text); }

html[data-theme="terminal"] .card-tag { border-radius: 0; background: transparent; border: none; }
html[data-theme="terminal"] .card-tag::before { content: '['; }
html[data-theme="terminal"] .card-tag::after  { content: ']'; }

.post-card h2 {
  font-size: 1.1rem;
  line-height: 1.4;
  margin-bottom: .45rem;
}
.post-card h2 a { color: var(--text); }
.post-card h2 a:hover { color: var(--accent); text-decoration: none; }

.post-card p { font-size: .88rem; color: var(--muted); line-height: 1.65; }

.read-link {
  display: inline-block;
  margin-top: .75rem;
  font-size: .82rem;
  color: var(--accent);
  font-weight: 600;
}
.read-link:hover { text-decoration: none; opacity: .8; }

html[data-theme="terminal"] .read-link::before { content: '> '; }

/* =========================================================
   Sidebar / Widgets
   ========================================================= */
.sidebar { display: flex; flex-direction: column; gap: 1.25rem; }

.widget {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.widget-heading {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: .875rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

html[data-theme="terminal"] .widget { border-radius: 0; }
html[data-theme="terminal"] .widget-heading::before { content: '# '; }

.widget ul { list-style: none; }
.widget li {
  padding: .35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
}
.widget li:last-child { border-bottom: none; }
.widget a { color: var(--muted); }
.widget a:hover { color: var(--text); text-decoration: none; }

/* =========================================================
   Pagination
   ========================================================= */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: .88rem;
}

.page-btn {
  padding: .4rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  transition: border-color .15s, background .15s;
}
.page-btn:hover { border-color: var(--accent); background: var(--surface); text-decoration: none; }

.page-info { color: var(--muted); }

html[data-theme="terminal"] .page-btn { border-radius: 0; }
html[data-theme="terminal"] .page-btn::before { content: '$ '; }

/* =========================================================
   Category Header
   ========================================================= */
.category-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: .5rem;
}
.category-header h1 { font-size: 1.5rem; margin-bottom: .5rem; }
.category-header p { color: var(--muted); font-size: .9rem; }

.empty-state {
  color: var(--muted);
  font-style: italic;
  padding: 2rem;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* =========================================================
   Post Single
   ========================================================= */
.post-single {
  max-width: 760px;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
}

.post-breadcrumb {
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
}
.post-breadcrumb a { color: var(--muted); }
.post-breadcrumb a:hover { color: var(--accent); text-decoration: none; }
.post-breadcrumb .sep { margin: 0 .35rem; }

.post-title {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.25;
  margin-bottom: .75rem;
}

.post-description {
  font-size: 1.05rem;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: .75rem;
}

.post-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.post-hero-image {
  margin-bottom: 2rem;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.post-hero-image img { width: 100%; height: auto; }

/* Post content typography */
.post-content {
  font-size: 1rem;
  line-height: 1.8;
}

.post-content h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 2.25rem 0 .75rem;
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.post-content h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.75rem 0 .5rem;
  color: var(--text);
}

.post-content p { margin-bottom: 1.25rem; }

.post-content ul, .post-content ol {
  margin: 0 0 1.25rem 1.5rem;
}

.post-content li { margin-bottom: .35rem; }

.post-content code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: .1em .4em;
  font-family: var(--font-mono);
  font-size: .88em;
  color: var(--green);
}

.post-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  line-height: 1.55;
}

.post-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: .875em;
  color: var(--text);
}

html[data-theme="terminal"] .post-content pre { border-radius: 0; }
html[data-theme="terminal"] .post-content pre::before {
  content: '$ cat';
  display: block;
  color: var(--muted);
  font-size: .75rem;
  margin-bottom: .5rem;
}

.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: .9rem;
}

.post-content th, .post-content td {
  border: 1px solid var(--border);
  padding: .6rem .875rem;
  text-align: left;
}

.post-content th {
  background: var(--surface);
  font-weight: 600;
  color: var(--text);
}

.post-content td { color: var(--muted); }

.post-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  margin: 1.5rem 0;
  color: var(--muted);
  font-style: italic;
}

.post-content a { color: var(--accent); }

.post-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.post-tags { display: flex; gap: .5rem; flex-wrap: wrap; }

.back-link { font-size: .85rem; color: var(--accent); }

/* =========================================================
   Search Page
   ========================================================= */
.page-content { max-width: 760px; margin: 2.5rem auto; padding: 0 1.5rem; }
.page-inner h1 { font-size: 1.75rem; margin-bottom: 1.5rem; }

.page-lead { font-size: 1.05rem; color: var(--muted); margin-bottom: 2rem; line-height: 1.6; }

.page-inner h2 { font-size: 1.2rem; font-weight: 600; margin: 2rem 0 .75rem; }
.page-inner p { margin-bottom: 1rem; color: var(--muted); }
.page-inner ul { margin: 0 0 1rem 1.5rem; }
.page-inner li { margin-bottom: .5rem; color: var(--muted); }
.page-inner li strong a { color: var(--accent); }

.search-box { margin-bottom: 1.5rem; }

.search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  padding: .75rem 1rem;
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--muted); }

html[data-theme="terminal"] .search-input { border-radius: 0; font-family: var(--font-mono); }
html[data-theme="terminal"] .search-input::before { content: '$ grep -r "'; }

.search-status { font-size: .85rem; color: var(--muted); margin-bottom: 1rem; min-height: 1.4em; }

.search-results { list-style: none; display: flex; flex-direction: column; gap: 1rem; }

.search-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.search-result:hover { border-color: var(--accent); }

.search-result h3 { font-size: 1rem; margin-bottom: .35rem; }
.search-result h3 a { color: var(--text); }
.search-result h3 a:hover { color: var(--accent); text-decoration: none; }
.search-result p { font-size: .85rem; color: var(--muted); }

/* =========================================================
   Footer
   ========================================================= */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 3rem 0 2rem;
  margin-top: 4rem;
}

.footer-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Terminal footer command prefix */
html[data-theme="terminal"] .footer-inner::before {
  content: '$ cat sitemap.txt';
  display: block;
  font-family: var(--font-mono);
  font-size: .78rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

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

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

.footer-heading {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--green);
  margin-bottom: .75rem;
  font-family: var(--font-mono);
}

.footer-col ul { list-style: none; }
.footer-col li { margin-bottom: .375rem; }
.footer-col a { font-size: .84rem; color: var(--muted); }
.footer-col a:hover { color: var(--accent); text-decoration: none; }

.footer-bottom {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: .75rem;
  font-size: .76rem;
  color: var(--muted);
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--green);
  border-radius: 50%;
  margin-right: .4rem;
  animation: pulse 2.5s infinite;
}

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

.social-links a { margin-left: .875rem; color: var(--muted); font-size: .76rem; }
.social-links a:hover { color: var(--accent); text-decoration: none; }

/* =========================================================
   Cursor (terminal theme)
   ========================================================= */
html[data-theme="terminal"] .brand-name::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 14px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: middle;
  animation: blink .8s step-end infinite;
}

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* =========================================================
   404 Error Page
   ========================================================= */
.error-page {
  min-height: calc(100vh - 220px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  gap: 2rem;
}

#effect-stage {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

.err-label {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

.err-404 {
  font-family: var(--font-mono);
  font-size: clamp(5rem, 18vw, 9rem);
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -0.04em;
  margin: 0;
  transition: transform .05s, text-shadow .05s;
}

.err-sub {
  font-size: 1rem;
  color: var(--muted);
  font-family: var(--font-mono);
  margin: 0;
}

.err-hint {
  font-size: 0.78rem;
  color: var(--muted);
  opacity: 0.65;
  font-family: var(--font-mono);
  margin: 0;
}

.error-nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

/* Terminal session */
.term-session {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  text-align: left;
}

.term-session pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.75;
  white-space: pre;
  color: var(--text);
}

/* Terminal text colour classes (shared by terminal effect and signal decay) */
.term-prompt { color: var(--green); }
.term-error  { color: #ff5555; }
.term-errt   { color: #ff8855; opacity: .85; }
.term-muted  { color: var(--muted); }
.term-ok     { color: var(--green); }
.term-warn   { color: #e3b341; }
.term-accent { color: var(--accent); }

.term-cursor {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: term-blink 1s step-end infinite;
}

@keyframes term-blink { 50% { opacity: 0; } }

/* Signal decay session */
.decay-session {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  text-align: left;
}

.decay-line {
  margin: 0.15rem 0;
  white-space: nowrap;
  overflow: hidden;
}
