:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #f59e0b;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --white: #ffffff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

/* ── NAV ── */
.site-nav {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  height: 60px;
}

.nav-logo {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .4rem;
}

.nav-logo span { color: var(--accent); }

.nav-links {
  display: flex;
  list-style: none;
  gap: .25rem;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .4rem .85rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--muted);
  font-size: .93rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav-links a:hover,
.nav-links a.active {
  background: #eff6ff;
  color: var(--primary);
}

/* ── HERO ── */
.hero {
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 60%, #3b82f6 100%);
  color: var(--white);
  padding: 5rem 1.5rem 4rem;
  text-align: center;
}

.hero h1 { font-size: clamp(1.8rem, 4vw, 3rem); font-weight: 800; margin-bottom: 1rem; }
.hero p  { font-size: 1.15rem; opacity: .88; max-width: 540px; margin: 0 auto 2rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .7rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: .95rem;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: filter .15s, transform .1s;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-primary   { background: var(--accent); color: var(--white); }
.btn-secondary { background: rgba(255,255,255,.15); color: var(--white); border: 1px solid rgba(255,255,255,.3); }

/* ── CARDS ── */
.section { padding: 4rem 1.5rem; max-width: 1100px; margin: 0 auto; }
.section-title { font-size: 1.6rem; font-weight: 700; margin-bottom: .5rem; }
.section-sub   { color: var(--muted); margin-bottom: 2.5rem; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .15s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-icon { font-size: 2rem; margin-bottom: .75rem; }
.card h3   { font-size: 1.05rem; font-weight: 600; margin-bottom: .35rem; }
.card p    { font-size: .88rem; color: var(--muted); }

/* ── MATH PAGE ── */
.page-header {
  background: linear-gradient(135deg, #1e40af, #2563eb);
  color: var(--white);
  padding: 3rem 1.5rem 2.5rem;
  text-align: center;
}
.page-header h1 { font-size: clamp(1.4rem, 3vw, 2.2rem); font-weight: 800; }
.page-header p  { opacity: .85; margin-top: .5rem; }

.controls-bar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
}

.controls-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-end;
}

.control-group { display: flex; flex-direction: column; gap: .4rem; }
.control-group label { font-size: .82rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

.grade-pills { display: flex; gap: .5rem; flex-wrap: wrap; }

.grade-pill {
  padding: .45rem 1.1rem;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: var(--white);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  transition: all .15s;
  color: var(--muted);
}
.grade-pill:hover    { border-color: var(--primary); color: var(--primary); }
.grade-pill.selected { border-color: var(--primary); background: var(--primary); color: var(--white); }

.num-input {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.num-input button {
  width: 32px; height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .1s;
}
.num-input button:hover { background: var(--border); }
.num-input span { font-weight: 700; min-width: 2ch; text-align: center; font-size: 1rem; }

.controls-inner .btn-generate {
  background: var(--primary);
  color: var(--white);
  padding: .55rem 1.4rem;
  border-radius: var(--radius);
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: .95rem;
  transition: background .15s;
}
.controls-inner .btn-generate:hover { background: var(--primary-dark); }

/* ── SHEET PREVIEW ── */
.preview-area {
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.empty-state {
  text-align: center;
  padding: 5rem 1rem;
  color: var(--muted);
}
.empty-state .icon { font-size: 3.5rem; margin-bottom: 1rem; }
.empty-state p { font-size: 1.05rem; }

.sheet {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.sheet-header {
  background: #f1f5f9;
  padding: .75rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  font-size: .85rem;
  color: var(--muted);
  font-weight: 500;
}

.sheet-body {
  padding: 1.5rem;
}

.sheet-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: .25rem;
}

.sheet-meta {
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  display: flex;
  gap: 1rem;
}

.problems-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .6rem 1.5rem;
}

.problem {
  display: flex;
  align-items: baseline;
  gap: .4rem;
  font-family: 'Courier New', monospace;
  font-size: 1.05rem;
  padding: .35rem 0;
}

.prob-num  { color: var(--muted); font-size: .8rem; min-width: 1.6rem; }
.problem.wide { grid-column: 1 / -1; }
.prob-expr { font-weight: 600; white-space: nowrap; }
.prob-hint { font-family: system-ui, sans-serif; font-weight: 400; font-size: .72rem; color: var(--muted); margin-left: .15rem; }
.inline-blank { display: inline-block; border-bottom: 2px solid var(--text); height: 1.05em; vertical-align: -3px; margin: 0 .2rem; }
.prob-blank {
  flex: 1;
  border-bottom: 2px solid var(--text);
  min-width: 80px;
  max-width: 140px;
  height: 1.1em;
}

/* print action bar */
.print-bar {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: #f8fafc;
}

.btn-print {
  background: var(--primary);
  color: var(--white);
  border: none;
  padding: .5rem 1.2rem;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .4rem;
  transition: background .15s;
}
.btn-print:hover { background: var(--primary-dark); }

/* ── FOOTER ── */
.site-footer {
  background: var(--white);
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 1.5rem;
  font-size: .85rem;
  color: var(--muted);
}

/* ── SEO / FAQ CONTENT (below the fold, hidden when printing) ── */
.seo-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
}
.seo-content h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0 0 .75rem;
}
.seo-content h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 2rem 0 .75rem;
}
.seo-content p {
  color: var(--muted);
  margin-bottom: 1rem;
  font-size: .95rem;
}
.seo-content .lead { color: var(--text); }
.faq { margin-top: .5rem; }
.faq details {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .1rem 1rem;
  margin-bottom: .6rem;
}
.faq summary {
  cursor: pointer;
  font-weight: 600;
  padding: .85rem 0;
  list-style: none;
  color: var(--text);
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: '＋'; float: right; color: var(--muted); font-weight: 400; }
.faq details[open] summary::after { content: '−'; }
.faq details p { margin: 0 0 .85rem; }

/* ── ANSWER KEY SHEET ── */
.control-check { justify-content: center; }
.answer-toggle {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-weight: 600;
  font-size: .9rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.answer-toggle input { width: 1.05rem; height: 1.05rem; cursor: pointer; accent-color: var(--primary); }
.sheet.answer-key { border-color: #16a34a; }
.sheet.answer-key .sheet-header { background: #dcfce7; color: #15803d; }
.sheet.answer-key .sheet-title { color: #15803d; }
.answer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .35rem 1.5rem;
  font-size: .9rem;
}
.answer-grid.two-col { grid-template-columns: repeat(2, 1fr); }
.answer-item { display: flex; gap: .4rem; padding: .2rem 0; }
.answer-item .a-num { color: var(--muted); min-width: 1.6rem; font-size: .8rem; }
.answer-item .a-val { font-weight: 600; }
.btn-copy {
  background: var(--white);
  color: var(--primary);
  border: 2px solid var(--border);
  padding: .5rem 1.1rem;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  font-size: .9rem;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  transition: border-color .15s, color .15s;
}
.btn-copy:hover { border-color: var(--primary); }
.btn-copy.copied { border-color: #16a34a; color: #16a34a; }

/* ── PRINT MEDIA ── */
@media print {
  .site-nav, .page-header, .controls-bar, .print-bar, .sheet-header, .site-footer,
  .ignlab-footer, .seo-content { display: none !important; }

  html, body { margin: 0; padding: 0; background: white; }

  .preview-area { padding: 0; margin: 0; gap: 0; }

  /* Each sheet = one printed page */
  .sheet {
    box-shadow: none;
    border: none;
    page-break-after: always;
    break-after: page;
    width: 100%;
  }

  /* No blank trailing page after the last sheet */
  .sheet:last-child {
    page-break-after: avoid;
    break-after: avoid;
  }

  .sheet-body {
    padding: 1rem 1.5rem;
  }

  .sheet-title { font-size: 1.1rem; margin-bottom: .25rem; }
  .sheet-meta  { font-size: .8rem; margin-bottom: 1.2rem; gap: 1rem; }

  .problems-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .55rem 2rem;
  }

  .problem      { font-size: 1.05rem; padding: .3rem 0; }
  .prob-blank   { min-width: 100px; }
}

@media (max-width: 600px) {
  .controls-inner { flex-direction: column; align-items: stretch; }
}

/* Narrow screens: stack math problems in one column so large numbers never clip */
@media (max-width: 700px) {
  .problems-grid { grid-template-columns: 1fr; }
  .answer-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── IGNLAB SHARED FOOTER (portable, self-contained) ── */
.ignlab-footer{background:#0f1117;border-top:1px solid #2a2f42;margin:0;font-family:system-ui,-apple-system,'Segoe UI',Roboto,sans-serif;color:#9aa0b4;padding:14px 20px;box-sizing:border-box}
.ignlab-footer *{box-sizing:border-box;margin:0}
.if-inner{max-width:1200px;margin:0 auto;display:flex;align-items:center;flex-wrap:wrap;gap:8px 18px}
.if-brand{font-weight:800;font-size:14px;text-decoration:none;letter-spacing:-.3px;background:linear-gradient(135deg,#6c63ff,#00d4aa);-webkit-background-clip:text;background-clip:text;-webkit-text-fill-color:transparent;white-space:nowrap}
.if-links{display:flex;flex-wrap:wrap;gap:3px 5px;flex:1 1 auto;align-items:center}
.if-links a{color:#9aa0b4;text-decoration:none;font-size:12.5px;font-weight:500;padding:3px 9px;border-radius:999px;white-space:nowrap;transition:background .15s,color .15s}
.if-links a:hover{background:rgba(108,99,255,.18);color:#fff}
.if-links a.active{background:#6c63ff;color:#fff;font-weight:600}
.if-copy{font-size:12px;color:#6b7280;white-space:nowrap}
.if-x{display:inline-flex;align-items:center;gap:5px;color:#fff;background:#1d1f2b;border:1px solid #2a2f42;text-decoration:none;font-size:12px;font-weight:600;padding:4px 11px;border-radius:999px;white-space:nowrap;transition:background .15s,border-color .15s}
.if-x:hover{background:#000;border-color:#6c63ff;color:#fff}
.if-x svg{width:13px;height:13px;fill:currentColor}
@media(max-width:640px){.if-inner{flex-direction:column;align-items:flex-start;gap:10px}}

/* ── TELLING TIME ── */
.clock-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem 1rem;
  margin-top: .5rem;
}
.clock-item { text-align: center; }
.clock-face { width: 120px; height: 120px; max-width: 100%; }
.clock-q { margin-top: .4rem; font-size: .85rem; color: var(--text); }
.clock-line {
  display: inline-block;
  border-bottom: 2px solid var(--text);
  min-width: 70px;
  height: 1.1em;
  vertical-align: -3px;
  margin-left: .3rem;
}
@media (max-width: 600px) {
  .clock-grid { grid-template-columns: repeat(2, 1fr); }
}
@media print {
  .clock-face { width: 110px; height: 110px; }
  .clock-grid { gap: 1.25rem 1rem; }
}
