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

:root {
  --ink: #ffffff;
  --panel: #f7f6f2;
  --panel-hover: #efeee6;
  --line: #e2ded3;
  --line-strong: #cdc7b8;
  --paper: #1d2024;
  --dim: #5c6167;
  --faint: #7d828a;
  --signal: #d9622a;
  --signal-dim: rgba(217, 98, 42, 0.1);
  --route: #3a8b7a;
  --route-dim: rgba(58, 139, 122, 0.1);
  --danger: #c0392b;
  --danger-dim: rgba(192, 57, 43, 0.08);
  --font-display: 'Noto Serif SC', 'Songti SC', serif;
  --font-body: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --max-width: 1200px;
  --radius: 6px;
}

html { scroll-behavior: smooth; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

body {
  font-family: var(--font-body);
  background: var(--ink);
  color: var(--paper);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--signal); text-decoration: none; transition: color 0.2s; }
a:hover { color: #b34d1a; }

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: 2px;
}

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

/* === Header === */
.header {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.logo {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--paper);
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: baseline;
}

.logo::before {
  content: '#';
  font-family: var(--font-mono);
  font-weight: 400;
  color: var(--route);
  margin-right: 0.45em;
  font-size: 0.9em;
}

.nav { display: flex; gap: 1.5rem; align-items: center; }
.nav a {
  color: var(--dim);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
  transition: color 0.2s;
  position: relative;
}
.nav a:hover { color: var(--signal); }
.nav a::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--signal);
  transition: width 0.25s;
}
.nav a:hover::after { width: 100%; }

/* Mobile nav toggle */
.nav-toggle { display: none; background: none; border: none; color: var(--paper); font-size: 1.4rem; cursor: pointer; }

/* === Hero === */
.hero {
  padding: 3.5rem 0 3rem;
  text-align: center;
  position: relative;
  background-image:
    radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: center -10px;
  -webkit-mask-image: linear-gradient(to bottom, black, transparent 92%);
  mask-image: linear-gradient(to bottom, black, transparent 92%);
}

.hero h1 {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--paper);
  margin-bottom: 0.85rem;
  letter-spacing: -0.01em;
}

.hero p {
  color: var(--dim);
  font-size: 1.05rem;
  max-width: 600px;
  margin: 0 auto;
}

/* === Route diagram (signature element) === */
.route-diagram {
  max-width: 720px;
  margin: 2.25rem auto 0;
  padding: 0 1rem;
}

.route-track {
  position: relative;
  height: 14px;
}

.route-track svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

.route-path {
  stroke: var(--line-strong);
  stroke-width: 1.5;
  fill: none;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw-route 1.3s 0.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes draw-route {
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .route-path { animation: none; stroke-dashoffset: 0; }
}

.route-stops {
  display: flex;
  justify-content: space-between;
  margin-top: -7px;
}

.route-stop { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; width: 25%; }

.route-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink);
  border: 1.5px solid var(--route);
}

.route-stop:first-child .route-dot,
.route-stop:last-child .route-dot {
  background: var(--signal);
  border-color: var(--signal);
}

.route-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--dim);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.route-tags {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.route-tags span {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--faint);
  border: 1px solid var(--line);
  padding: 0.2rem 0.55rem;
  border-radius: 3px;
  letter-spacing: 0.04em;
}

/* === Post Grid === */
.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
  padding-bottom: 4rem;
}

/* === Post Card === */
.post-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.4rem;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
  position: relative;
  display: flex;
  flex-direction: column;
}

.post-card:hover {
  border-color: var(--line-strong);
  background: var(--panel-hover);
  transform: translateY(-1px);
}

.post-card.pinned {
  border-color: rgba(217, 98, 42, 0.35);
}

.pin-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--signal);
  margin-bottom: 0.75rem;
}

.pin-badge::before { content: '\25B8\00a0'; }

.post-card h2 {
  font-family: var(--font-display);
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.45;
  margin-bottom: 0.6rem;
}

.post-card h2 a { color: var(--paper); }
.post-card h2 a:hover { color: var(--signal); }
.post-card h2 a::after { content: ''; position: absolute; inset: 0; }

.post-meta {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--faint);
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.post-meta .category {
  color: var(--route);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.post-meta .category::before { content: '['; color: var(--faint); }
.post-meta .category::after { content: ']'; color: var(--faint); }

.post-excerpt {
  color: var(--dim);
  font-size: 0.9rem;
  line-height: 1.6;
  flex: 1;
}

/* === Article === */
.article {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.article-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
  position: relative;
}

.article-header::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--signal);
  transform: translateY(-2.5px);
}

.article-header h1 {
  font-family: var(--font-display);
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.4;
  margin-bottom: 1rem;
  letter-spacing: -0.01em;
}

.article-meta {
  display: flex;
  gap: 1rem;
  align-items: center;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.article-meta span {
  color: var(--route);
}

.article-meta span::before { content: '['; color: var(--faint); }
.article-meta span::after { content: ']'; color: var(--faint); }

/* Markdown content styles */
.article-content h1, .article-content h2, .article-content h3,
.article-content h4, .article-content h5, .article-content h6 {
  font-family: var(--font-display);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--paper);
}

.article-content h1 { font-size: 1.6rem; }
.article-content h2 { font-size: 1.4rem; border-bottom: 1px solid var(--line); padding-bottom: 0.5rem; }
.article-content h3 { font-size: 1.15rem; }

.article-content p { margin-bottom: 1.25rem; color: var(--paper); }

.article-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin: 1rem 0;
}

.article-content code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--route-dim);
  color: var(--route);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

.article-content pre {
  background: #f2f0e9;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  position: relative;
}

.article-content pre code {
  background: none;
  color: var(--paper);
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.6;
}

.article-content blockquote {
  border-left: 2px solid var(--signal);
  padding: 0.75rem 1rem;
  margin: 1.5rem 0;
  background: var(--signal-dim);
  color: var(--dim);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.article-content ul, .article-content ol {
  padding-left: 1.5rem;
  margin-bottom: 1.25rem;
}

.article-content li {
  margin-bottom: 0.35rem;
  color: var(--paper);
}

.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  overflow-x: auto;
  display: block;
}

.article-content th, .article-content td {
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  text-align: left;
}

.article-content th {
  background: var(--panel);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

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

.article-content a {
  color: var(--signal);
  text-decoration: underline;
  text-decoration-color: rgba(217, 98, 42, 0.35);
  text-underline-offset: 2px;
}
.article-content a:hover {
  text-decoration-color: var(--signal);
}

/* === Footer === */
.footer {
  margin-top: auto;
  padding: 2rem 0;
  border-top: 1px solid var(--line);
  text-align: center;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

/* === 404 === */
.not-found {
  text-align: center;
  padding: 6rem 1rem;
}
.not-found h1 {
  font-family: var(--font-mono);
  font-size: 4rem;
  font-weight: 600;
  color: var(--line-strong);
  letter-spacing: 0.02em;
}
.not-found h1::before,
.not-found h1::after { content: '/'; color: var(--signal); }
.not-found p { color: var(--dim); margin: 1rem 0 2rem; }
.not-found a {
  display: inline-block;
  padding: 0.7rem 1.75rem;
  background: transparent;
  border: 1px solid var(--signal);
  color: var(--signal);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius);
  transition: background 0.2s, color 0.2s;
}
.not-found a:hover { background: var(--signal); color: var(--ink); }

/* === Admin === */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-family: var(--font-body);
}
.admin-table th, .admin-table td {
  padding: 0.75rem;
  border: 1px solid var(--line);
  text-align: left;
  font-size: 0.875rem;
}
.admin-table th { background: var(--panel); font-weight: 600; font-family: var(--font-mono); font-size: 0.78rem; letter-spacing: 0.02em; }
.admin-table tr:hover { background: var(--panel); }

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-mono);
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary { background: var(--signal); color: #1a1005; }
.btn-primary:hover { background: #ffa869; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-dim); }

.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  font-weight: 500;
  margin-bottom: 0.4rem;
  color: var(--dim);
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 3px var(--signal-dim);
}
.form-group textarea {
  min-height: 400px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.checkbox-group input[type="checkbox"] {
  width: auto;
  accent-color: var(--signal);
}

/* === Back link === */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  margin-bottom: 1rem;
  transition: color 0.2s;
}
.back-link:hover { color: var(--signal); }

/* === Login === */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
  padding: 2rem;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2.5rem;
  position: relative;
}
.login-card::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 1.5rem;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--signal);
  transform: translateY(-2.5px);
}
.login-card h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.5rem;
}
.login-card .subtitle {
  text-align: center;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  margin-bottom: 2rem;
}
.login-error {
  background: var(--danger-dim);
  border: 1px solid rgba(226, 104, 95, 0.35);
  color: var(--danger);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
  text-align: center;
}
.login-card .btn-primary {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

/* === Responsive === */
@media (max-width: 768px) {
  .hero h1 { font-size: 1.6rem; }
  .hero p { font-size: 1rem; }
  .route-label { font-size: 0.6rem; }
  .post-grid { grid-template-columns: 1fr; gap: 1rem; }
  .article-header h1 { font-size: 1.4rem; }
  .article { padding: 1.5rem 1rem 3rem; }
  .form-row { grid-template-columns: 1fr; }
  .header-inner { position: relative; }
  .nav {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(16px);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--line);
    gap: 0.75rem;
  }
  .nav.open { display: flex; }
  .nav a::after { display: none; }
  .nav-toggle { display: block; }
  .admin-table { font-size: 0.75rem; min-width: 640px; }
  .admin-table th, .admin-table td { padding: 0.5rem; }
}

@media (max-width: 560px) {
  .route-label { display: none; }
  .route-stop:first-child .route-label,
  .route-stop:last-child .route-label { display: block; }
}

@media (max-width: 480px) {
  .hero { padding: 2.25rem 0 2rem; }
  .post-card { padding: 1.15rem; }
  .post-card h2 { font-size: 1rem; }
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--ink); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

/* === Selection === */
::selection { background: var(--signal-dim); color: var(--paper); }
