/* ==========================================================================
   NATE THAYER ARCHIVE - SYSTEM STYLE SHEET (v2.0)
   Philosophy: Semantic Tokens, High-Contrast, System-Adaptive.
   ========================================================================== */

:root {
  /* --- IDENTITY (Constant in both modes) --- */
  --accent-red: #E00025; /* The "Phnom Penh Post" Red */
  
  /* --- TYPOGRAPHY STACKS --- */
  --font-serif: Charter, 'Bitstream Charter', 'Sitka Text', Cambria, Georgia, serif;
  --font-mono: 'Nimbus Mono PS', 'Courier New', Courier, monospace;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* --- LIGHT MODE TOKENS (Default) --- */
  color-scheme: light;
  --text-main:   #1a1a1a;  /* Soft Black */
  --text-meta:   #555555;  /* Metadata Grey */
  --text-muted:  #999999;  /* Placeholders / Watermarks */
  
  --bg-body:     #f4f4f4;  /* The canvas */
  --bg-paper:    #ffffff;  /* The reading sheet */
  --bg-surface:  #f9f9f9;  /* Secondary elements (boxes, cards) */
  --bg-dark:     #111111;  /* Navbar/Footer (Always dark in light mode) */
  --bg-header-text: #ffffff; /* Text inside the dark header */

  --border-subtle: #eeeeee;
  --border-strong: #dddddd;
  --border-focus:  #cccccc;
}

/* --- DARK MODE TOKENS (System Triggered) --- */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --text-main:   #e6e6e6;  /* Soft White */
    --text-meta:   #b0b0b0;  /* Lightened Silver (9:1 Contrast) */
    --text-muted:  #888888;  /* AA Compliant Grey (4.9:1 Contrast) */
    
    --bg-body:     #0a0a0a;  /* Deepest Black */
    --bg-paper:    #161616;  /* Dark Grey Sheet */
    --bg-surface:  #1f1f1f;  /* Slightly lighter for inputs/boxes */
    --bg-dark:     #000000;  /* Pure Black for header */
    --bg-header-text: #e6e6e6;

    --border-subtle: #2a2a2a;
    --border-strong: #333333;
    --border-focus:  #444444;
    
    /* OVERRIDE: Brightened Red for Dark Mode Readability (Passes WCAG AA) */
    --accent-red:  #ff3f3f;
  }
  
  /* Visual Tweak: Reduce image glare in dark mode */
  img { opacity: 0.85; transition: opacity 0.2s; }
  img:hover { opacity: 1; }
}

/* ==========================================================================
   1. RESET & BASE
   ========================================================================== */
* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: var(--font-serif);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text-main); text-decoration: underline; text-decoration-color: var(--border-focus); text-underline-offset: 3px; }
a:hover { color: var(--accent-red); text-decoration-color: var(--accent-red); }

img { max-width: 100%; height: auto; display: block; margin: 1.5rem auto; }

hr { border: 0; border-top: 1px solid var(--border-strong); margin: 2rem 0; }

/* ==========================================================================
   2. GLOBAL LAYOUT
   ========================================================================== */

/* The Navigation Bar */
.top-bar {
  background-color: var(--bg-dark);
  color: var(--bg-header-text);
  padding: 0.75rem 0;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  margin-bottom: 0;
}

.nav-content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-logo {
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--bg-header-text);
  text-decoration: none;
}

.nav-links a {
  color: #aaa; /* Deliberately fixed grey for contrast against black header */
  text-decoration: none;
  margin-left: 1.5rem;
  text-transform: uppercase;
  font-size: 0.8rem;
  font-weight: bold;
}
.nav-links a:hover { color: #fff; text-decoration: underline; }
.nav-divider { color: #444; margin-left: 1.5rem; }

/* The Main Paper Sheet */
main {
  background: var(--bg-paper);
  max-width: 1000px;
  margin: 0 auto;
  padding: 3rem 4rem;
  min-height: 100vh;
  box-shadow: 0 0 15px rgba(0,0,0,0.05); /* Very subtle shadow */
}

/* ==========================================================================
   3. ARCHIVE / LEDGER VIEW
   ========================================================================== */
.archive-header {
  margin-bottom: 3rem;
  border-bottom: 4px solid var(--bg-dark);
  padding-bottom: 1.5rem;
}

.archival-kicker {
  font-family: var(--font-mono);
  color: var(--accent-red);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.5rem;
  display: block;
}

.archive-title {
  font-family: var(--font-sans);
  font-weight: 900;
  font-size: 2.5rem;
  margin: 0;
  line-height: 1;
  text-transform: uppercase;
  color: var(--text-main);
}

.archive-subtitle {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--text-meta);
  margin-top: 0.5rem;
  max-width: 60ch;
}

/* --- SEARCH & FILTERS --- */
.filter-controls {
  margin-top: 2rem;
  max-width: 600px;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 15px;
  font-size: 1rem;
  opacity: 0.5;
  pointer-events: none;
}

#ledgerSearch {
  width: 100%;
  padding: 1rem 1rem 1rem 3rem;
  font-family: var(--font-sans);
  font-size: 1rem;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-surface);
  color: var(--text-main);
  transition: all 0.2s;
}

#ledgerSearch:focus {
  outline: none;
  border-color: var(--accent-red);
  box-shadow: 0 0 0 3px rgba(224, 0, 37, 0.1);
}

/* --- LEDGER LIST ITEMS --- */
.year-break {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 4rem;
  color: var(--border-focus); /* Increased contrast (#ccc) for legibility */  
  margin: 4rem 0 1rem -5px;
  line-height: 0.8;
  z-index: -1;
  user-select: none;
}

.ledger-item {
  display: grid;
  grid-template-columns: 120px 1fr auto;
  gap: 1.5rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-subtle);
  text-decoration: none;
  align-items: baseline;
  transition: background 0.1s;
}

.ledger-item:hover { background: var(--bg-surface); }
.ledger-item:hover .ledger-title { color: var(--accent-red); }
.ledger-item[style*="display: none"] { display: none !important; }

.ledger-date {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-meta);
}

.ledger-title {
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.3;
}

.ledger-pub {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  color: var(--border-focus);
}

/* ==========================================================================
   4. POST / ARTICLE VIEW
   ========================================================================== */

.post-header {
  margin-bottom: 3rem;
  text-align: center;
  max-width: 75ch;
  margin-left: auto;
  margin-right: auto;
}

.post-meta {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-red);
  margin-bottom: 1rem;
  display: inline-block;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 5px;
}

.post-full h1 {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 2.8rem;
  line-height: 1.1;
  margin: 0 0 1.5rem 0;
  color: var(--text-main);
}

.post-subtitle {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  line-height: 1.3;
  color: var(--text-meta);
  font-weight: 300;
  margin-top: -1rem; 
  margin-bottom: 2.5rem;
  font-style: italic;
}

.post-lead {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  line-height: 1.4;
  font-style: italic;
  color: var(--text-meta);
  margin-top: 1rem;
  border-top: 4px solid var(--border-subtle);
  padding-top: 1.5rem;
}

/* The Body Text */
.post-content {
  max-width: 65ch;
  margin: 0 auto;
  font-size: 1.125rem;
  line-height: 1.65;
}

.post-content p { margin-bottom: 1.5em; hyphens: auto; }
.post-content h2 { 
  margin-top: 2.5em; 
  font-family: var(--font-sans); 
  text-transform: uppercase; 
  font-size: 1.5rem; 
  letter-spacing: 0.05em; 
  border-bottom: 2px solid var(--text-main); 
  padding-bottom: 0.5rem; 
  color: var(--text-main);
}
.post-content h3 { margin-top: 2em; font-family: var(--font-sans); font-weight: bold; font-size: 1.2rem; color: var(--text-main); }
.post-content blockquote { 
  border-left: 4px solid var(--accent-red); 
  padding-left: 1.5rem; 
  margin-left: 0; 
  font-style: italic; 
  color: var(--text-meta); 
}

/* Figures */
figure {
  margin: 2.5rem -2rem;
  background: var(--bg-surface);
  padding: 1rem;
  border: 1px solid var(--border-subtle);
}
figcaption {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  color: var(--text-meta);
  margin-top: 0.5rem;
  text-align: center;
}

/* Media Player */
.media-player {
  margin: 3rem 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 5px solid var(--accent-red);
  padding: 0;
  display: flex;
  flex-direction: column;
}
.media-hook {
  background: var(--bg-paper);
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-style: italic;
  color: var(--text-main);
  margin: 0;
  padding: 1.5rem 2rem;
  line-height: 1.4;
  border-bottom: 1px solid var(--border-subtle);
}
.media-player a {
  font-size: 0.7rem;
  font-family: var(--font-sans);
  text-transform: uppercase;
  text-decoration: none;
  color: var(--text-muted);
  display: block;
  text-align: right;
  padding: 0 1rem 0.5rem 0;
}
.media-player a:hover { text-decoration: underline; color: var(--accent-red); }

.end-mark {
  color: var(--accent-red);
  font-size: 1.2em;       /* Boosted to match Cap Height */
  line-height: 1;         
  margin-left: 0.25rem;   /* Slight space from last word */ 
  vertical-align: 1px;    
  font-weight: bold;
  display: inline-block;
}

/* ==========================================================================
   5. FORENSIC METADATA
   ========================================================================== */

/* Archivist Note */
.archival-context {
  background: var(--bg-surface);
  padding: 1.5rem;
  margin: 2rem auto;
  max-width: 65ch;
  border-left: 4px solid var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-main);
}
.context-label {
  font-family: var(--font-sans);
  font-weight: 900;
  font-size: 0.75rem;
  color: var(--accent-red);
  letter-spacing: 0.1em;
  margin-bottom: 0.75rem;
  display: block;
  text-transform: uppercase;
}
.context-toggle {
    background: none;
    border: none;
    color: var(--accent-red);
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    padding: 0;
    margin-top: 0.5rem;
    text-decoration: underline;
}
.context-body.is-clamped {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Post Footer (The Big Index) */
.post-footer {
  margin-top: 5rem;
  padding-top: 3rem;
  border-top: 4px solid var(--bg-dark); /* Matches header style */
  width: 100%;
}

.forensic-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 2rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-meta);
}

.footer-section { margin-bottom: 2rem; }
.footer-section h4 {
  margin: 0 0 0.5rem 0;
  text-transform: uppercase;
  color: var(--text-main);
  font-size: 0.75rem;
  letter-spacing: 1px;
  font-family: var(--font-sans);
}
.meta-row code { background: var(--border-subtle); padding: 2px 4px; border-radius: 2px; }
.meta-row.hash { font-size: 0.75em; color: var(--text-muted); margin-top: 0.5rem; }

.forensic-link { 
  color: var(--accent-red); 
  font-weight: bold; 
  text-decoration: underline dotted;
  font-size: 0.8rem;
 }

/* Tiny Tags */
.tiny-tag {
  display: inline-block;
  background: var(--bg-paper);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  padding: 2px 8px;
  border-radius: 3px;
  text-decoration: none;
  font-size: 0.75rem;
  text-transform: uppercase;
  margin: 0 5px 5px 0;
}
.tiny-tag:hover { border-color: var(--accent-red); color: var(--accent-red); }

/* Aliases List */
.alias-list a {
  text-decoration: none;
  color: var(--text-meta);
  border-bottom: 1px dotted var(--text-muted);
}
.alias-list a:hover { color: var(--accent-red); border-bottom-style: solid; }

/* ==========================================================================
   6. COMMENTS & NAV
   ========================================================================== */

.comments-container {
    margin-top: 2.5rem;
    padding-top: 1rem;
    border-top: 2px solid var(--border-subtle);
    max-width: 65ch;
    margin-left: auto;
    margin-right: auto;
}

.comments-toggle {
    cursor: pointer;
    font-family: var(--font-sans);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.8rem;
    color: var(--text-meta);
    padding: 0.5rem 0;
    user-select: none;
}

.comments-list {
    margin-top: 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: 1.5rem;
}

.comment-block {
    margin-bottom: 1.5rem;
    border-bottom: 1px dashed var(--border-strong);
    padding-bottom: 1.5rem;
}
.comment-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.comment-meta {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--accent-red);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
}
.comment-date { color: var(--text-muted); margin-left: 5px; }
.comment-body p { margin-bottom: 0.5em; font-size: 0.95rem; line-height: 1.4; color: var(--text-main); }
/* Cleanup Markdown Ghosts */
.comment-block br { display: none; }
.comments-list > p { display: none; }

.comment-reply {
    margin-left: 2rem;
    border-left: 2px solid #eee;
    padding-left: 1rem;
    margin-top: 1rem;
}

/* Post Navigation */
.post-nav {
  max-width: 65ch;
  margin: 4rem auto;
  padding-top: 2rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  gap: 2rem;
}
.nav-item { width: 48%; display: flex; flex-direction: column; }
.nav-next { text-align: right; align-items: flex-end; }
.nav-label { font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.5rem; letter-spacing: 1px; }
.nav-item a { font-family: var(--font-serif); font-weight: bold; font-size: 1rem; line-height: 1.3; text-decoration: none; color: var(--text-main); }
.nav-item a:hover { color: var(--accent-red); text-decoration: underline; }

/* ==========================================================================
   7. RESPONSIVE & PRINT
   ========================================================================== */
@media (max-width: 768px) {
  main { padding: 1.5rem; }
  .ledger-item { grid-template-columns: 1fr; gap: 0.5rem; }
  .ledger-date { font-size: 0.85rem; color: var(--accent-red); margin-bottom: -5px; }
  .year-break { font-size: 2.5rem; margin-left: 0; }
  figure { margin: 2rem 0; }
  .post-full h1 { font-size: 2rem; }
}

@media print {
  .top-bar, .filter-controls, .post-footer, footer { display: none; }
  main { box-shadow: none; padding: 0; margin: 0; background: #fff; }
  body { background: #fff; color: #000; }
  .post-content { max-width: 100%; }
}

/* ==========================================================================
   8. FORENSIC SPECIFICS (Restored & Tokenized)
   ========================================================================== */

/* --- PDF & DOCUMENT CARDS --- */
.pdf-card {
  border-left-color: var(--text-main) !important; /* Matches text color (Black/White) */
}

.pdf-container {
  padding: 1rem;
  text-align: center;
}

.pdf-button {
  display: inline-block;
  background: var(--bg-paper);
  border: 2px solid var(--text-main);
  color: var(--text-main) !important;
  padding: 10px 20px;
  font-family: var(--font-sans);
  font-weight: bold;
  text-transform: uppercase;
  text-decoration: none;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.pdf-button:hover {
  background: var(--text-main);
  color: var(--bg-paper) !important; /* Inverts on hover */
  text-decoration: none;
}

/* --- VIDEO CARDS (16:9 Responsive) --- */
.video-card {
  border-left: 5px solid #000; /* Always black strip for video */
}

.video-container {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
  height: 0;
  overflow: hidden;
  background: #000;
  margin-top: 0.5rem;
}

.video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* --- DOMAIN GROUPS (Footer Indexing) --- */
.alias-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.domain-group { margin-bottom: 1.5rem; }

.domain-header {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--text-main);
  border-bottom: 2px solid var(--text-main);
  padding-bottom: 5px;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.path-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 85%;
  direction: rtl; /* Truncates the start of long URLs */
  text-align: left;
}

.wayback-arrow {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  padding: 0 5px;
  transition: transform 0.2s;
}

.wayback-arrow:hover {
  color: var(--accent-red);
  transform: translateX(3px) translateY(-3px);
}

/* Unsafe / Security Flags */
.unsafe-group .domain-header {
  border-color: #d32f2f;
  color: #d32f2f;
}