/* ============================================
   iOS Exploit Starterpack - Dark Theme
   ============================================ */

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

:root {
  --bg-primary: #0d1117;
  --bg-surface: #161b22;
  --bg-sidebar: #010409;
  --bg-header: #010409;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-heading: #f0f6fc;
  --text-link: #58a6ff;
  --text-link-hover: #79c0ff;
  --border-default: #30363d;
  --border-muted: #21262d;
  --code-bg: #1f2937;
  --code-text: #e5e7eb;
  --inline-code-bg: #2d333b;
  --inline-code-text: #adbac7;
  --selection-bg: #1f6feb33;
  --accent-blue: #58a6ff;
  --accent-green: #3fb950;
  --accent-orange: #d29922;
  --accent-red: #f85149;
  --accent-purple: #bc8cff;
  --sidebar-width: 280px;
  --header-height: 56px;
  --content-max-width: 900px;
  --toc-width: 220px;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

::selection {
  background: var(--selection-bg);
}

html {
  scroll-behavior: smooth;
  scrollbar-color: #484f58 transparent;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #484f58;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #6e7681;
}

/* --- Links --- */
a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--text-link-hover);
  text-decoration: underline;
}

/* --- Header --- */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-default);
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 16px;
  max-width: 100%;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background var(--transition-fast);
}

.hamburger:hover {
  background: var(--border-muted);
}

.site-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-heading);
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
}

.site-title:hover {
  color: var(--text-heading);
  text-decoration: none;
}

.site-logo {
  display: flex;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.lang-switcher {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--border-muted);
  border-radius: 6px;
  padding: 2px;
}

.lang-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition-fast);
  letter-spacing: 0.5px;
}

.lang-btn:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.lang-btn.active {
  background: var(--accent-blue);
  color: #ffffff;
}

/* --- Layout --- */
.layout-wrapper {
  display: flex;
  padding-top: var(--header-height);
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-default);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 50;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  padding: 16px 16px 8px;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

.nav-sections {
  list-style: none;
  padding: 0 0 24px;
}

.nav-section {
  border-bottom: 1px solid var(--border-muted);
}

.nav-section:last-child {
  border-bottom: none;
}

.nav-section-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast);
}

.nav-section-toggle:hover {
  background: var(--border-muted);
}

.nav-section-icon {
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.nav-section-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-section-arrow {
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  transition: transform var(--transition-fast);
  flex-shrink: 0;
}

.nav-section.expanded .nav-section-arrow {
  transform: rotate(180deg);
}

.nav-items {
  list-style: none;
  display: none;
  padding: 0 0 4px;
}

.nav-section.expanded .nav-items {
  display: block;
}

.nav-item {
  margin: 0;
}

.nav-link {
  display: block;
  padding: 6px 16px 6px 44px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition-fast);
  border-left: 2px solid transparent;
}

.nav-link:hover {
  color: var(--text-primary);
  background: rgba(88, 166, 255, 0.05);
  text-decoration: none;
}

.nav-link.active {
  color: var(--text-link);
  border-left-color: var(--accent-blue);
  background: rgba(88, 166, 255, 0.08);
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 32px 40px 80px;
  min-width: 0;
  position: relative;
}

.main-content.full-width {
  margin-left: 0;
}

/* --- Page Content --- */
.page-content {
  max-width: var(--content-max-width);
}

.page-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-default);
}

.phase-indicator {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-blue);
  margin-bottom: 8px;
}

.page-description {
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 1.5;
  margin-top: 8px;
}

/* --- Content with TOC --- */
.content-with-toc {
  display: flex;
  gap: 40px;
}

.content-body {
  flex: 1;
  min-width: 0;
}

/* --- Table of Contents Sidebar --- */
.toc-sidebar {
  width: var(--toc-width);
  flex-shrink: 0;
}

.toc-wrapper {
  position: sticky;
  top: calc(var(--header-height) + 32px);
  max-height: calc(100vh - var(--header-height) - 64px);
  overflow-y: auto;
}

.toc-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-muted);
}

.toc-nav a {
  display: block;
  padding: 4px 0 4px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 1px solid var(--border-muted);
  transition: all var(--transition-fast);
  line-height: 1.4;
}

.toc-nav a:hover {
  color: var(--text-primary);
  text-decoration: none;
}

.toc-nav a.active {
  color: var(--text-link);
  border-left-color: var(--accent-blue);
}

.toc-nav a.toc-h3 {
  padding-left: 24px;
  font-size: 12px;
}

/* --- Typography --- */
.content-body h1,
.content-body h2,
.content-body h3,
.content-body h4,
.content-body h5,
.content-body h6 {
  color: var(--text-heading);
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2em;
  margin-bottom: 0.5em;
}

.content-body h1 { font-size: 2em; margin-top: 0; }
.content-body h2 { font-size: 1.5em; padding-bottom: 0.3em; border-bottom: 1px solid var(--border-default); }
.content-body h3 { font-size: 1.25em; }
.content-body h4 { font-size: 1em; }

.content-body p {
  margin-bottom: 1em;
}

.content-body ul,
.content-body ol {
  margin-bottom: 1em;
  padding-left: 2em;
}

.content-body li {
  margin-bottom: 0.25em;
}

.content-body li > ul,
.content-body li > ol {
  margin-top: 0.25em;
  margin-bottom: 0;
}

.content-body blockquote {
  padding: 1px 16px;
  margin: 0 0 1em;
  border-left: 4px solid var(--accent-blue);
  background: rgba(88, 166, 255, 0.05);
  border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
}

.content-body blockquote p {
  margin: 12px 0;
}

.content-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border-default);
}

.content-body hr {
  border: none;
  border-top: 1px solid var(--border-default);
  margin: 2em 0;
}

/* --- Inline Code --- */
.content-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--inline-code-bg);
  color: var(--inline-code-text);
  padding: 0.15em 0.4em;
  border-radius: 4px;
}

/* --- Code Blocks --- */
.content-body pre {
  position: relative;
  margin-bottom: 1em;
  border-radius: 8px;
  border: 1px solid var(--border-default);
  overflow: hidden;
}

.content-body pre code {
  display: block;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.6;
  border-radius: 0;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--border-muted);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: all var(--transition-fast);
  font-family: var(--font-body);
  z-index: 1;
}

.content-body pre:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background: var(--border-default);
  color: var(--text-primary);
}

.copy-btn.copied {
  color: var(--accent-green);
}

/* --- Tables --- */
.content-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1em;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.content-body thead {
  background: var(--bg-surface);
}

.content-body th {
  font-weight: 600;
  color: var(--text-heading);
  text-align: left;
  padding: 10px 16px;
  border: 1px solid var(--border-default);
  font-size: 14px;
  white-space: nowrap;
}

.content-body td {
  padding: 8px 16px;
  border: 1px solid var(--border-default);
  font-size: 14px;
}

.content-body tbody tr:nth-child(odd) {
  background: var(--bg-primary);
}

.content-body tbody tr:nth-child(even) {
  background: var(--bg-surface);
}

.content-body tbody tr:hover {
  background: rgba(88, 166, 255, 0.04);
}

/* --- Rouge Syntax Highlighting --- */
.highlight .c,
.highlight .cm,
.highlight .c1,
.highlight .cs { color: #8b949e; font-style: italic; }
.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .kp,
.highlight .kr,
.highlight .kt,
.highlight .kv { color: #ff7b72; }
.highlight .n { color: #e5e7eb; }
.highlight .o { color: #ff7b72; }
.highlight .p { color: #e5e7eb; }
.highlight .s,
.highlight .sb,
.highlight .sc,
.highlight .sd,
.highlight .s2,
.highlight .sh,
.highlight .s1 { color: #a5d6ff; }
.highlight .na { color: #79c0ff; }
.highlight .nb { color: #ffa657; }
.highlight .nc { color: #ffa657; }
.highlight .nd { color: #d2a8ff; }
.highlight .nf { color: #d2a8ff; }
.highlight .ni { color: #e5e7eb; }
.highlight .nn { color: #ffa657; }
.highlight .nt { color: #7ee787; }
.highlight .nv,
.highlight .vi,
.highlight .vg,
.highlight .vc,
.highlight .vs { color: #79c0ff; }
.highlight .m,
.highlight .mf,
.highlight .mi,
.highlight .mo,
.highlight .mh,
.highlight .mx { color: #79c0ff; }
.highlight .dl { color: #a5d6ff; }
.highlight .se { color: #79c0ff; }
.highlight .si { color: #a5d6ff; }
.highlight .sr { color: #7ee787; }
.highlight .ss { color: #a5d6ff; }
.highlight .err { color: #f85149; }
.highlight .gd { color: #ffa198; background: rgba(248, 81, 73, 0.1); }
.highlight .gi { color: #56d364; background: rgba(63, 185, 80, 0.1); }

/* --- Back to Top --- */
.back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all var(--transition-normal);
  z-index: 40;
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.back-to-top:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

/* --- Footer --- */
.site-footer {
  margin-left: var(--sidebar-width);
  padding: 24px 40px;
  border-top: 1px solid var(--border-default);
}

.footer-inner {
  max-width: var(--content-max-width);
  text-align: center;
}

.footer-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.footer-links {
  font-size: 12px;
  color: var(--text-secondary);
}

.footer-links a {
  color: var(--text-link);
}

.footer-sep {
  margin: 0 8px;
}

/* --- Sidebar Overlay (Mobile) --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 45;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.sidebar-overlay.active {
  opacity: 1;
}

/* --- Landing Page --- */
.landing-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 20px;
}

.hero {
  text-align: center;
  padding: 80px 0 60px;
}

.hero-title {
  font-size: 3em;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 16px;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.hero-subtitle {
  font-size: 1.25em;
  color: var(--text-secondary);
  margin-bottom: 40px;
  line-height: 1.5;
}

.hero-glow {
  display: inline-block;
  background: linear-gradient(135deg, #58a6ff, #bc8cff, #f78166);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.lang-cards {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 80px;
}

.lang-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 48px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 12px;
  text-decoration: none;
  transition: all var(--transition-normal);
  min-width: 200px;
}

.lang-card:hover {
  border-color: var(--accent-blue);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  text-decoration: none;
}

.lang-card-flag {
  font-size: 48px;
  line-height: 1;
}

.lang-card-label {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-heading);
}

.lang-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

/* --- Overview Section --- */
.overview-section {
  margin-bottom: 80px;
}

.section-title {
  font-size: 1.5em;
  font-weight: 600;
  color: var(--text-heading);
  text-align: center;
  margin-bottom: 40px;
}

.phase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.phase-card {
  padding: 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
  transition: border-color var(--transition-fast);
}

.phase-card:hover {
  border-color: var(--border-muted);
}

.phase-card-number {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-blue);
  margin-bottom: 6px;
}

.phase-card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 6px;
}

.phase-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* --- Stats Section --- */
.stats-section {
  margin-bottom: 80px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat-card {
  text-align: center;
  padding: 24px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 8px;
}

.stat-number {
  font-size: 2em;
  font-weight: 700;
  color: var(--accent-blue);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

/* --- Page Progress Bar --- */
.page-progress {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  z-index: 99;
}

.page-progress-bar {
  height: 100%;
  background: var(--accent-blue);
  width: 0;
  transition: width 50ms linear;
}

/* --- Mobile --- */
@media (max-width: 1200px) {
  .toc-sidebar {
    display: none;
  }

  .content-with-toc {
    display: block;
  }
}

@media (max-width: 768px) {
  .hamburger {
    display: flex;
  }

  .site-title-text {
    font-size: 14px;
  }

  .sidebar {
    transform: translateX(-100%);
    z-index: 55;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .main-content {
    margin-left: 0;
    padding: 24px 16px 80px;
  }

  .main-content.full-width {
    margin-left: 0;
  }

  .site-footer {
    margin-left: 0;
    padding: 24px 16px;
  }

  .hero {
    padding: 40px 0 40px;
  }

  .hero-title {
    font-size: 2em;
  }

  .hero-subtitle {
    font-size: 1em;
  }

  .lang-cards {
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-bottom: 48px;
  }

  .lang-card {
    width: 100%;
    max-width: 320px;
    padding: 24px;
  }

  .phase-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .back-to-top {
    bottom: 20px;
    right: 20px;
  }

  .content-body pre code {
    font-size: 12px;
  }

  .content-body table {
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stat-card {
    padding: 16px 8px;
  }

  .stat-number {
    font-size: 1.5em;
  }
}

/* --- Page Transition --- */
.main-content {
  animation: fadeIn 300ms ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Utility --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
