/* Khmer Digital by MPTC, SIL Open Font License 1.1 (see assets/fonts/OFL.txt) */
@font-face {
  font-family: "Khmer Digital";
  src: url("../fonts/KhmerDigital-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Khmer Digital";
  src: url("../fonts/KhmerDigital-Medium.ttf") format("truetype");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Khmer Digital";
  src: url("../fonts/KhmerDigital-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #0a0e0b;
  --panel: #0f1511;
  --line: #1e2b22;
  --fg: #c7d5cb;
  --dim: #71857a;
  --accent: #3ee07f;
  --accent-2: #f5b942;
  --link: #62c9ff;
  --err: #ff6f6f;
  --glow: rgba(62, 224, 127, 0.18);
  /* Latin renders in the monospace face; Khmer falls through to Khmer Digital */
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", "Cascadia Mono", Menlo, Consolas,
    "Liberation Mono", "DejaVu Sans Mono", "Khmer Digital", monospace;
  --khmer: "Khmer Digital", "Khmer OS Battambang", "Noto Sans Khmer", sans-serif;
}
[data-theme="amber"] {
  --bg: #0f0b05; --panel: #161008; --line: #2e2212; --fg: #e2cfa8; --dim: #8d7a55;
  --accent: #ffb62e; --accent-2: #ff7a45; --link: #ffd98a; --glow: rgba(255, 182, 46, 0.18);
}
[data-theme="ice"] {
  --bg: #080c12; --panel: #0d131c; --line: #1b2636; --fg: #c5d2e2; --dim: #6c7d93;
  --accent: #5cc8ff; --accent-2: #b392f0; --link: #7ee0c3; --glow: rgba(92, 200, 255, 0.18);
}
[data-theme="paper"] {
  --bg: #f6f4ee; --panel: #ece9e0; --line: #d5d0c2; --fg: #2b2f2c; --dim: #71756f;
  --accent: #14773f; --accent-2: #a85d00; --link: #0b5fa8; --err: #b3261e; --glow: transparent;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; overflow-x: clip; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.7 var(--mono);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: var(--bg); }
a { color: var(--link); text-decoration: underline dashed 1px; text-underline-offset: 4px; }
a:hover, a:focus-visible { color: var(--accent); }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
[lang="km"], .km { font-family: var(--khmer); line-height: 1.9; }

.term { position: relative; z-index: 1; max-width: 1000px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ── title bar + section tabs ─────────────────────────── */
.bar { position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--line); }
.bar { padding-top: env(safe-area-inset-top); }
.bar-top { display: flex; align-items: center; gap: 12px; padding: 9px max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left)); }
.dots { display: inline-flex; gap: 7px; }
.dots i { width: 11px; height: 11px; border-radius: 50%; background: #ff5f57; }
.dots i:nth-child(2) { background: #febc2e; }
.dots i:nth-child(3) { background: #28c840; }
.bar-title { flex: 1; text-align: center; color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-org { color: var(--accent); font-weight: 700; font-size: 12px; letter-spacing: 0.08em; display: inline-flex; align-items: center; gap: 7px; }
.bar-org img { display: block; border-radius: 4px; }
.tabs { display: flex; gap: 2px; padding: 0 10px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  font: inherit; font-size: 13px; color: var(--dim); background: none; border: 0;
  border-bottom: 2px solid transparent; padding: 6px 10px 7px; cursor: pointer; white-space: nowrap;
}
.tabs button::before { content: "./"; opacity: 0.55; }
.tabs button:hover, .tabs button:focus-visible { color: var(--fg); }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

/* ── screen ───────────────────────────────────────────── */
.screen {
  flex: 1; cursor: text; min-width: 0; overflow-wrap: break-word;
  padding: 18px max(16px, env(safe-area-inset-right)) calc(35vh + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.entry { scroll-margin-top: 92px; margin-bottom: 18px; }
.echo { display: flex; flex-wrap: wrap; gap: 0 8px; }
.echo .typed { color: var(--fg); font-weight: 600; word-break: break-word; }
.ps1 { color: var(--accent); white-space: nowrap; user-select: none; }
.ps1 .path { color: var(--link); }
.ps1 .sep { color: var(--dim); }
.outp { margin-top: 6px; min-width: 0; }
.outp p { margin: 0 0 10px; max-width: 78ch; }
.dim { color: var(--dim); }
.err { color: var(--err); }
.ok { color: var(--accent); }
.kbd { color: var(--accent); cursor: pointer; border: 0; background: none; font: inherit; padding: 0; border-bottom: 1px dashed currentColor; }
.kbd:hover { color: var(--accent-2); }

.prompt { display: flex; align-items: baseline; gap: 8px; }
.prompt input {
  flex: 1; min-width: 0; font: inherit; font-weight: 600; color: var(--fg); background: none; border: 0; outline: 0;
  padding: 0; caret-color: var(--accent); caret-shape: block;
}
.prompt.busy { visibility: hidden; }

/* ── banner ───────────────────────────────────────────── */
.banner {
  margin: 4px 0 12px; color: var(--accent); font: inherit; line-height: 1.12; overflow: hidden;
  font-size: clamp(5px, 2.15vw, 15px); text-shadow: 0 0 14px var(--glow);
}
.banner-meta { margin: 0 0 4px; }
.banner-meta .km { display: block; color: var(--fg); font-size: 16px; font-weight: 500; }
.banner-meta .org { color: var(--dim); }
.tagline { color: var(--accent-2); }
.ministry {
  display: inline-flex; align-items: center; gap: 12px; margin: 4px 0 6px; padding: 8px 14px 8px 8px; max-width: 100%;
  border: 1px solid var(--line); border-radius: 3px; background: var(--panel); color: var(--fg);
}
.ministry:hover, .ministry:focus-visible { border-color: var(--accent); color: var(--fg); }
.ministry img { flex: none; width: 44px; height: 44px; background: #fff; border-radius: 50%; }
.ministry span { display: block; min-width: 0; }
.ministry .km { font-weight: 500; line-height: 1.7; }
.ministry .en { color: var(--dim); font-size: 13px; line-height: 1.5; }

/* ── section output ───────────────────────────────────── */
.h { margin: 2px 0 10px; font-size: inherit; font-weight: 700; color: var(--accent); display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.h::before { content: "##"; color: var(--dim); font-weight: 400; }
.h .km { color: var(--dim); font-weight: 400; }
.sub { margin: 16px 0 8px; color: var(--dim); font-weight: 400; font-size: inherit; }
.sub::before { content: "── "; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 18px; margin: 0 0 10px; }
.kv dt { color: var(--accent-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(290px, 100%), 1fr)); gap: 10px; margin: 0; padding: 0; list-style: none; align-items: start; }
.card { border: 1px solid var(--line); background: var(--panel); padding: 12px 14px; border-radius: 3px; min-width: 0; }
.card:hover { border-color: var(--accent); }
.card-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.avatar {
  flex: none; width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid var(--accent);
  color: var(--accent); font-weight: 700; border-radius: 3px;
}
.card .name { font-weight: 700; color: var(--fg); line-height: 1.35; }
.card .name .km { display: block; font-weight: 400; color: var(--dim); font-size: 13px; }
.card .role { color: var(--accent-2); font-size: 13px; }
.card .meta { color: var(--dim); font-size: 13px; overflow-wrap: anywhere; }
.card .bio { margin: 0 0 8px; font-size: 13px; line-height: 1.6; max-width: none; }
.tags { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { font-size: 12px; line-height: 1.5; color: var(--accent); border: 1px solid var(--line); padding: 1px 7px; border-radius: 2px; }

.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.proj { border-left: 2px solid var(--line); padding: 2px 0 2px 14px; }
.proj:hover { border-left-color: var(--accent); }
.proj-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; }
.proj-name { font-weight: 700; color: var(--fg); }
.proj p { margin: 2px 0; }
.tag { font-size: 12px; white-space: nowrap; }
.tag.active { color: var(--accent); }
.tag.planned { color: var(--accent-2); }
.tag.done { color: var(--dim); }
.stack { color: var(--dim); font-size: 13px; }

.help { display: grid; grid-template-columns: max-content 1fr; gap: 2px 20px; margin: 0; }
.help dt { margin: 0; }
.help dd { margin: 0; color: var(--dim); }

.cursor { display: inline-block; width: 0.6em; height: 1.1em; background: var(--accent); vertical-align: text-bottom; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ── motion and effects (all off when data-fx="off") ───── */
:root { --shine: #f2fff7; }
[data-theme="amber"] { --shine: #fff6e0; }
[data-theme="ice"] { --shine: #f0faff; }
[data-theme="paper"] { --shine: var(--accent-2); }

#bg {
  position: fixed; inset: 0; z-index: 0; width: 100%; height: 100vh; height: 100lvh;
  pointer-events: none; opacity: 0; transition: opacity 1.4s ease;
}
#bg.on { opacity: 0.6; }
[data-theme="paper"] #bg.on { opacity: 0.45; }
[data-fx="off"] #bg { display: none; }

.bootlog { color: var(--dim); margin-bottom: 14px; }
.tabs button { transition: color 0.2s, border-color 0.2s; }
.card { transition: transform 0.25s ease-out, border-color 0.25s, box-shadow 0.25s; }

[data-fx="on"] .card,
[data-fx="on"] .ministry {
  background: color-mix(in srgb, var(--panel) 72%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
[data-fx="on"] .card { transform: perspective(700px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); }
[data-fx="on"] .card:hover { box-shadow: 0 14px 40px -18px var(--accent), 0 0 24px -10px var(--glow); }
[data-fx="on"] .avatar { box-shadow: 0 0 14px -4px var(--accent); }

/* output prints in, one block after another */
@keyframes rise { from { opacity: 0; transform: translateY(10px); filter: blur(4px); } }
@keyframes pop { from { opacity: 0; transform: perspective(700px) translateY(16px) rotateX(-12deg); } }
[data-fx="on"] .outp > *,
[data-fx="on"] .kv > *,
[data-fx="on"] .help > * { animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
[data-fx="on"] .grid > li,
[data-fx="on"] .plist > li { animation: pop 0.55s cubic-bezier(0.2, 0.7, 0.2, 1) backwards; }
[data-fx="on"] :is(.outp, .kv, .help, .grid, .plist) > :nth-child(2) { animation-delay: 60ms; }
[data-fx="on"] :is(.outp, .kv, .help, .grid, .plist) > :nth-child(3) { animation-delay: 120ms; }
[data-fx="on"] :is(.outp, .kv, .help, .grid, .plist) > :nth-child(4) { animation-delay: 180ms; }
[data-fx="on"] :is(.outp, .kv, .help, .grid, .plist) > :nth-child(5) { animation-delay: 240ms; }
[data-fx="on"] :is(.outp, .kv, .help, .grid, .plist) > :nth-child(6) { animation-delay: 300ms; }
[data-fx="on"] :is(.outp, .kv, .help, .grid, .plist) > :nth-child(7) { animation-delay: 360ms; }
[data-fx="on"] :is(.outp, .kv, .help, .grid, .plist) > :nth-child(n + 8) { animation-delay: 420ms; }

/* banner wipes in, then a highlight sweeps across it */
@keyframes wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes shimmer { from { background-position: 130% 0; } to { background-position: -130% 0; } }
[data-fx="on"] .outp > .banner {
  background: linear-gradient(100deg, var(--accent) 42%, var(--shine) 50%, var(--accent) 58%) 0 0 / 260% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none;
  filter: drop-shadow(0 0 10px var(--glow));
  animation: wipe 0.9s steps(30) backwards, shimmer 7s linear 1s infinite;
}

/* faint CRT scanlines */
[data-fx="on"] body::after {
  content: ""; position: fixed; inset: 0; z-index: 9; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.14) 2px 3px);
}
[data-fx="on"][data-theme="paper"] body::after { content: none; }

/* ── small screens ────────────────────────────────────── */
@media (max-width: 560px) {
  body { font-size: 13px; }
  .ps1 .long { display: none; }
  .screen { padding-top: 14px; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .bar-top { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .tabs { padding: 0 4px; }
  .tabs button { flex: 1 0 auto; padding-inline: 8px; }
  .kv, .help { grid-template-columns: 1fr; }
  .kv dd, .help dd { margin-bottom: 8px; }
  .banner-meta .km { font-size: 15px; }
  .grid { gap: 8px; }
  .card { padding: 10px 12px; }
  .outp p { max-width: none; }
}
@media (max-width: 700px) {
  #bg.on { opacity: 0.38; }
}
@media (max-width: 380px) {
  .tabs button::before { content: none; }
  .bar-title { visibility: hidden; }
  .avatar { width: 36px; height: 36px; }
}
/* Touch screens: bigger tap targets, and 16px input text so iOS does not zoom on focus */
@media (pointer: coarse) {
  .tabs button { min-height: 44px; }
  .prompt { min-height: 44px; align-items: center; }
  .prompt input { font-size: 16px; min-height: 44px; }
  .kbd { padding: 6px 2px; margin: -6px 0; }
  .card a, .kv a { display: inline-block; padding: 4px 0; }
  .entry { scroll-margin-top: 104px; }
}
/* Phones held sideways: keep the header short */
@media (max-height: 480px) and (orientation: landscape) {
  .bar-top { padding-top: 5px; padding-bottom: 2px; }
  .tabs button { min-height: 36px; padding-block: 4px; }
  .entry { scroll-margin-top: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .cursor { animation: none; }
}
