/* ============================================
   RedGames Documentation - Styles
   ============================================ */

/* --- CSS Variables / Theming --- */
:root {
  /* Dark theme (default) */
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-code: #0d1117;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;

  --accent-primary: #e83d3d;
  --accent-primary-hover: #ff5252;
  --accent-secondary: #238636;
  --accent-tertiary: #1f6feb;

  --border-primary: #30363d;
  --border-secondary: #21262d;

  --link-color: #58a6ff;
  --link-hover: #79b8ff;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;

  --header-height: 64px;
  --sidebar-width: 260px;
  --content-max-width: 900px;
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eaeef2;
  --bg-code: #f6f8fa;

  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-muted: #8c959f;

  --accent-primary: #cf222e;
  --accent-primary-hover: #a40e26;

  --border-primary: #d0d7de;
  --border-secondary: #e6e8eb;

  --link-color: #0969da;
  --link-hover: #0550ae;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.16);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 24px);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 600;
  line-height: 1.25;
}

h2 { font-size: 1.75rem; }
h3 { font-size: 1.35rem; }
h4 { font-size: 1.1rem; }

p {
  margin: 0 0 1rem;
}

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

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

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

li {
  margin: 0.35rem 0;
}

/* --- Code --- */
code, pre {
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  font-size: 0.875rem;
}

code {
  background: var(--bg-tertiary);
  padding: 0.2em 0.45em;
  border-radius: var(--radius-sm);
  font-size: 0.85em;
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
  position: relative;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
}

/* Copy button for code blocks */
.code-wrapper {
  position: relative;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 4px;
}

.code-wrapper:hover .copy-btn {
  opacity: 1;
}

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

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

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
}

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

th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

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

/* --- Header --- */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(22, 27, 34, 0.85);
}

[data-theme="light"] .header {
  background: rgba(255, 255, 255, 0.85);
}

.header-inner {
  max-width: 1400px;
  height: 100%;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-spacer {
  flex: 1;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
}

.logo:hover {
  text-decoration: none;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent-primary), #ff6b6b);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

/* Search */
.search-wrapper {
  position: relative;
  width: 240px;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  height: 40px;
  padding: 0 1rem 0 2.5rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  box-sizing: border-box;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(232, 61, 61, 0.15);
}

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

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-results-count {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-left: 0.5rem;
  white-space: nowrap;
}

.version-badge {
  padding: 0.35rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

.nav-toggle {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* --- Layout --- */
.layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  padding-top: var(--header-height);
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: max(0px, calc((100vw - 1400px) / 2));
  width: var(--sidebar-width);
  height: calc(100vh - var(--header-height));
  padding: 1.5rem 1rem 2rem 1.5rem;
  overflow-y: auto;
  border-right: 1px solid var(--border-primary);
  background: var(--bg-primary);
}

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

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

.nav-group {
  margin-bottom: 1.5rem;
}

.nav-group-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
}

.nav-link {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.nav-link:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-link.active {
  background: rgba(232, 61, 61, 0.1);
  color: var(--accent-primary);
  font-weight: 500;
}

/* Main content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 2rem 2.5rem 4rem;
  max-width: calc(100% - var(--sidebar-width));
  min-height: calc(100vh - var(--header-height));
}

.content-wrapper {
  max-width: var(--content-max-width);
}

/* --- Cards/Sections --- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  transition: border-color var(--transition-fast);
}

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

.card:target {
  animation: highlight 2s ease-out;
}

@keyframes highlight {
  0% {
    box-shadow: 0 0 0 3px rgba(232, 61, 61, 0.4);
  }
  100% {
    box-shadow: none;
  }
}

.card h2 {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card h3 {
  margin: 1.75rem 0 0.75rem;
  color: var(--accent-primary);
}

.card h4 {
  margin: 1.25rem 0 0.5rem;
  color: var(--text-primary);
}

/* --- Grid layouts --- */
.grid {
  display: grid;
  gap: 1.25rem;
}

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

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

/* --- Callouts --- */
.callout {
  padding: 1rem 1.25rem;
  margin: 1rem 0;
  border-radius: var(--radius-md);
  border-left: 4px solid;
}

.callout-tip {
  background: rgba(35, 134, 54, 0.1);
  border-color: var(--accent-secondary);
}

.callout-warning {
  background: rgba(227, 179, 65, 0.1);
  border-color: #e3b341;
}

.callout-info {
  background: rgba(31, 111, 235, 0.1);
  border-color: var(--accent-tertiary);
}

.callout strong {
  display: block;
  margin-bottom: 0.25rem;
}

/* --- Back to top --- */
.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: all var(--transition-normal);
  z-index: 50;
}

.back-to-top:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-2px);
}

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

.back-to-top svg {
  width: 24px;
  height: 24px;
}

/* --- Footer --- */
.footer {
  padding: 1.5rem 2.5rem;
  margin-left: var(--sidebar-width);
  border-top: 1px solid var(--border-primary);
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.last-updated {
  font-size: 0.8rem;
}

/* --- Search highlighting --- */
.search-highlight {
  background: rgba(232, 61, 61, 0.25);
  padding: 0.1em 0.2em;
  border-radius: 3px;
}

.card.search-hidden {
  display: none;
}

/* --- Responsive --- */
@media (max-width: 1100px) {
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 900px) {
  :root {
    --sidebar-width: 0px;
  }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    width: 100%;
    transform: translateX(-100%);
    z-index: 90;
    transition: transform var(--transition-normal);
    border-right: none;
    box-shadow: var(--shadow-lg);
  }

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

  .nav-toggle {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    max-width: 100%;
    padding: 1.5rem;
  }

  .footer {
    margin-left: 0;
    padding: 1.5rem;
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }

  .grid-2, .grid-3 {
    grid-template-columns: 1fr;
  }

  .search-wrapper {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: 100%;
    padding: 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
  }

  .search-wrapper.open {
    display: block;
  }

  .header-spacer {
    display: none;
  }

  .version-badge {
    display: none;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 15px;
  }

  .header-inner {
    padding: 0 1rem;
  }

  .card {
    padding: 1.25rem;
  }

  .card h2 {
    font-size: 1.4rem;
  }

  pre {
    font-size: 0.8rem;
    padding: 0.85rem;
  }

  table {
    font-size: 0.85rem;
  }

  th, td {
    padding: 0.5rem 0.65rem;
  }
}

/* --- Print styles --- */
@media print {
  .header,
  .sidebar,
  .back-to-top,
  .theme-toggle,
  .nav-toggle,
  .copy-btn,
  .footer {
    display: none !important;
  }

  .main-content {
    margin-left: 0;
    padding: 0;
    max-width: 100%;
  }

  .layout {
    padding-top: 0;
  }

  .card {
    break-inside: avoid;
    border: 1px solid #ddd;
    box-shadow: none;
    margin-bottom: 1rem;
  }

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

  pre {
    white-space: pre-wrap;
    word-wrap: break-word;
  }

  body {
    background: white;
    color: black;
  }
}

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

.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}
