/* ============================================================
   Custom Properties
   ============================================================ */
:root {
  --color-text:       #111;
  --color-muted:      #666;
  --color-border:     #eee;
  --color-accent:     #3364ff;
  --color-surface:    #f8f9fa;
  --color-code-bg:    #f4f4f4;
  --color-code-dark:  #1e1e1e;
  --color-code-text:  #d4d4d4;

  --font-sans:  -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono:  "SF Mono", Menlo, Monaco, "Courier New", monospace;

  --radius-sm:  3px;
  --radius-md:  4px;
  --radius-lg:  6px;
  --radius-xl:  8px;

  --layout-max: 45rem;
  --layout-px:  1.5rem;
}

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

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

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-text);
}

/* ============================================================
   Layout Shell
   ============================================================ */
header, main, footer {
  max-width: var(--layout-max);
  margin: 0 auto;
  padding: 0 var(--layout-px);
}

main {
  min-height: calc(100vh - 10rem);
  padding-block: 2rem 4rem;
}

/* ============================================================
   Header & Navigation
   ============================================================ */
header {
  padding-block: 2rem 1rem;
  border-bottom: 1px solid var(--color-border);

  & nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
  }

  & .site-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;

    &:hover { color: var(--color-accent); }
  }

  & .nav-links {
    display: flex;
    gap: 1.5rem;

    & a {
      color: var(--color-text);
      text-decoration: none;
      font-size: 0.95rem;

      &:hover, &.active {
        color: var(--color-accent);
        text-decoration: underline;
      }
    }
  }
}

/* ============================================================
   Footer
   ============================================================ */
footer {
  padding: 2rem var(--layout-px);
  border-top: 1px solid var(--color-border);
  text-align: center;
  color: var(--color-muted);
  font-size: 0.875rem;
}

.main-header, .main-footer {
  background: linear-gradient(90deg, #e3ffe7 0%, #d9e7ff 100%);
}

/* ============================================================
   Typography
   ============================================================ */
h1, h2, h3, h4, h5, h6 {
  margin: 2rem 0 1rem;
  line-height: 1.3;
  font-weight: 700;
  color: var(--color-text);
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem;  }
h3 { font-size: 1.2rem;  }
h4 { font-size: 1.1rem;  }

p { margin: 0 0 1.5rem; }

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

  &:hover { text-decoration: underline; }
}

/* ============================================================
   Post List
   ============================================================ */
.post-list {
  list-style: none;
  padding: 0;
  margin: 2rem 0;

  & li {
    position: relative;
    padding-left: 2.5rem;
    margin-bottom: 1.5rem;
  }

  & a {
    display: block;
    font-weight: 600;
    color: var(--color-text);
    font-size: 1.1rem;
    margin-bottom: 0.25rem;

    &:hover { color: var(--color-accent); }
  }

  & time {
    display: block;
    color: var(--color-muted);
    font-size: 0.8125rem;
  }
}

/* ============================================================
   Post Labels & Meta
   ============================================================ */
.category-label {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-weight: 600;
  margin-right: 0.5rem;
}

.post-meta {
  display: flex;
  align-items: center;
  margin-top: 0.25rem;

  & time {
    display: inline;
    color: var(--color-muted);
    font-size: 0.8125rem;
  }
}

/* ============================================================
   Single Post
   ============================================================ */
.post-header {
  margin-bottom: 2.5rem;
  text-align: center;

  & h1 { margin-bottom: 0.5rem; }

  & time {
    color: var(--color-muted);
    font-size: 0.875rem;
  }

  & .tags {
    margin-top: 0.75rem;

    & a {
      display: inline-block;
      margin-right: 0.5rem;
      font-size: 0.8125rem;
      color: var(--color-muted);

      &:hover { color: var(--color-accent); }
    }
  }
}

/* ============================================================
   Post Content
   ============================================================ */
.post-content {
  line-height: 1.5;

  & h2 { margin-top: 2.5rem; }
  & h3 { margin-top: 2rem; }

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

  & ul, & ol {
    margin: 0 0 1.5rem;
    padding-left: 1.5rem;
  }

  & li { margin-bottom: 0.5rem; }

  & blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.5rem;
    border-left: 3px solid var(--color-accent);
    background: var(--color-surface);
    color: #444;
    font-style: italic;

    & p { margin: 0; }
    & p + p { margin-top: 1rem; }
  }

  & code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--color-code-bg);
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-sm);
  }

  & pre {
    position: relative;
    margin: 1.5rem 0;
    padding: 1rem 1.25rem;
    background: var(--color-code-dark);
    border-radius: var(--radius-lg);
    overflow-x: auto;

    & code {
      background: none;
      padding: 0;
      color: var(--color-code-text);
      font-size: 0.875rem;
      line-height: 1.5;
      white-space: pre-wrap;
      word-wrap: break-word;
    }
  }

  & .highlight {
    position: relative;
    margin: 1.5rem 0;

    & pre { margin: 0; }
  }

  & table {
    width: 100%;
    margin: 1.5rem 0;
    border-collapse: collapse;
  }

  & th, & td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
  }

  & th {
    font-weight: 600;
    border-bottom: 2px solid #ddd;
  }

  & dl { margin: 1.5rem 0; }

  & dt {
    font-weight: 700;
    margin-top: 1.25rem;

    &::before {
      content: "▸";
      margin-right: 0.5rem;
      color: var(--color-accent);
    }

    &:first-child { margin-top: 0; }
  }

  & dd {
    margin: 0.5rem 0 1rem 0;
    padding-left: 1.5rem;
    line-height: 1;

    &::before {
      content: "▪";
      margin-right: 0.5rem;
      color: #888;
      font-size: 0.5rem;
      vertical-align: middle;
    }

    & + dt { margin-top: 1.25rem; }
  }

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

/* ============================================================
   Code Copy Button
   ============================================================ */
.code-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.25rem 0.5rem;
  background: yellow;
  color: black;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;

  &:hover { background: yellow; color: black; }
  &.copied { background: cyan; color: black; }
}

.post-content pre:hover .code-copy-btn,
.post-content .highlight:hover .code-copy-btn {
  opacity: 1;
}

/* ============================================================
   Post Navigation
   ============================================================ */
.post-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.9rem;

  & a {
    color: var(--color-muted);
    &:hover { color: var(--color-accent); }
  }

  & .next { margin-left: auto; }
}

/* ============================================================
   Home Page
   ============================================================ */
.home {
  & h1:first-child { margin-top: 0; }
}

.home-sections {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 2rem;

  & section {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    border: 1px solid var(--color-border);

    & h2 {
      font-size: 1.1rem;
      margin: 0 0 1rem 0;
      padding-bottom: 0.75rem;
      border-bottom: 2px solid var(--color-accent);
      color: #333;
    }
  }

  & .post-list {
    margin: 0;

    & li { padding-left: 0; margin-bottom: 1rem; }
    & a  { font-size: 1rem; }
  }

  & .view-all {
    margin: 1rem 0 0 0;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.875rem;
  }
}

.recent-posts h2 {
  font-size: 1.25rem;
  margin-top: 3rem;
}

/* ============================================================
   Legend
   ============================================================ */
.legend {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.legend-label {
  margin-right: 1.5rem;
  font-size: 0.875rem;
  color: var(--color-muted);
}

/* ============================================================
   All Posts / List Pages
   ============================================================ */
.all-posts .post-list {
  & li { padding-left: 0; }
  & a  { display: inline-block; }
}

.list-page h1 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.comment-via-email { text-align: center; }

/* ============================================================
   Email Popup
   ============================================================ */
.email-popup-wrap {
  position: relative;
  display: inline-block;
  text-align: center;
  width: 100%;
  margin: 2rem 0;
}

.email-icon-btn {
  background-color: #432DD7;
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}

.email-popup {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 0.5rem;
  background: white;
  border: 1px solid #ddd;
  border-radius: var(--radius-xl);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 0.75rem;
  z-index: 100;
  min-width: 200px;

  &.open { display: block; }

  & a, & button {
    display: block;
    width: 100%;
    padding: 0.6rem 1rem;
    border: none;
    background: none;
    text-align: center;
    cursor: pointer;
    font-size: 0.9rem;
    color: #333;
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: background 0.2s;

    &:hover { background: #f0f0f0; }
  }

  & a + a, & a + button,
  & button + a, & button + button {
    margin-top: 0.25rem;
  }
}

.email-popup-wrap.open .email-popup { display: block; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 600px) {
  html { font-size: 15px; }

  header, main, footer {
    padding: 0 0.75rem;
    max-width: 100%;
  }

  main { padding-top: 1.5rem; }

  nav {
    flex-direction: column;
    align-items: flex-start;
  }

  header .nav-links { gap: 1rem; }

  .post-list li { padding-left: 2rem; }

  .home-sections {
    grid-template-columns: 1fr;
    gap: 1.5rem;

    & .post-list li { padding-left: 0; }
  }

  .post-content {
    & input, & textarea, & select {
      width: 100%;
      padding: 0.5rem;
      background: #fff;
      border: 1px solid #ccc;
      border-radius: var(--radius-md);
      font-size: 1rem;
      font-family: inherit;
    }

    & form { max-width: 100%; }
  }
}
