/* vuducnam.dev — Hành trình ngọn lửa
   Cảnh 3D cố định phía sau; mỗi chương là một màn cuộn. Desktop: chữ bên trái, cảnh bên phải.
   Mobile: cảnh ở nửa trên, chữ trong khung ở dưới. */
:root {
  --bg: #110C0A;
  --panel: rgba(17, 12, 10, 0.84);
  --line: #2E221B;
  --line-strong: #4A372C;
  --text: #F4ECE4;
  --muted: #BCAB9E;
  --dim: #948275;
  --accent: #FF6B2C;
  --ember: #FF8F40;
  --amber: #FFC15E;
  --link: #FFB98F;
  --on-accent: #170D08;
  --sans: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --hand: 'Caveat', 'Segoe Script', cursive;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: var(--link); text-decoration: none; }
a:hover { color: #FFD9C2; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; border-radius: 4px; }
h1, h2, h3, p, ol, ul { margin: 0; }

.skip {
  position: absolute; left: -9999px; top: 8px; z-index: 30;
  padding: 10px 14px; border-radius: 6px; background: var(--accent); color: var(--on-accent); font-weight: 700;
}
.skip:focus { left: 16px; color: var(--on-accent); }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
.no-webgl #scene { display: none; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }

/* ---------- HUD ---------- */
.hud {
  position: fixed; z-index: 5; left: 0; right: 0; top: env(safe-area-inset-top, 0px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: 12px;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  font-family: var(--mono); font-size: 13px;
  pointer-events: none;
}
.hud a, .hud .lang { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--text); font-weight: 700; font-size: 15px; }
.brand:hover { color: var(--text); }
.brand b { color: var(--accent); }
.hud-end { display: flex; align-items: center; gap: 10px; }
.chapter {
  display: flex; align-items: baseline; gap: 10px; padding: 8px 14px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--panel); color: var(--muted);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.chapter strong { color: var(--amber); font-variant-numeric: tabular-nums; }
.lang { display: flex; padding: 2px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--panel); font-size: 12px; }
.lang a { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 40px; padding: 0 10px; border-radius: 999px; color: var(--muted); }
.lang a:hover { color: var(--text); }
.lang a[aria-current] { background: var(--line); color: var(--text); font-weight: 700; }

.rail {
  position: fixed; z-index: 5; top: 50%; transform: translateY(-50%);
  right: max(20px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 4px;
}
.rail a { display: flex; align-items: center; justify-content: flex-end; gap: 12px; min-height: 32px; color: var(--dim); font-family: var(--mono); font-size: 12px; }
.rail a span { opacity: 0; transform: translateX(6px); transition: opacity .2s ease, transform .2s ease; white-space: nowrap; }
.rail a i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--dim); transition: all .25s ease; }
.rail a:hover span, .rail a:focus-visible span { opacity: 1; transform: none; }
.rail a[aria-current="step"] { color: var(--amber); }
.rail a[aria-current="step"] i { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 12px rgba(255, 107, 44, 0.8); transform: scale(1.3); }

/* ---------- Chapters ---------- */
main { position: relative; z-index: 2; }
.ch {
  min-height: 100vh; min-height: 100svh;
  display: flex; align-items: center;
  padding-block: 96px;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  scroll-margin-top: 0;
}
/* Desktop: chữ nằm trong cột trái (~42% bề ngang); cảnh 3D tự căn trong cột phải (src/story.js). */
.panel { width: 100%; max-width: min(36rem, 40vw); margin-left: clamp(0px, 4vw, 72px); display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.label { font-family: var(--mono); font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ember); }
.label b { color: var(--amber); }
h1 { font-size: clamp(46px, 5.6vw, 92px); line-height: 0.96; font-weight: 800; letter-spacing: -0.035em; text-wrap: balance; }
h2 { font-size: clamp(30px, 4.2vw, 50px); line-height: 1.1; font-weight: 800; letter-spacing: -0.025em; text-wrap: balance; }
.prompt { display: flex; flex-direction: column; gap: 2px; font-family: var(--mono); font-size: 14px; line-height: 1.6; }
.prompt .cmd { color: var(--dim); }
.prompt .host { color: var(--ember); }
.cursor { display: inline-block; width: 9px; height: 17px; margin-left: 6px; vertical-align: -3px; background: var(--accent); animation: blink 1.1s steps(1) infinite; }
.role { font-size: clamp(18px, 2.2vw, 22px); line-height: 1.45; font-weight: 600; }
.role span { color: var(--ember); }
.lead { font-size: 19px; color: var(--muted); text-wrap: pretty; }
.body { font-size: 18px; color: var(--muted); text-wrap: pretty; }
.sig { font-family: var(--hand); font-size: 46px; line-height: 1; font-weight: 700; color: var(--amber); transform: rotate(-4deg); transform-origin: left center; }
.cue { display: inline-flex; align-items: center; gap: 12px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.cue i { position: relative; width: 1px; height: 40px; background: var(--line-strong); overflow: hidden; }
.cue i::after { content: ""; position: absolute; left: 0; top: -40%; width: 1px; height: 40%; background: var(--accent); animation: drip 1.8s ease-in-out infinite; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0; list-style: none; }
.chips li { padding: 4px 12px; border: 1px solid var(--line-strong); border-radius: 999px; font-family: var(--mono); font-size: 13px; background: rgba(17, 12, 10, 0.6); }

.roles { list-style: none; padding: 0; display: flex; flex-direction: column; }
.roles li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; padding: 12px 0; border-top: 1px solid var(--line); }
.roles li:last-child { border-bottom: 1px solid var(--line); }
.roles b { min-width: 9.5rem; font-size: 19px; font-weight: 800; color: var(--amber); }
.roles span { font-size: 17px; }

.principles { list-style: none; padding: 0; counter-reset: p; display: flex; flex-direction: column; }
.principles li { display: grid; grid-template-columns: 44px 1fr; align-items: baseline; gap: 2px 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.principles li:last-child { border-bottom: 1px solid var(--line); }
.principles li::before { counter-increment: p; content: counter(p, decimal-leading-zero); font-family: var(--mono); font-size: 20px; font-weight: 700; line-height: 1.3; color: var(--accent); }
.principles b { font-size: clamp(19px, 2vw, 23px); line-height: 1.3; font-weight: 700; }

.aside { font-size: 15px; color: var(--muted); padding-left: 14px; border-left: 2px solid var(--line-strong); }

.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.email { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 8px 8px 8px 16px; border: 1px solid var(--accent); border-radius: 8px; background: rgba(255, 107, 44, 0.08); }
.email a { font-family: var(--mono); font-size: 15px; font-weight: 700; color: var(--text); overflow-wrap: anywhere; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line-strong); border-radius: 6px; background: transparent;
  color: var(--text); font: 600 14px/1 var(--sans); cursor: pointer;
}
.btn:hover { color: var(--text); border-color: var(--ember); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.btn-primary:hover { color: var(--on-accent); filter: brightness(1.08); }
.foot { font-family: var(--mono); font-size: 12px; color: var(--dim); }
.foot a { color: var(--muted); }

/* ---------- HUD link (story + work page) ---------- */
.hud-link {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--panel);
  color: var(--text); font-size: 12px; white-space: nowrap;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.hud-link:hover { color: var(--text); border-color: var(--ember); }

/* ---------- Work page ---------- */
.work-page { background-image: radial-gradient(rgba(255, 107, 44, 0.07) 1px, transparent 1.3px); background-size: 22px 22px; background-attachment: fixed; }
.hud-solid { position: sticky; background: rgba(17, 12, 10, 0.92); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.w-main {
  max-width: 980px; margin: 0 auto;
  padding-block: clamp(48px, 8vw, 96px) 64px;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: clamp(48px, 7vw, 80px);
}
.w-intro { display: flex; flex-direction: column; gap: 20px; max-width: 40rem; }
.w-intro h1 { font-size: clamp(44px, 6vw, 80px); }
.w-group { display: grid; grid-template-columns: minmax(0, 15rem) minmax(0, 1fr); gap: 16px 48px; align-items: start; }
.w-group-name {
  display: flex; flex-direction: column; gap: 6px; position: sticky; top: 92px;
  font-size: 22px; line-height: 1.25; font-weight: 800; letter-spacing: -0.01em;
}
.w-group-name span { font-family: var(--mono); font-size: 13px; font-weight: 700; color: var(--accent); }
.w-items { list-style: none; padding: 0; display: flex; flex-direction: column; }
.w-items li { display: flex; flex-direction: column; gap: 6px; padding: 20px 0; border-top: 1px solid var(--line); }
.w-items li:last-child { border-bottom: 1px solid var(--line); }
.w-items h3 { font-size: 19px; line-height: 1.35; font-weight: 700; }
.w-items p { color: var(--muted); text-wrap: pretty; }
.w-tech { font-family: var(--mono); font-size: 12px; color: var(--amber); }
.w-open .body { grid-column: 2; margin-top: -4px; }
.w-open .w-group-name { grid-row: span 2; }
.w-repos { grid-column: 2; list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 14px; }
.w-repo {
  display: flex; flex-direction: column; gap: 8px; height: 100%; padding: 20px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: rgba(26, 19, 16, 0.85); color: var(--text);
  transition: border-color .2s ease, transform .2s ease;
}
.w-repo:hover { color: var(--text); border-color: var(--accent); transform: translateY(-2px); }
.w-repo-name { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 18px; font-weight: 700; }
.w-repo-name svg { color: var(--ember); flex: none; }
.w-repo-detail { font-size: 15px; color: var(--muted); }
.w-repo-url { margin-top: auto; font-family: var(--mono); font-size: 11px; color: var(--dim); overflow-wrap: anywhere; }
.w-nda { display: flex; flex-direction: column; gap: 18px; padding-top: 40px; border-top: 1px solid var(--line-strong); }
.w-nda > p:first-child { font-size: clamp(22px, 3vw, 30px); line-height: 1.3; font-weight: 700; max-width: 30em; text-wrap: balance; }
.w-nda .email { align-self: flex-start; padding: 12px 16px; }
@media (max-width: 760px) {
  .w-group { grid-template-columns: minmax(0, 1fr); }
  .w-group-name { position: static; flex-direction: row; align-items: baseline; gap: 12px; }
  .w-open .body, .w-repos { grid-column: 1; }
  .w-open .w-group-name { grid-row: auto; }
}
@media (max-width: 440px) {
  .hud:not(.hud-solid) .hud-link { display: none; }
  .hud-solid .hud-link { padding: 0 12px; }
  .hud-solid .brand span { display: none; }
}

.notfound {
  min-height: 100vh; display: flex; flex-direction: column; justify-content: center; gap: 32px;
  max-width: 900px; margin: 0 auto;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
}

@keyframes blink { 50% { opacity: 0; } }
@keyframes drip { 0% { top: -40%; } 100% { top: 100%; } }

/* ---------- Phone & tablet portrait ----------
   Cảnh 3D ghim ở nửa trên (46% chiều cao), chữ cuộn ở nửa dưới, không chồng lên nhau. */
@media (max-width: 860px) {
  .rail { display: none; }
  #scene {
    height: 46vh; height: 46svh; z-index: 3;
    -webkit-mask-image: linear-gradient(#000 80%, transparent);
    mask-image: linear-gradient(#000 80%, transparent);
  }
  main { padding-top: 46vh; padding-top: 46svh; padding-bottom: 22vh; padding-bottom: 22svh; }
  .ch { min-height: 54vh; min-height: 54svh; align-items: center; padding-block: 36px; }
  .panel { margin-left: 0; max-width: 36rem; gap: 16px; }
  h1 { font-size: clamp(42px, 12vw, 56px); }
  h2 { font-size: clamp(28px, 7.6vw, 36px); }
  .lead { font-size: 17px; }
  .body { font-size: 17px; }
  .sig { font-size: 40px; }
  .cue { display: none; }
  .no-webgl main { padding-top: 72px; }
  .chapter span { display: none; }
  .roles li { flex-direction: column; gap: 2px; }
  .roles b { min-width: 0; }
}
@media (max-width: 380px) {
  .chapter { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .cursor, .cue i::after { animation: none; }
}
