/* ══════════════════════════════════════════════════════
   Design Patterns — Shared Styles
   ══════════════════════════════════════════════════════ */

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

/* ──── Variables: Light ──── */
:root {
  --bg:             #F7F3EB;
  --bg-deep:        #EFE9DD;
  --bg-code:        #F0EBE1;
  --code-text:      #2A2524;
  --bg-translucent: rgba(247, 243, 235, 0.92);
  --text:           #2A2524;
  --text-muted:     #7A706A;
  --text-light:     #A89E96;
  --accent:         #8B2500;
  --accent-hover:   #A83010;
  --green:          #4E7A3E;
  --blue:           #3A5F8A;
  --purple:         #7B5EA7;
  --teal:           #2E7D7B;
  --orange:         #B8621B;
  --border:         #D8D0C4;
  --border-light:   #E8E2D8;
  --shadow:         rgba(42, 37, 36, 0.06);
  --radius:         4px;
}

/* ──── Variables: Dark ──── */
[data-theme="dark"] {
  --bg:             #1A1918;
  --bg-deep:        #141312;
  --bg-code:        #232120;
  --code-text:      #D4CFCA;
  --bg-translucent: rgba(26, 25, 24, 0.92);
  --text:           #D4CFCA;
  --text-muted:     #9A938C;
  --text-light:     #5E5852;
  --accent:         #D4896A;
  --accent-hover:   #E09A7A;
  --green:          #8EBD78;
  --blue:           #7CAFC2;
  --purple:         #B497D6;
  --teal:           #6DC4C0;
  --orange:         #D4976A;
  --border:         #333130;
  --border-light:   #2A2827;
  --shadow:         rgba(0, 0, 0, 0.3);
}

/* ──── Transitions ──── */
body, .site-nav, pre, pre code, .key-insight, .badge,
.pattern, .part-header, .toc, .preface, footer,
.lang-card, .cat-card {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ──── Base ──── */
html { scroll-behavior: smooth; }

body {
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-size: 17px;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

/* ──── Navigation ──── */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg-translucent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.nav-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 32px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.5px;
}

.nav-brand:hover { color: var(--accent); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 24px;
}

.nav-link {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 1.5px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.nav-link:hover,
.nav-link[aria-current="page"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ──── Theme Toggle ──── */
.theme-toggle {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
  transition: color 0.2s, border-color 0.2s, transform 0.3s;
  line-height: 1;
}

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

.theme-toggle::after { content: '\263E'; }
[data-theme="dark"] .theme-toggle::after { content: '\2600'; }

/* ──── Layout ──── */
.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 32px;
}

/* ──── Title Page ──── */
.title-page {
  min-height: 82vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 80px 32px;
  position: relative;
}

.title-page::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 180px;
  height: 1px;
  background: var(--accent);
}

.title-page .edition {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-size: 14px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 40px;
}

.title-page h1 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-size: clamp(48px, 8vw, 80px);
  line-height: 1.05;
  color: var(--text);
  letter-spacing: -1px;
  margin-bottom: 12px;
}

.title-page h1 em {
  font-style: italic;
  font-weight: 300;
  color: var(--accent);
}

.title-page .subtitle {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 400;
  font-style: italic;
  font-size: 22px;
  color: var(--text-muted);
  margin-bottom: 60px;
}

.title-page .language-badge {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  padding: 8px 28px;
  border-radius: 2px;
}

/* ──── Table of Contents ──── */
.toc {
  padding: 80px 0;
  border-bottom: 1px solid var(--border);
}

.toc h2 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 32px;
  color: var(--text);
  margin-bottom: 40px;
  text-align: center;
  letter-spacing: 1px;
}

.toc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 40px 48px;
}

.toc-section h3 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.toc-section ol {
  list-style: none;
}

.toc-section.creational ol  { counter-reset: toc-item 0; }
.toc-section.structural ol  { counter-reset: toc-item 4; }
.toc-section.behavioral ol  { counter-reset: toc-item 8; }

.toc-section ol li {
  counter-increment: toc-item;
  margin-bottom: 6px;
}

.toc-section ol li a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.6;
  transition: color 0.2s;
}

.toc-section ol li a:hover { color: var(--accent); }

.toc-section ol li a::before {
  content: counter(toc-item) ".";
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-light);
  min-width: 22px;
}

/* ──── Preface ──── */
.preface {
  padding: 72px 0;
  border-bottom: 1px solid var(--border);
}

.preface h2 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 28px;
  margin-bottom: 24px;
  color: var(--text);
}

.preface p {
  max-width: 640px;
  color: var(--text-muted);
  font-size: 16px;
  margin-bottom: 16px;
  line-height: 1.8;
}

.preface p:last-child { margin-bottom: 0; }

/* ──── Parts ──── */
.part { padding: 80px 0 0; }

.part-header {
  text-align: center;
  padding: 48px 0 56px;
  margin-bottom: 48px;
  border-bottom: 1px solid var(--border);
}

.part-header .part-label {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-size: 14px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 12px;
}

.part-header h2 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 38px;
  color: var(--text);
  margin-bottom: 16px;
}

.part-header .part-desc {
  max-width: 540px;
  margin: 0 auto;
  font-size: 16px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.7;
}

/* ──── Pattern Articles ──── */
.pattern {
  padding: 56px 0;
  border-bottom: 1px solid var(--border-light);
}

.pattern:last-child { border-bottom: none; }

.pattern-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 8px;
}

.chapter-num {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 300;
  font-size: 56px;
  line-height: 1;
  color: var(--border);
  min-width: 48px;
  user-select: none;
}

.pattern-header h3 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 30px;
  color: var(--text);
  line-height: 1.2;
}

.badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 2px;
  white-space: nowrap;
  position: relative;
  top: -2px;
}

.badge.creational { color: var(--accent); border: 1px solid var(--accent); }
.badge.structural { color: var(--blue);   border: 1px solid var(--blue); }
.badge.behavioral { color: var(--green);  border: 1px solid var(--green); }

.intent {
  font-size: 17px;
  font-style: italic;
  color: var(--text-muted);
  margin-bottom: 24px;
  padding-left: 64px;
  line-height: 1.7;
}

.pattern-body { padding-left: 64px; }

.pattern-body h4 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 18px;
  color: var(--text);
  margin-bottom: 8px;
  margin-top: 28px;
  letter-spacing: 0.5px;
}

.pattern-body h4:first-child { margin-top: 0; }

.pattern-body p {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 12px;
  line-height: 1.75;
}

/* ──── Key Insight ──── */
.key-insight {
  background: var(--bg-deep);
  border-left: 3px solid var(--accent);
  padding: 16px 20px;
  margin: 20px 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.key-insight p {
  font-size: 15px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.7;
}

.key-insight strong { color: var(--text); }

/* ──── When to Use ──── */
.when-to-use { margin-top: 24px; }

.when-to-use ul {
  list-style: none;
  padding: 0;
}

.when-to-use ul li {
  position: relative;
  padding-left: 20px;
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 6px;
  line-height: 1.65;
}

.when-to-use ul li::before {
  content: '\2014';
  position: absolute;
  left: 0;
  color: var(--border);
}

/* ──── Code Blocks ──── */
pre {
  margin: 20px 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 2px 12px var(--shadow), 0 1px 3px var(--shadow);
}

pre code {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13.2px;
  line-height: 1.7;
  padding: 24px 28px;
  background: var(--bg-code);
  color: var(--code-text);
  overflow-x: auto;
  tab-size: 4;
  -moz-tab-size: 4;
}

/* ──── Syntax Theme: Light (warm sepia) ──── */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata        { color: #A09890; font-style: italic; }
.token.keyword       { color: #8B2500; }
.token.builtin       { color: #8B2500; }
.token.boolean       { color: #8B2500; }
.token.operator      { color: #5C554E; }
.token.punctuation   { color: #7A706A; }
.token.string,
.token.char          { color: #4E7A3E; }
.token.number        { color: #A07D2E; }
.token.function      { color: #3A5F8A; }
.token.class-name    { color: #8A6D2F; font-weight: 500; }
.token.decorator     { color: #7B5EA7; }
.token.regex         { color: #A07D2E; }
.token.template-string       { color: #4E7A3E; }
.token.template-punctuation  { color: #8B2500; }
.token.interpolation          { color: #2A2524; }

/* ──── Syntax Theme: Dark (warm dark) ──── */
[data-theme="dark"] .token.comment,
[data-theme="dark"] .token.prolog,
[data-theme="dark"] .token.doctype,
[data-theme="dark"] .token.cdata        { color: #6B6560; font-style: italic; }
[data-theme="dark"] .token.keyword       { color: #D4896A; }
[data-theme="dark"] .token.builtin       { color: #D4896A; }
[data-theme="dark"] .token.boolean       { color: #D4896A; }
[data-theme="dark"] .token.operator      { color: #B0A89E; }
[data-theme="dark"] .token.punctuation   { color: #8A837C; }
[data-theme="dark"] .token.string,
[data-theme="dark"] .token.char          { color: #A3B87C; }
[data-theme="dark"] .token.number        { color: #C9A86C; }
[data-theme="dark"] .token.function      { color: #7CAFC2; }
[data-theme="dark"] .token.class-name    { color: #C2A67C; font-weight: 500; }
[data-theme="dark"] .token.decorator     { color: #B497D6; }
[data-theme="dark"] .token.regex         { color: #C9A86C; }
[data-theme="dark"] .token.template-string       { color: #A3B87C; }
[data-theme="dark"] .token.template-punctuation  { color: #D4896A; }
[data-theme="dark"] .token.interpolation          { color: #D4CFCA; }

/* ──── Inline Code ──── */
code:not([class]) {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  background: var(--bg-deep);
  padding: 2px 7px;
  border-radius: 3px;
  color: var(--accent);
}

/* ──── Back to Top ──── */
.back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 44px;
  height: 44px;
  background: var(--bg-code);
  color: var(--code-text);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s, background 0.2s;
  z-index: 100;
  font-size: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

.back-to-top.visible { opacity: 1; transform: translateY(0); }
.back-to-top:hover   { background: var(--accent); }

/* ──── Footer ──── */
footer {
  text-align: center;
  padding: 64px 0;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

footer p {
  font-family: 'Cormorant Garamond', serif;
  font-size: 15px;
  color: var(--text-light);
  font-style: italic;
}

/* ──── Index Page: Language Cards ──── */
.editions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-top: 40px;
}

.lang-card {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.lang-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 20px var(--shadow);
  transform: translateY(-2px);
}

.lang-card h3 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 26px;
  margin-bottom: 8px;
  color: var(--text);
}

.lang-card .lang-version {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}

.lang-card p {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 16px;
}

.lang-card .card-arrow {
  font-family: 'Cormorant Garamond', serif;
  font-size: 15px;
  color: var(--accent);
  font-style: italic;
}

/* ──── Index Page: Category Cards ──── */
.cat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 28px;
  margin-top: 40px;
}

.cat-card {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
}

.cat-card h3 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 20px;
  margin-bottom: 8px;
  color: var(--text);
}

.cat-card p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: 14px;
}

.cat-card ul {
  list-style: none;
}

.cat-card ul li {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-light);
  padding: 3px 0;
  border-bottom: 1px solid var(--border-light);
}

.cat-card ul li:last-child { border-bottom: none; }

/* ──── Index Page: Intro Sections ──── */
.intro-section {
  padding: 72px 0;
  border-bottom: 1px solid var(--border);
}

.intro-section h2 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 32px;
  color: var(--text);
  margin-bottom: 20px;
  text-align: center;
  letter-spacing: 1px;
}

.intro-section > p {
  max-width: 620px;
  margin: 0 auto 16px;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1.8;
  text-align: center;
}

/* ──── Hello World Cards ──── */
.hw-era {
  padding: 64px 0 0;
}

.hw-era-header {
  text-align: center;
  margin-bottom: 40px;
}

.hw-decade {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
  display: block;
  margin-bottom: 8px;
}

.hw-era-header h2 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 32px;
  color: var(--text);
  margin-bottom: 10px;
}

.hw-era-desc {
  max-width: 540px;
  margin: 0 auto;
  font-size: 15px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.65;
}

.hw-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 48px;
  padding-bottom: 48px;
  border-bottom: 1px solid var(--border);
}

.hw-card {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  transition: border-color 0.2s, background-color 0.3s;
}

.hw-card:hover { border-color: var(--accent); }

.hw-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4px;
}

.hw-card-head h3 {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 700;
  font-size: 22px;
  color: var(--text);
}

.hw-year {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 1px 8px;
  border-radius: 2px;
}

.hw-creator {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.hw-note {
  font-size: 13px;
  color: var(--text-light);
  font-style: italic;
  margin-bottom: 12px;
}

.hw-card pre {
  margin: 0;
  box-shadow: none;
}

.hw-card pre code {
  font-size: 12px;
  line-height: 1.55;
  padding: 14px 16px;
}

/* ──── Language Switcher ──── */
.lang-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 64px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.lang-switcher-label {
  font-family: 'Cormorant Garamond', serif;
  font-size: 13px;
  color: var(--text-light);
  font-style: italic;
}

.lang-switcher-link {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: none;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 2px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.lang-switcher-link:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--bg-deep);
}

/* ──── Responsive ──── */
@media (max-width: 768px) {
  body { font-size: 16px; }
  .container { padding: 0 20px; }
  .nav-inner { padding: 0 20px; }
  .nav-right { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .nav-link { font-size: 9px; letter-spacing: 0.3px; }
  .title-page { min-height: 70vh; padding: 60px 20px; }
  .title-page h1 { font-size: 42px; }
  .toc-grid { grid-template-columns: 1fr; gap: 32px; }
  .pattern-header { flex-wrap: wrap; gap: 8px; }
  .chapter-num { font-size: 40px; min-width: 36px; }
  .intent { padding-left: 0; }
  .pattern-body { padding-left: 0; }
  .lang-switcher { padding-left: 0; }
  pre code { font-size: 12.5px; padding: 18px 16px; }
  .part-header h2 { font-size: 30px; }
  .editions-grid { grid-template-columns: 1fr; }
  .cat-grid { grid-template-columns: 1fr; }
  .hw-grid { grid-template-columns: 1fr; }
}
