// ==========================================================================
// Zorto Dark Theme
// ==========================================================================

// --------------------------------------------------------------------------
// 1. Google Fonts
// --------------------------------------------------------------------------
@import url("https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300..900;1,300..900&family=Space+Grotesk:wght@400;500;600;700&display=swap");

// --------------------------------------------------------------------------
// 2. CSS Variables
// --------------------------------------------------------------------------
:root {
  --accent: #60a5fa;
  --accent-alpha-70: rgba(96, 165, 250, .7);
  --accent-alpha-20: rgba(96, 165, 250, .2);
  --accent-secondary: #22d3ee;
  --accent-secondary-alpha-20: rgba(34, 211, 238, .2);
  --background: #0f172a;
  --background-raised: #1e293b;
  --color: #e2e8f0;
  --color-muted: rgba(226, 232, 240, .6);
  --border-color: rgba(96, 165, 250, .15);
  --code-bg: rgba(0, 0, 0, 0.3);
  --max-width: 1200px;
}

[data-theme="light"] {
  --accent: #2563eb;
  --accent-alpha-70: rgba(37, 99, 235, .7);
  --accent-alpha-20: rgba(37, 99, 235, .2);
  --accent-secondary: #0891b2;
  --accent-secondary-alpha-20: rgba(8, 145, 178, .2);
  --background: #ffffff;
  --background-raised: #f8fafc;
  --color: #1e293b;
  --color-muted: rgba(30, 41, 59, .6);
  --border-color: #e2e8f0;
  --code-bg: #f1f5f9;
}

// --------------------------------------------------------------------------
// 3. Breakpoints
// --------------------------------------------------------------------------
$phone-max-width: 683px;
$tablet-max-width: 899px;
$nav-collapse-width: 600px;

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}
section[id] { scroll-margin-top: 80px; }

body {
  font-family: "Public Sans", system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--color);
  background-color: var(--background);
  transition: background-color 0.2s ease, color 0.2s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

// --------------------------------------------------------------------------
// 5. Typography
// --------------------------------------------------------------------------
h1, h2, h3, h4, h5, h6 {
  font-family: "Space Grotesk", "Public Sans", sans-serif;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.75rem;
  color: var(--color);
}

h1 { font-size: 2.25rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.375rem; }
h4 { font-size: 1.125rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

@media (max-width: $phone-max-width) {
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.375rem; }
  h3 { font-size: 1.125rem; }
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;

  &:hover {
    color: var(--accent-alpha-70);
    text-decoration: underline;
  }
}

p {
  margin-bottom: 1rem;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

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

// --------------------------------------------------------------------------
// 6. Code Blocks
// --------------------------------------------------------------------------
code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.2em 0.4em;
  border-radius: 4px;
}

pre {
  background: var(--code-bg);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-color);

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

.code-block-wrapper {
  position: relative;
  margin-bottom: 1.5rem;

  pre {
    margin-bottom: 0;
  }
}

.copy-button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--background-raised);
  border: 1px solid var(--border-color);
  color: var(--color-muted);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;

  .code-block-wrapper:hover & {
    opacity: 1;
  }

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

// --------------------------------------------------------------------------
// 7. Blockquotes
// --------------------------------------------------------------------------
blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1.25rem;
  margin: 1.5rem 0;
  background: var(--background-raised);
  border-radius: 0 6px 6px 0;
  color: var(--color-muted);

  p:last-child {
    margin-bottom: 0;
  }
}

// --------------------------------------------------------------------------
// 8. Tables
// --------------------------------------------------------------------------
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.925rem;
}

thead {
  border-bottom: 2px solid var(--border-color);
}

th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--color);
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
}

tbody tr:hover {
  background: var(--background-raised);
}

// --------------------------------------------------------------------------
// 9. Lists
// --------------------------------------------------------------------------
ul, ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.35rem;

  ul, ol {
    margin-bottom: 0;
    margin-top: 0.35rem;
  }
}

// --------------------------------------------------------------------------
// 10. External Link Icon
// --------------------------------------------------------------------------
a[href^="http"]::after,
a[href^="https://"]::after {
  content: "\00a0\2197";
  font-size: 0.75em;
  vertical-align: super;
  opacity: 0.5;
}

// Internal overrides
a[href^="http"].no-external-icon::after,
.navbar a[href^="http"]::after,
.navbar a[href^="https://"]::after {
  content: none;
}

// --------------------------------------------------------------------------
// 11. Navbar
// --------------------------------------------------------------------------
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--background);
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.2s ease;

  &__inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 3.5rem;
  }

  &__logo {
    font-family: "Space Grotesk", sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color);
    text-decoration: none;

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

  &__links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    list-style: none;
    padding: 0;
    margin: 0;

    a {
      color: var(--color);
      font-size: 0.925rem;
      font-weight: 500;
      text-decoration: none;
      transition: color 0.15s ease;

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

    &--right {
      margin-left: auto;
    }
  }

  &__icon-link {
    display: flex;
    align-items: center;

    svg {
      width: 1.25rem;
      height: 1.25rem;
      fill: var(--color);
      transition: fill 0.15s ease;
    }

    &:hover svg {
      fill: var(--accent);
    }
  }

  // Hamburger toggle (mobile)
  &__toggle-input {
    display: none;
  }

  &__hamburger {
    display: none;
    cursor: pointer;
    width: 1.5rem;
    height: 1.25rem;
    position: relative;
    flex-direction: column;
    justify-content: space-between;

    span {
      display: block;
      height: 2px;
      width: 100%;
      background: var(--color);
      border-radius: 2px;
      transition: transform 0.2s ease, opacity 0.2s ease;
    }
  }

  &__menu {
    display: flex;
    align-items: center;
    gap: 1.5rem;
  }

  @media (max-width: $nav-collapse-width) {
    &__hamburger {
      display: flex;
    }

    &__menu {
      display: none;
      position: absolute;
      top: 3.5rem;
      left: 0;
      right: 0;
      background: var(--background);
      border-bottom: 1px solid var(--border-color);
      flex-direction: column;
      padding: 1rem 1.5rem;
      gap: 0.75rem;
      align-items: flex-start;
    }

    &__toggle-input:checked ~ &__menu {
      display: flex;
    }

    &__toggle-input:checked ~ &__hamburger {
      span:nth-child(1) {
        transform: rotate(45deg) translate(4px, 4px);
      }
      span:nth-child(2) {
        opacity: 0;
      }
      span:nth-child(3) {
        transform: rotate(-45deg) translate(4px, -4px);
      }
    }
  }
}

// --------------------------------------------------------------------------
// 12. Theme Toggle
// --------------------------------------------------------------------------
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color);
  transition: color 0.15s ease;

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

  svg {
    width: 1.25rem;
    height: 1.25rem;
  }

  .icon-sun { display: block; }
  .icon-moon { display: none; }
}

[data-theme="light"] .theme-toggle {
  .icon-sun { display: none; }
  .icon-moon { display: block; }
}

// --------------------------------------------------------------------------
// 13. Main Content Area
// --------------------------------------------------------------------------
.main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
  flex: 1;
}

// --------------------------------------------------------------------------
// 14. Hero Section
// --------------------------------------------------------------------------
.hero {
  text-align: center;
  padding: 4rem 1.5rem;

  h1 {
    font-size: 2.75rem;
    margin-bottom: 1rem;

    @media (max-width: $phone-max-width) {
      font-size: 2rem;
    }
  }

  p {
    font-size: 1.2rem;
    color: var(--color-muted);
    max-width: 640px;
    margin: 0 auto 2rem;
  }
}

// --------------------------------------------------------------------------
// 15. Features Grid
// --------------------------------------------------------------------------
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 3rem;
}

.feature-card {
  background: var(--background-raised);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;

  &:hover {
    border-color: var(--accent-alpha-20);
    box-shadow: 0 2px 12px var(--accent-alpha-20);
  }

  h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
  }

  p {
    color: var(--color-muted);
    font-size: 0.925rem;
    margin-bottom: 0;
  }
}

// --------------------------------------------------------------------------
// 16. Page Content
// --------------------------------------------------------------------------
.page-content {
  max-width: 800px;
  margin: 0 auto;

  h1, h2, h3, h4, h5, h6 {
    margin-top: 2rem;
  }
}

// --------------------------------------------------------------------------
// 17. Posts
// --------------------------------------------------------------------------
.posts {
  max-width: 800px;
  margin: 0 auto;
}

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

  &:last-child {
    border-bottom: none;
  }
}

.post-title {
  margin-bottom: 0.25rem;

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

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

.post-meta-inline {
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-bottom: 0.5rem;
}

.post-tags-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;

  a {
    font-size: 0.8rem;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    background: var(--accent-alpha-20);
    color: var(--accent);
    text-decoration: none;

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

.post-content {
  max-width: 800px;
  margin: 0 auto;

  h1, h2, h3, h4, h5, h6 {
    margin-top: 2rem;
  }
}

// --------------------------------------------------------------------------
// 18. Buttons
// --------------------------------------------------------------------------
.button {
  display: inline-block;
  padding: 0.6rem 1.4rem;
  border-radius: 6px;
  font-size: 0.925rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s ease, box-shadow 0.15s ease;

  &:hover {
    background: var(--accent-alpha-70);
    text-decoration: none;
    color: #fff;
  }

  &--outline {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent);

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

.read-more {
  font-weight: 500;
  font-size: 0.925rem;
  color: var(--accent);

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

// --------------------------------------------------------------------------
// 19. Pagination
// --------------------------------------------------------------------------
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin: 2rem 0;
  font-size: 0.925rem;

  a {
    padding: 0.4rem 0.9rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    color: var(--color);
    text-decoration: none;

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

  .current {
    padding: 0.4rem 0.9rem;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
  }
}

// --------------------------------------------------------------------------
// 20. Executable Code Block Output
// --------------------------------------------------------------------------
.code-block-executed {
  margin-bottom: 1.5rem;
}

.code-output {
  background: var(--background-raised);
  border: 1px solid var(--border-color);
  border-radius: 0 0 8px 8px;
  border-top: none;
  padding: 1rem 1.25rem;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  overflow-x: auto;
}

.code-error {
  @extend .code-output;
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.05);
}

// --------------------------------------------------------------------------
// 21. Tabs
// --------------------------------------------------------------------------
.tabs {
  margin-bottom: 1.5rem;

  &__nav {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 0;
    overflow-x: auto;
  }

  &__tab {
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    border: none;
    background: none;
    font-size: 0.925rem;
    font-weight: 500;
    color: var(--color-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color 0.15s ease, border-color 0.15s ease;

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

    &--active {
      color: var(--accent);
      border-bottom-color: var(--accent);
    }
  }

  &__content {
    display: none;
    padding: 1rem 0;

    &--active {
      display: block;
    }
  }
}

// --------------------------------------------------------------------------
// 22. Footer
// --------------------------------------------------------------------------
footer {
  border-top: 1px solid var(--border-color);
  padding: 2rem 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-muted);

  a {
    color: var(--accent);
  }
}

// --------------------------------------------------------------------------
// 23. Anchor Links
// --------------------------------------------------------------------------
.zorto-anchor {
  color: var(--color-muted);
  text-decoration: none;
  opacity: 0;
  margin-left: 0.35rem;
  font-size: 0.85em;
  transition: opacity 0.15s ease;

  h1:hover &,
  h2:hover &,
  h3:hover &,
  h4:hover &,
  h5:hover &,
  h6:hover & {
    opacity: 1;
  }

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

// --------------------------------------------------------------------------
// 24. Callouts
// --------------------------------------------------------------------------
.callout {
  border-left: 3px solid var(--accent);
  background: var(--background-raised);
  border-radius: 0 6px 6px 0;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-size: 0.95rem;

  p:last-child {
    margin-bottom: 0;
  }

  &__title {
    font-weight: 600;
    margin-bottom: 0.35rem;
  }

  &--note {
    border-left-color: #3b82f6;
    .callout__title { color: #3b82f6; }
  }

  &--tip {
    border-left-color: #22c55e;
    .callout__title { color: #22c55e; }
  }

  &--warning {
    border-left-color: #f59e0b;
    .callout__title { color: #f59e0b; }
  }

  &--danger {
    border-left-color: #ef4444;
    .callout__title { color: #ef4444; }
  }

  &--caution {
    border-left-color: #f97316;
    .callout__title { color: #f97316; }
  }

  &--important {
    border-left-color: #a855f7;
    .callout__title { color: #a855f7; }
  }
}

// --------------------------------------------------------------------------
// 25. Details Shortcode
// --------------------------------------------------------------------------
details {
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  background: var(--background-raised);

  summary {
    cursor: pointer;
    font-weight: 600;
    user-select: none;

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

  &[open] summary {
    margin-bottom: 0.75rem;
  }
}

// --------------------------------------------------------------------------
// 26. Figure Shortcode
// --------------------------------------------------------------------------
figure {
  margin: 1.5rem 0;
  text-align: center;

  img {
    margin: 0 auto;
    border-radius: 6px;
  }

  figcaption {
    font-size: 0.85rem;
    color: var(--color-muted);
    margin-top: 0.5rem;
    font-style: italic;
  }
}

// --------------------------------------------------------------------------
// 27. YouTube Shortcode
// --------------------------------------------------------------------------
.youtube-container {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  margin-bottom: 1.5rem;
  border-radius: 8px;
  overflow: hidden;

  iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
  }
}

// --------------------------------------------------------------------------
// 28. Mermaid
// --------------------------------------------------------------------------
.mermaid {
  display: flex;
  justify-content: center;
  margin: 1.5rem 0;
  background: var(--background-raised);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
}

// Markdown FAB
.md-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  &__toggle {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    border: 1px solid var(--border-color, #333);
    background: var(--bg-color, #1a1a2e);
    color: var(--text-color, #e0e0e0);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: background 0.2s;
    svg { width: 1.25rem; height: 1.25rem; }
    &:hover { opacity: 0.8; }
  }
  &--copied .md-fab__toggle {
    border-color: #22d3ee;
    color: #22d3ee;
  }
  &__menu {
    position: absolute;
    bottom: 3.25rem;
    right: 0;
    background: var(--bg-color, #1a1a2e);
    border: 1px solid var(--border-color, #333);
    border-radius: 0.5rem;
    padding: 0.25rem;
    min-width: 11rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  }
  &__item {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    background: none;
    color: var(--text-color, #e0e0e0);
    cursor: pointer;
    text-align: left;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    &:hover { background: var(--bg-hover, rgba(255,255,255,0.05)); }
  }
}
