/* ============================================
   DCInside Gallery Viewer - Engineered Aesthetic
   Strict adherence to Vercel/Linear Design Guidelines
   High-performance, accessible, developer-focused.
   ============================================ */

/* Import Inter and JetBrains Mono */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  /* ==========================================
     Design Tokens
     ========================================== */
  
  /* Color System - Monochrome / Geist-like */
  --bg-background: #ffffff;
  --bg-accents-1: #fafafa;
  --bg-accents-2: #eaeaea;
  --bg-accents-3: #999999;
  --bg-accents-4: #888888;
  --bg-accents-5: #666666;
  --bg-accents-6: #444444;
  --bg-accents-7: #333333;
  --bg-accents-8: #111111;
  
  --fg-text-primary: #000000;
  --fg-text-secondary: #666666;
  --fg-text-tertiary: #888888;

  --border-primary: #eaeaea;
  --border-focus: #000000;
  
  --color-success: #0070f3; /* Vercel Blue - used sparingly */
  --color-error: #e00;
  --color-warning: #f5a623;
  
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  
  /* Spacing */
  --space-unit: 4px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  
  /* Radii */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  
  /* Shadows */
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.08); /* Sophisticated subtle shadow */
  --shadow-active: 0 2px 4px rgba(0, 0, 0, 0.05);
  
  /* Layout */
  --max-width: 720px; /* Balanced width */
  --header-height: 64px;
}

/* Dark Mode Theme */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-background: #000000;
    --bg-accents-1: #111111;
    --bg-accents-2: #333333;
    --bg-accents-3: #444444;
    --bg-accents-4: #666666;
    --bg-accents-5: #888888;
    --bg-accents-6: #999999;
    --bg-accents-7: #eaeaea;
    --bg-accents-8: #fafafa;
    
    --fg-text-primary: #ffffff;
    --fg-text-secondary: #888888;
    --fg-text-tertiary: #666666;

    --border-primary: #333333;
    --border-focus: #ffffff;
    
    --color-success: #3291ff;
  }
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  /* Guidelines: intentionally set touch highlight */
  -webkit-tap-highlight-color: transparent;
}

html {
  /* Guidelines: color-scheme for correct scrollbars */
  color-scheme: light dark;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-background);
  color: var(--fg-text-primary);
  font-size: 16px; /* 16px base as standard */
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Guidelines: touch manipulation */
  touch-action: manipulation;
  overflow-x: hidden;
}

img {
  /* Guidelines: prevent CLS with explicit sizing or block display */
  display: block;
  max-width: 100%;
  height: auto;
}

button {
  all: unset; /* Complete reset for strict control */
}

/* ============================================
   Focus States (Guideline: Mandatory Visible Focus)
   ============================================ */
*:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================
   Layout
   ============================================ */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-8) var(--space-5);
  min-height: 100vh;
  overflow: hidden;
}

/* ============================================
   Header
   ============================================ */
header {
  margin-bottom: var(--space-12);
  /* Pure layout, no decorative borders in header for this clean style */
}

h1 {
  font-family: var(--font-sans);
  font-size: 2.5rem; /* Large, bold */
  font-weight: 800;
  letter-spacing: -0.04em; /* Tight tracking for "Geist" look */
  line-height: 1.1;
  color: var(--fg-text-primary);
  text-wrap: balance; /* Guidelines: balance text */
}

.subtitle {
  margin-top: var(--space-2);
  font-size: 1.125rem;
  color: var(--fg-text-secondary);
  font-weight: 500;
  letter-spacing: -0.02em;
}

.controls {
  margin-top: var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-primary);
}

.control-group {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.control-group label {
  font-size: 0.875rem;
  color: var(--fg-text-tertiary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-mono); /* Technical look */
}

/* ============================================
   Input & Interaction
   ============================================ */
select {
  appearance: none;
  background-color: var(--bg-background);
  color: var(--fg-text-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-8) var(--space-2) var(--space-3);
  font-size: 0.875rem;
  font-family: var(--font-mono);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23666666' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

select:hover {
  border-color: var(--fg-text-tertiary);
  background-color: var(--bg-accents-1);
}

.button-group {
  display: flex;
  gap: var(--space-3);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--space-4);
  height: 36px;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-sans);
  border: 1px solid transparent; /* Prepare for border */
}

#load-btn {
  background-color: var(--fg-text-primary); /* Solid black/white */
  color: var(--bg-background); /* Inverted */
  border: 1px solid var(--fg-text-primary);
}

#load-btn:hover:not(:disabled) {
  background-color: transparent;
  color: var(--fg-text-primary);
}

#refresh-btn {
  background-color: transparent;
  color: var(--fg-text-secondary);
  border: 1px solid var(--border-primary);
}

#refresh-btn:hover:not(:disabled) {
  border-color: var(--fg-text-primary);
  color: var(--fg-text-primary);
}

button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ============================================
   Cache Status
   ============================================ */
.cache-status {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--fg-text-tertiary);
}

.cache-status span.cache-hit,
.cache-status span.cache-fresh {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
}

.cache-hit {
  background-color: var(--bg-accents-2);
  color: var(--fg-text-secondary);
}

.cache-fresh {
  background-color: var(--color-success); /* Vercel Blue */
  color: white;
}

@media (prefers-color-scheme: dark) {
  .cache-fresh {
    color: white; /* Ensure text is visible on blue */
  }
}

/* ============================================
   Posts Grid
   ============================================ */
.posts-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  padding-bottom: var(--space-12);
  max-width: 100%;
  overflow: hidden;
}

.loading, .error {
  text-align: center;
  padding: var(--space-12);
  font-family: var(--font-mono);
  color: var(--fg-text-secondary);
  /* Flex 정렬 - JS에서 display: flex로 설정됨 */
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--bg-accents-2);
  border-top-color: var(--fg-text-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto var(--space-4);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================
   Post Card - Minimalist
   ============================================ */
.post-card {
  position: relative;
  border: none;
  border-bottom: 1px solid var(--border-primary);
  border-radius: 0;
  padding: var(--space-6) 0;
  background: var(--bg-background);
  max-width: 100%;
  overflow: hidden;
}

/* Rank Badge - Tabular Nums */
/* Rank Badge - Top Left (Classic) */
.rank {
  position: absolute;
  top: 24px;
  left: 0;
  right: auto;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  font-weight: 700;
  color: var(--fg-text-tertiary);
  width: auto;
  text-align: left;
  opacity: 0.3;
}

.post-card:nth-child(-n+3) .rank {
  color: var(--fg-text-primary);
  opacity: 1;
}

/* Card Layout */
.post-header {
  margin-left: 0;
  padding-left: 32px; /* Space for rank */
  padding-right: 0;
}

.post-title {
  display: block;
  font-size: 1.125rem; /* ~18px */
  font-weight: 600;
  color: var(--fg-text-primary);
  text-decoration: none;
  line-height: 1.5;
  margin-bottom: var(--space-2);
  letter-spacing: -0.015em;
  transition: color 0.15s ease;
}

.post-title:hover {
  color: var(--color-success); /* Hover state visual feedback */
}

.post-meta {
  display: flex;
  gap: var(--space-4);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--fg-text-tertiary);
  margin-bottom: var(--space-4);
}

.post-meta .author {
  color: var(--fg-text-secondary);
  font-weight: 500;
}

/* Stats */
.post-stats {
  display: flex;
  gap: var(--space-3);
  margin-left: 0;
  margin-bottom: var(--space-4);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  color: var(--fg-text-secondary);
}

.post-stats span {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  background: var(--bg-accents-1);
  border-radius: 4px;
  border: 1px solid transparent;
}

.recommends {
  color: var(--color-error); /* Keep error color for emphasis on recommends only */
  background: rgba(255, 0, 0, 0.05) !important;
}

/* Images & Content */
.post-content-html {
  margin-top: var(--space-4);
  margin-left: 0;
  font-size: 1rem;
  color: var(--fg-text-secondary);
  line-height: 1.7; /* Relaxed reading */
  max-width: 100%;
  overflow: hidden;
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Normalize injected DCInside wrapper width */
.post-content-html .write_div,
.post-content-html * {
  width: auto !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* Guidelines: Explicit constraints on images */
.post-content-html img,
.post-images img {
  display: block !important;
  float: none !important;
  width: auto !important;
  max-width: 100% !important;
  height: auto !important;
  margin: var(--space-3) 0 !important;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  background-color: var(--bg-accents-2);
}

/* 방어적 CSS: src 없는 이미지 숨김 (추가 안전장치) */
.post-content-html img:not([src]),
.post-content-html img[src=""],
.post-content-html img[src^="data:image/gif;base64,R0lGOD"] {
  display: none !important;
}

.read-more {
  display: inline-block;
  margin-left: 0;
  margin-top: var(--space-4);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--fg-text-secondary);
  text-decoration: none;
  transition: color 0.15s ease;
}

.read-more:hover {
  color: var(--fg-text-primary);
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Comments */
.comments-section {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  margin-left: 0; /* Aligned with content */
  border-top: 1px solid var(--border-primary);
}

.comments-header {
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--fg-text-secondary);
  transition: color 0.15s ease;
}

.comments-header:hover {
  color: var(--fg-text-primary);
}

.comments-list {
  margin-top: var(--space-3);
}

.comment {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-primary);
  font-size: 0.875rem;
}
.comment:last-child { border-bottom: none; }

.comment-name {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--fg-text-primary);
}

.comment-date {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--fg-text-tertiary);
  margin-left: var(--space-2);
}

.comment-content {
  margin-top: var(--space-1);
  color: var(--fg-text-secondary);
  line-height: 1.5;
}

/* Guidelines: Responsive Typography and Layout */
@media (max-width: 600px) {
  :root {
    --header-height: auto;
  }
  
  .container {
    padding: var(--space-5) var(--space-4);
  }
  
  h1 { font-size: 2rem; }
  
  .post-header, .post-content-html, .post-stats, .comments-section, .read-more {
    margin-left: 0;
  }
  
  .rank {
    position: relative;
    top: 0;
    left: 0;
    display: inline-block;
    width: auto;
    margin-bottom: var(--space-2);
    text-align: left;
    background: var(--bg-accents-2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    opacity: 1;
    color: var(--fg-text-primary);
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-4);
  }
  
  .control-group {
    justify-content: space-between;
  }
  
  select, button {
    width: 100%;
  }
  
  .button-group {
    width: 100%;
  }
}
