/* Color scheme and variables */
:root {
  --bg-color: #fafafa;
  --surface-color: #ffffff;
  --text-color: #1a1a1a;
  --text-secondary: #666666;
  --text-muted: #999999;
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #dc2626;
  --accent-color: #059669;
  --border-color: #e5e7eb;
  --border-light: #f3f4f6;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --code-bg: #f8fafc;
  --code-color: #374151;
  --code-border: #e2e8f0;
  --heading-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --body-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono-font: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --text-color: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --border-light: #1e293b;
    --code-bg: #1e293b;
    --code-color: #e2e8f0;
    --code-border: #475569;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
  }
}

/* Base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

/* Container */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--heading-font);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.025em;
  color: var(--text-color);
}

h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-align: center;
  letter-spacing: -0.05em;
}

h2 {
  font-size: 2rem;
  margin-top: 4rem;
  margin-bottom: 2rem;
  position: relative;
  padding-bottom: 0.75rem;
}

h2::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 48px;
  height: 3px;
  background-color: var(--primary-color);
  border-radius: 2px;
}

h3 {
  font-size: 1.5rem;
  margin-top: 2.5rem;
  margin-bottom: 1.25rem;
  font-weight: 600;
}

h4 {
  font-size: 1.25rem;
  margin-top: 2rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

p {
  margin-bottom: 1.25rem;
  color: var(--text-color);
  line-height: 1.7;
}

.subtitle {
  font-size: 1.125rem;
  color: var(--text-secondary);
  font-weight: 400;
  text-align: center;
  margin-bottom: 2.5rem;
  line-height: 1.6;
}

/* Header */
header {
  position: relative;
  text-align: center;
  margin-bottom: 3rem;
}

/* Navigation */
nav {
  margin: 2.5rem 0 3rem 0;
}

nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  list-style-type: none;
  justify-content: center;
  padding: 0;
}

nav ul li {
  margin: 0;
}

nav ul li a {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.625rem 1.25rem;
  border-radius: 50px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid var(--border-color);
  background-color: var(--surface-color);
  display: inline-block;
  white-space: nowrap;
}

nav ul li a:hover,
nav ul li a:focus {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}

.section-nav {
  list-style: none;
  display: flex;
  gap: 1rem;
  padding: 0;
  margin: 0;
  justify-content: center;
  flex-wrap: wrap;
}

#pre-security-nav {
  padding: 2rem 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 3rem;
}

/* Links */
a {
  color: var(--primary-color);
  text-decoration: none;
  transition: all 0.2s ease;
}

a:hover,
a:focus {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Content sections */
section {
  margin-bottom: 4rem;
}

section:last-child {
  margin-bottom: 0;
}

/* Lists */
ul, ol {
  margin-bottom: 1.5rem;
  padding-left: 1.75rem;
}

ul li, ol li {
  margin-bottom: 0.75rem;
  line-height: 1.7;
  color: var(--text-color);
}

ul ul, ol ol, ul ol, ol ul {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.bullet-list {
  margin-bottom: 2rem;
}

.bullet-list ul {
  list-style-type: none;
  display: grid;
  gap: 1rem;
  padding-left: 0;
}

.bullet-list li {
  padding: 1.5rem;
  background-color: var(--surface-color);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  margin-bottom: 0;
}

.bullet-list li:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-color);
}

/* Code styling */
code {
  font-family: var(--mono-font);
  background-color: var(--code-bg);
  color: var(--code-color);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.875em;
  border: 1px solid var(--code-border);
  font-weight: 500;
  word-wrap: break-word;
}

pre {
  background-color: var(--code-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  border: 1px solid var(--code-border);
  box-shadow: var(--shadow-sm);
  line-height: 1.6;
}

pre code {
  padding: 0;
  background-color: transparent;
  color: var(--code-color);
  border: none;
  font-size: 0.875rem;
  word-wrap: normal;
}

/* CTF Walkthrough specific styles */
article {
  margin-bottom: 3rem;
}

.challenge-info {
  background-color: var(--surface-color);
  padding: 2rem;
  border-radius: var(--radius-lg);
  margin-bottom: 3rem;
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary-color);
  box-shadow: var(--shadow-sm);
}

.challenge-info p {
  margin-bottom: 0;
  line-height: 1.7;
}

.challenge-info > div {
  margin-bottom: 1rem;
}

.level-solution {
  margin-bottom: 3rem;
  padding-bottom: 3rem;
  border-bottom: 1px solid var(--border-light);
}

.level-solution:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.level-solution h3 {
  margin-top: 0;
}

.level-solution > p:first-of-type {
  margin-top: 1rem;
}

.flag-container {
  display: block;
  padding: 1rem 1.5rem;
  background-color: var(--surface-color);
  border-radius: var(--radius);
  margin: 1.5rem 0;
  font-family: var(--mono-font);
  border: 2px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  font-size: 0.875rem;
  line-height: 1.6;
}

.flag-container strong {
  color: var(--accent-color);
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}

.flag-container strong:last-child {
  margin-bottom: 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  padding: 0.5rem 0;
  transition: all 0.2s ease;
}

.back-link:hover {
  color: var(--primary-color);
  text-decoration: none;
}

.back-link::before {
  content: "←";
  margin-right: 0.5rem;
  font-size: 1.125rem;
}

.backtotop {
  display: inline-block;
  margin-top: 2rem;
  color: var(--primary-color);
  font-weight: 500;
  transition: all 0.2s ease;
}

.backtotop:hover {
  color: var(--primary-hover);
}

/* Footer */
footer {
  margin-top: 5rem;
  padding: 2.5rem 0 2rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  border-top: 1px solid var(--border-color);
}

footer p {
  margin-bottom: 0.5rem;
}

footer a {
  color: var(--text-secondary);
  font-weight: 500;
}

footer a:hover {
  color: var(--primary-color);
}

/* Utility classes */
.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-muted);
}

.mt-4 {
  margin-top: 2rem;
}

.mb-4 {
  margin-bottom: 2rem;
}

/* Enhanced interactive elements */
button, .btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  font-family: var(--body-font);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  font-size: 1rem;
}

button:hover, .btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

button:active, .btn:active {
  transform: translateY(0);
}

/* Focus states for accessibility */
a:focus,
button:focus,
nav ul li a:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Media queries */
@media (max-width: 768px) {
  body {
    font-size: 15px;
  }
  
  h1 {
    font-size: 2rem;
  }
  
  h2 {
    font-size: 1.625rem;
    margin-top: 3rem;
    margin-bottom: 1.5rem;
  }

  h3 {
    font-size: 1.375rem;
    margin-top: 2rem;
  }
  
  .container {
    padding: 2rem 1.5rem;
  }

  .challenge-info {
    padding: 1.5rem;
    margin-bottom: 2.5rem;
  }

  nav {
    margin: 2rem 0 2.5rem 0;
  }

  #pre-security-nav {
    padding: 1.5rem 0;
    margin-bottom: 2.5rem;
  }

  .level-solution {
    margin-bottom: 2.5rem;
    padding-bottom: 2.5rem;
  }

  pre {
    padding: 1.25rem;
    margin: 1.25rem 0;
  }

  .flag-container {
    padding: 0.875rem 1.25rem;
    margin: 1.25rem 0;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  h1 {
    font-size: 1.75rem;
  }
  
  h2 {
    font-size: 1.5rem;
    margin-top: 2.5rem;
    margin-bottom: 1.25rem;
  }

  h3 {
    font-size: 1.25rem;
    margin-top: 1.75rem;
  }
  
  .container {
    padding: 1.5rem 1rem;
  }
  
  nav ul {
    gap: 0.5rem;
  }

  nav ul li a {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
  }
  
  .section-nav {
    gap: 0.5rem;
  }
  
  .challenge-info {
    padding: 1.25rem;
    margin-bottom: 2rem;
  }

  pre {
    padding: 1rem;
    font-size: 0.8125rem;
    margin: 1rem 0;
  }

  code {
    font-size: 0.8125em;
    padding: 0.2rem 0.4rem;
  }

  .flag-container {
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    margin: 1rem 0;
  }

  .level-solution {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
  }

  ul, ol {
    padding-left: 1.5rem;
  }

  ul li, ol li {
    margin-bottom: 0.5rem;
  }
}

.pagination {
  display: flex;
  justify-content: center;
  margin: 2em 0;
  gap: 6px;
}

.pagination button:hover {
  background: #eaeaea;
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Print styles */
@media print {
  body {
    background-color: white;
    color: black;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }

  nav, .back-link, footer {
    display: none;
  }

  a {
    color: black;
    text-decoration: underline;
  }

  pre, code {
    border: 1px solid #ddd;
    background-color: #f5f5f5;
  }
}