/* ============================================================
   Mod's Engineering Mathematics — design system
   Concept: กระดาษกราฟวิศวกรรม + ปากกาแดงอาจารย์
   ============================================================ */

:root {
  /* paper */
  --paper:      #F1F4EF;
  --paper-2:    #E8EDE6;
  --paper-3:    #DFE6DC;
  --grid:       rgba(27, 42, 46, 0.055);
  --grid-major: rgba(27, 42, 46, 0.10);

  /* ink */
  --ink:        #1B2A2E;
  --ink-2:      #3C4F54;
  --ink-3:      #6B7C80;
  --hair:       rgba(27, 42, 46, 0.16);

  /* pens */
  --red:        #C4362C;
  --red-soft:   rgba(196, 54, 44, 0.10);
  --blue:       #2E5C86;
  --blue-soft:  rgba(46, 92, 134, 0.10);

  /* type */
  --display: "Trirong", Georgia, serif;
  --body:    "IBM Plex Sans Thai", system-ui, -apple-system, sans-serif;
  --mono:    "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

  /* metrics */
  --shell:   1180px;
  --gutter:  clamp(20px, 5vw, 56px);
  --margin-rule: 96px;   /* notebook left margin on desktop */
  --header-h: 66px;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 24px); }
body {
  margin: 0;
  font-family: var(--body);
  font-weight: 400;
  font-size: 17px;
  line-height: 1.75;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px);
  background-size: 26px 26px, 26px 26px, 130px 130px, 130px 130px;
  overflow-wrap: break-word;
}
img, svg { max-width: 100%; display: block; }
a { color: var(--blue); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--red); }
:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; border-radius: 2px; }

h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; line-height: 1.18; margin: 0; letter-spacing: -0.01em; }
p { margin: 0 0 1.1em; }
p:last-child { margin-bottom: 0; }

/* ---------- shell ---------- */
.shell { width: 100%; max-width: var(--shell); margin-inline: auto; padding-inline: var(--gutter); }

/* section wrapper carries the red notebook margin rule */
.band { position: relative; padding-block: clamp(56px, 8vw, 104px); }
.band + .band { border-top: 1px solid var(--hair); }
.band--tint { background: var(--paper-2); }
.band--ink  { background: var(--ink); color: var(--paper); }
.band--ink h1, .band--ink h2, .band--ink h3 { color: #fff; }
.band--ink a { color: #C9DCEF; }

/* ---------- eyebrow: exercise-book annotation ---------- */
.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--red);
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 18px;
}
.eyebrow::before {
  content: "";
  width: 26px; height: 2px;
  background: var(--red);
  flex: none;
}
.band--ink .eyebrow { color: #E8907F; }
.band--ink .eyebrow::before { background: #E8907F; }

/* ---------- header ---------- */
.hdr {
  position: sticky; top: 0; z-index: 60;
  height: var(--header-h);
  display: flex; align-items: center;
  background: rgba(241, 244, 239, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hair);
}
.hdr__in { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand {
  font-family: var(--display); font-weight: 600;
  font-size: clamp(16px, 2.2vw, 19px);
  color: var(--ink); text-decoration: none; letter-spacing: -0.015em;
  display: flex; align-items: baseline; gap: 9px;
}
.brand__mark {
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  color: var(--red); border: 1.5px solid var(--red);
  padding: 1px 5px; letter-spacing: 0.04em; align-self: center;
}
.brand:hover { color: var(--ink); }

/* hamburger */
.burger {
  appearance: none; border: 1px solid var(--hair); background: transparent;
  height: 42px; padding: 0 14px 0 16px; cursor: pointer;
  display: flex; align-items: center; gap: 11px;
  font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink);
  transition: border-color .18s, background .18s;
}
.burger:hover { border-color: var(--red); background: var(--red-soft); }
.burger__lines { display: grid; gap: 4px; width: 20px; }
.burger__lines i { display: block; height: 1.5px; background: var(--ink); transition: transform .3s, opacity .2s; }
.burger__lines i:nth-child(2) { width: 70%; margin-left: auto; }
.burger[aria-expanded="true"] .burger__lines i:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
.burger[aria-expanded="true"] .burger__lines i:nth-child(2) { opacity: 0; }
.burger[aria-expanded="true"] .burger__lines i:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }
.burger__label { display: none; }
@media (min-width: 560px) { .burger__label { display: inline; } }

/* ---------- nav panel ---------- */
.nav {
  position: fixed; inset: 0; z-index: 55;
  background: var(--ink);
  background-image:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 26px 26px;
  padding-top: var(--header-h);
  overflow-y: auto;
  opacity: 0; visibility: hidden;
  transition: opacity .28s ease, visibility .28s;
}
.nav[data-open="true"] { opacity: 1; visibility: visible; }
.nav__in {
  display: grid; gap: clamp(32px, 5vw, 56px);
  grid-template-columns: 1fr;
  padding-block: clamp(28px, 5vw, 52px) 64px;
}
@media (min-width: 900px) { .nav__in { grid-template-columns: 1.15fr 1fr; } }

.nav__head {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; color: #E8907F;
  padding-bottom: 10px; margin-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,.14);
}
.nav__list { list-style: none; margin: 0; padding: 0; }
.nav__list li { border-bottom: 1px solid rgba(255,255,255,.08); }
.nav__link {
  display: flex; align-items: baseline; gap: 14px;
  padding: 13px 4px; text-decoration: none; color: #EEF2EC;
  transition: color .16s, padding-left .16s;
}
.nav__link:hover, .nav__link:focus-visible { color: #fff; padding-left: 12px; }
.nav__link:hover .nav__num { color: var(--red); }
.nav__num { font-family: var(--mono); font-size: 11px; color: rgba(238,242,236,.45); flex: none; width: 24px; transition: color .16s; }
.nav__t { font-family: var(--display); font-size: clamp(21px, 3.4vw, 29px); font-weight: 500; line-height: 1.25; }
.nav__s { font-size: 13px; color: rgba(238,242,236,.55); margin-left: auto; text-align: right; }

.nav__list--sub .nav__t { font-family: var(--body); font-size: 16px; font-weight: 500; }
.nav__list--sub .nav__link { padding: 10px 4px; }

.nav__cta {
  display: block; margin-top: 26px; padding: 18px 20px;
  background: var(--red); color: #fff !important; text-decoration: none;
  transition: background .18s;
}
.nav__cta:hover { background: #A82A21; }
.nav__cta b { display: block; font-family: var(--display); font-size: 20px; font-weight: 600; }
.nav__cta span { font-size: 13.5px; opacity: .88; }

.nav__meta { margin-top: 22px; font-family: var(--mono); font-size: 12px; color: rgba(238,242,236,.5); line-height: 2; }
.nav__meta a { color: rgba(238,242,236,.8); text-decoration: none; }
.nav__meta a:hover { color: #fff; }

body[data-lock="true"] { overflow: hidden; }

/* ---------- hero ---------- */
.hero { padding-block: clamp(56px, 10vw, 116px) clamp(48px, 8vw, 92px); position: relative; }
.hero__grid { display: grid; gap: clamp(34px, 5vw, 60px); }
@media (min-width: 940px) { .hero__grid { grid-template-columns: 1.35fr .85fr; align-items: end; } }

.hero h1 {
  font-size: clamp(38px, 7.2vw, 78px);
  font-weight: 600; line-height: 1.06; letter-spacing: -0.025em;
  margin-bottom: 26px;
}
.hero h1 em { font-style: normal; position: relative; display: inline-block; }
.hero h1 em svg { position: absolute; left: -2%; bottom: -0.16em; width: 104%; height: .34em; overflow: visible; }
.hero h1 em path { fill: none; stroke: var(--red); stroke-width: 7; stroke-linecap: round;
  stroke-dasharray: 620; stroke-dashoffset: 620; animation: draw 1.05s .5s cubic-bezier(.65,0,.35,1) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

.hero__lede { font-size: clamp(17px, 2.1vw, 20px); color: var(--ink-2); max-width: 54ch; margin-bottom: 30px; }
.hero__lede strong { color: var(--ink); font-weight: 600; }

/* the "worked line" card — signature */
.solve {
  border: 1px solid var(--hair); background: rgba(255,255,255,.62);
  padding: 22px 24px;
}
.solve__cap {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3); border-bottom: 1px dashed var(--hair); padding-bottom: 10px; margin-bottom: 16px;
}
.solve ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 13px; }
.solve li { display: grid; grid-template-columns: 26px 1fr; gap: 12px; align-items: baseline; }
.solve li > span:first-child { font-family: var(--mono); font-size: 11px; color: var(--red); }
.solve code { font-family: var(--mono); font-size: clamp(13px, 1.7vw, 15.5px); color: var(--ink); background: none; }
.solve li small { display: block; font-size: 12.5px; color: var(--ink-3); font-family: var(--body); margin-top: 2px; }
.solve__foot { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--hair); font-size: 13.5px; color: var(--ink-2); }

/* ---------- buttons ---------- */
.btns { display: flex; flex-wrap: wrap; gap: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 13px 22px; text-decoration: none;
  font-family: var(--body); font-size: 15.5px; font-weight: 500;
  border: 1.5px solid var(--ink); color: var(--ink); background: transparent;
  transition: background .18s, color .18s, border-color .18s, transform .18s;
}
.btn:hover { background: var(--ink); color: var(--paper); transform: translateY(-1px); }
.btn--red { background: var(--red); border-color: var(--red); color: #fff; }
.btn--red:hover { background: #A82A21; border-color: #A82A21; color: #fff; }
.btn--ghost { border-color: var(--hair); color: var(--ink-2); }
.btn--ghost:hover { border-color: var(--ink); background: transparent; color: var(--ink); }
.btn--yt { border-color: var(--hair); }
.btn--yt:hover { background: #C4302B; border-color: #C4302B; color: #fff; }

/* ---------- generic heading block ---------- */
.head { max-width: 62ch; margin-bottom: clamp(32px, 4.5vw, 52px); }
.head h2 { font-size: clamp(28px, 4.4vw, 44px); margin-bottom: 16px; }
.head p { color: var(--ink-2); font-size: clamp(16px, 1.9vw, 18px); }

/* ---------- topic cards ---------- */
.cards { display: grid; gap: 1px; background: var(--hair); border: 1px solid var(--hair); }
@media (min-width: 700px)  { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .cards { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--paper); padding: 26px 24px 24px;
  text-decoration: none; color: inherit; display: flex; flex-direction: column;
  transition: background .2s;
  position: relative;
}
.card:hover { background: #fff; color: inherit; }
.card:hover .card__go { color: var(--red); transform: translateX(4px); }
.card__sym { font-family: var(--mono); font-size: 24px; color: var(--blue); line-height: 1; margin-bottom: 16px; }
.card__cat { font-family: var(--mono); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 8px; }
.card h3 { font-size: 21px; margin-bottom: 8px; }
.card p { font-size: 14.5px; color: var(--ink-2); line-height: 1.65; margin-bottom: 18px; }
.card__go { margin-top: auto; font-family: var(--mono); font-size: 12px; letter-spacing: .1em; color: var(--ink-3); transition: color .18s, transform .18s; display: inline-block; }

/* ---------- two-column prose ---------- */
.split { display: grid; gap: clamp(30px, 5vw, 58px); }
@media (min-width: 900px) { .split { grid-template-columns: 1fr 1fr; align-items: start; } }
@media (min-width: 900px) { .split--wide { grid-template-columns: 1.25fr .75fr; } }

.prose { max-width: 68ch; }
.prose h2 { font-size: clamp(26px, 3.6vw, 36px); margin: 1.6em 0 .5em; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: clamp(19px, 2.4vw, 23px); margin: 1.7em 0 .45em; }
.prose ul, .prose ol { margin: 0 0 1.2em; padding-left: 1.25em; }
.prose li { margin-bottom: .5em; }
.prose code { font-family: var(--mono); font-size: .92em; background: var(--blue-soft); padding: 1px 5px; }

/* callout — red pen note */
.note {
  border-left: 3px solid var(--red); background: var(--red-soft);
  padding: 16px 20px; margin: 1.6em 0; font-size: 15.5px;
}
.note b { font-family: var(--mono); font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--red); display: block; margin-bottom: 5px; }

/* ---------- spec list (prereq / outcomes) ---------- */
.spec { border: 1px solid var(--hair); background: rgba(255,255,255,.55); padding: 22px 24px; }
.spec + .spec { margin-top: 16px; }
.spec__h { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 12px; }
.spec ul { list-style: none; margin: 0; padding: 0; }
.spec li { display: grid; grid-template-columns: 16px 1fr; gap: 9px; font-size: 15px; line-height: 1.6; padding: 6px 0; border-bottom: 1px dashed var(--hair); }
.spec li:last-child { border-bottom: 0; }
.spec li::before { content: "✓"; color: var(--red); font-size: 13px; }
.spec--plain li::before { content: "·"; color: var(--ink-3); }

/* ---------- chapter list ---------- */
.chapters { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--hair); }
.chapters li { border-bottom: 1px solid var(--hair); }
.chapters a {
  display: grid; grid-template-columns: 54px 1fr auto; gap: 14px; align-items: center;
  padding: 15px 6px; text-decoration: none; color: var(--ink);
  transition: background .16s, padding-left .16s;
}
.chapters a:hover { background: rgba(255,255,255,.7); padding-left: 14px; color: var(--ink); }
.chapters a:hover .ch__go { color: var(--red); }
.ch__n { font-family: var(--mono); font-size: 11.5px; color: var(--red); letter-spacing: .06em; }
.ch__t { font-weight: 500; font-size: 16px; line-height: 1.4; }
.ch__t small { display: block; font-weight: 400; font-size: 13px; color: var(--ink-3); font-family: var(--mono); letter-spacing: .02em; }
.ch__go { font-family: var(--mono); font-size: 11px; color: var(--ink-3); transition: color .16s; }

/* ---------- training / price table ---------- */
.courses-b { display: grid; gap: 1px; background: var(--hair); border: 1px solid var(--hair); }
@media (min-width: 800px) { .courses-b { grid-template-columns: repeat(2, 1fr); } }
.cb { background: var(--paper); padding: 28px 26px; }
.cb__tag { font-family: var(--mono); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--red); margin-bottom: 10px; }
.cb h3 { font-size: 22px; margin-bottom: 10px; }
.cb p { font-size: 15px; color: var(--ink-2); margin-bottom: 16px; }
.cb ul { list-style: none; margin: 0 0 4px; padding: 0; font-size: 14.5px; }
.cb li { padding: 5px 0; border-top: 1px dashed var(--hair); display: flex; justify-content: space-between; gap: 12px; color: var(--ink-2); }
.cb li b { font-weight: 500; color: var(--ink); font-family: var(--mono); font-size: 13px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--hair); border: 1px solid var(--hair); }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--paper); padding: 22px 20px; }
.band--ink .stat { background: var(--ink); }
.stat b { display: block; font-family: var(--display); font-size: clamp(26px, 4vw, 38px); font-weight: 600; line-height: 1; margin-bottom: 7px; }
.stat span { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.band--ink .stat span { color: rgba(238,242,236,.55); }

/* ---------- timeline ---------- */
.tl { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--hair); }
.tl li { position: relative; padding: 0 0 30px 26px; }
.tl li::before { content: ""; position: absolute; left: -4.5px; top: 9px; width: 8px; height: 8px; background: var(--paper); border: 1.5px solid var(--ink-3); border-radius: 50%; }
.tl li[data-now]::before { background: var(--red); border-color: var(--red); }
.tl__y { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.tl li[data-now] .tl__y { color: var(--red); }
.tl h3 { font-size: 20px; margin: 3px 0 5px; }
.tl p { font-size: 14.5px; color: var(--ink-2); }

/* ---------- FAQ ---------- */
.faq { border-top: 1px solid var(--hair); }
.faq details { border-bottom: 1px solid var(--hair); }
.faq summary {
  cursor: pointer; padding: 18px 34px 18px 4px; position: relative;
  font-family: var(--display); font-size: clamp(17px, 2.2vw, 20px); font-weight: 500;
  list-style: none;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-family: var(--mono); color: var(--red); font-size: 19px; }
.faq details[open] summary::after { content: "−"; }
.faq details > div { padding: 0 34px 20px 4px; font-size: 15.5px; color: var(--ink-2); }

/* ---------- contact ---------- */
.chan { display: grid; gap: 1px; background: var(--hair); border: 1px solid var(--hair); }
@media (min-width: 700px) { .chan { grid-template-columns: repeat(3, 1fr); } }
.chan a { background: var(--paper); padding: 24px 22px; text-decoration: none; color: inherit; display: block; transition: background .18s; }
.chan a:hover { background: #fff; color: inherit; }
.chan__k { font-family: var(--mono); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--red); margin-bottom: 9px; }
.chan b { font-family: var(--display); font-size: 19px; font-weight: 600; display: block; margin-bottom: 4px; }
.chan span { font-size: 14px; color: var(--ink-2); }

.form { display: grid; gap: 16px; max-width: 560px; }
.field { display: grid; gap: 6px; }
.field label { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.field input, .field select, .field textarea {
  font-family: var(--body); font-size: 16px; color: var(--ink);
  background: rgba(255,255,255,.72); border: 1px solid var(--hair);
  padding: 12px 14px; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--red); outline-offset: 0; border-color: transparent; }
.field textarea { min-height: 140px; resize: vertical; }
.form__note { font-size: 13px; color: var(--ink-3); }
.form__status { font-size: 14.5px; padding: 12px 14px; border-left: 3px solid var(--ink-3); background: rgba(255,255,255,.6); }
.form__status[data-ok="1"] { border-color: #2E7D4F; }
.form__status[data-ok="0"] { border-color: var(--red); }

/* ---------- CTA band ---------- */
.cta__h { font-size: clamp(28px, 4.6vw, 46px); margin-bottom: 16px; max-width: 20ch; }
.cta__p { color: rgba(238,242,236,.72); max-width: 52ch; margin-bottom: 28px; font-size: 17px; }
.band--ink .btn { border-color: rgba(255,255,255,.34); color: #fff; }
.band--ink .btn:hover { background: #fff; color: var(--ink); border-color: #fff; }
.band--ink .btn--red { background: var(--red); border-color: var(--red); }
.band--ink .btn--red:hover { background: #fff; color: var(--red); }

/* ---------- footer ---------- */
.ft { background: var(--paper-2); border-top: 1px solid var(--hair); padding-block: 46px 34px; font-size: 14.5px; }
.ft__in { display: grid; gap: 30px; }
@media (min-width: 800px) { .ft__in { grid-template-columns: 1.4fr 1fr 1fr; } }
.ft h4 { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); font-weight: 500; margin-bottom: 12px; }
.ft ul { list-style: none; margin: 0; padding: 0; }
.ft li { margin-bottom: 7px; }
.ft a { color: var(--ink-2); text-decoration: none; }
.ft a:hover { color: var(--red); }
.ft__legal { margin-top: 34px; padding-top: 18px; border-top: 1px solid var(--hair); font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between; }

/* ---------- breadcrumb ---------- */
.crumb { font-family: var(--mono); font-size: 11.5px; letter-spacing: .08em; color: var(--ink-3); padding-top: 26px; }
.crumb a { color: var(--ink-3); text-decoration: none; }
.crumb a:hover { color: var(--red); }

/* ---------- utility ---------- */
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -9999px; top: 0; z-index: 100; background: var(--red); color: #fff; padding: 10px 16px; }
.skip:focus { left: 8px; top: 8px; color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
  .hero h1 em path { stroke-dashoffset: 0; }
}
