/* ===== CSS Variables ===== */
:root {
  --bg-color: #0d0618;
  --text-color: #f0f0f5;
  --text-muted: rgba(240, 240, 245, 0.45);
  --text-faint: rgba(240, 240, 245, 0.22);
  --accent-color: #f0f0f5;
  --sidebar-width: 220px;
  --content-max-width: 760px;
  --list-height: 504px;
  --item-height: 56px;
  --transition-fast: 0.2s ease;
  --transition-medium: 0.35s ease;
  --transition-slow: 0.65s ease;
  --font-sans: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", monospace;
}

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

html {
  font-size: 16px;
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  color: var(--text-color);
  height: 100%;
  overflow: hidden;
  background: var(--bg-color);
}

/* ===== Background Layers ===== */
#bg-layer {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: var(--bg-color);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: background var(--transition-slow);
}

#bg-overlay {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: transparent;
  transition: background var(--transition-slow);
  pointer-events: none;
}

/* ===== Scroll Progress Bars ===== */
.progress-bar {
  position: fixed;
  left: 0;
  height: 3px;
  background: var(--text-color);
  width: 0%;
  opacity: 0;
  transition: opacity 0.25s ease, width 0.25s ease;
  pointer-events: none;
  z-index: 100;
}

.progress-bar.no-transition {
  transition: none !important;
}

.progress-bar.top {
  top: 0;
}

.progress-bar.bottom {
  bottom: 0;
}

.progress-bar.visible {
  opacity: 1;
}

/* ===== App Layout ===== */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  padding: 0 32px 0 0;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  border-right: 1px solid var(--text-faint);
}

.search-box {
  position: absolute;
  top: 48px;
  right: 32px;
  width: 140px;
  z-index: 5;
}

.search-box input {
  width: 100%;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--text-muted);
  border-radius: 999px;
  background: transparent;
  color: var(--text-color);
  font-family: var(--font-sans);
  font-size: 14px;
  text-align: center;
  outline: none;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-box input:focus {
  border-color: var(--text-color);
  background: rgba(255, 255, 255, 0.05);
}

.search-box .clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: var(--text-muted);
  color: var(--bg-color);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), background var(--transition-fast);
}

.search-box .clear-btn.visible {
  opacity: 1;
  pointer-events: auto;
}

.search-box .clear-btn:hover {
  background: var(--text-color);
}

/* iOS picker style list */
.article-list-mask {
  position: relative;
  width: 100%;
  height: var(--list-height);
  overflow: hidden;
  display: flex;
  justify-content: flex-end;
  -webkit-mask-image: none;
  mask-image: none;
}

.article-list-mask.masked-vertical {
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 15%,
    black 85%,
    transparent 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    black 15%,
    black 85%,
    transparent 100%
  );
}

/* Fixed highlight indicator in the middle */
.article-list-mask::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: var(--item-height);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
  z-index: 0;
}

.article-list {
  position: relative;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  padding: calc(var(--list-height) / 2 - var(--item-height) / 2) 16px calc(var(--list-height) / 2 - var(--item-height) / 2) 0;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  z-index: 1;
}

.article-list::-webkit-scrollbar {
  display: none;
}

.article-item {
  position: relative;
  flex-shrink: 0;
  height: var(--item-height);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 12px;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 400;
  line-height: var(--item-height);
  color: var(--text-muted);
  cursor: pointer;
  text-align: right;
  white-space: nowrap;
  transition: color var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast);
  opacity: 0.6;
  user-select: none;
}

.article-item:hover {
  color: var(--text-color);
  opacity: 0.85;
}

.article-item.active {
  color: var(--text-color);
  opacity: 1;
  font-weight: 600;
  transform: scale(1.25);
}

.no-results {
  font-size: 13px;
  color: var(--text-muted);
  text-align: right;
  padding: 20px 0;
}

/* ===== Content Area ===== */
.content-area {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  z-index: 5;
}

.content-wrapper {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8vh 6vw 6vh;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-medium), opacity var(--transition-medium);
}

.content-wrapper::-webkit-scrollbar {
  width: 5px;
}
.content-wrapper::-webkit-scrollbar-track {
  background: transparent;
}
.content-wrapper::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

/* Animation states */
.content-wrapper.exiting {
  transform: translateX(-80px);
  opacity: 0;
}

.content-wrapper.exiting.reverse {
  transform: translateX(80px);
}

.content-wrapper.entering {
  transform: translateX(80px);
  opacity: 0;
}

.content-wrapper.entering.reverse {
  transform: translateX(-80px);
}

.content-wrapper.no-transition {
  transition: none !important;
}

/* Empty state */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 16px;
}

/* ===== Article Content ===== */
article {
  width: 100%;
  max-width: var(--content-max-width);
  margin: auto;
}

.article-header {
  margin-bottom: 48px;
  text-align: right;
}

.article-header h1 {
  font-family: var(--font-sans);
  font-size: clamp(38px, 6vw, 72px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin-bottom: 28px;
}

.article-excerpt {
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 400;
  font-style: italic;
  line-height: 1.7;
  color: var(--text-muted);
  padding-left: 24px;
  border-left: 2px solid var(--text-muted);
  max-width: 520px;
  text-align: left;
}

.article-body {
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.85;
  color: var(--text-color);
  text-align: left;
}

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  margin-top: 40px;
  margin-bottom: 18px;
  line-height: 1.3;
}

.article-body h1 { font-size: 30px; }
.article-body h2 { font-size: 24px; }
.article-body h3 { font-size: 20px; }
.article-body h4 { font-size: 18px; }

.article-body p {
  margin-bottom: 20px;
}

.article-body a {
  color: var(--text-color);
  text-decoration: underline;
  text-decoration-color: var(--text-muted);
  text-underline-offset: 4px;
  transition: text-decoration-color var(--transition-fast);
}

.article-body a:hover {
  text-decoration-color: var(--text-color);
}

.article-body ul,
.article-body ol {
  margin-bottom: 20px;
  padding-left: 26px;
}

.article-body li {
  margin-bottom: 8px;
}

.article-body blockquote {
  margin: 28px 0;
  padding: 10px 24px;
  border-left: 2px solid var(--text-muted);
  color: var(--text-muted);
  font-style: italic;
}

.article-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

.article-body pre {
  background: var(--code-bg, rgba(0, 0, 0, 0.35));
  padding: 20px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 20px;
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.5;
}

.article-body pre code {
  background: none;
  padding: 0;
}

.article-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 24px 0;
}

.article-body hr {
  border: none;
  border-top: 1px solid var(--text-faint);
  margin: 40px 0;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 15px;
}

.article-body th,
.article-body td {
  padding: 10px 14px;
  border: 1px solid var(--text-faint);
  text-align: left;
}

.article-body th {
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
}

/* ===== Footer ===== */
.site-footer {
  padding: 16px 6vw 24px;
  text-align: right;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: flex-end;
  gap: 32px;
  flex-shrink: 0;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100vw;
    --list-height: 200px;
  }

  html,
  body {
    height: auto;
    overflow: auto;
  }

  #app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    height: auto;
    width: 100%;
    padding: 16px 0 12px;
    align-items: center;
    gap: 12px;
    border-right: none;
    border-bottom: 1px solid var(--text-faint);
  }

  .search-box {
    position: relative;
    top: auto;
    right: auto;
    margin: 0 auto;
  }

  .article-list-mask {
    height: calc(var(--item-height) + 24px);
    justify-content: center;
  }

  .article-list-mask.masked-horizontal {
    -webkit-mask-image: linear-gradient(
      to right,
      transparent 0%,
      black 15%,
      black 85%,
      transparent 100%
    );
    mask-image: linear-gradient(
      to right,
      transparent 0%,
      black 15%,
      black 85%,
      transparent 100%
    );
  }

  .article-list-mask::before {
    left: 50%;
    right: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 160px;
    height: var(--item-height);
  }

  .article-list {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    padding: 0 50vw;
    gap: 24px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .article-item {
    justify-content: center;
    text-align: center;
    padding-right: 0;
    flex-shrink: 0;
    min-width: 80px;
    padding: 0 12px;
  }

  .content-area {
    height: auto;
    min-height: 0;
    flex: 1;
  }

  .content-wrapper {
    overflow: visible;
    padding: 5vh 8vw;
  }

  .article-header {
    text-align: right;
  }

  .article-header h1 {
    font-size: clamp(32px, 10vw, 52px);
  }

  .article-excerpt {
    font-size: 16px;
  }

  .article-body {
    font-size: 16px;
  }

  .site-footer {
    justify-content: center;
    padding-right: 0;
  }
}
