/* =======================================================================
   AskSia Cheatsheet Design System v2.1
   Calibrated to match production PDF reference (ECON 101).
   - Top-bar section headers (full-width colored block, white italic title)
   - Notebook-paper background
   - Dense 3-column A4 grid
   - Inline tables, mini-boxes, dark procedure callouts, red trap callouts
   - Click-affordance pill (screen only, hidden on print)
   ======================================================================= */

:root {
  /* 8-color palette — matched against PDF reference */
  --c-blue:   #1E40AF;
  --c-green:  #047857;
  --c-pink:   #BE185D;  /* elasticity, applied */
  --c-red:    #B91C1C;  /* failure, traps, consumer-theory section */
  --c-violet: #6D28D9;  /* analytical */
  --c-purple: #7C3AED;  /* market structures */
  --c-cyan:   #0E7490;  /* synthesis / macro */
  --c-amber:  #B45309;
  --c-slate:  #1E293B;  /* always section 8 / decision box */

  /* Light tints for inline mini-boxes */
  --tint-blue:   #EFF6FF;
  --tint-green:  #ECFDF5;
  --tint-pink:   #FDF2F8;
  --tint-red:    #FEF2F2;
  --tint-violet: #F5F3FF;
  --tint-purple: #F5F3FF;
  --tint-cyan:   #ECFEFF;
  --tint-amber:  #FFFBEB;
  --tint-slate:  #F1F5F9;
  --tint-yellow: #FEFCE8;

  /* Surface */
  --paper:    #fdfcf7;
  --ink:      #0f172a;
  --ink-soft: #475569;
  --rule:     #e2e8f0;
  --rule-hi:  #cbd5e1;

  /* Typography */
  --f-body: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --f-mono: "Space Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --f-hand: "Caveat", "Comic Sans MS", cursive;

  /* Density — match reference (~6.5px on A4) */
  --t-base: 6.5px;
  --t-sm:   5.8px;
  --t-md:   7.5px;
  --t-lg:   9px;
  --t-xl:   12px;
  --t-2xl:  18px;
  --t-3xl:  22px;
}

/* ---------- 1. Page frame ---------- */
@page { size: A4; margin: 0; }

* { box-sizing: border-box; }

.cs-page {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--t-base);
  line-height: 1.28;
  padding: 5mm 5mm 4mm 5mm;
  background-image:
    linear-gradient(to bottom, transparent calc(4mm - 0.5px), rgba(30,64,175,0.045) 4mm, transparent calc(4mm + 0.5px));
  background-size: 100% 4mm;
  position: relative;
  box-sizing: border-box;
}

/* ---------- 2. Header strip (page top) ---------- */
.cs-head {
  border-bottom: 1.5px solid var(--ink);
  padding-bottom: 2.5mm;
  margin-bottom: 2.5mm;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4mm;
  align-items: end;
}
.cs-head-l { min-width: 0; }
.cs-head .cs-course {
  font-family: var(--f-hand);
  font-weight: 700;
  font-style: italic;
  font-size: 26px;
  line-height: 1;
  color: var(--ink);
  letter-spacing: 0;
}
.cs-head .cs-course .dot { color: var(--ink-soft); margin: 0 4px; font-weight: 400; }
.cs-head .cs-course .sub {
  font-family: var(--f-hand);
  font-weight: 500;
  font-size: 22px;
  color: var(--ink);
  font-style: italic;
}
.cs-head-tags {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 4px;
}
.cs-tag {
  font-family: var(--f-mono);
  font-size: 5.5px;
  font-weight: 700;
  padding: 1.5px 5px;
  border-radius: 1.5px;
  letter-spacing: 0.5px;
  color: #fff;
  white-space: nowrap;
  text-transform: uppercase;
  text-decoration: none;
}
.cs-head-r {
  text-align: right;
  font-family: var(--f-mono);
  font-size: 6px;
  color: var(--ink-soft);
  font-style: italic;
  letter-spacing: 0.3px;
  line-height: 1.4;
  white-space: nowrap;
}
.cs-head-r .cs-brand-mark { color: var(--ink); font-weight: 700; font-style: normal; }

/* ---------- 3. 3-column grid ---------- */
.cs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 3mm;
}
.cs-col { display: flex; flex-direction: column; gap: 2mm; min-width: 0; }

/* ---------- 4. Section ---------- */
.cs-sec {
  break-inside: auto;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #ffffff;
  position: relative;
}

/* but keep individual elements internally protected */
.sk-trap, .sk-procedure, .cs-mb, .sk-formula, .sk-table { break-inside: avoid; }

/* ---- top colored bar (the signature look) ---- */
.cs-sec-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  background: var(--c-blue);
  color: #ffffff;
  font-family: var(--f-hand);
  font-style: italic;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.3px;
  line-height: 1;
  border-radius: 3px 3px 0 0;
}
.cs-sec[data-theme="blue"]   .cs-sec-bar { background: var(--c-blue); }
.cs-sec[data-theme="green"]  .cs-sec-bar { background: var(--c-green); }
.cs-sec[data-theme="pink"]   .cs-sec-bar { background: var(--c-pink); }
.cs-sec[data-theme="red"]    .cs-sec-bar { background: var(--c-red); }
.cs-sec[data-theme="violet"] .cs-sec-bar { background: var(--c-violet); }
.cs-sec[data-theme="purple"] .cs-sec-bar { background: var(--c-purple); }
.cs-sec[data-theme="cyan"]   .cs-sec-bar { background: var(--c-cyan); }
.cs-sec[data-theme="amber"]  .cs-sec-bar { background: var(--c-amber); }
.cs-sec[data-theme="slate"]  .cs-sec-bar { background: var(--c-slate); }

.cs-sec-num   { font-size: 14px; }
.cs-sec-title { flex: 1; min-width: 0; }

/* click affordance pill (screen only) */
.cs-sec-pill {
  font-family: var(--f-mono);
  font-style: normal;
  font-weight: 700;
  font-size: 5.5px;
  letter-spacing: 0.6px;
  padding: 2px 5px;
  background: rgba(255,255,255,0.18);
  border: 0.8px solid rgba(255,255,255,0.6);
  border-radius: 999px;
  color: #fff;
  white-space: nowrap;
  text-transform: uppercase;
  transition: background 120ms ease, transform 120ms ease;
}
.cs-sec[data-clickable="true"] { cursor: pointer; }
.cs-sec[data-clickable="true"]:hover .cs-sec-pill {
  background: #fff;
  color: var(--ink);
  transform: scale(1.05);
}
.cs-sec[data-clickable="true"]:hover {
  border-color: var(--ink);
  box-shadow: 0 1px 6px rgba(0,0,0,0.10);
}

/* ---- body ---- */
.cs-sec-body {
  padding: 3px 5px 4px 5px;
  font-size: var(--t-base);
}
.cs-sec-body p { margin: 1px 0; }
.cs-sec-body p + p { margin-top: 1.5px; }
.cs-sec-body b, .cs-sec-body strong { font-weight: 700; color: var(--ink); }
.cs-sec-body ul { margin: 1px 0; padding-left: 9px; }
.cs-sec-body li { margin: 0.5px 0; }

/* ---------- 5. Subheading inside section (italic Caveat-ish) ---------- */
.cs-sh {
  font-family: var(--f-hand);
  font-style: italic;
  font-weight: 700;
  font-size: 11px;
  margin: 3px 0 1px 0;
  color: var(--ink);
  letter-spacing: 0.2px;
  line-height: 1;
}
.cs-sh-rule {
  border-top: 0.5px dotted var(--rule-hi);
  margin: 3px 0;
}

/* ---------- 6. Formula box ---------- */
.sk-formula {
  display: block;
  font-family: var(--f-mono);
  font-size: var(--t-sm);
  background: #f1f5f9;
  border: 0.5px solid var(--rule);
  padding: 2px 4px;
  margin: 1.5px 0;
  border-radius: 1.5px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
  color: var(--ink);
}

/* ---------- 7. Table ---------- */
.sk-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5px 0;
  font-size: var(--t-base);
  table-layout: fixed;
}
.sk-table th, .sk-table td {
  border: 0.4px solid var(--rule-hi);
  padding: 1px 3px;
  text-align: left;
  vertical-align: top;
  word-wrap: break-word;
  line-height: 1.2;
}
.sk-table th {
  background: #f1f5f9;
  font-weight: 700;
  font-size: 5.6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--ink);
}
.sk-table td b { font-weight: 700; }

/* ---------- 8. Trap (red bottom callout) ---------- */
.sk-trap {
  background: var(--tint-red);
  border: 0.5px solid #fecaca;
  border-left: 2.5px solid var(--c-red);
  padding: 2.5px 5px;
  margin: 3px 0 1px 0;
  border-radius: 1.5px;
}
.sk-trap-lbl {
  display: block;
  font-family: var(--f-mono);
  font-weight: 700;
  font-size: 5.6px;
  color: var(--c-red);
  letter-spacing: 0.4px;
  margin-bottom: 1px;
  text-transform: uppercase;
}
.sk-trap p { margin: 0; }

/* ---------- 9. Note (amber, optional insight) ---------- */
.sk-note {
  background: var(--tint-amber);
  border: 0.5px solid #fde68a;
  border-left: 2px solid var(--c-amber);
  padding: 2px 4px;
  margin: 1.5px 0;
  border-radius: 1.5px;
  font-style: italic;
}

/* ---------- 10. Procedure (▼ dark) callout ---------- */
.sk-procedure {
  background: var(--ink);
  color: #fff;
  border-radius: 2px;
  padding: 3px 6px;
  margin: 2.5px 0;
  font-size: var(--t-base);
  line-height: 1.3;
}
.sk-procedure-title {
  font-family: var(--f-mono);
  font-size: 5.8px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #fbbf24;
  margin-bottom: 1.5px;
}
.sk-procedure p { margin: 0.5px 0; }
.sk-procedure b { color: #fff; }

/* ---------- 11. Hint (handwritten Sia voice) ---------- */
.sk-hint {
  font-family: var(--f-hand);
  font-style: italic;
  font-size: 9.5px;
  color: var(--ink-soft);
  display: block;
  margin: 1px 0;
  line-height: 1.15;
  font-weight: 500;
}

/* ---------- 12. Mono inline ---------- */
.sk-mono {
  font-family: var(--f-mono);
  font-size: 6px;
  background: #f1f5f9;
  padding: 0.5px 2px;
  border-radius: 1.5px;
  color: var(--ink);
}

/* ---------- 13. Highlights (inline color emphasis) ---------- */
.cs-hb { color: var(--c-blue);   font-weight: 700; }
.cs-hg { color: var(--c-green);  font-weight: 700; }
.cs-hp { color: var(--c-pink);   font-weight: 700; }
.cs-hr { color: var(--c-red);    font-weight: 700; }
.cs-hv { color: var(--c-violet); font-weight: 700; }
.cs-hpu{ color: var(--c-purple); font-weight: 700; }
.cs-hc { color: var(--c-cyan);   font-weight: 700; }
.cs-ha { color: var(--c-amber);  font-weight: 700; }

/* ---------- 14. 2-col / 3-col inside section ---------- */
.cs-two, .cs-three {
  display: grid; gap: 3px; margin: 1.5px 0;
}
.cs-two { grid-template-columns: 1fr 1fr; }
.cs-three { grid-template-columns: 1fr 1fr 1fr; }

/* ---------- 15. Mini-box (light tinted, with title) ---------- */
.cs-mb {
  background: var(--tint-yellow);
  border: 0.5px solid #fde68a;
  border-radius: 2px;
  padding: 2.5px 4px;
}
.cs-mb-title {
  font-family: var(--f-hand);
  font-style: italic;
  font-weight: 700;
  font-size: 9.5px;
  margin-bottom: 0.5px;
  line-height: 1;
  color: var(--ink);
}
.cs-mb p { margin: 0.5px 0; }

.cs-mb.cs-mb-blue   { background: var(--tint-blue);   border-color: #bfdbfe; }
.cs-mb.cs-mb-green  { background: var(--tint-green);  border-color: #a7f3d0; }
.cs-mb.cs-mb-pink   { background: var(--tint-pink);   border-color: #fbcfe8; }
.cs-mb.cs-mb-red    { background: var(--tint-red);    border-color: #fecaca; }
.cs-mb.cs-mb-violet { background: var(--tint-violet); border-color: #ddd6fe; }
.cs-mb.cs-mb-cyan   { background: var(--tint-cyan);   border-color: #a5f3fc; }
.cs-mb.cs-mb-amber  { background: var(--tint-amber);  border-color: #fde68a; }
.cs-mb.cs-mb-slate  { background: var(--tint-slate);  border-color: #cbd5e1; }

/* ---------- 16. Footer strip ---------- */
.cs-foot {
  margin-top: 3mm;
  padding-top: 2mm;
  border-top: 0.5px solid var(--rule);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  font-family: var(--f-mono);
  font-size: 5.5px;
  color: var(--ink-soft);
  letter-spacing: 0.3px;
}
.cs-foot-mid { font-family: var(--f-hand); font-style: italic; font-size: 12px; color: var(--ink); font-weight: 700; }
.cs-foot-r { text-align: right; }
.cs-foot a { color: var(--c-blue); text-decoration: none; }

/* =======================================================================
   17. INTERACTION LAYER (NOT printed)
   ======================================================================= */

/* First-time hint banner */
.cs-tap-hint {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(90deg, #6D28D9, #BE185D);
  color: #fff;
  font-family: var(--f-body);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 7px 14px;
  letter-spacing: 0.2px;
}
.cs-tap-hint .cs-tap-hint-emoji { font-size: 14px; vertical-align: -2px; margin-right: 4px; }
.cs-tap-hint button {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.4);
  color: #fff;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  margin-left: 10px;
}
.cs-tap-hint button:hover { background: rgba(255,255,255,0.3); }

/* Modal */
.cs-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.cs-overlay.is-open { display: flex; }
.cs-modal {
  background: #fff;
  border-radius: 10px;
  max-width: 760px; width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex; flex-direction: column;
  font-family: var(--f-body);
  font-size: 14px; line-height: 1.5;
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.cs-modal-hdr {
  padding: 14px 18px;
  border-bottom: 1px solid var(--rule);
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px;
}
.cs-modal-hdr h3 {
  margin: 0;
  font-size: 17px; font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cs-modal-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.cs-modal-share-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff; color: var(--ink);
  border: 1px solid var(--ink); padding: 5px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: inherit;
  transition: all 120ms ease;
}
.cs-modal-share-btn:hover { background: var(--ink); color: #fff; }
.cs-modal-close {
  background: none; border: none;
  font-size: 22px; cursor: pointer;
  color: var(--ink-soft); line-height: 1; padding: 0 4px;
}
.cs-modal-viz {
  padding: 14px 18px 8px;
  border-bottom: 1px solid var(--rule);
  background: #fafaf7;
  display: none;
}
.cs-modal-viz svg { display: block; margin: 0 auto; }
.cs-modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--rule);
  padding: 0 18px;
  gap: 4px;
  flex-shrink: 0;
}
.cs-modal-tab {
  background: none; border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 12px;
  font-size: 12px; font-weight: 600;
  color: var(--ink-soft); cursor: pointer;
  font-family: var(--f-body);
}
.cs-modal-tab.is-active {
  color: var(--ink); border-bottom-color: var(--c-violet);
}
.cs-modal-body {
  padding: 18px; overflow-y: auto; flex: 1;
}
.cs-modal-pane { display: none; }
.cs-modal-pane.is-active { display: block; }
.cs-modal-pane h4 {
  margin: 0 0 8px 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-soft);
  font-weight: 700;
}
.cs-modal-pane code,
.cs-modal-pane .sk-formula {
  font-size: 13px; padding: 6px 10px;
  display: block; margin: 6px 0;
  font-family: var(--f-mono);
}
.cs-modal-pane p { margin: 8px 0; }

/* ---------- 18. Mobile responsive ---------- */
@media (max-width: 760px) {
  .cs-page {
    width: 100%; min-height: auto;
    padding: 12px 10px; font-size: 11px;
    background-size: 100% 8mm;
  }
  .cs-grid { grid-template-columns: 1fr; gap: 8px; }
  .cs-head { grid-template-columns: 1fr; }
  .cs-head-r { text-align: left; white-space: normal; }
  .cs-head .cs-course { font-size: 22px; }
  .cs-head .cs-course .sub { font-size: 18px; }
  .cs-sec-body { font-size: 11px; }
  .cs-sh { font-size: 14px; }
  .cs-sec-bar { font-size: 14px; padding: 6px 8px; }
  .cs-sec-num { font-size: 16px; }
  .sk-formula, .sk-table { font-size: 10.5px; }
  .sk-table th { font-size: 9.5px; }
  .sk-trap-lbl, .sk-procedure-title { font-size: 9px; }
  .sk-hint { font-size: 13px; }
  .sk-mono { font-size: 10.5px; }
  .cs-mb-title { font-size: 13px; }
  .cs-tag { font-size: 9px; padding: 2px 6px; }
  .cs-foot { grid-template-columns: 1fr; gap: 4px; text-align: center; font-size: 9px; }
  .cs-foot-r { text-align: center; }
  .cs-foot-mid { font-size: 14px; }
  .cs-sec-pill { font-size: 8px; padding: 3px 7px; }
}

/* ---------- 19. Print = exact PDF reference (overrides mobile) ---------- */
@media print {
  .cs-overlay, .cs-no-print, .cs-tap-hint { display: none !important; }
  body { background: white !important; margin: 0 !important; }
  .cs-page {
    width: 100% !important;
    min-height: auto !important;
    margin: 0 !important;
    padding: 5mm 5mm 4mm 5mm !important;
    background-image: none !important;
    box-shadow: none !important;
    font-size: var(--t-base) !important;
    line-height: 1.28 !important;
  }
  .cs-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr 1fr !important;
    gap: 3mm !important;
  }
  .cs-col { gap: 2mm !important; }
  .cs-head { grid-template-columns: 1fr auto !important; }
  .cs-head-r { text-align: right !important; white-space: nowrap !important; font-size: 6px !important; }
  .cs-head .cs-course { font-size: 26px !important; }
  .cs-head .cs-course .sub { font-size: 22px !important; }
  .cs-sec-bar { font-size: 13px !important; padding: 4px 7px !important; }
  .cs-sec-num { font-size: 14px !important; }
  .cs-sec-body { font-size: var(--t-base) !important; padding: 3px 5px 4px 5px !important; }
  .cs-sh { font-size: 11px !important; }
  .sk-formula, .sk-table { font-size: var(--t-sm) !important; }
  .sk-table th { font-size: 5.6px !important; }
  .sk-trap-lbl, .sk-procedure-title { font-size: 5.6px !important; }
  .sk-hint { font-size: 9.5px !important; }
  .sk-mono { font-size: 6px !important; }
  .cs-mb-title { font-size: 9.5px !important; }
  .cs-tag { font-size: 5.5px !important; padding: 1.5px 5px !important; }
  .cs-foot { grid-template-columns: 1fr auto 1fr !important; gap: 0 !important; text-align: left !important; font-size: 5.5px !important; }
  .cs-foot-r { text-align: right !important; }
  .cs-foot-mid { font-size: 12px !important; }
  .cs-sec[data-clickable="true"] { cursor: default !important; box-shadow: none !important; border-color: var(--rule) !important; }
  .cs-sec-pill { display: none !important; }
  .cs-actionbar, .cs-viral, .cs-mobile-hint { display: none !important; }
}
