/* Shared stylesheet for all concept-explainer pages. Self-contained: no external
   fonts/images/CDNs, so pages work fully offline and are safe to publish as static
   files (e.g. GitHub Pages) as-is. Respects the OS/browser light-dark preference. */

:root {
  --color-bg: #fdfcf9;
  --color-text: #24272b;
  --color-muted: #5b6167;
  --color-border: #e2ddd2;

  --color-concrete: #a85a19;
  --color-concrete-bg: #fdf1e3;
  --color-pictorial: #1f5a99;
  --color-pictorial-bg: #e9f2fb;
  --color-symbolic: #62368f;
  --color-symbolic-bg: #f2ecf8;
  --color-example: #2a7048;
  --color-example-bg: #eaf6ee;
  --color-anchor: #a3780a;
  --color-anchor-bg: #fdf7e3;
  --color-parent: #4a4f57;
  --color-parent-bg: #f0efec;

  --tile-positive: #2a7048;
  --tile-negative: #a83d29;

  --radius: 8px;
  --max-width: 720px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1a1c1f;
    --color-text: #e8e7e4;
    --color-muted: #a8abb0;
    --color-border: #383b40;

    --color-concrete: #e0954f;
    --color-concrete-bg: #35281a;
    --color-pictorial: #7bb0e8;
    --color-pictorial-bg: #182839;
    --color-symbolic: #c19be3;
    --color-symbolic-bg: #271f34;
    --color-example: #7bcb9a;
    --color-example-bg: #152c1e;
    --color-anchor: #e3c15a;
    --color-anchor-bg: #302711;
    --color-parent: #c7c9cd;
    --color-parent-bg: #26282c;

    --tile-positive: #3c8f61;
    --tile-negative: #c05a41;
  }
}

/* Explicit override for pages embedded where a host page stamps a theme attribute
   on the root element (harmless no-op when this file is opened standalone). */
:root[data-theme="dark"] {
  --color-bg: #1a1c1f;
  --color-text: #e8e7e4;
  --color-muted: #a8abb0;
  --color-border: #383b40;
  --color-concrete: #e0954f; --color-concrete-bg: #35281a;
  --color-pictorial: #7bb0e8; --color-pictorial-bg: #182839;
  --color-symbolic: #c19be3; --color-symbolic-bg: #271f34;
  --color-example: #7bcb9a; --color-example-bg: #152c1e;
  --color-anchor: #e3c15a; --color-anchor-bg: #302711;
  --color-parent: #c7c9cd; --color-parent-bg: #26282c;
  --tile-positive: #3c8f61; --tile-negative: #c05a41;
}
:root[data-theme="light"] {
  --color-bg: #fdfcf9; --color-text: #24272b; --color-muted: #5b6167; --color-border: #e2ddd2;
  --color-concrete: #a85a19; --color-concrete-bg: #fdf1e3;
  --color-pictorial: #1f5a99; --color-pictorial-bg: #e9f2fb;
  --color-symbolic: #62368f; --color-symbolic-bg: #f2ecf8;
  --color-example: #2a7048; --color-example-bg: #eaf6ee;
  --color-anchor: #a3780a; --color-anchor-bg: #fdf7e3;
  --color-parent: #4a4f57; --color-parent-bg: #f0efec;
  --tile-positive: #2a7048; --tile-negative: #a83d29;
}

* { box-sizing: border-box; }

html { overflow-x: hidden; }

body {
  margin: 0;
  padding: 0 1rem 2.5rem;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, "Segoe UI", Roboto, Verdana, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  overflow-x: hidden;
}

main, .page-header, footer {
  max-width: var(--max-width);
  margin: 0 auto;
}

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.5rem; margin: 0.4rem 0 0.2rem; }
h2 { font-size: 1.1rem; margin-top: 0; }

a { color: var(--color-pictorial); }
a:visited { color: var(--color-symbolic); }

code {
  font-family: "SF Mono", "Consolas", "Menlo", monospace;
  background: rgba(127, 127, 127, 0.14);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  font-size: 0.95em;
}

.line-graph {
  display: block;
  width: 100%;
  max-width: 340px;
  margin: 0.8rem auto;
}

.shape-diagram {
  display: block;
  width: 100%;
  max-width: 240px;
  margin: 1rem auto;
}

.angle-wedge {
  display: block;
  width: 100%;
  max-width: 210px;
  margin: 1.2rem auto;
}

.breadcrumb {
  font-size: 0.85rem;
  color: var(--color-muted);
  padding-top: 1.3rem;
}
.breadcrumb a { color: var(--color-muted); text-decoration: underline; }

.level-badge {
  display: inline-block;
  background: var(--color-pictorial-bg);
  color: var(--color-pictorial);
  border: 1px solid var(--color-pictorial);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-weight: 600;
  font-size: 0.78rem;
}

.tagline {
  font-size: 0.98rem;
  color: var(--color-muted);
  margin-top: 0;
}

section {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin: 1.1rem 0;
  max-width: 100%;
  overflow-x: auto;
}

section.concrete  { border-left: 5px solid var(--color-concrete); background: var(--color-concrete-bg); }
section.pictorial { border-left: 5px solid var(--color-pictorial); background: var(--color-pictorial-bg); }
section.symbolic  { border-left: 5px solid var(--color-symbolic); background: var(--color-symbolic-bg); }
section.worked-example { border-left: 5px solid var(--color-example); background: var(--color-example-bg); }
section.brain-dump { border-left: 5px solid var(--color-anchor); background: var(--color-anchor-bg); }

section.concrete h2  { color: var(--color-concrete); }
section.pictorial h2 { color: var(--color-pictorial); }
section.symbolic h2  { color: var(--color-symbolic); }
section.worked-example h2 { color: var(--color-example); }
section.brain-dump h2 { color: var(--color-anchor); }

.callout {
  background: rgba(163, 120, 10, 0.12);
  background: color-mix(in srgb, var(--color-anchor) 14%, transparent);
  border: 1px dashed var(--color-anchor);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  margin: 0.7rem 0;
  font-weight: 600;
  font-size: 0.95rem;
}

/* ---- Diagram components ---- */

.diagram-caption {
  font-size: 0.82rem;
  font-style: italic;
  color: var(--color-muted);
  margin-top: 0.35rem;
}

.number-line {
  display: flex;
  align-items: flex-end;
  gap: 0;
  margin: 1rem 0 1.4rem;
  max-width: 100%;
  overflow-x: auto;
}
.number-line .tick {
  flex: 1 0 auto;
  min-width: 1.9rem;
  font-size: 0.85rem;
  text-align: center;
  border-left: 2px solid var(--color-text);
  padding-top: 1.1rem;
  position: relative;
}
.number-line .tick:last-child { border-right: 2px solid var(--color-text); }
.number-line .tick::before {
  content: "";
  position: absolute;
  top: 0; left: -1px;
  width: calc(100% + 2px);
  height: 2px;
  background: var(--color-text);
}
.number-line .tick.marked { font-weight: 700; color: var(--color-pictorial); }
.number-line .tick.marked::after {
  content: "●";
  position: absolute;
  top: -0.5rem;
  left: 50%;
  transform: translateX(-50%);
  color: var(--color-pictorial);
}

.tile-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.7rem 0;
}
.tile {
  min-width: 1.9rem;
  height: 1.9rem;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
}
.tile.positive { background: var(--tile-positive); }
.tile.negative { background: var(--tile-negative); }
.tile.variable { background: var(--color-symbolic); min-width: 2.6rem; }

.fraction-bar {
  display: flex;
  border: 2px solid var(--color-text);
  border-radius: 6px;
  overflow: hidden;
  margin: 0.7rem 0;
  max-width: 100%;
}
.fraction-bar .cell {
  flex: 1;
  height: 2.1rem;
  border-right: 2px solid var(--color-text);
}
.fraction-bar .cell:last-child { border-right: none; }
.fraction-bar .cell.filled { background: var(--color-pictorial); }
.fraction-bar .cell.empty { background: transparent; }

.grid-array {
  display: inline-grid;
  gap: 2px;
  margin: 0.7rem 0;
  max-width: 100%;
  overflow-x: auto;
}
.grid-array .cell {
  width: 1.25rem;
  height: 1.25rem;
  background: var(--color-pictorial);
  border-radius: 3px;
}
.grid-array .cell.dim { background: var(--color-border); }

.balance-scale {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin: 0.9rem 0;
  border-bottom: 4px solid var(--color-text);
  max-width: 100%;
  overflow-x: auto;
}
.balance-scale .pan {
  flex: 1;
  border: 2px solid var(--color-text);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 0.6rem;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.35rem;
  min-height: 3.2rem;
  min-width: 6rem;
}
.balance-scale .fulcrum {
  flex: 0 0 2px;
  background: var(--color-text);
}

table.data-table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
  border-collapse: collapse;
  margin: 0.7rem 0;
  font-size: 0.88rem;
  -webkit-overflow-scrolling: touch;
}
table.data-table th, table.data-table td {
  border: 1px solid var(--color-border);
  padding: 0.3rem 0.5rem;
  text-align: center;
  white-space: nowrap;
}
table.data-table th { background: rgba(127,127,127,0.1); }

.related-links ul { padding-left: 1.1rem; }
.related-links li { margin: 0.3rem 0; font-size: 0.95rem; }

details.parent-notes {
  max-width: var(--max-width);
  margin: 1.8rem auto 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-parent-bg);
  padding: 0.75rem 1rem;
  font-size: 0.92rem;
}
details.parent-notes summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--color-parent);
}
details.parent-notes .parent-notes-content {
  margin-top: 0.7rem;
  color: var(--color-parent);
}
details.parent-notes .parent-notes-content p { margin: 0.45rem 0; }

footer {
  margin-top: 1.6rem;
  font-size: 0.85rem;
}
footer a { color: var(--color-muted); }
