/* Shared styles for the React Beginner Book */
:root {
  --bg: #ffffff;
  --surface: #f6f7f9;
  --surface-2: #eef0f3;
  --border: #e3e5e8;
  --text: #2b2f36;
  --muted: #6b7280;
  --heading: #0f1115;
  --accent: #087ea4;
  --accent-soft: #e6f4f8;
  --code-bg: #f5f6f8;
  --code-text: #24292f;
  --code-comment: #6e7781;
  --tip-bg: #ecfdf3;
  --tip-border: #16a34a;
  --warn-bg: #fff7e6;
  --warn-border: #e5a00d;
  --bad-bg: #fef2f2;
  --bad-border: #dc2626;
  --sidebar-w: 270px;
}
@media (prefers-color-scheme: dark) {
  /* no theme chosen yet (scripts off): follow the OS */
  :root:not([data-theme]) {
    --bg: #16181d;
    --surface: #1e2128;
    --surface-2: #262a33;
    --border: #2e323b;
    --text: #d1d5db;
    --muted: #9ca3af;
    --heading: #f3f4f6;
    --accent: #58c4dc;
    --accent-soft: #1b2c33;
    --code-bg: #1c1f26;
    --code-text: #e5e7eb;
    --code-comment: #8b949e;
    --tip-bg: #13261b;
    --tip-border: #22c55e;
    --warn-bg: #2a2416;
    --warn-border: #c9922a;
    --bad-bg: #2b1717;
    --bad-border: #ef4444;
  }
}
/* the theme chosen in the site header (shared/site.js) */
:root[data-theme="dark"] {
  --bg: #16181d;
  --surface: #1e2128;
  --surface-2: #262a33;
  --border: #2e323b;
  --text: #d1d5db;
  --muted: #9ca3af;
  --heading: #f3f4f6;
  --accent: #58c4dc;
  --accent-soft: #1b2c33;
  --code-bg: #1c1f26;
  --code-text: #e5e7eb;
  --code-comment: #8b949e;
  --tip-bg: #13261b;
  --tip-border: #22c55e;
  --warn-bg: #2a2416;
  --warn-border: #c9922a;
  --bad-bg: #2b1717;
  --bad-border: #ef4444;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3, h4 { color: var(--heading); line-height: 1.25; }
h1 { font-size: 2.2rem; margin: 0 0 8px; }
h2 { font-size: 1.55rem; margin: 56px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
h3 { font-size: 1.18rem; margin: 32px 0 8px; }
p, ul, ol { margin: 10px 0; }
li { margin: 4px 0; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  font-size: 0.92rem;
}
#sidebar .all-courses { display: inline-block; margin-bottom: 12px; padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border, #ccc); color: var(--accent); font-weight: 600; font-size: 0.85rem; text-decoration: none; }
#sidebar .all-courses:hover { background: var(--surface-2); }
#sidebar .book-title { display: block; font-weight: 700; color: var(--heading); text-decoration: none; font-size: 1.05rem; margin-bottom: 12px; }
#sidebar .part { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; margin: 16px 0 4px; }
#sidebar ol { list-style: none; padding: 0; margin: 0; }
#sidebar a.ch { display: block; padding: 4px 8px; border-radius: 6px; color: var(--text); text-decoration: none; }
#sidebar a.ch:hover { background: var(--surface-2); }
#sidebar a.ch.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#sidebar .n { display: inline-block; width: 22px; color: var(--muted); }
main { flex: 1; min-width: 0; max-width: 860px; margin: 0 auto; padding: 40px 32px 80px; }

@media (max-width: 860px) {
  .layout { display: block; }
  #sidebar { position: static; width: auto; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  #sidebar details:not([open]) ol, #sidebar details:not([open]) .part { display: none; }
  main { padding: 24px 16px 64px; }
  h1 { font-size: 1.8rem; }
}
#sidebar summary { cursor: pointer; color: var(--heading); font-weight: 600; }
@media (min-width: 861px) { #sidebar summary { display: none; } }

/* Chapter header */
.eyebrow { color: var(--accent); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8rem; margin: 0; }
.lead { font-size: 1.12rem; color: var(--muted); margin-top: 4px; }
.goals { background: var(--accent-soft); border-radius: 12px; padding: 12px 20px; margin: 20px 0; }
.goals ul { margin: 6px 0; }

/* Code */
code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 0 5px;
  border-radius: 4px;
}
figure.code { margin: 16px 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--code-bg); }
figure.code .code-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font: 0.8rem ui-monospace, Menlo, monospace; color: var(--muted);
}
figure.code button {
  font: inherit; color: var(--muted); background: none; border: 1px solid var(--border);
  border-radius: 6px; padding: 1px 8px; cursor: pointer;
}
figure.code button:hover { color: var(--accent); border-color: var(--accent); }
figure.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; line-height: 1.55; }
figure.code pre code { background: none; border: 0; padding: 0; font-size: 0.86rem; color: var(--code-text); }
.tok-c { color: var(--code-comment); font-style: italic; }

/* Callouts */
.callout { border-left: 4px solid; border-radius: 8px; padding: 10px 16px; margin: 18px 0; }
.callout > strong:first-child { display: block; margin-bottom: 2px; }
.tip { background: var(--tip-bg); border-color: var(--tip-border); }
.note { background: var(--accent-soft); border-color: var(--accent); }
.pitfall { background: var(--warn-bg); border-color: var(--warn-border); }
.bad { background: var(--bad-bg); border-color: var(--bad-border); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 16px 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface); color: var(--heading); }

/* Recap & exercises */
.recap { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px 20px 12px; margin-top: 40px; }
.exercise { border: 2px dashed var(--accent); border-radius: 12px; padding: 4px 20px 14px; margin: 20px 0; }
.exercise h3 { margin-top: 14px; }
.lvl { font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; margin-left: 8px; vertical-align: middle; border: 1px solid var(--border); color: var(--muted); }
details.solution { margin-top: 10px; }
details.solution summary { cursor: pointer; color: var(--accent); font-weight: 600; }

/* Pager */
#pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--border); }
#pager a {
  flex: 1; max-width: 48%; text-decoration: none; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; color: var(--heading);
}
#pager a:hover { border-color: var(--accent); }
#pager a.next { text-align: right; margin-left: auto; }
#pager small { display: block; color: var(--muted); }

/* Index page cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin: 16px 0; }
.card { display: block; text-decoration: none; color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: var(--surface); }
.card:hover { border-color: var(--accent); }
.card .n { color: var(--accent); font-weight: 700; font-size: 0.8rem; }
.card h3 { margin: 2px 0 4px; font-size: 1.05rem; }
.card p { margin: 0; font-size: 0.9rem; color: var(--muted); }

.docs-links { font-size: 0.92rem; color: var(--muted); }

/* long URLs and identifiers in inline code wrap on narrow screens */
:not(pre) > code { overflow-wrap: anywhere; }
