/* Mathify Kids - site styles
   Identity: graph paper + a ruler. Ink navy, pencil yellow, marker green. */
:root {
  --ink: #1d2b53;
  --ink-soft: #3b4a72;
  --muted: #56617c;
  --paper: #ffffff;
  --grid: #f2f6fc;
  --grid-line: #dbe5f3;
  --line: #d6deeb;
  --pencil: #ffc93c;
  --marker: #12805c;
  --marker-dark: #0c6547;
  --radius: 10px;
  --wrap: 1160px;
  --font: "Lexend", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--paper);
}
img { max-width: 100%; height: auto; }
a { color: var(--marker-dark); text-underline-offset: 3px; }
a:hover { color: var(--ink); }
:focus-visible { outline: 3px solid var(--pencil); outline-offset: 2px; border-radius: 4px; }

h1, h2, h3 { line-height: 1.2; font-weight: 700; margin: 0 0 .5em; }
h1 { font-size: clamp(2rem, 1.4rem + 2.4vw, 3rem); letter-spacing: -.02em; }
h2 { font-size: clamp(1.4rem, 1.2rem + .8vw, 1.75rem); margin-top: 2em; }
h3 { font-size: 1.2rem; margin-top: 1.5em; }
p, ul, ol { margin: 0 0 1em; }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 20px; }
.prose { max-width: 70ch; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: 8px 14px; z-index: 50; }
.skip-link:focus { left: 8px; }

/* ---------- header ---------- */
.site-header { border-bottom: 1px solid var(--line); background: var(--paper); position: relative; z-index: 20; }
.header-row { display: flex; align-items: center; gap: 24px; min-height: 68px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 1.2rem; }
.site-nav { display: flex; align-items: center; gap: 18px; margin-left: auto; }
.nav-list { display: flex; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.nav-link, .dd > summary {
  display: block; padding: 8px 12px; border-radius: 8px; color: var(--ink);
  text-decoration: none; font-weight: 500; cursor: pointer; list-style: none;
}
.dd > summary::-webkit-details-marker { display: none; }
.dd > summary::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 8px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-3px) rotate(45deg); }
.dd[open] > summary::after { transform: translateY(1px) rotate(-135deg); }
.nav-link:hover, .dd > summary:hover, .dd[open] > summary { background: var(--grid); }
.nav-link[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--pencil); }
.dd { position: relative; }
.dd-panel {
  position: absolute; top: calc(100% + 8px); left: 0; min-width: 230px; list-style: none; margin: 0; padding: 8px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(29, 43, 83, .14);
}
.dd-panel--wide { display: grid; grid-template-columns: repeat(3, minmax(170px, 1fr)); min-width: 560px; }
.dd-panel a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.dd-panel a:hover, .dd-panel a[aria-current="page"] { background: var(--grid); }
.menu-toggle { display: none; }

.btn {
  display: inline-block; padding: 11px 20px; border-radius: 8px; font: inherit; font-weight: 700;
  text-decoration: none; border: 2px solid transparent; cursor: pointer; line-height: 1.2;
}
.btn--primary { background: var(--marker); color: #fff; }
.btn--primary:hover { background: var(--marker-dark); color: #fff; }
.btn--ghost { border-color: var(--ink); color: var(--ink); background: var(--paper); }
.btn--ghost:hover { background: var(--ink); color: #fff; }
.btn--app { background: var(--pencil); color: var(--ink); }
.btn--app:hover { background: #ffb800; color: var(--ink); }

@media (max-width: 960px) {
  .menu-toggle {
    display: block; margin-left: auto; font: inherit; font-weight: 500; padding: 8px 14px;
    border: 2px solid var(--ink); border-radius: 8px; background: var(--paper); color: var(--ink);
  }
  .site-nav { display: block; position: absolute; left: 0; right: 0; top: 100%; background: var(--paper);
    border-bottom: 1px solid var(--line); padding: 8px 20px 20px; margin: 0; }
  .js .site-nav { display: none; }
  .js .site-nav.is-open { display: block; }
  .nav-list { flex-direction: column; align-items: stretch; margin-bottom: 12px; }
  .dd-panel, .dd-panel--wide { position: static; box-shadow: none; border: 0; min-width: 0; padding: 0 0 8px 12px;
    grid-template-columns: repeat(2, 1fr); }
  .btn--app { display: block; text-align: center; }
}

/* ---------- breadcrumbs ---------- */
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 16px 20px 0; font-size: .9rem; color: var(--muted); }
.breadcrumbs .wrap, .breadcrumbs { padding-left: 0; padding-right: 0; }
.breadcrumbs li + li::before { content: "/"; margin: 0 6px 0 2px; color: var(--line); }
.breadcrumbs a { color: var(--muted); }

/* ---------- hero: the graph-paper sheet ---------- */
.hero {
  background-color: var(--grid);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 24px 24px;
  border-bottom: 1px solid var(--line);
  padding: 40px 0 44px;
}
.hero .lede { font-size: 1.2rem; max-width: 56ch; color: var(--ink-soft); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }

/* Ruler underline: the one signature element */
.ruled { display: inline-block; padding-bottom: 14px; position: relative; }
.ruled::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 10px;
  background:
    repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 24px) bottom left / 100% 10px no-repeat,
    repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px 12px) bottom left / 100% 5px no-repeat,
    linear-gradient(var(--pencil), var(--pencil)) bottom left / 100% 3px no-repeat;
}

.section { padding: 8px 0 24px; }
.section > h2:first-child { margin-top: 1.6em; }

/* ---------- link tiles (hubs) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; list-style: none; padding: 0; margin: 0 0 1em; }
.tiles a {
  display: block; height: 100%; padding: 14px 16px; border: 1.5px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none; background: var(--paper);
}
.tiles a:hover { border-color: var(--ink); }
.tiles strong { display: block; font-weight: 700; }
.tiles span { display: block; font-size: .92rem; color: var(--muted); margin-top: 2px; }

.grade-row { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; padding: 0; margin: 0 0 1em; }
.grade-row a {
  display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%;
  border: 2px solid var(--ink); color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.3rem; background: var(--paper);
}
.grade-row a:hover { background: var(--pencil); }

.link-cols { columns: 3 220px; column-gap: 32px; list-style: none; padding: 0; }
.link-cols li { break-inside: avoid; padding: 3px 0; }
.group { break-inside: avoid; margin-bottom: 1.4em; }
.group h3 { margin-top: 0; }
.group ul { list-style: none; padding: 0; margin: 0; }
.group li { padding: 2px 0; }
.groups { columns: 3 260px; column-gap: 36px; }

/* ---------- worksheet download ---------- */
.download {
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px 28px; margin: 24px 0; padding: 20px 22px;
  border: 1.5px solid var(--line); border-left: 8px solid var(--pencil); border-radius: var(--radius); background: var(--paper);
}
.download p { margin: 0; }
.download .meta { color: var(--muted); font-size: .95rem; }

/* ---------- worked example ---------- */
.example { background: var(--grid); border-radius: var(--radius); padding: 18px 22px; margin: 1em 0 1.5em; }
.example ol { margin-bottom: 0; }
.column-math { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 1.35rem; line-height: 1.35; white-space: pre; margin: 0 0 12px; }

/* ---------- tool / chart slot ---------- */
.tool-slot { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px; margin: 1em 0 2em; text-align: center; color: var(--muted); }

/* ---------- FAQ ---------- */
.faq { padding-bottom: 32px; }
.faq details { border-bottom: 1px solid var(--line); padding: 14px 0; max-width: 70ch; }
.faq summary { font-weight: 700; cursor: pointer; }
.faq details p { margin: 10px 0 0; }

/* ---------- footer ---------- */
.site-footer { background: var(--ink); color: #e7ecf6; margin-top: 56px; padding: 40px 0 24px; }
.site-footer a { color: #fff; }
.site-footer a:hover { color: var(--pencil); }
.author-box { display: flex; gap: 18px; align-items: center; padding-bottom: 28px; border-bottom: 1px solid rgba(255, 255, 255, .18); }
.author-box img { border-radius: 50%; background: #fff; flex: none; }
.author-box p { margin: 0 0 4px; max-width: 70ch; }
.author-name { font-weight: 700; }
.footer-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 24px; padding: 28px 0; }
.footer-cols h2 { font-size: 1rem; margin: 0 0 10px; color: var(--pencil); }
.footer-cols ul { list-style: none; padding: 0; margin: 0; }
.footer-cols li { padding: 3px 0; }
.footer-cols a { text-decoration: none; }
.copyright { font-size: .9rem; color: #b9c3d9; margin: 0; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
@media print { .site-header, .site-footer, .breadcrumbs, .hero-actions { display: none; } }

/* Text pages: keep the reading column left-aligned with breadcrumbs and FAQ */
.wrap.prose { max-width: var(--wrap); }
.wrap.prose > * { max-width: 70ch; }
.wrap.prose > .download, .wrap.prose > .tool-slot, .wrap.prose > .example { max-width: 760px; }
.breadcrumbs + .wrap { padding-top: 20px; }

/* Try-it practice problems */
.try { max-width: 70ch; margin-bottom: 1.5em; }
.try details { border: 1.5px solid var(--line); border-radius: var(--radius); padding: 10px 16px; margin-bottom: 8px; }
.try summary { cursor: pointer; font-weight: 500; }
.try summary::after { content: "Show answer"; float: right; font-size: .85rem; color: var(--marker-dark); font-weight: 500; }
.try details[open] summary::after { content: "Hide"; }
.try details p { margin: 8px 0 0; font-weight: 700; color: var(--marker-dark); }
.example + h3, .wrap.prose h3 { margin-top: 1.4em; }

.contact-email { font-size: 1.3rem; font-weight: 700; }
.reviewed { color: var(--muted); font-size: .9rem; margin-top: 28px; }
.download--extra { margin-top: -12px; border-left-color: var(--line); }
