/* ============================================================
   CSS Custom Properties
   ============================================================ */
:root {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #656d76;
  --link: #0969da;
  --link-hover: #0550ae;
  --code-bg: #f6f8fa;
  --code-border: #d0d7de;
  --tag-bg: #ddf4ff;
  --tag-text: #0550ae;
  --tag-border: rgba(84, 174, 255, 0.4);
  --accent: #0969da;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
  --radius: 6px;
  --radius-lg: 10px;
  --max-width: 860px;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --link: #58a6ff;
    --link-hover: #79c0ff;
    --code-bg: #161b22;
    --code-border: #30363d;
    --tag-bg: #1c2d3f;
    --tag-text: #79c0ff;
    --tag-border: rgba(31, 111, 235, 0.5);
    --accent: #58a6ff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.2);
  }
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Typography
   ============================================================ */
h1, h2, h3, h4, h5, h6 {
  color: var(--text);
  font-weight: 600;
  line-height: 1.3;
  margin-top: 1.75em;
  margin-bottom: 0.5em;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }
h5, h6 { font-size: 1rem; }

p { margin-bottom: 1rem; }

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

ul, ol {
  padding-left: 2em;
  margin-bottom: 1rem;
}
li { margin-bottom: 0.25rem; }
li > ul, li > ol { margin-top: 0.25rem; margin-bottom: 0; }

blockquote {
  border-left: 4px solid var(--border);
  padding: 0.5rem 1rem;
  color: var(--text-muted);
  margin: 1.5rem 0;
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
}
blockquote p { margin-bottom: 0; }

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

img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  display: block;
  margin: 1.5rem auto;
}

strong { font-weight: 600; }

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5rem 0;
  font-size: 0.9rem;
}
th, td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
th {
  background: var(--surface);
  font-weight: 600;
}
tr:nth-child(even) td {
  background: var(--surface);
}

/* ============================================================
   Code
   ============================================================ */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 3px;
  padding: 0.15em 0.4em;
  color: var(--text);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1.5rem 0;
  position: relative;
}

pre code {
  display: block;
  padding: 1.25rem 1.5rem;
  background: none;
  border: none;
  border-radius: 0;
  font-size: 0.875rem;
  line-height: 1.6;
  color: inherit;
  overflow-x: auto;
  tab-size: 2;
}

/* Language label on code blocks */
pre[data-lang]::before {
  content: attr(data-lang);
  display: block;
  background: var(--surface);
  border-bottom: 1px solid var(--code-border);
  padding: 0.35rem 1.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius) var(--radius) 0 0;
}

/* Highlight.js theme override — One Dark-inspired */
.hljs { background: transparent; padding: 0; }

/* ============================================================
   Mermaid diagrams
   ============================================================ */
.mermaid {
  display: flex;
  justify-content: center;
  margin: 1.5rem 0;
  overflow-x: auto;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* ============================================================
   Layout
   ============================================================ */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.site-main {
  flex: 1;
  padding: 2.5rem 0;
}

/* ============================================================
   Header / Navigation
   ============================================================ */
.site-header {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

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

.site-logo {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
}

.site-logo:hover { text-decoration: none; }

.logo-mark {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

.site-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-link {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface);
  text-decoration: none;
}

.nav-link.active {
  color: var(--accent);
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  color: var(--text);
}

@media (max-width: 600px) {
  .nav-toggle { display: flex; align-items: center; }
  .site-nav {
    display: none;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 0.75rem;
    gap: 0.25rem;
  }
  .site-nav.open { display: flex; }
  .nav-link { width: 100%; }
}

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.footer-copy {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.footer-social {
  display: flex;
  gap: 0.75rem;
}

.footer-social a {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-decoration: none;
  transition: color 0.15s;
}
.footer-social a:hover { color: var(--accent); text-decoration: none; }

/* ============================================================
   Post Card (blog listing)
   ============================================================ */
.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.post-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: box-shadow 0.15s, border-color 0.15s;
  background: var(--bg);
}

.post-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

.post-card-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.post-card-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  line-height: 1.4;
}

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

.post-card-excerpt {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 0.75rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-card-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ============================================================
   Tags & Categories
   ============================================================ */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--tag-border);
  border-radius: 2em;
  padding: 0.15em 0.65em;
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.tag:hover { opacity: 0.85; text-decoration: none; color: var(--tag-text); }

.category {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 2em;
  padding: 0.15em 0.65em;
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.category:hover { background: var(--border); color: var(--text); text-decoration: none; }

/* ============================================================
   Post Page
   ============================================================ */
.post-header {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.post-header .post-title {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 0.75rem;
  margin-bottom: 1rem;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.post-meta-sep { color: var(--border); }

.post-content {
  max-width: 100%;
}

.post-content h1:first-child,
.post-content h2:first-child,
.post-content h3:first-child { margin-top: 0; }

.post-tags {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.post-tags-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.post-tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.post-share {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.post-share-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.post-share-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border-radius: 2rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.825rem;
  font-weight: 500;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  line-height: 1;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.share-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--tag-bg);
  text-decoration: none;
}

.share-btn-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.post-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.post-nav-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.post-nav-item:hover { border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.post-nav-item:nth-child(2) { text-align: right; }

.post-nav-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-bottom: 0.25rem;
}

.post-nav-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
}

/* ============================================================
   Page layout
   ============================================================ */
.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
}

/* ============================================================
   Home page
   ============================================================ */
.home-hero {
  padding: 3rem 0 2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

.home-hero h1 {
  font-size: 2.25rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  border: none;
  padding: 0;
}

.home-hero p {
  color: var(--text-muted);
  font-size: 1.1rem;
  max-width: 600px;
  margin: 0;
}

.section-heading {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1.5rem;
}

/* ============================================================
   Pagination
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.pagination a,
.pagination span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.pagination a:hover { background: var(--surface); border-color: var(--accent); text-decoration: none; }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination .disabled { opacity: 0.4; pointer-events: none; }

/* ============================================================
   Categories page
   ============================================================ */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.category-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  background: var(--bg);
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.category-card:hover { box-shadow: var(--shadow); border-color: var(--accent); text-decoration: none; }

.category-card-name { font-weight: 600; color: var(--text); }
.category-card-count {
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 2em;
  padding: 0.1em 0.6em;
  font-size: 0.8rem;
}

/* ============================================================
   Apps page
   ============================================================ */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.app-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  background: var(--bg);
  text-decoration: none;
  display: block;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.app-card:hover { box-shadow: var(--shadow-md); border-color: var(--accent); text-decoration: none; }

.app-card-icon {
  width: 48px;
  height: 48px;
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.app-card-title { font-size: 1.1rem; font-weight: 600; color: var(--text); margin: 0 0 0.5rem; }
.app-card-desc { font-size: 0.9rem; color: var(--text-muted); margin: 0; }

/* ============================================================
   Tool page (embedded tool)
   ============================================================ */
.tool-area {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 1.5rem 0;
}

.tool-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin: 1.5rem 0;
}
.tool-zone:hover, .tool-zone.dragover {
  border-color: var(--accent);
  background: var(--surface);
}

.tool-output {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  word-break: break-all;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.9; text-decoration: none; color: #fff; }
.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-outline:hover { background: var(--tag-bg); color: var(--accent); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 700px) {
  h1, .post-header .post-title { font-size: 1.625rem; }
  h2 { font-size: 1.25rem; }

  .home-hero h1 { font-size: 1.75rem; }
  .home-hero p { font-size: 1rem; }

  .post-nav { grid-template-columns: 1fr; }
  .post-nav-item:nth-child(2) { text-align: left; }
}

@media (max-width: 480px) {
  .container { padding: 0 1rem; }
  pre code { font-size: 0.8rem; padding: 1rem; }
}

/* ============================================================
   AdSense
   ============================================================ */
.ad-unit {
  margin: 2rem 0;
  text-align: center;
}

/* ============================================================
   Reading progress bar
   ============================================================ */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: var(--accent);
  z-index: 200;
  transition: width 0.1s linear;
}
