/* three.js Learning Lab — shared design system
   minimalist warm editorial · Fraunces / Noto Sans Thai / JetBrains Mono */

:root {
  --paper:   #f7f4ee;
  --surface: #fffdf9;
  --ink:     #1c1a17;
  --muted:   #6d685f;
  --faint:   #726c60;   /* darkened 2026-06-02: เดิม #908a7f ratio ~3.3 < AA — บัดนี้ ~4.7 ผ่าน AA ทั้ง lab */
  --line:    #e7e1d6;
  --line-2:  #d9d2c4;
  --accent:  #b4530a;   /* warm terracotta */
  --accent-soft: #f0e2d4;
  --ok:      #3f7d4e;
  --shadow:  0 1px 2px rgba(28,26,23,.05), 0 8px 28px -12px rgba(28,26,23,.18);
  --radius:  14px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --thai: "Noto Sans Thai", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--thai);
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; text-decoration: none; }
canvas { display: block; }

/* ---------- topbar (demo pages) ---------- */
.topbar {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.back {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 12px; letter-spacing: .04em;
  color: var(--muted); padding: 6px 10px; border-radius: 8px;
  transition: background .18s ease, color .18s ease;
}
.back:hover { background: var(--accent-soft); color: var(--accent); }
.crumb { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.crumb .sub { color: var(--faint); font-weight: 400; font-size: 14px; }
.tag {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--ink); color: var(--paper);
  font-family: var(--mono); font-weight: 600; font-size: 13px;
}
.spacer { flex: 1; }
.btn {
  font-family: var(--thai); font-size: 13px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  padding: 7px 14px; border-radius: 9px; display: inline-flex; align-items: center; gap: 7px;
  transition: border-color .18s, background .18s, transform .1s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn i { font-size: 12px; }

/* ---------- demo stage ---------- */
body.demo { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.stage { flex: 1 1 auto; position: relative; overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

/* HUD elements inside stage */
.hud { position: absolute; z-index: 20; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud.bl { left: 18px; bottom: 18px; }
.hud.tr { right: 18px; top: 18px; }
.hud.tl { left: 18px; top: 18px; }
.hud.br { right: 18px; bottom: 18px; }

/* live renderer.info stats */
.stats {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px;
  box-shadow: var(--shadow); font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  min-width: 150px;
}
.stats .row { display: flex; justify-content: space-between; gap: 16px; line-height: 1.8; }
.stats .row b { color: var(--ink); font-weight: 600; }
.stats .row .hot { color: var(--accent); }
.stats h4 { margin: 0 0 6px; font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--faint); font-weight: 600; }

.status {
  font-family: var(--mono); font-size: 11px; letter-spacing: .03em;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 7px;
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }

/* color legend (data viz) */
.legend {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  box-shadow: var(--shadow); width: 190px;
}
.legend h4 { margin: 0 0 8px; font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--faint); }
.legend canvas { width: 100%; height: 14px; border-radius: 5px; border: 1px solid var(--line); }
.legend .scale { display: flex; justify-content: space-between; font-family: var(--mono);
  font-size: 11px; color: var(--muted); margin-top: 6px; }

/* hover tooltip */
.tooltip {
  position: absolute; z-index: 25; pointer-events: none;
  background: var(--ink); color: var(--paper);
  font-family: var(--mono); font-size: 12px; padding: 6px 10px; border-radius: 8px;
  transform: translate(-50%, calc(-100% - 12px)); white-space: nowrap;
  opacity: 0; transition: opacity .12s ease;
}
.tooltip.on { opacity: 1; }

/* 3D HTML label (CSS2D) */
.label3d {
  font-family: var(--mono); font-size: 12px; color: var(--ink);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line-2); border-radius: 999px; padding: 5px 11px;
  box-shadow: var(--shadow); white-space: nowrap; user-select: none;
}
.label3d b { color: var(--accent); }
.label3d::after {
  content: ""; position: absolute; left: 14px; bottom: -5px;
  width: 9px; height: 9px; background: inherit; border-right: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2); transform: rotate(45deg);
}

/* loading */
.loader {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 15;
  background: var(--paper); transition: opacity .5s ease;
}
.loader.hide { opacity: 0; pointer-events: none; }
.loader .ring { width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
.loader .pct { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* notice banner (webgpu backend) */
.notice {
  font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 8px 12px; max-width: 320px;
}
.notice b { color: var(--ink); }

/* ---------- info panel (slide-in lesson) ---------- */
.info {
  position: absolute; z-index: 40; top: 0; left: 0; bottom: 0; width: min(420px, 88vw);
  background: var(--surface); border-right: 1px solid var(--line);
  box-shadow: 0 0 60px -10px rgba(28,26,23,.25);
  padding: 28px 26px 40px; overflow-y: auto;
  transform: translateX(-102%); transition: transform .34s cubic-bezier(.4,0,.2,1);
}
.info.open { transform: translateX(0); }
.info h2 { font-family: var(--display); font-weight: 600; font-size: 26px; margin: 0 0 4px; letter-spacing: -.01em; }
.info .kicker { font-family: var(--mono); font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 14px; }
.info p { color: var(--muted); font-size: 14.5px; margin: 0 0 14px; }
.info h3 { font-size: 13px; font-family: var(--mono); letter-spacing: .04em; text-transform: uppercase;
  color: var(--faint); margin: 22px 0 8px; }
.info ul { margin: 0 0 14px; padding-left: 18px; color: var(--ink); font-size: 14px; }
.info li { margin-bottom: 6px; }
.info code, .skills code, .info .api {
  font-family: var(--mono); font-size: .88em; background: var(--accent-soft);
  color: #8a3f06; padding: 1px 6px; border-radius: 5px;
}
.info .close { position: absolute; top: 16px; right: 16px; }

/* code block (fundamentals) */
pre.code {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.7;
  background: #221f1b; color: #ece6da; border-radius: 12px; padding: 18px 20px;
  overflow-x: auto; margin: 0; tab-size: 2;
}
pre.code .c { color: #8f8676; font-style: italic; }   /* comment */
pre.code .k { color: #e0a071; }                         /* keyword */
pre.code .s { color: #9bb98a; }                         /* string */

/* ===================================================================
   GALLERY (index)
   =================================================================== */
body.gallery { min-height: 100vh; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px; }

.hero { padding: 84px 0 48px; border-bottom: 1px solid var(--line); }
.hero .eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 18px; }
.hero h1 { font-family: var(--display); font-weight: 900; font-size: clamp(38px, 6vw, 68px);
  line-height: 1.02; letter-spacing: -.02em; margin: 0 0 20px; max-width: 14ch; }
.hero h1 em { font-style: italic; font-weight: 400; color: var(--accent); }
.hero p { font-size: 17px; color: var(--muted); max-width: 56ch; margin: 0; }
.hero .meta { margin-top: 26px; display: flex; gap: 22px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 12.5px; color: var(--faint); }
.hero .meta span { display: inline-flex; align-items: center; gap: 7px; }
.hero .meta i { color: var(--accent); }

.callout { margin: 36px 0 4px; padding: 16px 20px; background: var(--surface);
  border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px;
  font-size: 14.5px; color: var(--muted); }
.callout b { color: var(--ink); }

.grid { padding: 40px 0 90px; display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.card {
  position: relative; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px 22px 20px; overflow: hidden;
  transition: transform .22s cubic-bezier(.4,0,.2,1), box-shadow .22s, border-color .22s;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--line-2); }
.card .letter { font-family: var(--display); font-weight: 900; font-size: 40px;
  line-height: 1; color: var(--accent-soft); position: absolute; top: 16px; right: 20px;
  transition: color .22s; }
.card:hover .letter { color: var(--accent); }
.card .ico { font-size: 20px; color: var(--accent); margin-bottom: 16px; }
.card h3 { font-family: var(--display); font-weight: 600; font-size: 21px; margin: 0 0 2px; letter-spacing: -.01em; }
.card .th { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.card .skill { font-size: 13.5px; color: var(--ink); margin: 0 0 18px; flex: 1; }
.card .skill b { color: var(--accent); font-weight: 500; }
.card .foot { display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--line); padding-top: 14px; }
.card .go { font-family: var(--mono); font-size: 12px; letter-spacing: .03em; color: var(--ink);
  display: inline-flex; align-items: center; gap: 7px; }
.card .go i { transition: transform .2s; }
.card:hover .go i { transform: translateX(3px); }
.card .src { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--faint); }
.card .src:hover { color: var(--accent); }

footer.foot { border-top: 1px solid var(--line); padding: 30px 0; color: var(--faint);
  font-family: var(--mono); font-size: 12px; }

/* ---------- HUB (home) ---------- */
.hubback { display: inline-flex; align-items: center; gap: 8px; font-family: var(--mono);
  font-size: 12px; letter-spacing: .04em; color: var(--muted); margin-bottom: 22px; transition: color .18s; }
.hubback:hover { color: var(--accent); }
.cats { padding: 40px 0 14px; display: grid; gap: 18px; }
.cat { display: block; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 30px 30px 26px;
  transition: transform .22s cubic-bezier(.4,0,.2,1), box-shadow .22s, border-color .22s; }
.cat:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--line-2); }
.cat-head { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.cat-head > i { font-size: 34px; color: var(--accent); }
.cat-head h2 { font-family: var(--display); font-weight: 600; font-size: 27px; margin: 0; letter-spacing: -.01em; }
.cat-head p { color: var(--muted); font-size: 14.5px; margin: 4px 0 0; }
.cat-head .count { margin-left: auto; font-family: var(--mono); font-size: 12px; color: #9a4608;
  border: 1px solid var(--accent-soft); background: var(--accent-soft); padding: 6px 12px;
  border-radius: 999px; white-space: nowrap; }   /* color darkened 2026-06-02: accent บน accent-soft ~3.95 < AA → #9a4608 ~5.0 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 22px 0; }
.chips span { font-family: var(--mono); font-size: 11.5px; color: var(--muted);
  background: var(--paper); border: 1px solid var(--line); border-radius: 7px; padding: 5px 10px; }
.cat .go { font-family: var(--mono); font-size: 13px; color: var(--ink);
  display: inline-flex; align-items: center; gap: 8px; }
.cat .go i { transition: transform .2s; }
.cat:hover .go i { transform: translateX(3px); }
.next { padding: 26px 0 90px; }
.next h3 { font-family: var(--display); font-weight: 600; font-size: 20px; margin: 0 0 8px; }
.next p { color: var(--muted); font-size: 15px; margin: 0; max-width: 62ch; }
.next .soon { display: inline-flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.next .soon span { font-family: var(--mono); font-size: 11.5px; color: var(--faint);
  border: 1px dashed var(--line-2); border-radius: 7px; padding: 5px 10px; }

/* ---------- CATEGORY PAGES (scrolling, sticky topbar) ---------- */
body.page { min-height: 100vh; }
body.page .topbar { position: sticky; top: 0; }
.pagehead { padding: 48px 0 10px; }
.pagehead .eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 14px; }
.pagehead h1 { font-family: var(--display); font-weight: 900; font-size: clamp(30px, 5vw, 52px);
  line-height: 1.05; letter-spacing: -.02em; margin: 0 0 16px; }
.pagehead h1 em { font-style: italic; font-weight: 400; color: var(--accent); }
.pagehead p { font-size: 16px; color: var(--muted); max-width: 60ch; margin: 0; }

/* sketch / example grid */
.sgrid { display: grid; gap: 18px; padding: 34px 0 80px;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }
.scard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.scard canvas, .scard .viz { display: block; width: 100%; height: 270px; background: #0d0b09; }
.scard .cap { padding: 14px 16px; display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--line); }
.scard .cap .t h3 { font-family: var(--display); font-size: 17px; margin: 0; font-weight: 600; }
.scard .cap .t p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.scard .cap .btn { margin-left: auto; padding: 6px 12px; }

/* web-animation reveal + bits */
.reveal { opacity: 0; transform: translateY(26px); transition: opacity .7s cubic-bezier(.4,0,.2,1), transform .7s cubic-bezier(.4,0,.2,1); }
.reveal.in { opacity: 1; transform: none; }
.section { padding: 46px 0; border-top: 1px solid var(--line); }
.section h2 { font-family: var(--display); font-weight: 600; font-size: 24px; margin: 0 0 6px; }
.section .lead { color: var(--muted); font-size: 15px; margin: 0 0 26px; max-width: 58ch; }
.stagger { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.stagger .it { background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; font-family: var(--mono); font-size: 13px; color: var(--ink); }
.counter { font-family: var(--display); font-weight: 900; font-size: 56px; color: var(--accent); line-height: 1; }
.microrow { display: flex; flex-wrap: wrap; gap: 14px; }
.mbtn { cursor: pointer; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font-family: var(--thai); font-size: 14px; padding: 11px 20px; border-radius: 10px;
  transition: transform .18s cubic-bezier(.34,1.56,.64,1), box-shadow .18s, background .18s, color .18s; }
.mbtn:hover { transform: translateY(-3px); box-shadow: var(--shadow); background: var(--accent); color: #fff; border-color: var(--accent); }
.mbtn:active { transform: translateY(0) scale(.97); }
.tilt { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 26px;
  transition: transform .15s ease, box-shadow .15s ease; transform-style: preserve-3d; will-change: transform; }

/* creative-css showcases */
.csgrid { display: grid; gap: 18px; padding: 34px 0 80px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.cscard { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line);
  min-height: 220px; display: grid; place-items: center; position: relative; text-align: center; padding: 24px; }
.cscard .lbl { position: absolute; left: 14px; bottom: 12px; font-family: var(--mono);
  font-size: 11px; color: var(--faint); }
/* การ์ดพื้นเข้ม/สี: label ต้องสว่าง (2026-06-02 — กัน --faint ที่เข้มขึ้นไปจมพื้นดำ neon) */
.neon .lbl, .glass-wrap .lbl, .grad-anim .lbl { color: #ece7dd; }
.grad-anim { background: linear-gradient(120deg, #ff8a4c, #b4530a, #6aa0ff, #b06aff); background-size: 300% 300%;
  animation: gradmove 8s ease infinite; }
.grad-anim, .neon, .glass-wrap { color: #fff; }
@keyframes gradmove { 0%{background-position:0% 50%} 50%{background-position:100% 50%} 100%{background-position:0% 50%} }
.glass-wrap { background: linear-gradient(135deg, #6aa0ff, #b4530a); }
.glass { backdrop-filter: blur(12px); background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.35);
  border-radius: 14px; padding: 22px 26px; color: #fff; font-family: var(--mono); font-size: 14px; }
.neon { background: #0d0b16; }
.neon .txt { font-family: var(--display); font-weight: 900; font-size: 34px; color: #fff;
  text-shadow: 0 0 6px #ff7ad9, 0 0 16px #ff7ad9, 0 0 34px #c264ff; animation: flick 3s infinite; }
@keyframes flick { 0%,92%,100%{opacity:1} 93%,95%{opacity:.55} }
.flip { perspective: 900px; background: var(--paper); }
.flip .inner { width: 100%; max-width: 200px; height: 130px; position: relative; transform-style: preserve-3d;
  transition: transform .7s cubic-bezier(.4,0,.2,1); }
.flip:hover .inner { transform: rotateY(180deg); }
.flip .face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 12px;
  display: grid; place-items: center; font-family: var(--display); font-weight: 600; font-size: 19px; }
.flip .front { background: var(--ink); color: var(--paper); }
.flip .back { background: var(--accent); color: #fff; transform: rotateY(180deg); }

/* data-charts tooltip */
.charttip { position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: var(--paper);
  font-family: var(--mono); font-size: 12px; padding: 6px 10px; border-radius: 8px; opacity: 0; transition: opacity .12s; }
.charttip.on { opacity: 1; }

@media (max-width: 560px) {
  .hero { padding: 56px 0 34px; }
  .info { padding: 22px 18px 32px; }
}
