/* ============================================================
   The Crack in the Wall — Design System
   Clean, typographic, content-first.
   Inspired by darioamodei.com and claude.com/blog
   ============================================================ */

/* --- Reset & base ------------------------------------------ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:           #fafaf8;
  --bg-sidebar:   #f3f2ef;
  --text:         #1a1a1a;
  --text-muted:   #6b6b6b;
  --text-faint:   #9a9a9a;
  --accent:       #8b4513;       /* earthy amber/saddle brown */
  --accent-light: #c4712a22;     /* translucent for highlights */
  --border:       #e2e0db;
  --badge-bg:     #fff3e0;
  --badge-text:   #8b4513;
  --warn-bg:      #fffbf0;
  --warn-border:  #f0c060;
  --warn-text:    #7a5800;

  --sidebar-width: 240px;
  --content-max:   680px;
  --content-pad:   2rem;

  --font-serif: 'Cardo', Georgia, serif;
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', 'Menlo', monospace;
}

html {
  font-size: 17px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* --- Layout ------------------------------------------------- */

.layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar ------------------------------------------------ */

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.2s ease;
}

.sidebar-header {
  padding: 1.5rem 1.25rem 1rem;
}

.site-title {
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.site-title-main {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.site-badge {
  display: inline-block;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1em 0.5em;
  border-radius: 3px;
  border: 1px solid #f0c060;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  width: fit-content;
}

/* --- Site logo (sidebar header) ---------------------------- */
.site-logo {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
}

/* --- Homepage logo (centred hero display) ------------------ */
.home-logo {
  display: block;
  width: 100%;
  max-width: 420px;
  height: auto;
  margin: 0 auto 0.5rem;
  border-radius: 8px;
}

.nav-list {
  list-style: none;
  padding: 0.75rem 0 1rem;
  flex: 1;
}

.nav-section-label {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 1rem 1.25rem 0.3rem;
}

.nav-link {
  display: block;
  padding: 0.3rem 1.25rem;
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--text);               /* black — top-level links */
  font-weight: 700;                 /* bold — top-level links */
  text-decoration: none;
  border-radius: 0;
  transition: color 0.15s;
}

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

.nav-link.active {
  color: var(--accent);
  font-weight: 700;
}

.nav-link.nav-sub {
  padding-left: 2rem;
  font-size: 0.94rem;
  color: var(--text-muted);         /* grey — sub-page links */
  font-weight: 400;                 /* regular weight */
}

.nav-link.nav-sub.active {
  padding-left: 2rem;
  color: var(--accent);
  font-weight: 400;
}


/* --- Mobile nav toggle ------------------------------------- */

.nav-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
}

.nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

/* --- Main content ------------------------------------------ */

.content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  padding: 3.5rem var(--content-pad) 6rem;
}

.prose {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* --- Page header ------------------------------------------- */

.page-header {
  margin-bottom: 2rem;
  padding-bottom: 0;
}


.page-header h1 {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
}

.subtitle {
  margin-top: 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text-muted);
  font-style: italic;
}

/* --- Prose typography -------------------------------------- */

.prose h1 { font-size: 2rem; margin-top: 3rem; }
.prose h2 { font-size: 1.45rem; margin-top: 2.5rem; }
.prose h3 { font-size: 1.15rem; margin-top: 2rem; }
.prose h4 { font-size: 1rem; margin-top: 1.5rem; }

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 0.6rem;
}

/* Don't double-margin after .page-header h1 */
.page-header + .prose h1:first-child,
article.prose > h1:first-child {
  display: none;
}

.prose h2 {
  padding-bottom: 0;
}

.prose p {
  margin-bottom: 1.1rem;
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.prose a:hover {
  text-decoration-thickness: 2px;
}

.prose strong {
  font-weight: 700;
  color: var(--text);
}

.prose em {
  font-style: italic;
}

.prose ul, .prose ol {
  margin: 0.75rem 0 1.1rem 1.5rem;
}

.prose li {
  margin-bottom: 0.3rem;
}

.prose li > ul, .prose li > ol {
  margin-top: 0.3rem;
  margin-bottom: 0.3rem;
}

.prose blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.75rem 1.25rem;
  background: var(--accent-light);
  font-style: italic;
  color: var(--text-muted);
}

.prose blockquote p:last-child {
  margin-bottom: 0;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.82em;
  background: #f0ede8;
  padding: 0.15em 0.4em;
  border-radius: 3px;
  color: #5c3317;
}

.prose pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 1.25rem 1.5rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-family: var(--font-mono);
  font-size: 0.82em;
  line-height: 1.6;
}

.prose pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.prose hr {
  border: none;
  margin: 3rem 0;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.88rem;
}

.prose th {
  text-align: left;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  padding: 0.5rem 0.75rem;
}

.prose td {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  vertical-align: top;
}

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

/* --- Special callouts -------------------------------------- */

.callout {
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  line-height: 1.6;
}

.callout-info {
  background: #f0f7ff;
  border: 1px solid #b8d4f0;
  color: #1a3a5c;
}

.callout-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
}

.callout-tip {
  background: #f0fff4;
  border: 1px solid #86efac;
  color: #1a4a2e;
}

/* --- Homepage cards ---------------------------------------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin: 2rem 0;
}

.card {
  display: block;
  padding: 1.25rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}

.card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(139,69,19,0.1);
  transform: translateY(-1px);
}

.card-icon {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  display: block;
}

.card-title {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
  color: var(--text);
}

.card-desc {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* --- Stat block (for species/classes) ---------------------- */

.stat-block {
  background: #fff;
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 6px;
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  font-family: var(--font-sans);
  font-size: 0.88rem;
}

.stat-block h4 {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}

.stat-row {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

/* --- Level features list ----------------------------------- */

.level-list {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
}

.level-item {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.75rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.level-item:last-child {
  border-bottom: none;
}

.level-num {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 0.1rem;
}

.level-content strong {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  margin-bottom: 0.2rem;
}

.level-content p {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

/* --- Species images ---------------------------------------- */

/* Hero image — cinematic full-content-area strip.
   The image lives inside .prose (max-width:680px, margin:auto) inside
   .content (margin-left:240px, padding:2rem on each side).
   Math: from inside .prose the element's left is at viewport-x = sidebar/2 + viewport/2 - 340.
   To shift it to sidebar-width from viewport left: margin-left = calc(-50vw + sidebar/2 + 50%).
   Width spans from sidebar to viewport right edge. */
/* Both hero and role images share the same full-width treatment.
   Natural aspect ratio is preserved (no max-height crop). */
.species-hero,
.role-image {
  display: block;
  margin-left: calc(-50vw + var(--sidebar-width) / 2 + 50%);
  width: calc(100vw - var(--sidebar-width));
  height: auto;
  border-radius: 0;
  box-shadow: none;
}

.species-hero {
  margin-top: -3.5rem;   /* pull up flush to remove content top padding */
  margin-bottom: 2rem;
}

.role-image {
  margin-top: 3rem;
  margin-bottom: 3rem;
}

/* --- Responsive -------------------------------------------- */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }

  .nav-toggle {
    display: flex;
  }

  .content {
    margin-left: 0;
    padding: 1.25rem 1.25rem 4rem;
    padding-top: 4rem;
  }

  .prose h1 { font-size: 1.6rem; }
  .prose h2 { font-size: 1.25rem; }

  /* On tablet/mobile the sidebar is off-screen — both image types fill full viewport */
  .species-hero,
  .role-image {
    margin-left: calc(-50vw + 50%);
    width: 100vw;
  }

  .species-hero {
    margin-top: -4rem;
  }
}

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

/* --- Nav accordion ----------------------------------------- */

/* Top-level accordion link: flex so chevron can be right-aligned */
.nav-link-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Chevron indicator — CSS border-triangle, rotates open/closed */
.nav-chevron {
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--text-faint);
  border-bottom: 1.5px solid var(--text-faint);
  transform: rotate(-45deg);   /* points right = collapsed */
  transition: transform 0.2s ease, border-color 0.15s;
  flex-shrink: 0;
  margin-left: 0.25rem;
}

.nav-accordion-section.open > .nav-link-top .nav-chevron {
  transform: rotate(45deg);    /* points down = expanded */
}

.nav-link-top.active .nav-chevron {
  border-color: var(--accent);
}

/* Sub-item list — collapsed by default, animated via max-height */
.nav-sub-list {
  list-style: none;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
/* JS sets max-height to scrollHeight inline when open */

/* --- Print ------------------------------------------------- */

@media print {
  .sidebar, .nav-toggle { display: none; }
  .content { margin-left: 0; }
}

/* --- Sidebar footer & theme toggle ------------------------- */

.sidebar-footer {
  padding: 1rem 1.25rem 1.5rem;
  margin-top: auto;
}

/* Theme switch */
.theme-switch {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  color: var(--text-muted);
  user-select: none;
}

.theme-switch-icon {
  font-size: 1rem;
  line-height: 1;
  width: 1.1rem;
  text-align: center;
  flex-shrink: 0;
}

/* Hidden native checkbox */
.theme-switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

/* Track */
.theme-switch-track {
  position: relative;
  display: inline-block;
  width: 2.2rem;
  height: 1.2rem;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.2s;
  flex-shrink: 0;
}

/* Thumb */
.theme-switch-thumb {
  position: absolute;
  top: 0.15rem;
  left: 0.15rem;
  width: 0.9rem;
  height: 0.9rem;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
  pointer-events: none;
}

.theme-switch-input:checked + .theme-switch-thumb {
  transform: translateX(1rem);
}

/* Active (dark) state */
.theme-switch-track:has(.theme-switch-input:checked) {
  background: var(--accent);
}

.theme-switch-track:has(.theme-switch-input:checked) .theme-switch-thumb {
  background: #fff;
}

/* --- Dark mode -------------------------------------------- */

html.dark {
  --bg:           #181816;
  --text:         #e8e6e1;
  --text-muted:   #9a9890;
  --text-faint:   #636260;
  --accent:       #c4783a;
  --accent-light: #c4712a33;
  --border:       #2e2c28;
  --badge-bg:     #2e2318;
  --badge-text:   #c4783a;
  --warn-bg:      #2a2010;
  --warn-border:  #6b5520;
  --warn-text:    #c4a060;
}

html.dark .card {
  background: #1e1c19;
}

html.dark .stat-block {
  background: #1e1c19;
}

html.dark .prose code {
  background: #2a2826;
  color: #c4a080;
}

html.dark .prose pre {
  background: #111110;
}
