/* ==========================================================================
   1. Theme Variables (Default: Dark Slate/Amber Terminal; Light Override)
   ========================================================================== */
:root {
  --bg-primary: #12151a;
  --bg-surface: #1b2028;
  --bg-elevated: #242b36;
  --text-main: #e6edf3;
  --text-muted: #9aa5b4;
  --accent-primary: #ffb000;   /* Retro Amber Terminal Glow */
  --accent-secondary: #38bdf8; /* Modern Cyber Blue */
  --border-color: #303846;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Cascadia Code", "Fira Code", Consolas, monospace;
  --max-width: 1040px;
}

:root[data-theme="light"] {
  --bg-primary: #f4f6f8;
  --bg-surface: #ffffff;
  --bg-elevated: #e9eef4;
  --text-main: #1e293b;
  --text-muted: #475569;
  --accent-primary: #b45309;   /* High-contrast Warm Amber/Bronze */
  --accent-secondary: #0369a1; /* Deep Cobalt Blue */
  --border-color: #cbd5e1;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.65;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

a {
  color: var(--accent-secondary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover, a:focus {
  color: var(--accent-primary);
  text-decoration: underline;
}

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

/* ==========================================================================
   2. Header, Responsive Navigation & Mobile Hamburger Drawer
   ========================================================================== */
.site-header {
  background-color: var(--bg-surface);
  border-bottom: 2px solid var(--border-color);
  padding: 0.85rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}

.header-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.site-brand {
  font-family: var(--font-mono);
  font-size: clamp(1.05rem, 2.5vw, 1.25rem);
  font-weight: 700;
  color: var(--accent-primary);
  letter-spacing: -0.5px;
  text-decoration: none;
}

.site-brand span {
  color: var(--text-muted);
  font-weight: 400;
}

.menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  background-color: var(--bg-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 0.5rem 0.85rem;
  border-radius: 4px;
  cursor: pointer;
  min-height: 44px;
}

/* Mobile-first: hidden by default on phones until 'is-open' is added by layout.js */
.nav-group {
  display: none;
  flex-direction: column;
  align-items: stretch;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  gap: 0.75rem;
}

.nav-group.is-open {
  display: flex;
}

.main-nav ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

.main-nav a,
.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.92rem;
  padding: 0.5rem 0.75rem;
  min-height: 44px;
  border-radius: 4px;
}

.main-nav a:hover,
.main-nav a.active {
  background-color: var(--bg-elevated);
  color: var(--accent-primary);
  text-decoration: none;
}

.theme-btn {
  background-color: var(--bg-elevated);
  color: var(--accent-primary);
  border: 1px solid var(--border-color);
  cursor: pointer;
}

/* Desktop & Tablet (> 820px): switch to horizontal bar and hide hamburger button */
@media (min-width: 821px) {
  .header-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .header-top-row {
    width: auto;
  }

  .menu-toggle {
    display: none;
  }

  .nav-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding-top: 0;
    border-top: none;
    gap: 1rem;
  }

  .main-nav ul {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
  }

  .main-nav a,
  .theme-btn {
    width: auto;
  }
}

/* ==========================================================================
   3. Main Layout, Hero & Responsive Grids
   ========================================================================== */
.container {
  max-width: var(--max-width);
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.25rem;
  flex: 1;
}

.hero-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent-primary);
  border-radius: 6px;
  padding: clamp(1.25rem, 3vw, 1.85rem);
  margin-bottom: 2rem;
}

.hero-box h1 {
  font-size: clamp(1.45rem, 4vw, 1.9rem);
  margin-bottom: 0.75rem;
  line-height: 1.25;
}

.hero-box p {
  color: var(--text-muted);
  max-width: 75ch;
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.75rem;
}

@media (min-width: 821px) {
  .content-grid {
    grid-template-columns: 2fr 1fr;
  }
}

.section-title {
  font-family: var(--font-mono);
  font-size: clamp(1.02rem, 2.5vw, 1.15rem);
  color: var(--accent-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
  margin-bottom: 1.25rem;
}

/* ==========================================================================
   4. Cards, Tags, Code Blocks & Responsive Tables
   ========================================================================== */
.post-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: clamp(1.1rem, 2.5vw, 1.45rem);
  margin-bottom: 1.25rem;
}

.post-meta {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.tag {
  background-color: var(--bg-elevated);
  color: var(--accent-secondary);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  border: 1px solid var(--border-color);
}

.post-card h2 {
  font-size: clamp(1.15rem, 2.8vw, 1.3rem);
  margin-bottom: 0.5rem;
  line-height: 1.35;
}

pre {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.9rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  margin: 0.75rem 0;
}

/* Responsive Horizontal Scroll Wrapper for Tables on Mobile */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.resource-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  min-width: 480px;
}

.resource-table th,
.resource-table td {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.resource-table th {
  font-family: var(--font-mono);
  color: var(--accent-primary);
  background-color: var(--bg-elevated);
}

.sidebar-widget {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.sidebar-widget ul {
  list-style: none;
  margin-top: 0.75rem;
}

.sidebar-widget li {
  border-bottom: 1px dashed var(--border-color);
  font-size: 0.94rem;
}

.sidebar-widget li a {
  display: block;
  padding: 0.55rem 0;
}

.sidebar-widget li:last-child {
  border-bottom: none;
}

/* ==========================================================================
   5. Pure CSS Blog Category Filtering (Touch-Friendly Pills)
   ========================================================================== */
.filter-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.filter-controls label {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 0.55rem 0.9rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  cursor: pointer;
}

@media (max-width: 540px) {
  .filter-controls label {
    flex: 1 1 calc(50% - 0.5rem);
    justify-content: center;
  }
}

#filter-all:checked ~ .filter-controls label[for="filter-all"],
#filter-tech:checked ~ .filter-controls label[for="filter-tech"],
#filter-retro:checked ~ .filter-controls label[for="filter-retro"],
#filter-personal:checked ~ .filter-controls label[for="filter-personal"] {
  background-color: var(--accent-primary);
  color: #12151a;
  font-weight: 700;
  border-color: var(--accent-primary);
}

#filter-tech:checked ~ .posts-list .post-card:not([data-category="tech"]),
#filter-retro:checked ~ .posts-list .post-card:not([data-category="retro"]),
#filter-personal:checked ~ .posts-list .post-card:not([data-category="personal"]) {
  display: none;
}

/* ==========================================================================
   6. Responsive Gallery & Mobile-Friendly Lightbox Modal
   ========================================================================== */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1.25rem;
}

.gallery-item {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.gallery-item img,
.gallery-item svg {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid var(--border-color);
}

.gallery-caption {
  padding: 0.9rem;
  font-size: 0.92rem;
}

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  padding: 1rem;
  align-items: center;
  justify-content: center;
}

.lightbox:target {
  display: flex;
}

.lightbox-content {
  background: var(--bg-surface);
  border: 2px solid var(--accent-primary);
  border-radius: 6px;
  max-width: 820px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  padding: 1rem;
  text-align: center;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 65vh;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.close-lightbox {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.75rem;
  font-family: var(--font-mono);
  background: var(--accent-primary);
  color: #12151a;
  padding: 0.55rem 1.1rem;
  min-height: 44px;
  border-radius: 4px;
  font-weight: 700;
}

/* ==========================================================================
   7. Footer
   ========================================================================== */
.site-footer {
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  text-align: center;
  padding: 1.5rem 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
