/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fdfdfc;
  --sidebar-bg: #f6f5f2;
  --text: #1a1a18;
  --text-secondary: #5e5e58;
  --text-muted: #8a8a82;
  --border: #e2e0d8;
  --link: #1a56db;
  --link-hover: #1040b0;
  --link-visited: #6b3fc4;
  --hover-bg: #eeede8;
  --code-bg: #f0efea;
  --callout-bg: #fefbec;
  --callout-border: #f0dc8c;
  --callout-accent: #d4a017;
  --max-width: 760px;
  --sidebar-width: 260px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", system-ui, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Cascadia Code", monospace;
}

html {
  font-size: 16px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 1.75rem 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar .logo {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.sidebar .logo a {
  color: var(--text);
  text-decoration: none;
}

.sidebar .logo a:hover {
  color: var(--link);
}

.sidebar .logo span {
  display: block;
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.sidebar nav ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar nav a {
  display: block;
  padding: 0.3rem 0.6rem;
  border-radius: 5px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background 0.1s;
}

.sidebar nav a:hover {
  background: var(--hover-bg);
}

.sidebar nav a.active {
  background: #e4e2d9;
  font-weight: 500;
  color: #000;
}

.sidebar .section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 1.75rem;
  margin-bottom: 0.35rem;
  padding-left: 0.6rem;
}

.sidebar .home-link {
  margin-bottom: 0.75rem;
}

/* ===== MAIN CONTENT ===== */
.main {
  flex: 1;
  max-width: var(--max-width);
  padding: 2.5rem 2.5rem 5rem;
  min-width: 0;
}

.main h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-bottom: 0.4rem;
  padding-bottom: 0.6rem;
  border-bottom: 2px solid var(--border);
}

.main h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
}

.main h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
}

.main p {
  margin-bottom: 1rem;
  max-width: 65ch;
}

.main ul:not(.steps):not(.related-links),
.main ol:not(.steps) {
  margin-bottom: 1rem;
  padding-left: 1.4rem;
}

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

.main strong {
  font-weight: 600;
}

.main a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.main a:hover {
  color: var(--link-hover);
  text-decoration-thickness: 2px;
}

.main a:visited {
  color: var(--link-visited);
}

/* ===== NUMBERED STEPS ===== */
.steps {
  list-style: none;
  padding-left: 0;
  counter-reset: step;
  margin: 1.25rem 0 1.5rem;
}

.steps li {
  counter-increment: step;
  position: relative;
  padding: 0.6rem 0 0.6rem 2.5rem;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}

.steps li:first-child {
  padding-top: 0;
}

.steps li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.6rem;
  width: 1.65rem;
  height: 1.65rem;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.steps li:first-child::before {
  top: 0;
}

/* ===== SUB-STEPS (for steps within steps) ===== */
.steps .sub-steps {
  list-style: none;
  padding-left: 0;
  margin-top: 0.4rem;
  counter-reset: sub-step;
}

.steps .sub-steps li {
  counter-increment: sub-step;
  border-bottom: none;
  padding: 0.2rem 0;
  font-size: 0.93rem;
}

.steps .sub-steps li::before {
  content: counter(sub-step, lower-alpha);
  width: 1.3rem;
  height: 1.3rem;
  font-size: 0.7rem;
  background: transparent;
  border: 1px solid var(--border);
}

/* ===== CODE / KEYBOARD ===== */
kbd {
  display: inline-block;
  background: #fff;
  border: 1px solid #c8c6bd;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.1rem 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.4;
}

code {
  background: var(--code-bg);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ===== TABLES ===== */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.5rem;
  font-size: 0.93rem;
}

thead th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  background: var(--sidebar-bg);
  font-size: 0.85rem;
}

tbody td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover td {
  background: #fafaf7;
}

/* ===== CALLOUT BOX ===== */
.callout {
  background: var(--callout-bg);
  border: 1px solid var(--callout-border);
  border-left: 4px solid var(--callout-accent);
  border-radius: 6px;
  padding: 0.9rem 1.15rem;
  margin: 1.25rem 0;
}

.callout h4 {
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.callout p {
  margin-bottom: 0;
  font-size: 0.93rem;
  color: #5e5800;
}

.callout code {
  background: #fff;
  border: 1px solid #e8d88a;
}

.callout.error {
  background: #fef5f5;
  border-color: #f5c6c6;
  border-left-color: #d94444;
}

.callout.error p {
  color: #7a1a1a;
}

.callout.tip {
  background: #f2faf5;
  border-color: #b8e0c5;
  border-left-color: #2d8a4e;
}

.callout.tip p {
  color: #1a4a2a;
}

/* ===== HIERARCHY DIAGRAM ===== */
.hierarchy {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.7;
  margin: 1rem 0;
  white-space: pre;
  overflow-x: auto;
}

/* ===== FIGURE / ILLUSTRATION ===== */
.figure {
  margin: 1.5rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.figure img {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}

.figure figcaption {
  padding: 0.65rem 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--sidebar-bg);
  line-height: 1.4;
}

.figure figcaption strong {
  color: var(--text-secondary);
}

/* ===== RELATED LINKS ===== */
.related {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--border);
}

.related h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.related-links {
  list-style: none;
  padding-left: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
}

.related-links a {
  font-size: 0.9rem;
}

/* ===== BREADCRUMB ===== */
.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

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

.breadcrumb span {
  margin: 0 0.35rem;
}

/* ===== HOMEPAGE GRID ===== */
.session-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.25rem 0 2rem;
}

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

.session-card:hover {
  border-color: #b0c4e8;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  text-decoration: none;
}

.session-card .tag {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  background: var(--sidebar-bg);
  padding: 0.15rem 0.55rem;
  border-radius: 4px;
  margin-bottom: 0.55rem;
  color: var(--text-secondary);
}

.session-card h3 {
  font-size: 1.05rem;
  margin: 0.3rem 0;
  color: var(--link);
}

.session-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0;
  line-height: 1.45;
}

.session-card.muted {
  opacity: 0.5;
  pointer-events: none;
  cursor: default;
  background: var(--sidebar-bg);
}

.session-card.muted h3 {
  color: var(--text-secondary);
}

/* ===== PAGE META ===== */
.page-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: -0.2rem;
  margin-bottom: 1.5rem;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
  }

  .sidebar .section-label {
    margin-top: 1rem;
  }

  .main {
    padding: 1.5rem 1.25rem 3rem;
  }

  .main h1 {
    font-size: 1.55rem;
  }

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

  .related-links {
    flex-direction: column;
    gap: 0.25rem;
  }
}
