/* ===== Design tokens ===== */
:root {
  --bg: #101010;
  --text: #f2f2f2;
  --text-muted: #f2f2f2a6;
  --text-faint: #f2f2f266;
  --line: #f2f2f21a;
  --box-border: #f2f2f224;
  --box-bg: linear-gradient(190deg, #1f1f1f, #131313 70%);
  --accent: #8b7bff;
  --accent-2: #22d3ee;
  --green: #4ade80;
  --radius: 16px;
  --max: 1080px;
  --ease: cubic-bezier(0.165, 0.84, 0.44, 1);
  --serif: "Instrument Serif", "Itim", Georgia, serif; /* Itim covers Thai glyphs */
  --mono: "JetBrains Mono", "Noto Sans Thai Looped", ui-monospace, monospace;
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; scroll-padding-top: 90px; }

body {
  font-family: "Inter", "Noto Sans Thai Looped", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, #f2f2f21f, transparent 70%),
    var(--bg);
  background-repeat: no-repeat;
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
/* Film grain over everything, like a printed surface */
body::after {
  content: ""; position: fixed; inset: 0; z-index: 300; pointer-events: none; opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

:root[data-lang="th"] body { font-family: "Noto Sans Thai Looped", "Inter", system-ui, sans-serif; }

.container { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 24px; }
a { color: inherit; text-decoration: none; }
.serif { font-family: var(--serif); font-style: italic; font-weight: 400; letter-spacing: -0.5px; font-size: 1.45em; }
:root[data-lang="th"] .serif { font-style: normal; letter-spacing: 0; } /* Itim is upright, so no fake italic */
.muted-strong { color: var(--text); font-weight: 500; }

.label, .overline {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-faint);
}
.overline { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.overline__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text); box-shadow: 0 0 10px #fff8; }

/* ===== The box: card with a soft double-border ring ===== */
.box {
  position: relative;
  background: var(--box-bg);
  border: 1px solid var(--box-border);
  border-radius: var(--radius);
  box-shadow:
    0 0 0 8px #f2f2f208,
    0 0 0 9px #f2f2f20f,
    0 40px 80px #00000080;
}
/* thin highlight along the top edge */
.box::before {
  content: ""; position: absolute; top: -1px; left: 15%; right: 15%; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, #f2f2f299, transparent);
}
.box--pad { padding: 28px; }

/* ===== Navigation ===== */
.nav {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(#101010e6, #10101000);
  padding: 16px 0 28px;
}
.nav__inner {
  padding: 0 32px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
}
.nav__brand { display: flex; align-items: center; gap: 10px; justify-self: start; }
.nav__brand img { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; border: 1px solid var(--box-border); }
.nav__brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.nav__brand-text strong { font-weight: 600; }
.nav__brand-text small { font-size: 0.78rem; color: var(--text-muted); }

.nav__pill {
  list-style: none; display: flex; gap: 2px; padding: 4px;
  border-radius: 999px; border: 1px solid var(--box-border);
  background: #1a1a1acc; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px #0006;
}
.nav__pill a {
  display: block; padding: 8px 16px; border-radius: 999px; font-size: 0.9rem; font-weight: 500;
  color: var(--text-muted); transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
}
.nav__pill a:hover, .nav__pill a.active { background: #f2f2f21a; color: var(--text); }

.nav__controls { display: flex; align-items: center; gap: 6px; justify-self: end; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 40px; padding: 0 14px;
  border-radius: 999px; border: none; background: transparent; color: var(--text);
  font: inherit; font-size: 0.9rem; font-weight: 500; cursor: pointer;
  transition: background-color 0.3s var(--ease);
}
.chip:hover { background: #f2f2f21a; }
#langToggle { font-family: var(--mono); font-size: 0.8rem; border: 1px solid var(--box-border); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; height: 44px; padding: 0 20px; border-radius: 999px;
  font-weight: 500; font-size: 0.92rem; border: 1px solid transparent; cursor: pointer;
  transition: transform 0.3s var(--ease), background-color 0.3s var(--ease), border-color 0.3s var(--ease);
}
.btn--primary { background: var(--text); color: #101010; }
.btn--primary:hover { transform: translateY(-2px); background: #fff; }
.btn--ghost { border-color: var(--box-border); color: var(--text); }
.btn--ghost:hover { transform: translateY(-2px); border-color: #f2f2f266; }

/* ===== Hero window ===== */
.hero { padding: 48px 0 24px; }
.window { overflow: hidden; }
.window__bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: 42px; padding: 0 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(to right, #f2f2f20a, #f2f2f21f 50%, #f2f2f20a);
}
.window__dots { display: flex; gap: 8px; }
.window__dots i { width: 12px; height: 12px; border-radius: 50%; background: #ff5f57; }
.window__dots i:nth-child(2) { background: #febc2e; }
.window__dots i:nth-child(3) { background: #28c840; }
.window__url { font-family: var(--mono); font-size: 0.75rem; color: var(--text-muted); }

.window__content { position: relative; padding: 80px 48px 80px; overflow: hidden; }
.window__content > *:not(.hero__glitch) { position: relative; z-index: 1; }

/* LetterGlitch layer (letter-glitch.js), faded toward the edges */
.hero__glitch {
  position: absolute; inset: 0; z-index: 0; pointer-events: none; opacity: 0.22;
  -webkit-mask-image: radial-gradient(90% 100% at 85% 20%, #000 0%, transparent 70%);
          mask-image: radial-gradient(90% 100% at 85% 20%, #000 0%, transparent 70%);
}

.hero__title {
  font-size: clamp(2.6rem, 7vw, 5rem); font-weight: 500; letter-spacing: -2px; line-height: 0.98;
  white-space: pre-line; /* \n in content.js = line break */
  text-shadow: 0 5px 12px #0057ff26, 0 -5px 12px #ff5a001a, 0 -5px 25px #ffffff33;
}
.hero__title .serif { letter-spacing: -1px; }
:root[data-lang="th"] .hero__title { line-height: 1.2; letter-spacing: -1px; }


/* ===== Sections ===== */
.section { padding: 72px 0; }
.section__title { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 500; letter-spacing: -1px; line-height: 1.1; margin-bottom: 36px; min-height: 1.1em; }
.shuffle-char { color: var(--text-faint); }
.section__lead { color: var(--text-muted); max-width: 600px; margin: -16px 0 36px; }

/* ===== About ===== */
.about { display: grid; grid-template-columns: 1.5fr 1fr; gap: 28px; }
.about__text p { color: var(--text-muted); white-space: pre-line; }
.about__text p + p { margin-top: 16px; }
.about__facts { list-style: none; display: flex; flex-direction: column; }
.about__facts li { display: flex; flex-direction: column; gap: 2px; padding: 14px 0; border-bottom: 1px solid var(--line); font-weight: 500; }
.about__facts li:first-child { padding-top: 0; }
.about__facts li:last-child { border-bottom: none; padding-bottom: 0; }

/* ===== Project card ===== */
/* Title on top, big video, info below */
.project {
  display: flex; flex-direction: column; gap: 24px;
  padding: 32px; overflow: hidden;
  transition: border-color 0.4s var(--ease);
}
.project:hover { border-color: #f2f2f266; }
.project__title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.project__meta { margin-left: auto; font-family: var(--mono); font-size: 0.78rem; color: var(--text-muted); }
.project__body { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 40px; }
.project__body > :not(.project__points) { grid-column: 1; }
.project__body .project__points { grid-column: 2; grid-row: 1 / span 4; margin: 0; }
.project__title { font-size: 2.2rem; font-weight: 500; letter-spacing: -0.5px; text-shadow: 0 -2px 10px #fff3; }
.project__desc { color: var(--text-muted); margin-bottom: 8px; }
.project__role { font-size: 0.88rem; color: var(--text); margin: -8px 0 14px; }
.project__points { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.project__points li { position: relative; padding-left: 18px; color: var(--text-muted); font-size: 0.9rem; line-height: 1.45; }
.project__points li::before { content: ""; position: absolute; left: 2px; top: 0.6em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px #8b7bff99; }
.tag {
  font-family: var(--mono); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.8px;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--box-border); color: var(--text-muted);
}
.tag--live { color: var(--green); border-color: #4ade8040; }
.tech { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.tech li { font-size: 0.8rem; color: var(--text-muted); background: #f2f2f20d; padding: 4px 10px; border-radius: 6px; }

/* ===== Projects: big coverflow of full project cards ===== */
/* All slides share one grid cell, so the track is as tall as the tallest card. */
.proj-track {
  display: grid; padding: 12px 0 24px; touch-action: pan-y;
  overflow-x: clip; overflow-y: visible;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}
.proj-slide {
  /* --o / --abs set by script.js */
  grid-area: 1 / 1; justify-self: center; width: min(92%, 980px);
  transform: translateX(calc(var(--o) * 96%)) scale(calc(1 - var(--abs) * 0.1));
  opacity: calc(1 - var(--abs) * 0.65);
  z-index: calc(10 - var(--abs));
  transition: transform 0.6s var(--ease), opacity 0.6s var(--ease);
}
.proj-slide:not([data-pos="0"]) { cursor: pointer; }
.proj-slide:not([data-pos="0"]) * { pointer-events: none; }
.proj-slide[data-pos="hidden"] { opacity: 0; pointer-events: none; }
.proj-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 8px; }
.proj-nav[hidden] { display: none; }
.proj-nav .cert-nav__btn { position: static; }
.project__link { margin-top: 20px; }

/* Project video: YouTube thumbnail, swapped for the player on click */
.project__visual {
  position: relative; aspect-ratio: 16 / 9; width: 100%; padding: 0; overflow: hidden; cursor: pointer;
  border-radius: 12px; border: 1px solid var(--line); background: #0c0c0c;
}
.project__visual img, .project__visual iframe { width: 100%; height: 100%; object-fit: cover; display: block; border: 0; }
.project__visual img { transition: transform 0.5s var(--ease), filter 0.5s var(--ease); filter: brightness(0.8); }
.project__visual:hover img { transform: scale(1.03); filter: none; }
.yt__play {
  position: absolute; inset: 0; margin: auto; width: 68px; height: 68px; border-radius: 50%;
  background: #f2f2f2e6; box-shadow: 0 10px 30px #0008; transition: transform 0.3s var(--ease);
}
.yt__play::after {
  content: ""; position: absolute; top: 50%; left: 54%; translate: -50% -50%;
  border-style: solid; border-width: 11px 0 11px 18px; border-color: transparent transparent transparent #101010;
}
.project__visual:hover .yt__play { transform: scale(1.08); }
.project__visual:focus-visible { outline: 2px solid var(--text); outline-offset: 4px; }

/* ===== Certificates: looping coverflow carousel ===== */
.cert-track {
  position: relative; height: clamp(260px, 42vw, 440px);
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
}
.cert-slide {
  /* --o: signed distance from the middle, --abs: |--o| (set by script.js) */
  position: absolute; top: 50%; left: 50%; width: min(60%, 560px); aspect-ratio: 3 / 2;
  padding: 0; border: 1px solid var(--box-border); border-radius: 12px; overflow: hidden;
  background: #0c0c0c; cursor: pointer;
  transform: translate(-50%, -50%) translateX(calc(var(--o) * 62%)) scale(calc(1 - var(--abs) * 0.22));
  opacity: calc(1 - var(--abs) * 0.45);
  z-index: calc(10 - var(--abs));
  box-shadow: 0 0 0 8px #f2f2f208, 0 0 0 9px #f2f2f20f, 0 40px 80px #000000a0;
  transition: transform 0.6s var(--ease), opacity 0.6s var(--ease), filter 0.6s var(--ease);
}
.cert-slide:not([data-pos="0"]) { filter: saturate(0.6) brightness(0.8); }
.cert-slide[data-pos="0"] { cursor: zoom-in; }
.cert-slide[data-pos="hidden"] { opacity: 0; pointer-events: none; }
.cert-slide img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; pointer-events: none; }
.cert-slide:focus-visible { outline: 2px solid var(--text); outline-offset: 4px; }
.cert-badge {
  position: absolute; top: 12px; left: 12px; z-index: 2;
  font-size: 0.75rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; color: #1a1a1a;
  box-shadow: 0 4px 12px #0006;
}
.cert-badge--gold { background: linear-gradient(135deg, #ffe08a, #d4af37); }
.cert-badge--silver { background: linear-gradient(135deg, #eef1f6, #b8c0cc); }

.cert-info {
  position: relative; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px;
  width: min(60%, 560px); margin: 32px auto 0;
}
.card__tag {
  display: inline-block; margin-bottom: 10px;
  font-family: var(--mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text-muted); padding: 3px 9px; border-radius: 999px; border: 1px solid var(--box-border);
}
/* Tag colour per category (data-kind is the English tag, slugified) */
.card__tag[data-kind] { color: var(--tag); border-color: color-mix(in srgb, var(--tag) 40%, transparent); background: color-mix(in srgb, var(--tag) 12%, transparent); }
.card__tag[data-kind="olympiad"] { --tag: #60a5fa; }
.card__tag[data-kind="game-dev"] { --tag: #a78bfa; }
.card__tag[data-kind="gold-medal"] { --tag: #facc15; }
.card__tag[data-kind="silver-medal"] { --tag: #cbd5e1; }
.card__tag[data-kind="hackathon"] { --tag: #22d3ee; }
.card__tag[data-kind="instructor"] { --tag: #4ade80; }
.card__tag[data-kind="workshop"] { --tag: #fb923c; }
.cert-info__title { font-size: 1.2rem; font-weight: 500; line-height: 1.3; letter-spacing: -0.3px; }
.cert-info__meta { color: var(--text-muted); font-size: 0.88rem; margin-top: 4px; }
/* Prev/next sit level with the title, just outside the middle certificate */
.cert-nav__btn { position: absolute; top: 25px; } /* fixed offset so it never shifts with 1- vs 2-line titles */
.cert-nav__btn--prev { right: calc(100% + 51px); }
.cert-nav__btn--next { left: calc(100% + 51px); }
.cert-nav__btn {
  width: 44px; height: 44px; border-radius: 50%; cursor: pointer; font-size: 1.1rem;
  background: #1a1a1acc; color: var(--text); border: 1px solid var(--box-border);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: background-color 0.3s var(--ease);
}
.cert-nav__btn:hover { background: #f2f2f21f; }
.cert-nav__count { flex-shrink: 0; font-family: var(--mono); font-size: 0.8rem; color: var(--text-muted); min-width: 5.5ch; text-align: center; }

/* ===== Contact ===== */
.contact { padding: 56px 48px; text-align: center; display: flex; flex-direction: column; align-items: center; overflow: hidden;
  background: radial-gradient(ellipse 60% 80% at 50% 0%, #f2f2f214, transparent 70%), var(--box-bg); }
.contact .overline { justify-content: center; }
.contact__title { white-space: pre-line; font-size: clamp(2.2rem, 6vw, 4rem); font-weight: 500; letter-spacing: -1.5px; line-height: 1; margin-bottom: 16px; }
.contact__lead { color: var(--text-muted); max-width: 480px; margin-bottom: 32px; }
.contact__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ===== Footer ===== */
.footer { border-top: 1px solid var(--line); padding: 48px 0 56px; margin-top: 40px; }
.footer__inner { display: flex; justify-content: space-between; gap: 32px; flex-wrap: wrap; }
.footer__brand strong { font-size: 1.4rem; font-weight: 600; }
.footer__brand p { color: var(--text-faint); font-size: 0.85rem; margin-top: 6px; }
.footer__cols { display: flex; gap: 64px; }
.footer__cols div { display: flex; flex-direction: column; gap: 8px; }
.footer__cols .label { margin-bottom: 4px; }
.footer__cols a { color: var(--text-muted); font-size: 0.92rem; transition: color 0.3s var(--ease); }
.footer__cols a:hover { color: var(--text); }

/* ===== Lightbox ===== */
.lightbox {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: #0a0a0ae0; backdrop-filter: blur(8px);
  opacity: 0; visibility: hidden; transition: opacity 0.25s ease, visibility 0.25s ease;
}
.lightbox.open { opacity: 1; visibility: visible; }
.lightbox__figure {
  max-width: 1000px; max-height: 90vh; display: flex; flex-direction: column; gap: 12px; align-items: center;
  transform: scale(0.96); transition: transform 0.25s ease;
}
.lightbox.open .lightbox__figure { transform: scale(1); }
.lightbox__img { max-width: 100%; max-height: 78vh; object-fit: contain; border-radius: 8px; box-shadow: 0 20px 60px #000a; background: #fff; }
.lightbox__caption { color: var(--text); font-size: 0.92rem; text-align: center; max-width: 640px; }
.lightbox__close {
  position: absolute; top: 18px; right: 22px; width: 44px; height: 44px; border-radius: 50%;
  background: #ffffff1f; color: #fff; border: none; font-size: 1.6rem; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: background 0.2s ease;
}
.lightbox__close:hover { background: #ffffff40; }

/* ===== Reveal on scroll ===== */
.reveal { opacity: 0; transform: translateY(24px); transition: opacity 0.7s var(--ease), transform 0.7s var(--ease); }
.reveal.visible { opacity: 1; transform: none; }

/* ===== Responsive ===== */
@media (max-width: 860px) {
  .chip--hide-sm { display: none; }

  .cert-info { width: 100%; }
  .cert-nav__btn { position: static; flex-shrink: 0; align-self: flex-start; margin-top: 25px; }
  .cert-slide { width: 72%; transform: translate(-50%, -50%) translateX(calc(var(--o) * 78%)) scale(calc(1 - var(--abs) * 0.18)); }
  .project__body { grid-template-columns: 1fr; }
  .project__body .project__points { grid-column: 1; grid-row: auto; margin-bottom: 8px; }
}
@media (max-width: 640px) {
  .window__content { padding: 56px 22px 56px; }
  .nav__inner { padding: 0 16px; gap: 8px; }
  .nav__brand-text { display: none; }
  .window__url { display: none; }
  .window__bar { grid-template-columns: 1fr auto; }
  .about { grid-template-columns: 1fr; }
  .project { padding: 24px; }
  .proj-slide { width: 92%; }
  .contact { padding: 40px 22px; }
  .cert-info { gap: 12px; }
  .footer__cols { gap: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; transition: none; }
}

/* \n in content.js = line break, for every text that comes from content.js */
.section__lead, .contact__lead, .project__desc, .project__role, .project__points li,
.cert-info__title, .cert-info__meta, .about__facts span { white-space: pre-line; }
