/* ==============================
   CSS Custom Properties
   ============================== */

:root {
  --color-bg: #ffffff;
  --color-surface: #f9fafb;
  --color-text: #1a1a1a;
  --color-text-secondary: #555555;
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-code-bg: #f3f4f6;
  --color-code-text: #1a1a1a;
  --color-border: #e5e7eb;
  --color-tag-bg: #eff6ff;
  --color-tag-text: #2563eb;
  --color-blockquote-bg: #f9fafb;
  --color-blockquote-border: #2563eb;
  --content-width: 680px;
}

[data-theme="dark"] {
  --color-bg: #18181b;
  --color-surface: #27272a;
  --color-text: #e4e4e7;
  --color-text-secondary: #a1a1aa;
  --color-accent: #60a5fa;
  --color-accent-hover: #93bbfd;
  --color-code-bg: #27272a;
  --color-code-text: #e4e4e7;
  --color-border: #3f3f46;
  --color-tag-bg: #1e3a5f;
  --color-tag-text: #93c5fd;
  --color-blockquote-bg: #27272a;
  --color-blockquote-border: #60a5fa;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg: #18181b;
    --color-surface: #27272a;
    --color-text: #e4e4e7;
    --color-text-secondary: #a1a1aa;
    --color-accent: #60a5fa;
    --color-accent-hover: #93bbfd;
    --color-code-bg: #27272a;
    --color-code-text: #e4e4e7;
    --color-border: #3f3f46;
    --color-tag-bg: #1e3a5f;
    --color-tag-text: #93c5fd;
    --color-blockquote-bg: #27272a;
    --color-blockquote-border: #60a5fa;
  }
}

/* ==============================
   Reset & Base
   ============================== */

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--color-text);
  background-color: var(--color-bg);
  transition: background-color 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  color: var(--color-accent-hover);
  text-decoration: underline;
}

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

/* ==============================
   Layout
   ============================== */

.container {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ==============================
   Header
   ============================== */

.site-header {
  border-bottom: 1px solid var(--color-border);
  padding: 1.25rem 0;
  transition: border-color 0.3s;
}

.site-intro {
  padding: 1.5rem 0 1.75rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2rem;
  transition: border-color 0.3s;
}

.site-intro p {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--color-text-secondary);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-title a {
  color: var(--color-text);
  text-decoration: none;
}

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

.theme-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  cursor: pointer;
  padding: 0.4rem 0.5rem;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--color-text);
  transition: background-color 0.2s, border-color 0.2s;
}

.theme-toggle:hover {
  background-color: var(--color-surface);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.visually-hidden:focus {
  position: fixed;
  top: 0;
  left: 0;
  width: auto;
  height: auto;
  padding: 0.75rem 1.5rem;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: var(--color-accent);
  color: #fff;
  z-index: 9999;
  font-size: 1rem;
}

/* ==============================
   Post Grid (index.html)
   ============================== */

.container-wide {
  max-width: 960px;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.list-header .section-title {
  margin: 0;
  padding: 0;
  border: none;
}

.view-toggle {
  display: flex;
  gap: 0.35rem;
}

.view-btn {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.4rem;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: color 0.2s, border-color 0.2s, background-color 0.2s;
  display: flex;
  align-items: center;
}

.view-btn:hover {
  color: var(--color-text);
  background-color: var(--color-surface);
}

.view-btn.active {
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.view-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.post-grid {
  display: grid;
  gap: 1.25rem;
}

.post-grid.view-list {
  grid-template-columns: repeat(2, 1fr);
}

.post-grid.view-grid {
  grid-template-columns: repeat(3, 1fr);
}

.post-card {
  display: block;
  border-radius: 12px;
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.post-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
  border-color: var(--color-accent);
  text-decoration: none;
}

.post-card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
}

.post-card-no-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--color-border);
}

.post-card-body {
  padding: 0.85rem 1rem 1rem;
}

.post-card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.45;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.view-list .post-card-summary {
  display: none;
}

.post-card-summary {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin: 2rem 0;
}

.page-btn {
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-btn:hover:not(:disabled) {
  background: var(--color-surface);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.page-btn.active {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.page-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.page-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Tags (used on post pages) */
.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
  padding: 0;
  list-style: none;
}

.tag {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
  background-color: var(--color-tag-bg);
  color: var(--color-tag-text);
  transition: background-color 0.3s, color 0.3s;
}

/* ==============================
   Post Content (post.html)
   ============================== */

.post-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.post-title {
  margin: 0 0 0.5rem;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.post-meta {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.75rem;
}

.back-link {
  display: inline-block;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
}

.back-link:hover {
  color: var(--color-accent);
}

.post-thumbnail {
  width: 100%;
  max-height: 400px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 2rem;
}

.post-content h1 { font-size: 1.75rem; margin: 2rem 0 1rem; font-weight: 700; letter-spacing: -0.02em; }
.post-content h2 { font-size: 1.45rem; margin: 1.75rem 0 0.75rem; font-weight: 700; letter-spacing: -0.01em; }
.post-content h3 { font-size: 1.2rem; margin: 1.5rem 0 0.5rem; font-weight: 600; }
.post-content h4 { font-size: 1.05rem; margin: 1.25rem 0 0.5rem; font-weight: 600; }

.post-content p {
  margin: 0 0 1.25rem;
}

.post-content ul,
.post-content ol {
  margin: 0 0 1.25rem;
  padding-left: 1.5rem;
}

.post-content li {
  margin-bottom: 0.35rem;
}

.post-content blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  border-left: 3px solid var(--color-blockquote-border);
  background-color: var(--color-blockquote-bg);
  border-radius: 0 8px 8px 0;
  color: var(--color-text-secondary);
  transition: background-color 0.3s, border-color 0.3s;
}

.post-content blockquote p:last-child {
  margin-bottom: 0;
}

.post-content code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.875em;
  padding: 0.15em 0.4em;
  background-color: var(--color-code-bg);
  color: var(--color-code-text);
  border-radius: 4px;
  transition: background-color 0.3s;
}

.post-content pre {
  margin: 1.5rem 0;
  padding: 1.25rem;
  background-color: var(--color-code-bg);
  border-radius: 8px;
  overflow-x: auto;
  transition: background-color 0.3s;
}

.post-content pre code {
  padding: 0;
  background: none;
  font-size: 0.85rem;
  line-height: 1.6;
}

.post-content hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2rem 0;
}

.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  overflow-x: auto;
  display: block;
}

.post-content th,
.post-content td {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  text-align: left;
}

.post-content th {
  background-color: var(--color-surface);
  font-weight: 600;
}

.post-content img {
  border-radius: 8px;
  margin: 1rem 0;
}

.post-content a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ==============================
   Footer
   ============================== */

.site-footer {
  margin-top: 3rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--color-border);
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

.site-footer p {
  margin: 0.5rem 0 0;
}

.footer-nav {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
}

.footer-nav a {
  color: var(--color-text-secondary);
  font-size: 0.85rem;
}

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

/* ==============================
   Section Titles
   ============================== */

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text-secondary);
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

/* ==============================
   Web App Cards
   ============================== */

.web-apps {
  margin-bottom: 2.5rem;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.app-card {
  display: block;
  padding: 1.25rem;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.app-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: var(--color-accent);
  text-decoration: none;
}

.app-card-emoji {
  display: block;
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.app-card-title {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
}

.app-card-desc {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--color-text-secondary);
}

/* ==============================
   Ad Container
   ============================== */

.ad-container {
  text-align: center;
}

.ad-container ins.adsbygoogle[data-ad-status="filled"] {
  margin: 1.5rem 0;
}

.ad-container ins.adsbygoogle:not([data-ad-status="filled"]) {
  height: 0 !important;
  overflow: hidden;
}

/* ==============================
   Static Pages
   ============================== */

.static-page {
  padding: 2rem 0;
}

/* ==============================
   States
   ============================== */

.loading {
  text-align: center;
  padding: 3rem 0;
  color: var(--color-text-secondary);
}

.error-message {
  text-align: center;
  padding: 3rem 0;
}

.error-message h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.error-message p {
  color: var(--color-text-secondary);
}

/* ==============================
   Responsive
   ============================== */

@media (max-width: 767px) {
  .post-grid.view-list {
    grid-template-columns: 1fr;
  }

  .post-grid.view-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .container-wide {
    max-width: var(--content-width);
  }
}

@media (max-width: 480px) {
  .post-grid.view-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 768px) {
  body {
    font-size: 18px;
  }

  .container {
    padding: 0 2rem;
  }

  .site-header {
    padding: 1.5rem 0;
    margin-bottom: 2.5rem;
  }

  .post-title {
    font-size: 2.5rem;
  }
}

/* ==============================
   Accessibility
   ============================== */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==============================
   Print
   ============================== */

@media print {
  .theme-toggle,
  .site-footer {
    display: none;
  }

  body {
    color: #000;
    background: #fff;
  }

  a {
    color: #000;
    text-decoration: underline;
  }
}
