/* ============================================================
   THE TERMINAL — First Principles
   Design System & Stylesheet
   Principle: Engineered Restraint
   ============================================================ */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400&display=swap');

/* --- Design Tokens --- */
:root {
  --bg: #0A0A0A;
  --text-primary: #D4D4D4;
  --text-secondary: #666666;
  --accent: #C0392B;
  --border: #1A1A1A;
  --border-light: #222222;

  --font: 'IBM Plex Mono', monospace;
  --body-size: 18px;
  --line-height: 1.75;
  --max-width: 680px;

  --meta-size: 13px;
  --small-size: 14px;
  --h1-size: 32px;
  --h2-size: 24px;
  --pull-quote-size: 22px;
  --nav-size: 12px;
  --tag-spacing: 0.12em;
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font);
  font-size: var(--body-size);
  font-weight: 400;
  line-height: var(--line-height);
  color: var(--text-primary);
  background-color: var(--bg);
  min-height: 100vh;
}

/* --- Semantic Elements Reset --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 500;
  line-height: 1.3;
}

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

a:hover {
  text-decoration: underline;
}

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

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

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

/* --- Layout --- */
.site-wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 48px 20px 80px;
}

/* --- Header --- */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 64px;
}

.site-logo {
  display: block;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.site-logo svg {
  width: 100%;
  height: 100%;
}

.site-nav {
  display: flex;
  gap: 24px;
}

.site-nav a {
  font-size: var(--nav-size);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: var(--tag-spacing);
  color: var(--text-secondary);
  transition: none;
}

.site-nav a:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.site-nav a.active {
  color: var(--text-primary);
}

/* --- Logo Animation (first visit only) --- */
.logo-animate .bar-1 {
  animation: barDrop 300ms ease-out 0ms both;
}
.logo-animate .bar-2 {
  animation: barDrop 300ms ease-out 50ms both;
}
.logo-animate .bar-3 {
  animation: barDrop 300ms ease-out 100ms both;
}
.logo-animate .bar-4 {
  animation: barDrop 300ms ease-out 150ms both;
}
.logo-animate .bar-5 {
  animation: barDrop 300ms ease-out 200ms both;
}
.logo-animate .bar-6 {
  animation: barDrop 300ms ease-out 250ms both;
}
.logo-animate .bar-7 {
  animation: barDrop 300ms ease-out 300ms both;
}

@keyframes barDrop {
  0% {
    opacity: 0;
    transform: translateY(-12px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Page Fade-In --- */
.page-content {
  opacity: 0;
  transition: opacity 200ms ease;
}

.page-content.loaded {
  opacity: 1;
}

/* --- Category Tags --- */
.tag {
  font-size: var(--nav-size);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: var(--tag-spacing);
  color: var(--text-secondary);
}

.tag--accent {
  color: var(--accent);
}

/* --- Metadata (dates, reading time) --- */
.meta {
  font-size: var(--meta-size);
  font-weight: 300;
  color: var(--text-secondary);
  line-height: 1.5;
}

.meta-separator::before {
  content: '·';
  margin: 0 8px;
}

/* --- Featured Article (Homepage) --- */
.featured {
  margin-bottom: 56px;
}

.featured .tag {
  display: block;
  margin-bottom: 16px;
}

.featured h1 {
  font-size: var(--h1-size);
  font-weight: 500;
  line-height: 1.25;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.featured .meta {
  margin-bottom: 28px;
}

.featured .excerpt {
  margin-bottom: 28px;
}

.featured .excerpt p {
  margin-bottom: 1em;
}

.continue-link {
  font-size: var(--small-size);
  color: var(--accent);
  font-weight: 400;
}

.continue-link:hover {
  text-decoration: underline;
}

/* --- Post List --- */
.post-list-heading {
  font-size: var(--meta-size);
  font-weight: 300;
  text-transform: uppercase;
  letter-spacing: var(--tag-spacing);
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.post-list {
  list-style: none;
  padding: 0;
}

.post-list li {
  padding: 20px 0;
  border-top: 1px solid var(--border);
}

.post-list li:last-child {
  border-bottom: 1px solid var(--border);
}

.post-list a {
  display: block;
}

.post-list .post-title {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.35;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.post-list a:hover .post-title {
  text-decoration: underline;
}

.post-list .post-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.post-list a:hover {
  text-decoration: none;
}

/* --- Article Page --- */
.article-header {
  margin-bottom: 48px;
}

.article-header .tag {
  display: block;
  margin-bottom: 16px;
}

.article-header h1 {
  font-size: var(--h1-size);
  font-weight: 500;
  line-height: 1.25;
  margin-bottom: 16px;
}

.article-header .meta {
  margin-bottom: 0;
}

/* --- Article Body --- */
.article-body {
  margin-bottom: 64px;
}

.article-body p {
  margin-bottom: 1.5em;
}

.article-body h2 {
  font-size: var(--h2-size);
  margin-top: 2.5em;
  margin-bottom: 1em;
}

.article-body h3 {
  font-size: 20px;
  margin-top: 2em;
  margin-bottom: 0.75em;
}

.article-body ul,
.article-body ol {
  margin-bottom: 1.5em;
}

.article-body li {
  margin-bottom: 0.5em;
}

.article-body code {
  font-family: var(--font);
  font-size: 0.9em;
  background: var(--border-light);
  padding: 2px 6px;
  border-radius: 2px;
}

.article-body pre {
  background: var(--border-light);
  padding: 20px;
  overflow-x: auto;
  margin-bottom: 1.5em;
  border-radius: 2px;
}

.article-body pre code {
  background: none;
  padding: 0;
}

/* --- Pull Quote --- */
.pull-quote {
  font-size: var(--pull-quote-size);
  font-weight: 300;
  line-height: 1.5;
  border-left: 2px solid var(--border-light);
  padding-left: 20px;
  margin: 2em 0;
  color: var(--text-primary);
}

/* --- Inline Figure (diagrams) --- */
.figure {
  margin: 2em 0;
}

.figure img {
  width: 100%;
  border: 1px solid var(--border);
}

.figure figcaption {
  font-size: var(--meta-size);
  font-weight: 300;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* --- Next Article --- */
.next-article {
  padding-top: 32px;
  border-top: 1px solid var(--border);
  margin-bottom: 48px;
}

.next-article .label {
  font-size: var(--meta-size);
  font-weight: 300;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tag-spacing);
  margin-bottom: 8px;
}

.next-article a {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
}

.next-article a:hover {
  text-decoration: underline;
}

/* --- Inline Subscribe (bottom of article) --- */
.inline-subscribe {
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.inline-subscribe p {
  font-size: var(--small-size);
  color: var(--text-secondary);
  font-weight: 300;
  margin-bottom: 16px;
}

.subscribe-form {
  display: flex;
  gap: 12px;
}

.subscribe-form input[type="email"] {
  font-family: var(--font);
  font-size: var(--small-size);
  font-weight: 300;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border-light);
  padding: 10px 14px;
  flex: 1;
  outline: none;
}

.subscribe-form input[type="email"]::placeholder {
  color: var(--text-secondary);
}

.subscribe-form input[type="email"]:focus {
  border-color: var(--text-secondary);
}

.subscribe-form button {
  font-family: var(--font);
  font-size: var(--nav-size);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: var(--tag-spacing);
  color: var(--bg);
  background: var(--text-primary);
  border: none;
  padding: 10px 20px;
  cursor: pointer;
}

.subscribe-form button:hover {
  background: var(--accent);
  color: #fff;
}

/* --- Subscribe Page --- */
.subscribe-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  text-align: center;
}

.subscribe-page h1 {
  font-size: var(--h2-size);
  font-weight: 500;
  margin-bottom: 16px;
}

.subscribe-page p {
  font-size: var(--small-size);
  color: var(--text-secondary);
  font-weight: 300;
  margin-bottom: 32px;
}

.subscribe-page .subscribe-form {
  width: 100%;
  max-width: 420px;
}

/* --- Archive Page --- */
.archive-month {
  margin-bottom: 40px;
}

.archive-month h2 {
  font-size: var(--meta-size);
  font-weight: 300;
  text-transform: uppercase;
  letter-spacing: var(--tag-spacing);
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.archive-list {
  list-style: none;
  padding: 0;
}

.archive-list li {
  padding: 12px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 16px;
}

.archive-list li:last-child {
  border-bottom: 1px solid var(--border);
}

.archive-date {
  font-size: var(--meta-size);
  font-weight: 300;
  color: var(--text-secondary);
  flex-shrink: 0;
  width: 48px;
}

.archive-title {
  font-size: 15px;
  font-weight: 400;
  color: var(--text-primary);
  flex: 1;
}

.archive-title:hover {
  text-decoration: underline;
}

.archive-tag {
  font-size: 11px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: var(--tag-spacing);
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* --- About Page --- */
.about-content {
  max-width: 580px;
}

.about-content h1 {
  font-size: var(--h2-size);
  font-weight: 500;
  margin-bottom: 32px;
}

.about-content p {
  margin-bottom: 1.5em;
  color: var(--text-primary);
}

.about-content .contact {
  margin-top: 2em;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-size: var(--small-size);
  color: var(--text-secondary);
  font-weight: 300;
}

/* --- Search Overlay (Cmd+K) --- */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.95);
  z-index: 1000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20vh;
}

.search-overlay.active {
  display: flex;
}

.search-container {
  width: 100%;
  max-width: 520px;
  padding: 0 20px;
}

.search-input {
  font-family: var(--font);
  font-size: var(--body-size);
  font-weight: 300;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-light);
  padding: 12px 0;
  width: 100%;
  outline: none;
}

.search-input::placeholder {
  color: var(--text-secondary);
}

.search-input:focus {
  border-bottom-color: var(--text-secondary);
}

.search-results {
  list-style: none;
  padding: 0;
  margin-top: 16px;
}

.search-results li {
  padding: 10px 0;
}

.search-results a {
  font-size: var(--small-size);
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.search-results a:hover {
  text-decoration: underline;
}

.search-results .result-tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: var(--tag-spacing);
  color: var(--text-secondary);
}

.search-hint {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 300;
  margin-top: 20px;
}

.search-hint kbd {
  font-family: var(--font);
  font-size: 11px;
  background: var(--border-light);
  padding: 2px 6px;
  border-radius: 2px;
  color: var(--text-secondary);
}

/* --- Footer hint for search --- */
.search-footer-hint {
  margin-top: 48px;
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 300;
}

.search-footer-hint kbd {
  font-family: var(--font);
  font-size: 11px;
  background: var(--border-light);
  padding: 2px 6px;
  border-radius: 2px;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  :root {
    --h1-size: 26px;
    --h2-size: 20px;
    --pull-quote-size: 19px;
  }

  .site-wrapper {
    padding: 32px 20px 64px;
  }

  .site-header {
    margin-bottom: 48px;
  }

  .site-nav {
    gap: 16px;
  }

  .featured {
    margin-bottom: 40px;
  }

  .subscribe-form {
    flex-direction: column;
  }

  .subscribe-form button {
    width: 100%;
    padding: 12px;
  }

  .archive-list li {
    flex-wrap: wrap;
    gap: 4px 12px;
  }

  .archive-tag {
    width: 100%;
    margin-top: -2px;
  }
}

/* --- Selection Color --- */
::selection {
  background: var(--accent);
  color: #fff;
}
