@layer ui.tokens, ui.base, ui.layout, ui.components, ui.patterns, ui.markdown, ui.hljs, ui.utilities;

@layer ui.patterns {
  /* Author Sidebar */
  .author-card {
    position: sticky;
    top: var(--sticky-offset, 74px);
    padding: 0;
  }

  .author-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .author-avatar-link {
    display: inline-block;
    border-radius: 50%;
    line-height: 0;
  }

  .author-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
    transition: border-color 0.15s ease;
  }
  .author-avatar-link:hover .author-avatar {
    border-color: var(--accent);
  }

  .author-name {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-secondary);
  }

  .author-bio {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
  }

  .author-links {
    list-style: none;
    margin: 16px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .author-links a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
  }
  .author-links a:hover {
    color: var(--accent);
  }

  .author-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: color 0.15s ease;
  }
  .author-links a:hover .author-icon {
    color: var(--accent);
  }

  /* Post List */
  .post-cards {
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .post-card {
    display: grid;
    grid-template-columns: 100px minmax(0, 1fr);
    gap: 4px 20px;
    align-items: baseline;
    padding: 12px 14px;
    margin: 0 -14px;
    border-radius: var(--radius, 8px);
    cursor: pointer;
    transition: background-color 0.15s ease;
  }
  .post-card:hover {
    background: color-mix(in srgb, var(--panel, #1e2132) 55%, transparent);
  }
  .post-card:hover .post-card-title a {
    color: var(--accent);
  }

  .post-card-date {
    font-family: var(--font-mono);
    font-size: 12.5px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    line-height: 1.5;
  }

  .post-card-body {
    min-width: 0;
  }

  .post-card-title {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.4;
  }
  .post-card-title a {
    color: var(--text-secondary);
  }
  .post-card-title a:hover {
    color: var(--accent);
    text-decoration: none;
  }

  .post-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    font-size: 12px;
    color: var(--text-muted);
  }

  .post-excerpt {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Archives */
  .archive-group {
    margin-bottom: 28px;
  }

  .archive-group-title {
    margin: 0 0 10px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-secondary);
    scroll-margin-top: var(--sticky-offset, 74px);
  }

  .archive-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .archive-item {
    display: flex;
    align-items: baseline;
    gap: 16px;
    padding: 8px 12px;
    margin: 0 -12px;
    border-radius: var(--radius-md, 6px);
    cursor: pointer;
    transition: background-color 0.15s ease;
  }
  .archive-item:hover {
    background: color-mix(in srgb, var(--panel, #1e2132) 55%, transparent);
  }
  .archive-item:hover .archive-link {
    color: var(--accent);
  }

  .archive-date {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
  }

  .archive-link {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-secondary);
  }
  .archive-link:hover {
    color: var(--accent);
  }

  /* Single Post View */
  .article-card {
    padding: 0;
  }

  .article-header {
    padding-bottom: 0;
    margin-bottom: 28px;
  }

  .article-title {
    margin: 0 0 10px;
    font-size: 26px;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text-secondary);
  }

  .article-footer {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .share-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .share-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 4px;
  }

  .post-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .post-nav-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px 0;
  }
  .post-nav-card:hover .post-nav-title {
    color: var(--accent);
  }
  .post-nav-card:hover {
    text-decoration: none;
  }
  .post-nav-card.next {
    text-align: right;
  }

  .post-nav-label {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
  }

  .post-nav-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
  }

  .related-section {
    margin-top: 28px;
  }

  .related-heading {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text-secondary);
  }

  .related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
  }

  .related-card {
    padding: 4px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .related-card:hover .related-card-title {
    color: var(--accent);
  }
  .related-card:hover {
    text-decoration: none;
  }

  .related-card-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.4;
  }

  .related-card-date {
    font-size: 11.5px;
    font-family: var(--font-mono);
    color: var(--text-muted);
  }

  /* App Sidebar List Items */
  .nav-list,
  .post-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
  }

  .nav-item,
  .post-item {
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    border-radius: var(--radius-md, 6px);
    padding: 9px 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 2px;
    transition: background-color 0.15s ease;
  }
  .nav-item:hover,
  .post-item:hover {
    background: color-mix(in srgb, var(--panel, #1e2132) 60%, transparent);
  }
  .nav-item.active,
  .post-item.active {
    background: var(--accent-dim);
  }
  .nav-item.active .nav-item-title,
  .post-item.active .post-item-title {
    color: var(--accent);
  }

  .nav-item-title,
  .post-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav-item-meta,
  .post-item-meta {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Media / App Card Grid */
  .media-grid {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }
  .media-grid > li {
    min-width: 0;
  }
  @media (min-width: 700px) {
    .media-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  .media-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg, 10px);
    background: var(--panel);
    color: inherit;
    text-decoration: none;
    overflow: hidden;
    transition: border-color 0.15s ease;
  }
  .media-card:hover {
    border-color: var(--accent);
    color: inherit;
    text-decoration: none;
  }
  .media-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  .media-card-thumb {
    position: relative;
    display: grid;
    place-items: center;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 12px;
  }
  .media-card-thumb:not(:has(img))::before {
    content: "Thumbnail";
  }
  .media-card-thumb[data-placeholder]:not(:has(img))::before {
    content: attr(data-placeholder);
  }
  .media-card-thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .media-card-body {
    padding: 14px 16px 16px;
  }

  .media-card-title {
    display: block;
    color: var(--accent);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    transition: color 0.15s ease;
  }
  .media-card:hover .media-card-title {
    color: var(--accent-hover);
  }

  .media-card-desc {
    display: block;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
  }

  /* Responsive */
  @media (max-width: 820px) {
    .author-card {
      position: static;
    }
    .author-header {
      flex-direction: row;
      align-items: center;
    }
    .author-avatar {
      width: 56px;
      height: 56px;
    }
    .author-links {
      flex-direction: row;
      flex-wrap: wrap;
      gap: 8px 16px;
    }
    .article-card {
      padding: 0;
    }
    .post-card {
      grid-template-columns: minmax(0, 1fr);
      padding: 10px 12px;
      margin: 0 -12px;
    }
    .article-title {
      font-size: 22px;
    }
    .post-nav {
      grid-template-columns: minmax(0, 1fr);
    }
    .post-nav-card.next {
      text-align: left;
    }
  }
}
