:root {
  --sand: #f7f1e6;
  --sand-deep: #efe4cf;
  --ink: #2a1d12;
  --ink-soft: #5c4a38;
  --maroon: #8c1d2c;
  --maroon-dark: #6e1422;
  --saffron: #e9851d;
  --gold: #c89b3c;
  --teal: #1f7a6f;
  --line: #e0d3ba;
  --white: #fffdf8;
  --shadow: 0 6px 24px rgba(60, 40, 20, 0.12);
  --radius: 14px;
  --font-display: 'Noto Sans Devanagari', 'Mangal', 'Kokila', system-ui, sans-serif;
  --font-body: 'Noto Sans Devanagari', 'Mangal', 'Kokila', system-ui, sans-serif;
}

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

html { font-size: 16px; } /* mobile & tablet base */
@media (min-width: 901px) {
  html { font-size: 17.5px; } /* slightly larger on PC — scales all rem sizes */
}

body {
  font-family: var(--font-body);
  background: var(--sand);
  color: var(--ink);
  line-height: 1.6;
  background-image: radial-gradient(circle at 100% 0, rgba(233, 133, 29, 0.06), transparent 40%);
}

a { color: var(--maroon); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink); line-height: 1.2; font-weight: 600; }

/* ===== Header ===== */
.navbar {
  background: var(--maroon);
  color: var(--white);
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.navbar .container { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; color: var(--white); letter-spacing: .3px; }
.brand span { color: var(--gold); }
.brand:hover { text-decoration: none; }
.nav-links { display: flex; gap: 6px; align-items: center; list-style: none; }
.nav-links a { color: #f3e6d0; padding: 8px 14px; border-radius: 8px; font-size: .95rem; transition: background .15s; }
.nav-links a:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.nav-links a.active { background: var(--maroon-dark); color: var(--white); }
.nav-toggle { display: none; background: none; border: 0; color: var(--white); font-size: 1.6rem; cursor: pointer; }

.btn {
  display: inline-block; padding: 10px 20px; border-radius: 10px; border: 0;
  font-family: var(--font-body); font-weight: 600; font-size: .95rem; cursor: pointer;
  transition: transform .12s, box-shadow .12s; text-align: center;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn-primary { background: var(--saffron); color: #fff; }
.btn-primary:hover { background: #d4760f; }
.btn-maroon { background: var(--maroon); color: #fff; }
.btn-outline { background: transparent; border: 2px solid var(--maroon); color: var(--maroon); }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-sm { padding: 6px 14px; font-size: .85rem; }
.btn-block { display: block; width: 100%; }

/* ===== Hero ===== */
.hero {
  background: linear-gradient(135deg, var(--maroon) 0%, var(--maroon-dark) 100%);
  color: var(--white); padding: 26px 0; position: relative; overflow: hidden;
}
.hero::after {
  content: ''; position: absolute; right: -80px; bottom: -80px; width: 340px; height: 340px;
  background: radial-gradient(circle, rgba(233,133,29,.35), transparent 70%); border-radius: 50%;
}
.hero h1 { color: var(--white); font-size: 1.9rem; margin-bottom: 8px; }
.hero h1 .accent { color: var(--gold); }
.hero p { font-size: .98rem; max-width: 620px; color: #f1e2cb; margin-bottom: 12px; }
.hero-actions { display: flex; gap: 14px; flex-wrap: wrap; }

/* ===== Sections ===== */
.section { padding: 48px 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; }
.section-head h2 { font-size: 1.9rem; position: relative; padding-left: 16px; }
.section-head h2::before { content: ''; position: absolute; left: 0; top: 6px; bottom: 6px; width: 5px; background: var(--saffron); border-radius: 4px; }

/* ===== Cards ===== */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); transition: transform .15s; display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-3px); }
.card h3 { font-size: 1.15rem; margin-bottom: 8px; }
.card .meta { font-size: .82rem; color: var(--ink-soft); margin-bottom: 12px; }
.card .desc { color: var(--ink-soft); font-size: .92rem; flex: 1; margin-bottom: 14px; }
.quiz-ref { font-size: .8rem; color: var(--maroon); background: var(--sand); border-left: 3px solid var(--saffron); border-radius: 0 6px 6px 0; padding: 7px 10px; margin: 0 0 12px; line-height: 1.4; }
.quiz-ref b { font-weight: 600; }
.tag { display: inline-block; background: var(--sand-deep); color: var(--ink-soft); font-size: .72rem; padding: 3px 10px; border-radius: 20px; margin-right: 6px; }
.tag.free { background: #e3f3ec; color: var(--teal); }
.tag.paid { background: #fde9d8; color: var(--saffron); }
.tag.pyq { background: #ece6f6; color: #5b3fa0; }

.cat-card { text-align: center; padding: 24px 14px; }
.cat-card .ico { font-size: 2rem; margin-bottom: 8px; }

.price { font-family: var(--font-display); font-size: 1.5rem; color: var(--maroon); font-weight: 700; }
.price .mrp { font-size: .9rem; color: var(--ink-soft); text-decoration: line-through; margin-left: 8px; font-weight: 400; }

/* ===== Forms ===== */
.form-wrap { max-width: 440px; margin: 48px auto; background: var(--white); padding: 36px; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.form-wrap.wide { max-width: 760px; }
.form-group { margin-bottom: 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .9rem; }
input, select, textarea {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px;
  font-family: var(--font-body); font-size: .95rem; background: var(--sand);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--saffron); border-color: var(--saffron); }
textarea { resize: vertical; min-height: 90px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 18px; font-size: .9rem; }
.alert-error { background: #fce8e8; color: var(--maroon-dark); border: 1px solid #f3c9c9; }
.alert-info { background: #e6f0ef; color: var(--teal); }

/* ===== Tables ===== */
.table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: .9rem; }
.table th { background: var(--sand-deep); font-family: var(--font-display); }
.table tr:last-child td { border-bottom: 0; }
.cat-group { margin-bottom: 26px; }
.cat-group-title { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); color: var(--maroon); font-size: 1.15rem; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--saffron); }
.cat-group-count { background: var(--saffron); color: #3a2a00; font-size: .8rem; font-weight: 700; border-radius: 20px; padding: 1px 10px; }

/* ===== Filter bar ===== */
.filterbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }
.filterbar a { padding: 7px 16px; border-radius: 20px; background: var(--white); border: 1px solid var(--line); color: var(--ink-soft); font-size: .88rem; }
.filterbar a.active { background: var(--maroon); color: #fff; border-color: var(--maroon); }
.filterbar a:hover { text-decoration: none; }

/* ===== Footer ===== */
.footer { background: var(--ink); color: #d8c8b2; padding: 40px 0 24px; margin-top: 48px; }
.footer .container { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 30px; }
.footer h4 { color: var(--gold); margin-bottom: 12px; }
.footer a { color: #d8c8b2; display: block; padding: 3px 0; font-size: .9rem; }
.footer .copy { grid-column: 1/-1; border-top: 1px solid #463222; padding-top: 18px; margin-top: 10px; text-align: center; font-size: .82rem; }

/* ===== Article ===== */
.article-body { max-width: 760px; background: var(--white); padding: 36px; border-radius: var(--radius); box-shadow: var(--shadow); }
.article-body h2 { margin: 24px 0 12px; }
.article-body p { margin-bottom: 14px; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .footer .container { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .nav-links { display: none; position: absolute; top: 64px; left: 0; right: 0; background: var(--maroon-dark); flex-direction: column; padding: 12px; }
  .nav-links.open { display: flex; }
  .nav-toggle { display: block; }
  .hero h1 { font-size: 2rem; }
  .section-head { flex-direction: column; gap: 8px; }
}

/* ===================================================================
   MOBILE-FRIENDLY ENHANCEMENTS (Android + iOS)
   Appended below the original styles so they take precedence.
   =================================================================== */

/* Prevent iOS from auto-resizing text on orientation change */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* Never let any element force horizontal scrolling */
html, body { overflow-x: hidden; max-width: 100%; }
img { max-width: 100%; height: auto; }

/* On phones, inputs must be >=16px or iOS Safari zooms in on focus */
@media (max-width: 768px) {
  input, select, textarea { font-size: 16px; }
}

/* Comfortable thumb-sized tap targets on touch screens */
@media (max-width: 768px) {
  .btn { padding: 12px 20px; }
  .btn-sm { padding: 9px 16px; font-size: .9rem; }
  .nav-links a { padding: 12px 14px; }
  .filterbar a { padding: 9px 16px; }
}

/* Tables: let wide admin/content tables scroll sideways instead of
   breaking the layout. Wrap a table in <div class="table-scroll"> in
   the EJS, OR this also gently handles bare tables. */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 768px) {
  .table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .table th, .table td { padding: 10px 12px; }
}

/* Tighten hero + sections on small screens */
@media (max-width: 640px) {
  /* Compact hero: headline + buttons + slim USP strip, then straight to
     Exam Categories — no more scrolling through a wall of maroon. */
  .hero { padding: 18px 0 16px; }
  .hero h1 { font-size: 1.35rem; margin-bottom: 8px; }
  .hero h1 br { display: none; }
  .hero p { display: none; }             /* the buttons say it all on mobile */
  .hero-actions { gap: 8px; }
  .hero-actions .btn { padding: 8px 14px; font-size: .85rem; }
  .section { padding: 24px 0; }
  .section-head h2 { font-size: 1.5rem; }
  .container { padding: 0 16px; }
  .card { padding: 16px; }
}

/* Quiz screen: roomier on phones */
@media (max-width: 640px) {
  .quiz-shell { margin: 14px auto; padding: 0 12px; }
  .quiz-bar { padding: 12px 14px; }
  .quiz-bar h1 { font-size: 1rem; }
  .q-text { font-size: 1.05rem; }
  .opt { padding: 14px 14px; }            /* easier to tap an option */
  .palette button { width: 34px; height: 34px; }
}

/* Result stat grid: 5 across is too tight on phones.
   3 across on small tablets, 2 across on phones. */
@media (max-width: 760px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr) !important; }
}
@media (max-width: 480px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .result-score { font-size: 2.2rem; }
}

/* Forms: full width and not cramped on phones */
@media (max-width: 640px) {
  .form-wrap { margin: 24px 12px; padding: 22px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }  /* admin form rows stack */
}

/* Sticky purchase card shouldn't stick on phones (it crowds the screen) */
@media (max-width: 768px) {
  .card[style*="sticky"] { position: static !important; }
}

/* Footer already stacks at 900px; tighten spacing on phones */
@media (max-width: 640px) {
  .footer { padding: 28px 0 18px; }
  .footer .container { gap: 18px; }
}

/* ===================================================================
   NAVBAR CROWDING FIX
   With 9+ nav items the bar was wrapping to two lines and squeezing
   the brand. These rules: (1) lock the brand to one line at full size,
   (2) tighten link spacing slightly, (3) collapse to the hamburger menu
   at a wider breakpoint so links never spill onto a second line.
   Appended last so they take precedence.
   =================================================================== */

/* Brand: never shrink, never wrap, always full size */
.navbar .brand {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 1.9rem;
}

/* Let the links area take the remaining room and sit to the right */
.navbar .nav-links {
  flex: 1 1 auto;
  justify-content: flex-end;
  gap: 2px;
  flex-wrap: nowrap;          /* on desktop, never wrap to a 2nd line */
}

/* Slightly more compact links so more fit before collapsing */
.navbar .nav-links a {
  padding: 8px 11px;
  font-size: .9rem;
  white-space: nowrap;
}

/* "Sign Up" button keeps a bit of separation */
.navbar .nav-links .btn { margin-left: 4px; }

/* Collapse into the ☰ menu while links still don't fit on one line.
   1024px comfortably covers laptops; below it the hamburger appears
   and links stack neatly in a dropdown instead of crowding the bar. */
@media (max-width: 1024px) {
  .navbar .nav-links {
    display: none;
    position: absolute;
    top: 64px; left: 0; right: 0;
    background: var(--maroon-dark);
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    gap: 2px;
    box-shadow: var(--shadow);
  }
  .navbar .nav-links.open { display: flex; }
  .navbar .nav-links a { padding: 12px 14px; font-size: .95rem; }
  .navbar .nav-links .btn { margin-left: 0; margin-top: 6px; }
  .nav-toggle { display: block; }
}

/* The old 640px rule still applies on phones; this just makes sure the
   brand stays full-size there too (it was being shrunk before). */
@media (max-width: 640px) {
  .navbar .brand { font-size: 1.6rem; }
}

/* ===================================================================
   REVISION-NOTE TABLES ON MOBILE
   The notes hold wide 3-column tables (क्र.सं. / प्रश्न / उत्तर) where the
   answer cell is a long paragraph. On phones we (a) let the table scroll
   sideways as a safety net, and (b) give the answer column real width and
   allow long Hindi words to wrap. NOTE: no `white-space: nowrap` here — that
   would force the long answers onto one line and make scrolling painful.
   The JS in revision-note-view.ejs additionally switches to stacked Q&A
   cards on narrow screens; these rules style that fallback too.
   =================================================================== */
.rn-body table { width: 100%; border-collapse: collapse; }

@media (max-width: 640px) {
  /* Table mode (when JS hasn't stacked it, or as a base): scroll sideways */
  .rn-body table.rn-keep-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .rn-body table.rn-keep-table th,
  .rn-body table.rn-keep-table td {
    min-width: 140px;
    font-size: .92rem;
    padding: 8px 10px;
    word-break: break-word;     /* long words wrap instead of overflowing */
    vertical-align: top;
  }
  .rn-body table.rn-keep-table td:last-child,
  .rn-body table.rn-keep-table th:last-child {
    min-width: 240px;           /* the answer column gets room */
  }

  /* Stacked Q&A card mode (added by JS): each row becomes a card */
  .rn-qa-card {
    background: var(--white);
    border: 1px solid var(--line);
    border-left: 4px solid var(--gold);
    border-radius: 12px;
    padding: 14px 16px;
    margin: 0 0 14px;
    box-shadow: var(--shadow);
  }
  .rn-qa-card .rn-qa-q {
    font-family: var(--font-display);
    font-weight: 600;
    color: var(--maroon);
    font-size: 1.02rem;
    margin: 0 0 8px;
    line-height: 1.5;
  }
  .rn-qa-card .rn-qa-a {
    font-size: .96rem;
    line-height: 1.7;
    color: var(--ink);
  }
  .rn-qa-card .rn-qa-num {
    display: inline-block;
    min-width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    background: var(--maroon);
    color: var(--white);
    border-radius: 50%;
    font-size: .8rem;
    margin-right: 8px;
  }
}

/* ===================================================================
   Question stem formatting  (output of /js/question-format.js)
   -------------------------------------------------------------------
   Ek lambi line me aaye सूची-I / सूची-II aur कथन A/B/C ab alag lines me.
   Layout FLEX se hai, hanging indent (text-indent: -Xem) se NAHI —
   negative indent marker ko card ke bahar dhakel deta tha.
   Marker ek fixed column hai, body uske right me wrap hoti hai.
   =================================================================== */
.qf-stem { margin: 0 0 2px; }

.qf-head {
  margin: 9px 0 3px;
  font-weight: 700;
  color: var(--maroon);
}

.qf-item {
  display: flex;
  align-items: baseline;      /* Devanagari ke liye baseline top se behtar */
  margin: 3px 0;
  line-height: 1.6;
}
.qf-item.qf-gap { margin-top: 10px; }

.qf-key {
  flex: 0 0 auto;
  min-width: 1.9em;           /* (a) aur (iii) dono ke baad body ek line par */
  margin-right: .45em;        /* flex gap ke bajaye margin: fallback me bhi kaam kare */
  font-weight: 700;
  color: var(--maroon);
}

.qf-body {
  flex: 1 1 auto;
  min-width: 0;               /* lambe shabd flex item ko overflow na karayein */
}

/* Parent .q-text par white-space:pre-line hai; in divs me newline hai hi nahi,
   isliye yahan normal wrapping chahiye. */
.q-text .qf-stem, .q-text .qf-head, .q-text .qf-item, .q-text .qf-body,
.q-text-hi .qf-stem, .q-text-hi .qf-head, .q-text-hi .qf-item, .q-text-hi .qf-body {
  white-space: normal;
}

@media (max-width: 640px) {
  .qf-key { min-width: 1.75em; margin-right: .35em; }
  .qf-item { line-height: 1.55; }
}
