/* =========================================================
   Old Dog New Skills — hand-crafted CSS
   No framework. CSS custom properties for design tokens.
   ========================================================= */

/* ---------------------------------------------------------
   Design tokens
   --------------------------------------------------------- */
:root {
  --color-bg:           #fafaf9;
  --color-surface:      #ffffff;
  --color-border:       #e7e5e4;
  --color-border-light: #f5f5f4;
  --color-text:         #1c1917;
  --color-muted:        #78716c;
  --color-subtle:       #a8a29e;
  --color-accent:       #0f766e;
  --color-accent-dark:  #115e59;
  --color-accent-bg:    #f0fdfa;
  --color-tag-text:     #0d9488;
  --color-tag-bg:       #ccfbf1;

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'Fira Code', 'Cascadia Code', ui-monospace, monospace;

  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);

  --max-width:     1000px;
  --sidebar-width: 260px;
  --gap:           2rem;
}

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

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

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--color-accent-dark);
}

ul, ol {
  padding-left: 1.5rem;
}

/* ---------------------------------------------------------
   Layout helpers
   --------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  padding-block: 2.5rem;
  flex: 1;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 1fr var(--sidebar-width);
  }
}

/* ---------------------------------------------------------
   Site header
   --------------------------------------------------------- */
.site-header {
  background:
    linear-gradient(rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.45)),
    url('/static/HeaderBackground.jpg') center / cover no-repeat;
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.site-header .site-title {
  color: #ffffff;
}

.site-header .site-title:hover {
  color: rgba(255, 255, 255, 0.85);
}

.site-header .site-tagline {
  color: rgba(255, 255, 255, 0.8);
}

.site-header .site-nav a {
  color: rgba(255, 255, 255, 0.8);
}

.site-header .site-nav a:hover,
.site-header .site-nav a.active {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.15);
}

.site-identity {
  padding-top: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border-light);
}

.site-title {
  display: inline-block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-accent);
  text-decoration: none;
  line-height: 1.2;
  letter-spacing: -0.02em;
  transition: color 0.15s;
}

.site-title:hover {
  color: var(--color-accent-dark);
}

.site-tagline {
  margin-top: 0.35rem;
  font-size: 0.8125rem;
  color: var(--color-muted);
  font-style: italic;
}

/* Navigation */
.site-nav {
  padding-block: 0.35rem;
}

.site-nav ul {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.125rem;
}

.site-nav a {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background-color 0.15s;
}

.site-nav a:hover {
  color: var(--color-accent);
  background-color: var(--color-accent-bg);
}

.site-nav a.active {
  color: var(--color-accent);
  background-color: var(--color-accent-bg);
}

/* ---------------------------------------------------------
   Post cards (home listing)
   --------------------------------------------------------- */
.section-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-subtle);
  margin-bottom: 1.25rem;
}

.post-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.post-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  position: relative;
}

.post-card:hover {
  border-color: #99f6e4;
  box-shadow: var(--shadow-md);
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.post-meta time {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-subtle);
  background: var(--color-border-light);
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
}

.tag {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-tag-text);
  background: var(--color-tag-bg);
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
}

.post-card-title {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 0.5rem;
}

.post-card-title a {
  color: var(--color-text);
  text-decoration: none;
}

/* Stretch link to cover whole card */
.post-card-title a::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
}

.post-card-title a:hover {
  color: var(--color-accent);
}

.post-card:hover .post-card-title a {
  color: var(--color-accent);
}

.post-card-excerpt {
  font-size: 0.9rem;
  color: var(--color-muted);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.read-more {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-accent);
  text-decoration: none;
  pointer-events: none; /* card link handles the click */
}

.post-card:hover .read-more {
  text-decoration: underline;
}

/* ---------------------------------------------------------
   Single post / page
   --------------------------------------------------------- */
.post-header {
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2rem;
}

.post-title {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--color-text);
  margin-top: 0.5rem;
}

.post-byline {
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--color-subtle);
}

.post-nav {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.back-link {
  font-size: 0.875rem;
  font-weight: 500;
}

/* ---------------------------------------------------------
   Prose (rendered markdown)
   --------------------------------------------------------- */
.prose {
  color: var(--color-text);
  line-height: 1.8;
  font-size: 1rem;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--color-text);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.prose h1 { font-size: 1.75rem; }
.prose h2 { font-size: 1.35rem; }
.prose h3 { font-size: 1.125rem; }
.prose h4 { font-size: 1rem; }

.prose p {
  margin-bottom: 1.25rem;
}

.prose a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose a:hover {
  color: var(--color-accent-dark);
}

.prose strong {
  font-weight: 600;
}

.prose ul,
.prose ol {
  margin-bottom: 1.25rem;
  padding-left: 1.5rem;
}

.prose li {
  margin-bottom: 0.4rem;
}

.prose li > ul,
.prose li > ol {
  margin-top: 0.4rem;
  margin-bottom: 0;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2rem 0;
}

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

.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-border-light);
  color: #be185d;
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
}

.prose pre {
  background: #1e1e2e;
  color: #cdd6f4;
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: 0.875rem;
  line-height: 1.6;
}

.prose pre code {
  background: none;
  color: inherit;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}

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

.prose th {
  background: var(--color-border-light);
  font-weight: 600;
}

.prose tr:nth-child(even) td {
  background: var(--color-bg);
}

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

/* Keep sidebar at top on large screens */
@media (min-width: 900px) {
  .sidebar {
    position: sticky;
    top: 1.5rem;
    align-self: start;
  }
}

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

.widget-title {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-subtle);
  margin-bottom: 0.875rem;
}

/* Search widget */
.search-box input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-box input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgb(15 118 110 / 0.12);
}

.search-results {
  list-style: none;
  padding: 0;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.search-results[hidden] {
  display: none;
}

.search-result-item a {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  line-height: 1.35;
}

.search-result-item a:hover {
  color: var(--color-accent);
}

.search-result-item time {
  font-size: 0.7rem;
  color: var(--color-subtle);
}

.search-no-results {
  font-size: 0.8125rem;
  color: var(--color-muted);
  font-style: italic;
  margin-top: 0.5rem;
}

/* Recent posts widget */
.recent-posts {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.recent-posts li a {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  line-height: 1.35;
  margin-bottom: 0.1rem;
}

.recent-posts li a:hover {
  color: var(--color-accent);
}

.recent-posts time {
  font-size: 0.7rem;
  color: var(--color-subtle);
}

/* Twitter link (used in sidebar & footer) */
.twitter-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.twitter-link:hover {
  color: var(--color-accent);
}

.twitter-link svg {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
  flex-shrink: 0;
}

/* ---------------------------------------------------------
   Footer
   --------------------------------------------------------- */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  margin-top: auto;
  padding-block: 1.5rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.875rem;
  color: var(--color-muted);
}

/* ---------------------------------------------------------
   404 page
   --------------------------------------------------------- */
.error-page {
  text-align: center;
  padding: 5rem 1rem;
  flex: 1;
}

.error-code {
  font-size: 6rem;
  font-weight: 800;
  color: var(--color-border);
  line-height: 1;
  letter-spacing: -0.04em;
  margin-bottom: 1rem;
  user-select: none;
}

.error-page h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.error-page p {
  color: var(--color-muted);
  margin-bottom: 2rem;
}

.btn {
  display: inline-block;
  background: var(--color-accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: background-color 0.15s;
}

.btn:hover {
  background: var(--color-accent-dark);
  color: #fff;
}

/* ---------------------------------------------------------
   htmx transitions — fade on navigation swap
   --------------------------------------------------------- */
body.htmx-swapping {
  opacity: 0;
  transition: opacity 0.1s ease-out;
}

/* Progress indicator bar at top when htmx is loading */
#htmx-indicator {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 2px;
  background: var(--color-accent);
  transition: width 0.3s ease;
  z-index: 9999;
  opacity: 0;
}

#htmx-indicator.htmx-request {
  opacity: 1;
  width: 70%;
}

/* ---------------------------------------------------------
   Syntax highlighting (Pygments — codehilite)
   --------------------------------------------------------- */
.highlight { background: #1e1e2e; border-radius: var(--radius-md); padding: 0; }
.highlight pre { margin: 0; }
.highlight .hll { background-color: #2a2a3e }
.highlight .c  { color: #6c7086; font-style: italic }
.highlight .k  { color: #cba6f7 }
.highlight .n  { color: #cdd6f4 }
.highlight .o  { color: #89dceb }
.highlight .s  { color: #a6e3a1 }
.highlight .nb { color: #89b4fa }
.highlight .nf { color: #89b4fa }
.highlight .mi { color: #fab387 }
.highlight .mf { color: #fab387 }
.highlight .kn { color: #cba6f7 }
.highlight .kd { color: #cba6f7 }
.highlight .kt { color: #f38ba8 }
.highlight .nc { color: #f9e2af }
.highlight .err { color: #f38ba8 }

/* ---------------------------------------------------------
   Responsive tweaks
   --------------------------------------------------------- */
@media (max-width: 640px) {
  .site-title { font-size: 1.4rem; }
  .post-title { font-size: 1.375rem; }
  .prose h1   { font-size: 1.4rem; }
  .prose h2   { font-size: 1.2rem; }
  .error-code { font-size: 4rem; }
}
