/* =========================================================================
   FreshWorksheets design system — modern, mobile-first, accessible.
   Light + dark themes via tokens. No framework.
   ========================================================================= */

:root {
  --green:      #1f8a5b;
  --green-600:  #177a4f;
  --green-700:  #12643f;
  --green-050:  #e9f6ef;
  --amber:      #f4a825;
  --amber-050:  #fdf3dd;

  --ink:    #16241f;
  --body:   #33443d;
  --muted:  #5f7169;

  --bg:      #f4f9f6;
  --surface: #ffffff;
  --surface-2: #fbfdfc;
  --line:    #e2ece7;
  --ring:    rgba(31,138,91,.30);

  --shadow-sm: 0 1px 2px rgba(16,40,30,.06), 0 1px 3px rgba(16,40,30,.05);
  --shadow-md: 0 6px 20px rgba(16,50,36,.08);
  --shadow-lg: 0 18px 44px rgba(16,50,36,.14);

  --radius:    16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --max: 1120px;

  --font: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --head-h: 66px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink:    #eaf3ee;
    --body:   #c4d3cc;
    --muted:  #93a69d;
    --bg:      #0f1714;
    --surface: #16211c;
    --surface-2: #1a2620;
    --line:    #26332c;
    --green-050: #14261d;
    --amber-050: #2a230f;
    --ring:    rgba(60,190,130,.35);
    --shadow-md: 0 6px 20px rgba(0,0,0,.45);
    --shadow-lg: 0 18px 44px rgba(0,0,0,.55);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  margin: 0; font-family: var(--font); color: var(--body); background: var(--bg);
  line-height: 1.65; font-size: 17px; -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { color: var(--ink); line-height: 1.18; margin: 0 0 .5em; font-weight: 800; letter-spacing: -.02em; }
p { margin: 0 0 1em; }
img, svg { max-width: 100%; }
a { color: var(--green-700); text-decoration-color: color-mix(in srgb, var(--green-700) 35%, transparent); text-underline-offset: 2px; }
a:hover { color: var(--green-600); }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }

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

.skip-link {
  position: absolute; left: -999px; top: 8px; background: var(--green); color: #fff;
  padding: 10px 16px; border-radius: 8px; z-index: 100; font-weight: 700;
}
.skip-link:focus { left: 12px; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--green); color: #fff; text-decoration: none; border: 0; cursor: pointer;
  padding: 12px 22px; border-radius: 999px; font-family: inherit; font-weight: 800;
  font-size: 16px; line-height: 1; box-shadow: var(--shadow-sm);
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { background: var(--green-600); color: #fff; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }
.btn.ghost { background: transparent; color: var(--green-700); border: 2px solid var(--green); box-shadow: none; padding: 10px 20px; }
.btn.ghost:hover { background: var(--green-050); color: var(--green-700); }
.btn-sm { padding: 9px 16px; font-size: 14px; }
.btn-lg { padding: 15px 30px; font-size: 18px; }

/* ---------------- header / nav ---------------- */
.site-head {
  position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px); border-bottom: 1px solid var(--line);
}
.head-inner { display: flex; align-items: center; gap: 14px; height: var(--head-h); }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--green), var(--green-700)); color: #fff;
  font-weight: 900; font-size: 14px; letter-spacing: -.5px; box-shadow: var(--shadow-sm);
}
.brand-word { font-weight: 900; font-size: 20px; color: var(--green-700); letter-spacing: -.03em; }
.brand-word span { color: var(--amber); }

.nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.nav > a, .nav-top { text-decoration: none; color: var(--ink); font-weight: 700; font-size: 15px; padding: 8px 12px; border-radius: 8px; display: inline-flex; align-items: center; gap: 4px; }
.nav > a:not(.btn):hover, .nav-top:hover { background: var(--green-050); color: var(--green-700); }
.nav .btn { margin-left: 6px; }
.caret { font-size: 10px; opacity: .6; }

/* mega-menu */
.nav-item { position: relative; }
.mega {
  position: absolute; left: 0; top: calc(100% + 6px); display: none; z-index: 60;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg);
  padding: 18px; min-width: 460px; grid-template-columns: 130px 1fr; gap: 18px;
}
.nav-item:hover .mega, .nav-item:focus-within .mega { display: grid; }
.mega-col h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.mega-col a { display: block; padding: 6px 8px; border-radius: 8px; font-size: 14px; font-weight: 700; color: var(--ink); text-decoration: none; }
.mega-col a:hover { background: var(--green-050); color: var(--green-700); }
.mega-topics { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.mega-topics a { display: flex; align-items: center; gap: 8px; }
.mega-badge { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; font-size: 12px; font-weight: 900; color: #fff; flex: none; }

/* colourful grade chips (big playful buttons) */
.grade-chips { gap: 14px; }
.grade-chip { color: #fff; border: 0; font-size: 17px; padding: 14px 28px; box-shadow: var(--shadow-md); }
.grade-chip:nth-child(6n+1) { background: linear-gradient(135deg, #22a06b, #12643f); color: #fff; }
.grade-chip:nth-child(6n+2) { background: linear-gradient(135deg, #8b5cf6, #6d28d9); color: #fff; }
.grade-chip:nth-child(6n+3) { background: linear-gradient(135deg, #3b82f6, #1e4fd1); color: #fff; }
.grade-chip:nth-child(6n+4) { background: linear-gradient(135deg, #f59e0b, #d97706); color: #fff; }
.grade-chip:nth-child(6n+5) { background: linear-gradient(135deg, #ec4899, #be185d); color: #fff; }
.grade-chip:nth-child(6n+6) { background: linear-gradient(135deg, #06b6d4, #0e7490); color: #fff; }
.grade-chip:hover { color: #fff; opacity: .92; }
.grade-row .grade-chip { font-size: 14px; padding: 9px 18px; }
.grade-chip.is-current { outline: 3px solid var(--ink); outline-offset: 2px; }

.nav-toggle {
  margin-left: auto; display: none; flex-direction: column; gap: 5px; width: 44px; height: 44px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer;
  align-items: center; justify-content: center;
}
.nav-toggle span { width: 20px; height: 2px; background: var(--ink); border-radius: 2px; transition: transform .2s, opacity .2s; }
body.nav-open .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.nav-open .nav-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  .nav {
    position: fixed; inset: var(--head-h) 0 auto 0; flex-direction: column; align-items: stretch;
    gap: 4px; background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 20px 20px;
    box-shadow: var(--shadow-lg); transform: translateY(-12px); opacity: 0; visibility: hidden;
    transition: transform .2s ease, opacity .2s ease, visibility .2s;
  }
  body.nav-open .nav { transform: translateY(0); opacity: 1; visibility: visible; overflow-y: auto; max-height: calc(100vh - var(--head-h)); }
  .nav > a, .nav-top { padding: 12px 14px; font-size: 17px; }
  .nav .btn { margin: 8px 0 0; }
  .nav-item { width: 100%; }
  .nav-top { justify-content: space-between; }
  .mega { position: static; display: grid !important; box-shadow: none; border: 0; border-radius: 0;
    padding: 4px 0 10px 16px; min-width: 0; grid-template-columns: 1fr; gap: 8px; }
  .mega-topics { grid-template-columns: 1fr 1fr; }
}

/* ---------------- hero ---------------- */
.hero {
  text-align: center; padding: 64px 0 44px;
  background:
    radial-gradient(60% 90% at 50% -10%, var(--green-050), transparent 70%),
    radial-gradient(40% 60% at 90% 0%, var(--amber-050), transparent 60%);
}
.pill {
  display: inline-block; background: var(--surface); border: 1px solid var(--line);
  color: var(--green-700); font-weight: 800; font-size: 13px; padding: 7px 16px;
  border-radius: 999px; margin-bottom: 20px; box-shadow: var(--shadow-sm); letter-spacing: .01em;
}
.hero h1 { font-size: clamp(32px, 6vw, 54px); font-weight: 900; margin: 0 0 16px; }
.hero-sub { font-size: clamp(17px, 2.4vw, 20px); color: var(--muted); max-width: 640px; margin: 0 auto 28px; }
.cta-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hero-badges { display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; margin-top: 30px; color: var(--muted); font-weight: 700; font-size: 15px; }

/* ---------------- generator card ---------------- */
.gen-section { padding: 34px 0; }
.hero + .gen-section { margin-top: -30px; }
.gen {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 26px; max-width: 900px; margin: 0 auto;
}
.gen-head h2 { margin: 0 0 4px; font-size: clamp(20px, 3vw, 26px); }
.gen .sub { color: var(--muted); margin: 0 0 20px; font-size: 15px; }
.gen-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.field label { display: block; font-size: 12px; font-weight: 800; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .06em; }
.field select {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  font-size: 16px; font-family: inherit; background: var(--surface-2); color: var(--ink);
  appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%235f7169' stroke-width='2' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
.field select:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px var(--ring); }
.gen-actions { display: flex; gap: 12px; margin-top: 18px; flex-wrap: wrap; align-items: center; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); font-weight: 700; margin-left: auto; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--green); }

.ws-preview { margin-top: 22px; border-top: 1px dashed var(--line); padding-top: 22px; }
.ws-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 28px; }
.ws-item { display: flex; align-items: baseline; gap: 8px; font-size: 18px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.ws-num { color: var(--muted); font-weight: 800; min-width: 26px; }
.ws-q { font-weight: 700; color: var(--ink); }
.ws-blank { flex: 1; border-bottom: 1.5px solid var(--line); min-width: 40px; margin-left: 6px; align-self: center; height: 0; }
.ws-a { margin-left: auto; color: var(--green-600); font-weight: 900; }
@media (max-width: 560px) { .ws-grid { grid-template-columns: 1fr; } }

/* ---------------- sections ---------------- */
.section { padding: 52px 0; }
.section-title { text-align: center; font-size: clamp(24px, 4vw, 32px); margin: 0 0 6px; }
.section-sub { text-align: center; color: var(--muted); max-width: 560px; margin: 0 auto 34px; }

/* topic grid + cards */
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.topic-card {
  display: flex; align-items: center; gap: 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; text-decoration: none; color: inherit;
  box-shadow: var(--shadow-sm); transition: transform .14s ease, box-shadow .14s ease, border-color .14s;
}
.topic-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--green) 40%, var(--line)); }
.topic-badge {
  flex: none; display: grid; place-items: center; width: 54px; height: 54px; border-radius: 14px;
  background: linear-gradient(135deg, var(--green-050), color-mix(in srgb, var(--amber-050) 70%, var(--green-050)));
  color: var(--green-700); font-size: 24px; font-weight: 900; border: 1px solid var(--line);
}
.topic-badge.sm { width: 40px; height: 40px; font-size: 18px; border-radius: 11px; }
.topic-card-body { display: flex; flex-direction: column; gap: 3px; }
.topic-card-name { font-weight: 800; color: var(--ink); font-size: 18px; }
.topic-card-blurb { color: var(--muted); font-size: 14px; line-height: 1.45; }

/* colourful category badges (homepage + hubs) */
.topic-badge.b0 { background: linear-gradient(135deg, #22a06b, #12643f); color: #fff; border: 0; }
.topic-badge.b1 { background: linear-gradient(135deg, #3b82f6, #1e4fd1); color: #fff; border: 0; }
.topic-badge.b2 { background: linear-gradient(135deg, #f59e0b, #d97706); color: #fff; border: 0; }
.topic-badge.b3 { background: linear-gradient(135deg, #8b5cf6, #6d28d9); color: #fff; border: 0; }
.topic-badge.b4 { background: linear-gradient(135deg, #ec4899, #be185d); color: #fff; border: 0; }
.topic-badge.b5 { background: linear-gradient(135deg, #06b6d4, #0e7490); color: #fff; border: 0; }

/* home hero + category sections */
.home-hero h1 { font-size: clamp(30px, 6vw, 50px); }
.cat-section:nth-of-type(even) { background: var(--green-050); }
.cat-more { text-align: center; margin-top: 22px; }

/* grades band */
.grades-band { background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.grade-chips { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.grade-chip {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 12px 22px;
  font-weight: 800; color: var(--ink); text-decoration: none; box-shadow: var(--shadow-sm);
  transition: transform .12s, box-shadow .12s, color .12s;
}
.grade-chip:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); color: var(--green-700); }

/* features */
.features { background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.feat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 26px; }
.feat { text-align: center; }
.feat-ico { font-size: 32px; margin-bottom: 8px; }
.feat h3 { font-size: 18px; margin: 0 0 6px; }
.feat p { color: var(--muted); font-size: 15px; margin: 0; }

/* ---------------- content pages ---------------- */
.content { padding: 28px 20px 20px; }
.content.narrow { max-width: 760px; }
.content > h2 { font-size: clamp(21px, 3vw, 26px); margin: 34px 0 10px; }
.content p, .content li { color: var(--body); }
.content ul, .content ol { padding-left: 22px; }
.content li { margin-bottom: 6px; }
.lead { font-size: clamp(17px, 2.3vw, 20px); color: var(--muted); }

.breadcrumb { font-size: 14px; color: var(--muted); margin: 4px 0 14px; }
.breadcrumb a { text-decoration: none; font-weight: 700; }
.breadcrumb .sep { opacity: .5; margin: 0 2px; }

.page-head { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 8px; }
.page-head h1 { font-size: clamp(26px, 5vw, 40px); margin: 0 0 8px; }
.page-head .topic-badge { width: 64px; height: 64px; font-size: 28px; }
@media (max-width: 560px) { .page-head .topic-badge { width: 52px; height: 52px; font-size: 24px; } }

.example-box {
  background: linear-gradient(180deg, var(--green-050), var(--surface));
  border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: var(--radius);
  padding: 20px 24px; margin: 22px 0;
}
.example-box .eq { font-size: 22px; font-weight: 900; color: var(--ink); margin: 0 0 10px; }
.example-box ol { margin: 0; }

.related-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 10px; }
.related-card {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px; text-decoration: none; color: var(--ink);
  font-weight: 800; box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s;
}
.related-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); color: var(--green-700); }

.cta-inline { margin-top: 24px; display: flex; gap: 12px; flex-wrap: wrap; }

/* hubs */
.hub-head { margin-bottom: 24px; }
.hub-head h1 { font-size: clamp(26px, 5vw, 40px); }
.hub-subject { margin-bottom: 34px; }
.hub-subject-head h2 { font-size: 22px; margin-bottom: 14px; }

/* ---------------- footer ---------------- */
.site-foot { background: var(--ink); color: #c9d6d0; margin-top: 56px; padding: 46px 0 30px; }
.foot-grid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 26px; }
.foot-brand p { color: #93a69d; max-width: 320px; margin: 12px 0 0; font-size: 15px; }
.brand-foot .brand-word { color: #fff; }
.brand-foot .brand-word span { color: var(--amber); }
.foot-col h4 { color: #fff; font-size: 15px; margin: 0 0 10px; }
.foot-col a { display: block; color: #c9d6d0; text-decoration: none; padding: 5px 0; font-size: 15px; }
.foot-col a:hover { color: #fff; }
.foot-copy { border-top: 1px solid #2b3d35; margin-top: 30px; padding-top: 20px; color: #8ba097; font-size: 13px; }
@media (max-width: 780px) { .foot-grid { grid-template-columns: 1fr 1fr; } .foot-brand { grid-column: 1 / -1; } }

/* ---------------- visual worksheets (colourful) ---------------- */
.gen-visual { background: linear-gradient(180deg, #fff, var(--green-050)); }
.vis-grid { display: grid; gap: 14px; }
.vis-count, .vis-shapes { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.vis-cell {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  background: var(--surface); border: 2px solid var(--line); border-radius: 16px; padding: 14px;
}
.vis-cell .vis-num { align-self: flex-start; color: var(--muted); font-weight: 800; }
.vis-svg { width: 100%; max-height: 96px; }
.vis-ans { font-weight: 800; color: var(--green-700); letter-spacing: 1px; }
.vis-rows { display: flex; flex-direction: column; gap: 10px; }
.vis-row {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  border: 2px solid var(--line); border-radius: 14px; padding: 10px 14px; flex-wrap: wrap;
}
.vis-row .vis-num { color: var(--muted); font-weight: 800; min-width: 24px; }
.vis-chip { display: inline-grid; place-items: center; width: 40px; height: 40px; }
.vis-chip-ans { background: var(--green-050); border-radius: 10px; }
.vis-q { font-size: 22px; font-weight: 900; color: var(--amber); border: 2px dashed var(--line); border-radius: 10px; }
.vis-mini { width: 30px; height: 30px; }
.vis-single { display: flex; justify-content: center; padding: 12px; }
.vis-single .vis-svg { max-width: 340px; max-height: 340px; width: 100%; }
.vis-clock { width: 84px; height: 84px; max-height: 84px; }
.vis-trace-rows { display: flex; flex-direction: column; gap: 4px; }
.vis-trace-row { display: flex; align-items: center; gap: 16px; border-bottom: 2px solid var(--line);
  padding: 8px 4px; font-size: clamp(26px, 6vw, 36px); font-weight: 800; font-family: var(--font); }
.tr-solid { color: var(--ink); }
.tr-faint { color: #cdd8d2; }

/* ---------------- ad slots (ready for AdSense) ---------------- */
.ad-slot { margin: 18px auto; text-align: center; }
.ad-slot:empty { display: none; }           /* hidden until an ad is placed */
.ad-leaderboard { min-height: 0; }
.ad-slot ins, .ad-slot iframe { max-width: 100%; }

/* ---------------- print ---------------- */
@media print {
  .site-head, .site-foot, .gen-actions, .cta-row, .hero-badges { display: none; }
  body { background: #fff; }
}
