:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --accent-secondary: #C4A0FF;
  --accent-hover: #B88FFF;
  --accent: #6DB8FF;
  --border: #30363d;
  --code-bg: #161b22;
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  display: flex;
}

.sidebar {
  width: clamp(240px, 20vw, 280px);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: clamp(1rem, 2vw, 1.5rem) clamp(0.75rem, 1.5vw, 1rem);
  position: fixed;
  height: 100vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

@media (max-width: 40em) {
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 80vh;
  }
}

.sidebar::-webkit-scrollbar {
  width: 6px;
}

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

.sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--accent-secondary);
  font-size: 1.1rem;
  font-weight: 600;
}

.sidebar-logo img {
  height: 28px;
  margin-right: 0.6rem;
}

.sidebar nav a {
  display: block;
  padding: 0.6rem 0.75rem;
  margin: 0.15rem 0;
  border-radius: 6px;
  font-weight: 400;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.sidebar nav a:hover {
  background: var(--bg-tertiary);
  color: var(--accent);
  text-decoration: none;
  transform: translateX(2px);
}

.nav-section {
  margin-bottom: 1rem;
}

.nav-section.hide-on-index {
  display: none;
}

.nav-toggle {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem !important;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.nav-toggle:hover {
  background: var(--accent-secondary);
  color: var(--text-primary);
}

.nav-submenu {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding-left: 0.5rem;
  margin-top: 0.3rem;
}

.nav-submenu.open {
  max-height: 60vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

@media (max-width: 40em) {
  .nav-submenu.open {
    max-height: 50vh;
  }
}

.nav-submenu.open::-webkit-scrollbar {
  width: 4px;
}

.nav-submenu.open::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.nav-submenu a {
  font-size: 0.85rem;
  font-weight: 400;
  border: none;
  padding: 0.4rem 0.6rem;
  margin: 0.1rem 0;
  color: var(--text-secondary);
}

.nav-submenu a:hover {
  color: var(--accent);
}

.nav-submenu a.h1 { padding-left: 0.6rem; font-weight: 500; font-size: 0.88rem; }
.nav-submenu a.h2 { padding-left: 1rem; }
.nav-submenu a.h3 { padding-left: 1.4rem; font-size: 0.82rem; }
.nav-submenu a.h4 { padding-left: 1.8rem; font-size: 0.8rem; }
.nav-submenu a.h5 { padding-left: 2.2rem; font-size: 0.8rem; }
.nav-submenu a.h6 { padding-left: 2.6rem; font-size: 0.8rem; }

.nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: var(--bg-tertiary);
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-bottom: 0.3rem;
  cursor: pointer;
  user-select: none;
}

.nav-header:hover {
  background: var(--accent-secondary);
}

.main-content {
  margin-left: clamp(240px, 20vw, 280px);
  flex: 1;
  padding: clamp(1rem, 3vw, 2rem);
  min-width: 0;
}

@media (max-width: 40em) {
  .main-content {
    margin-left: 0;
  }
}

.content-wrapper {
  width: 100%;
  max-width: clamp(300px, 90vw, 1400px);
  margin: 0 auto;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--accent-secondary);
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  line-height: 1.3;
  scroll-margin-top: 2rem;
}

h1:first-child,
h2:first-child,
h3:first-child {
  margin-top: 0;
}

h1 { font-size: clamp(1.75rem, 4vw + 1rem, 2.5rem); }
h2 { font-size: clamp(1.5rem, 3vw + 1rem, 2rem); }
h3 { font-size: clamp(1.25rem, 2vw + 1rem, 1.5rem); }

a {
  color: var(--accent);
  text-decoration: none;
}

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

code {
  background: var(--code-bg);
  padding: 3px 6px;
  border-radius: 4px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.9em;
  color: var(--accent);
  border: 1px solid var(--border);
  word-break: break-all;
}

pre {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  border: 1px solid var(--border);
}

pre code {
  background: none;
  padding: 0;
}

blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.75rem 1.25rem;
  background: var(--bg-secondary);
  border-radius: 0 6px 6px 0;
  font-style: italic;
  color: var(--text-secondary);
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  background: var(--bg-secondary);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

th, td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--accent-secondary);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover {
  background: var(--bg-tertiary);
}

.nav {
  background: var(--bg-secondary);
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.nav a {
  margin-right: 2rem;
  font-weight: 500;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
  gap: clamp(0.75rem, 2vw, 1rem);
  margin: clamp(1rem, 3vw, 2rem) 0;
}

.game-card {
  background: var(--bg-secondary);
  padding: 1.25rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.game-card img {
  width: clamp(60px, 15vw, 80px);
  height: clamp(80px, 20vw, 100px);
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  border: 2px solid var(--border);
}

@media (max-width: 36em) {
  .game-card {
    flex-direction: column;
    text-align: center;
  }
}

.game-card-content {
  flex: 1;
}

.game-card-content h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.1rem;
}

.game-card-content p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.game-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-secondary);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

.toc {
  background: var(--bg-secondary);
  padding: 1.5rem;
  border-radius: 8px;
  border: 1px solid var(--accent-secondary);
  margin: 2rem 0;
}

.toc ul {
  margin: 0;
  padding-left: 1.5rem;
}

.highlight-box {
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 1rem;
  margin: 1rem 0;
}

.main-content img {
  display: block;
  margin: 1rem auto;
  max-width: 60%;
  height: auto;
}

.main-content img.no-center {
  margin-left: 0;
  margin-right: 0;
}

@media (max-width: 40em) {
  body {
    flex-direction: column;
  }
}