/* ==========================================================================
   Tutorial shared stylesheet
   Used by /tutorial/ (index + ~387 subpages)
   Mobile-first responsive layout
   ========================================================================== */

/* Reset & base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: #f6f7f9;
  color: #1f2937;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue",
               Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: none; }

/* ==========================================================================
   Subpage (article) styles
   ========================================================================== */

.article-header {
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  padding: 44px 24px;
  text-align: center;
}
.article-header h1 {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 10px;
  color: #fff;
  line-height: 1.35;
  word-break: break-word;
}
.article-header p {
  font-size: 15px;
  color: rgba(255,255,255,0.9);
  margin: 0;
  line-height: 1.5;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  margin-bottom: 22px;
  background: #fff;
  border-radius: 8px;
  color: #1e40af;
  text-decoration: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.06);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s;
}
.back-link:hover { background: #eff6ff; }

.section { margin: 36px 0; }
.section h2 {
  font-size: 21px;
  color: #1f2937;
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid #3b82f6;
  font-weight: 600;
  line-height: 1.35;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 20px 0;
}
.card {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  border-left: 4px solid #3b82f6;
}
.card:nth-child(2) { border-left-color: #10b981; }
.card:nth-child(3) { border-left-color: #8b5cf6; }
.card:nth-child(4) { border-left-color: #f59e0b; }
.card:nth-child(5) { border-left-color: #ef4444; }
.card:nth-child(6) { border-left-color: #06b6d4; }
.card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: #1f2937;
  font-weight: 600;
}
.card p { margin: 0; color: #6b7280; font-size: 14px; }

.step-card {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  margin: 16px 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.step-card h3 {
  margin: 0 0 14px;
  font-size: 19px;
  color: #1f2937;
  font-weight: 600;
}
.step-card ol { margin: 0; padding-left: 22px; }
.step-card ol li { margin: 10px 0; color: #374151; }
.step-card p { margin: 10px 0; color: #374151; }
.step-card p strong { color: #1f2937; }

.prompt-box {
  background: #1e293b;
  border-radius: 8px;
  padding: 16px 18px;
  margin: 18px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.prompt-box pre {
  margin: 0;
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 13px;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
}

/* Tables: wrap with .table-wrap to enable horizontal scroll on small screens */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 18px 0;
  border-radius: 8px;
}
table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  background: #fff;
}
th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
  font-size: 14px;
  vertical-align: top;
}
th { color: #1e40af; font-weight: 600; background: #f3f4f6; }
td { color: #374151; }
tr:last-child td { border-bottom: none; }

.tip {
  background: #ecfdf5;
  border-left: 4px solid #10b981;
  padding: 14px 16px;
  margin: 14px 0;
  border-radius: 0 8px 8px 0;
  font-size: 14px;
  color: #1f2937;
}
.warning {
  background: #fef2f2;
  border-left: 4px solid #ef4444;
  padding: 14px 16px;
  margin: 14px 0;
  border-radius: 0 8px 8px 0;
  font-size: 14px;
  color: #1f2937;
}

code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 0.9em;
  word-break: break-word;
}

.footer {
  text-align: center;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid #e5e7eb;
  color: #6b7280;
  font-size: 13px;
}

/* ==========================================================================
   Index (目录) page styles
   ========================================================================== */

.idx-page { background: #fff; }

.idx-header {
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  padding: 36px 24px 30px;
  border-radius: 0 0 18px 18px;
  margin-bottom: 4px;
}
.idx-header h1 {
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  margin: 0 0 8px;
  line-height: 1.35;
}
.idx-header p {
  font-size: 14px;
  color: rgba(255,255,255,0.88);
  margin: 0;
}

.idx-body {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

/* Sticky top nav: jumping categories */
.idx-topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid #e5e7eb;
  margin: 0 -20px 20px;
  padding: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}
.idx-topnav a {
  padding: 6px 12px;
  color: #4b5563;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.idx-topnav a:hover { background: #f3f4f6; color: #2563eb; }
.idx-topnav a.active { background: #1e40af; color: #fff; }

/* Categories: responsive grid of cards */
.idx-cats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}
.idx-cat {
  background: #fff;
  border-radius: 12px;
  padding: 14px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border: 1px solid #eef0f3;
}
.idx-cat h2 {
  font-size: 15px;
  font-weight: 600;
  color: #111827;
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.idx-cat h2::after {
  content: "▾";
  font-size: 11px;
  color: #9ca3af;
  transition: transform 0.2s;
}
.idx-cat.collapsed h2::after { transform: rotate(-90deg); }
.idx-cat.collapsed ul { display: none; }
.idx-cat-count {
  display: inline-block;
  background: #eff6ff;
  color: #1e40af;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
.idx-cat ul {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 360px;
  overflow-y: auto;
}
.idx-cat li { padding: 1px 0; }
.idx-cat li a {
  display: block;
  padding: 6px 8px;
  font-size: 13.5px;
  color: #4b5563;
  border-radius: 4px;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
}
.idx-cat li a:hover { background: #f3f4f6; color: #2563eb; }

/* ==========================================================================
   Mobile breakpoint
   ========================================================================== */

@media (max-width: 640px) {
  body { font-size: 14.5px; line-height: 1.65; }

  /* Subpage */
  .article-header { padding: 28px 16px 24px; }
  .article-header h1 { font-size: 21px; }
  .article-header p { font-size: 13px; }

  .container { padding: 18px 14px 60px; }

  .back-link {
    padding: 8px 14px;
    font-size: 13px;
    margin-bottom: 16px;
  }

  .section { margin: 28px 0; }
  .section h2 { font-size: 18px; margin-bottom: 12px; }

  .card-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 14px 0;
  }
  .card { padding: 14px; border-radius: 10px; }
  .card h3 { font-size: 15px; }
  .card p { font-size: 13px; }

  .step-card { padding: 16px; border-radius: 10px; }
  .step-card h3 { font-size: 17px; }
  .step-card ol li { font-size: 14px; margin: 8px 0; }

  .prompt-box {
    padding: 12px;
    margin: 14px 0;
    border-radius: 6px;
  }
  .prompt-box pre { font-size: 12px; }

  /* Tables: full-bleed horizontal scroll */
  .table-wrap {
    margin: 14px -14px;
    border-radius: 0;
    padding: 0 14px;
  }
  .table-wrap > table {
    min-width: 480px;
    border-radius: 6px;
    overflow: hidden;
  }
  th, td { padding: 8px 10px; font-size: 13px; }

  .tip, .warning { padding: 12px 14px; font-size: 13px; }
  .footer { margin-top: 32px; padding-top: 18px; font-size: 12px; }

  /* Index */
  .idx-header { padding: 24px 16px 20px; border-radius: 0 0 14px 14px; }
  .idx-header h1 { font-size: 20px; }
  .idx-header p { font-size: 12.5px; }

  .idx-body { padding: 16px 14px 60px; }

  .idx-topnav {
    margin: 0 -14px 14px;
    padding: 8px 14px;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .idx-topnav::-webkit-scrollbar { display: none; }
  .idx-topnav a {
    padding: 5px 11px;
    font-size: 12.5px;
    flex-shrink: 0;
  }

  .idx-cats { grid-template-columns: 1fr; gap: 10px; }
  .idx-cat { padding: 12px 16px; border-radius: 10px; }
  .idx-cat h2 { font-size: 14px; margin-bottom: 8px; padding-bottom: 6px; }
  .idx-cat li a {
    font-size: 13px;
    padding: 7px 8px;
    min-height: 34px;
    display: flex;
    align-items: center;
  }
  .idx-cat ul { max-height: 260px; }
}

/* Tablet tweaks */
@media (min-width: 641px) and (max-width: 1024px) {
  .container { padding: 24px 22px 70px; }
  .card-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  .idx-cats { grid-template-columns: repeat(2, 1fr); }
  .idx-body { padding: 24px 18px 70px; }
}