/* ============================================
   tgwatson.com
   A site that feels like a handwritten note.
   ============================================ */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,600;1,400&family=Inter:wght@400;500&display=swap');

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

/* --- Design Tokens --- */
:root {
  --color-bg: #FAF6F0;
  --color-text: #2C2C2C;
  --color-muted: #7A7267;
  --color-accent: #8B6914;
  --color-border: #E0D8CC;
  --color-selection: #E8DCC8;

  --font-body: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --font-sans: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --font-size: 1.125rem;
  --line-height: 1.7;
  --measure: 640px;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 32px;
  --space-xl: 64px;
  --space-2xl: 96px;
  --space-3xl: 128px;

  --shadow-soft: 0 1px 3px rgba(139, 105, 20, 0.06), 0 4px 12px rgba(44, 44, 44, 0.04);
  --shadow-hover: 0 2px 8px rgba(139, 105, 20, 0.1), 0 8px 24px rgba(44, 44, 44, 0.06);
}

/* --- Dark Theme: The Study --- */
[data-theme="study"] {
  --color-bg: #1C1915;
  --color-text: #E8E0D4;
  --color-muted: #9B8E7E;
  --color-accent: #C4993B;
  --color-border: #3A342C;
  --color-selection: #3A342C;

  --shadow-soft: 0 1px 3px rgba(196, 153, 59, 0.08), 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-hover: 0 2px 8px rgba(196, 153, 59, 0.12), 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* --- Selection --- */
::selection {
  background: var(--color-selection);
  color: var(--color-text);
}

/* --- Base --- */
html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 500ms ease, color 400ms ease;
}

/* --- Paper Grain Texture --- */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
}

[data-theme="study"] body::after {
  opacity: 0.05;
}

/* --- Page Exit Transition --- */
body.page-exit {
  opacity: 0;
  transition: opacity 200ms ease;
}

/* --- Links --- */
a {
  color: var(--color-accent);
  text-decoration: none;
  background-image: linear-gradient(var(--color-accent), var(--color-accent));
  background-size: 0% 1px;
  background-position: left bottom;
  background-repeat: no-repeat;
  transition: background-size 300ms ease, color 200ms ease;
}

a:hover {
  background-size: 100% 1px;
  color: var(--color-text);
}

/* --- Typography Scale (perfect fourth 1.333x) --- */
h1 {
  font-size: 2.369rem;
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: 0.02em;
}

h2 {
  font-size: 1.777rem;
  font-weight: 400;
  line-height: 1.3;
}

h3 {
  font-size: 1.333rem;
  font-weight: 600;
  line-height: 1.4;
}

small, .text-sm {
  font-size: 0.844rem;
}

.text-muted {
  color: var(--color-muted);
}

/* --- Small Caps Utility --- */
.small-caps {
  font-family: var(--font-sans);
  font-variant: all-small-caps;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
}

/* --- Layout --- */
.container {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--space-lg) var(--space-lg);
}

/* --- Theme Toggle --- */
.theme-toggle {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 100;
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-muted);
  font-family: var(--font-sans);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 12px;
  cursor: pointer;
  transition: color 300ms ease, border-color 300ms ease;
}

.theme-toggle:hover {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

/* --- Landing Page --- */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  text-align: center;
  padding: var(--space-lg);
  position: relative;
}

.landing::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    transparent 50%,
    rgba(44, 44, 44, 0.04) 100%
  );
  z-index: 0;
}

[data-theme="study"] .landing::before {
  background: radial-gradient(
    ellipse at center,
    transparent 40%,
    rgba(0, 0, 0, 0.15) 100%
  );
}

.landing > * {
  position: relative;
  z-index: 1;
}

.landing h1 {
  font-size: 2.369rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-lg);
  animation: landingFadeIn 800ms ease both;
}

.landing .rule {
  width: 40px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--color-accent), transparent);
  margin: 0 auto var(--space-lg);
  animation: landingFadeIn 800ms ease 200ms both;
}

.landing .tagline {
  color: var(--color-muted);
  font-style: italic;
  margin-bottom: var(--space-xl);
  font-size: 1.125rem;
  animation: landingFadeIn 800ms ease 400ms both;
}

.landing-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.landing-links:nth-of-type(1) {
  animation: landingFadeIn 800ms ease 600ms both;
}

.landing-links:nth-of-type(2) {
  animation: landingFadeIn 800ms ease 750ms both;
}

.landing-links:nth-of-type(3) {
  animation: landingFadeIn 800ms ease 900ms both;
}

.landing-links .sep {
  color: var(--color-border);
  user-select: none;
}

@keyframes landingFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.colophon {
  position: absolute;
  bottom: var(--space-lg);
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.65rem;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  animation: landingFadeIn 800ms ease 1000ms both;
}

/* --- Page Nav --- */
.page-nav {
  padding: var(--space-lg);
  max-width: var(--measure);
  margin: 0 auto;
}

.page-nav a {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  background-image: none;
  transition: color 200ms ease;
}

.page-nav a:hover {
  color: var(--color-text);
  background-image: none;
}

/* --- Page Header --- */
.page-header {
  margin-bottom: var(--space-xl);
}

.page-header h1 {
  margin-bottom: var(--space-sm);
  letter-spacing: 0.04em;
}

.page-header .rule {
  width: 40px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--color-accent), transparent);
  margin-top: var(--space-lg);
}

/* --- Projects --- */
.project-list {
  list-style: none;
}

.project-item {
  padding: var(--space-lg);
  margin: 0 calc(-1 * var(--space-lg));
  border-bottom: 1px dotted var(--color-border);
  border-radius: 2px;
}

.project-item:last-child {
  border-bottom: none;
}

@media (hover: hover) {
  .project-item {
    transition: transform 300ms ease, box-shadow 300ms ease;
  }

  .project-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
  }
}

.project-title {
  font-size: 1.333rem;
  font-weight: 400;
  margin-bottom: var(--space-xs);
}

.project-title a {
  background-image: none;
}

.project-title a:hover {
  background-image: linear-gradient(var(--color-accent), var(--color-accent));
  background-size: 100% 1px;
}

.project-desc {
  color: var(--color-muted);
  margin-bottom: var(--space-xs);
}

.project-year {
  font-family: var(--font-sans);
  font-variant: all-small-caps;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  color: var(--color-muted);
}

/* --- Writing Index --- */
.writing-list {
  list-style: none;
}

.writing-item {
  margin-bottom: var(--space-xl);
  padding: var(--space-lg);
  margin-left: calc(-1 * var(--space-lg));
  margin-right: calc(-1 * var(--space-lg));
  border-radius: 2px;
}

@media (hover: hover) {
  .writing-item {
    transition: box-shadow 300ms ease;
  }

  .writing-item:hover {
    box-shadow: var(--shadow-soft);
  }
}

.writing-date {
  font-family: var(--font-sans);
  font-variant: all-small-caps;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-bottom: var(--space-xs);
}

.writing-title {
  font-size: 1.333rem;
  font-weight: 400;
  margin-bottom: var(--space-sm);
}

.writing-title a {
  background-image: none;
}

.writing-title a:hover {
  background-image: linear-gradient(var(--color-accent), var(--color-accent));
  background-size: 100% 1px;
}

.writing-excerpt {
  color: var(--color-muted);
}

/* --- Article (Blog Post) --- */
.article-header {
  margin-bottom: var(--space-xl);
}

.article-header .article-date {
  font-family: var(--font-sans);
  font-variant: all-small-caps;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-bottom: var(--space-sm);
}

.article-header h1 {
  line-height: 1.25;
  letter-spacing: 0.04em;
}

/* --- Drop Cap --- */
.article-content > p:first-of-type::first-letter {
  float: left;
  font-size: 3.5em;
  line-height: 0.8;
  padding-right: 8px;
  padding-top: 4px;
  color: var(--color-accent);
  font-weight: 400;
}

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

.article-content blockquote {
  border-left: 2px solid var(--color-accent);
  padding-left: var(--space-lg);
  margin: var(--space-lg) 0;
  color: var(--color-muted);
  font-style: italic;
}

/* --- Pull Quotes --- */
.pull-quote {
  font-size: 1.5rem;
  font-style: italic;
  color: var(--color-accent);
  text-align: center;
  margin: var(--space-2xl) auto;
  max-width: 80%;
  line-height: 1.5;
  border: none;
  padding: 0;
}

.pull-quote::before {
  content: '\201C';
  display: block;
  font-size: 3rem;
  color: var(--color-border);
  margin-bottom: var(--space-sm);
}

.article-content code {
  font-size: 0.9em;
  background: var(--color-selection);
  padding: 2px 6px;
  border-radius: 3px;
}

.article-content pre {
  background: var(--color-selection);
  padding: var(--space-md);
  border-radius: 4px;
  overflow-x: auto;
  margin-bottom: 1.5em;
}

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

.article-content ul,
.article-content ol {
  margin-bottom: 1.5em;
  padding-left: var(--space-lg);
}

.article-content li {
  margin-bottom: var(--space-sm);
}

.article-content h2 {
  margin-top: var(--space-xl);
  margin-bottom: var(--space-md);
  letter-spacing: 0.04em;
}

.article-content h3 {
  margin-top: var(--space-lg);
  margin-bottom: var(--space-md);
}

.article-content img {
  max-width: 100%;
  height: auto;
  margin: var(--space-lg) 0;
}

.article-content hr {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--color-accent), transparent);
  margin: var(--space-xl) auto;
  width: 40px;
}

.article-footer {
  margin-top: var(--space-2xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border);
}

.article-footer a {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  background-image: none;
}

.article-footer a:hover {
  color: var(--color-text);
  background-image: none;
}

/* --- 404 --- */
.not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  text-align: center;
  padding: var(--space-lg);
}

.not-found p {
  color: var(--color-muted);
  font-style: italic;
  margin-bottom: var(--space-lg);
}

/* --- Scroll Reveals --- */
.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 600ms ease, transform 600ms ease;
}

.reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

.reveal:nth-child(2) { transition-delay: 80ms; }
.reveal:nth-child(3) { transition-delay: 160ms; }
.reveal:nth-child(4) { transition-delay: 240ms; }

@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .landing h1,
  .landing .rule,
  .landing .tagline,
  .landing-links,
  .colophon {
    animation: none;
  }
}

/* --- Responsive --- */
@media (max-width: 600px) {
  :root {
    --font-size: 1rem;
  }

  h1 {
    font-size: 1.777rem;
  }

  h2 {
    font-size: 1.333rem;
  }

  .landing h1 {
    font-size: 1.777rem;
  }

  .container {
    padding: var(--space-md) var(--space-md);
  }

  .colophon {
    position: relative;
    bottom: auto;
    margin-top: var(--space-2xl);
  }

  .theme-toggle {
    top: var(--space-md);
    right: var(--space-md);
    font-size: 0.6rem;
    padding: 4px 8px;
  }

  .article-content > p:first-of-type::first-letter {
    font-size: 3em;
  }

  .pull-quote {
    font-size: 1.25rem;
    max-width: 90%;
  }

  .project-item,
  .writing-item {
    margin-left: calc(-1 * var(--space-md));
    margin-right: calc(-1 * var(--space-md));
    padding: var(--space-md);
  }
}
