/*
Theme Name: Tung Nguyen
Theme URI: https://tungnguyen.ai.vn
Author: Tung Nguyen
Description: A quiet, editorial personal-blog theme. Warm paper background, serif headings, generous whitespace, single-column reading measure, automatic dark mode.
Version: 1.0.9
Requires at least: 6.0
Tested up to: 6.8
Requires PHP: 7.4
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: tungnguyen
Tags: blog, one-column, custom-menu, editor-style, translation-ready, dark-mode
*/

/* ===========================================================
   tungnguyen.ai.vn — design system
   Calm editorial layout inspired by mustafa-suleyman.ai,
   with its own palette and type voice.
   =========================================================== */

:root {
  /* --- Palette: warm paper + deep ink + jade accent --- */
  --paper:        #faf8f4;
  --paper-alt:    #f2efe8;
  --card:         #ffffff;
  --ink:          #1a1a17;
  --ink-soft:     #4a4a44;
  --ink-faint:    #85847c;
  --rule:         #e3dfd5;
  --accent:       #1f6b52;
  --accent-soft:  #e6f0ec;

  /* --- Type --- */
  --serif: "Lora", "Times New Roman", Times, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  --step--1: clamp(0.83rem, 0.80rem + 0.15vw, 0.92rem);
  --step-0:  clamp(1.05rem, 1.00rem + 0.25vw, 1.19rem);
  --step-1:  clamp(1.30rem, 1.20rem + 0.50vw, 1.60rem);
  --step-2:  clamp(1.70rem, 1.45rem + 1.10vw, 2.40rem);
  --step-3:  clamp(2.30rem, 1.80rem + 2.20vw, 3.90rem);

  /* --- Space --- */
  --gutter: clamp(1.25rem, 5vw, 3rem);
  --measure: 100%;
  --wide: 78rem;
  --section-gap: clamp(4.5rem, 10vw, 8.5rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:       #14150f;
    --paper-alt:   #1c1d16;
    --card:        #1c1d16;
    --ink:         #f0ede4;
    --ink-soft:    #c2bfb4;
    --ink-faint:   #8c8a7e;
    --rule:        #2e2f26;
    --accent:      #7fc9a9;
    --accent-soft: #1e2a24;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 5rem; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--step-0);
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; display: block; height: auto; }

a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 0.22em; }
a:hover { text-decoration-color: var(--accent); }

::selection { background: var(--accent); color: var(--paper); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip {
  position: absolute; left: -9999px;
  background: var(--ink); color: var(--paper);
  padding: 0.6rem 1rem; border-radius: 4px; z-index: 100;
}
.skip:focus { left: 1rem; top: 1rem; }

/* --- Layout primitives --- */
.wrap { width: 100%; max-width: var(--wide); margin-inline: auto; padding-inline: var(--gutter); }
.prose { max-width: var(--measure); }

/* --- Header / nav --- */
.site-head {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s ease;
}
.site-head[data-scrolled="true"] { border-bottom-color: var(--rule); }

.site-head .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1.5rem; min-height: 4rem;
}

.wordmark {
  font-family: var(--serif);
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.nav ul {
  display: flex; gap: clamp(0.9rem, 2.5vw, 1.9rem); flex-wrap: wrap;
  list-style: none; margin: 0; padding: 0;
}
.nav a {
  font-size: var(--step--1);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-faint);
  text-decoration: none;
  padding-block: 0.35rem;
  border-bottom: 1px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.nav a:hover,
.nav .current-menu-item > a,
.nav .current_page_item > a,
.nav .current-menu-ancestor > a { color: var(--ink); border-bottom-color: var(--accent); }

@media (max-width: 34rem) {
  .nav { display: none; }
}

/* --- Hero --- */
.hero { padding-block: clamp(3.5rem, 9vw, 7rem) 0; }
.hero-grid {
  display: grid;
  gap: clamp(2rem, 5vw, 4rem);
  grid-template-columns: 1fr;
  align-items: center;
}
@media (min-width: 48rem) {
  .hero-grid { grid-template-columns: 1.15fr 0.85fr; }
}

.hero h1 {
  font-family: var(--serif);
  font-size: var(--step-3);
  font-weight: 400;
  line-height: 1.14;
  letter-spacing: -0.02em;
  margin: 0 0 1.25rem;
  text-wrap: balance;
}
.hero .lede {
  font-size: var(--step-1);
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0 0 2rem;
  max-width: 30ch;
  text-wrap: pretty;
}

.portrait {
  border-radius: 3px;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: var(--paper-alt);
  filter: grayscale(0.15);
  width: 50%;
  margin-inline: auto;
}

/* --- Social row --- */
.socials { display: flex; gap: 0.6rem; flex-wrap: wrap; padding: 0; margin: 0; list-style: none; }
.socials a {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem;
  border: 1px solid var(--rule);
  border-radius: 50%;
  text-decoration: none;
  color: var(--ink-soft);
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.socials a:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.socials svg { width: 1.05rem; height: 1.05rem; fill: currentColor; }

/* --- Sections --- */
.section { padding-block: var(--section-gap); border-top: 1px solid var(--rule); }
.section:first-of-type { border-top: none; }

.section-head { margin-bottom: clamp(2rem, 4vw, 3.25rem); }
.eyebrow {
  font-size: var(--step--1);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.75rem;
}
.section-head h2 {
  font-family: var(--serif);
  font-size: var(--step-2);
  font-weight: 400;
  line-height: 1.22;
  letter-spacing: -0.015em;
  margin: 0 0 0.6rem;
}
.section-head p { color: var(--ink-faint); margin: 0; max-width: 46ch; }

/* --- Writing list --- */
.posts { list-style: none; margin: 0; padding: 0; }
.posts li { border-top: 1px solid var(--rule); }
.posts li:last-child { border-bottom: 1px solid var(--rule); }

.tn-post {
  display: grid;
  gap: 0.35rem 2.5rem;
  grid-template-columns: 1fr;
  padding-block: clamp(1.5rem, 3vw, 2.25rem);
  text-decoration: none;
  transition: background 0.25s ease;
}
@media (min-width: 44rem) {
  .tn-post { grid-template-columns: 8.5rem 1fr; align-items: baseline; }
}
.tn-post:hover { background: var(--paper-alt); }
.tn-post:hover .post-title { color: var(--accent); }

.post-meta {
  font-size: var(--step--1);
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}
.post-title {
  display: block;
  font-family: var(--serif);
  font-size: var(--step-1);
  font-weight: 400;
  line-height: 1.38;
  margin: 0 0 0.4rem;
  transition: color 0.2s ease;
  text-wrap: balance;
}
.post-excerpt { margin: 0; color: var(--ink-soft); font-size: 0.97em; max-width: 54ch; text-wrap: pretty; }

.more {
  display: inline-flex; align-items: center; gap: 0.5rem;
  margin-top: 2rem;
  font-size: var(--step--1);
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent); text-decoration: none;
}
.more::after { content: "→"; transition: transform 0.2s ease; }
.more:hover::after { transform: translateX(3px); }

/* --- Footer --- */
.site-foot {
  border-top: 1px solid var(--rule);
  padding-block: clamp(2.5rem, 6vw, 4rem);
  color: var(--ink-faint);
  font-size: var(--step--1);
}
.site-foot .wrap {
  display: flex; flex-wrap: wrap; gap: 1.5rem;
  align-items: center; justify-content: space-between;
}

/* --- Article page --- */
.article { padding-block: clamp(3rem, 7vw, 5.5rem); }
.article-head { max-width: var(--measure); margin-bottom: clamp(2rem, 5vw, 3.5rem); }
.article-head h1 {
  font-family: var(--serif); font-weight: 400;
  font-size: var(--step-2); line-height: 1.2; letter-spacing: -0.02em;
  margin: 0.75rem 0 1rem; text-wrap: balance;
}
.article-head .dateline { font-size: var(--step--1); color: var(--ink-faint); letter-spacing: 0.06em; }

.article-body { max-width: var(--measure); font-size: 1.06em; }
.article-body p { line-height: 1.8; }
.article-body > * + * { margin-top: 1.5em; }
/* `margin: 0` here used to beat the `> * + *` flow rule on specificity,
   which is why paragraphs ran together with no gap. Spacing is explicit now. */
.article-body p {
  /* Must exceed the 1.8 line-height below, or the paragraph break reads as
     just another line of text. 2.4em ~= 48px vs a 36px line gap. */
  margin: 0 0 2.4em;
  color: var(--ink-soft);
  text-wrap: pretty;
  text-indent: 2em;
}
.article-body p:last-child { margin-bottom: 0; }
.article-body p:empty { display: none; }

/* Indent would look wrong on centred/right text and inside quotes. */
.article-body p[class*="has-text-align-center"],
.article-body p[class*="has-text-align-right"],
.article-body blockquote p,
.article-body figcaption {
  text-indent: 0;
}
.article-body h2 {
  font-family: var(--serif); font-weight: 400; font-size: var(--step-1);
  line-height: 1.38; margin-top: 2.4em; color: var(--ink);
}
.article-body a { color: var(--accent); }
.article-body blockquote {
  margin: 2.2em 0; padding-left: 1.5rem;
  border-left: 2px solid var(--accent);
  font-family: var(--serif); font-size: var(--step-1);
  line-height: 1.55; color: var(--ink);
}
.article-body blockquote p { color: inherit; font: inherit; margin-bottom: 0; }
.article-body ul, .article-body ol { padding-left: 1.3rem; color: var(--ink-soft); }
.article-body li + li { margin-top: 0.5em; }
.article-body img { margin-block: 2.5em; border-radius: 3px; }
.article-body figcaption { font-size: var(--step--1); color: var(--ink-faint); margin-top: 0.75rem; }
.article-body hr { border: none; border-top: 1px solid var(--rule); margin-block: 3em; }
.article-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em; background: var(--paper-alt);
  padding: 0.15em 0.4em; border-radius: 3px;
}

.back {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-size: var(--step--1); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-faint); text-decoration: none;
}
.back::before { content: "←"; }
.back:hover { color: var(--accent); }

/* --- Motion --- */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity 0.7s ease, transform 0.7s ease; }
.reveal.in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .reveal { opacity: 1; transform: none; }
}

/* ===========================================================
   WordPress-specific
   =========================================================== */

/* Admin bar shouldn't hide the sticky header */
body.admin-bar .site-head { top: 32px; }
@media screen and (max-width: 782px) {
  body.admin-bar .site-head { top: 46px; }
}

.screen-reader-text {
  border: 0; clip-path: inset(50%); height: 1px; overflow: hidden;
  position: absolute !important; width: 1px; word-wrap: normal !important;
}
.screen-reader-text:focus {
  clip-path: none; height: auto; width: auto;
  background: var(--ink); color: var(--paper);
  padding: 0.6rem 1rem; border-radius: 4px; z-index: 100;
  top: 1rem; left: 1rem;
}

/* Core block alignments inside the article measure */
.article-body .alignwide {
  width: 100%;
  margin-inline: 0;
  max-width: none;
}
.article-body .alignfull {
  width: 100vw;
  margin-inline: calc(50% - 50vw);
  max-width: none;
}
.article-body .alignleft {
  float: left; margin: 0.4em 2rem 1.5rem 0; max-width: 45%;
}
.article-body .alignright {
  float: right; margin: 0.4em 0 1.5rem 2rem; max-width: 45%;
}
.article-body .aligncenter { margin-inline: auto; }
.article-body::after { content: ""; display: table; clear: both; }

.wp-caption { max-width: 100%; }
.wp-caption-text, .blocks-gallery-caption, .wp-block-embed figcaption {
  font-size: var(--step--1); color: var(--ink-faint); margin-top: 0.75rem;
}
.wp-block-image { margin-block: 2.5em; }
.wp-block-image img { border-radius: 3px; }
.wp-block-pullquote, .wp-block-quote { border-left: 2px solid var(--accent); padding-left: 1.5rem; }
.wp-block-button__link {
  background: var(--accent); color: var(--paper);
  border-radius: 3px; padding: 0.7em 1.4em; text-decoration: none;
}
.wp-block-code, .wp-block-preformatted {
  background: var(--paper-alt); padding: 1.25rem; border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em; overflow-x: auto;
}
.wp-block-separator { border: none; border-top: 1px solid var(--rule); margin-block: 3em; }
.wp-block-table td, .wp-block-table th { border: 1px solid var(--rule); padding: 0.6em 0.8em; }

/* Sticky post marker */
.posts li.sticky .post-meta::after {
  content: "Pinned"; display: block; color: var(--accent);
  letter-spacing: 0.12em; text-transform: uppercase; margin-top: 0.3rem;
}

/* Pagination */
.pagination {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin-top: 3rem; font-size: var(--step--1);
}
.pagination .page-numbers {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.4rem; height: 2.4rem; padding-inline: 0.6rem;
  border: 1px solid var(--rule); border-radius: 3px;
  text-decoration: none; color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  transition: border-color 0.2s ease, color 0.2s ease;
}
.pagination .page-numbers:hover { border-color: var(--accent); color: var(--accent); }
.pagination .page-numbers.current { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.pagination .dots { border-color: transparent; }

/* Post navigation (prev/next on single) */
.post-nav {
  display: grid; gap: 1px; background: var(--rule);
  border-block: 1px solid var(--rule);
  margin-top: clamp(3rem, 7vw, 5rem);
  grid-template-columns: 1fr;
}
@media (min-width: 40rem) { .post-nav { grid-template-columns: 1fr 1fr; } }
.post-nav a {
  background: var(--paper); padding: clamp(1.25rem, 3vw, 1.75rem);
  text-decoration: none; display: block;
  transition: background 0.25s ease;
}
.post-nav a:hover { background: var(--paper-alt); }
.post-nav .dir {
  display: block; font-size: var(--step--1); letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 0.4rem;
}
.post-nav .label {
  font-family: var(--serif); font-size: 1.1rem; line-height: 1.42;
  color: var(--ink); text-wrap: balance;
}
.post-nav a:hover .label { color: var(--accent); }
.post-nav .next { text-align: right; }

/* Newest post has no "Next" and oldest has no "Previous". Without this the
   unused grid cell renders as a solid slab of the divider colour. */
.post-nav a:only-child { grid-column: 1 / -1; }

/* Comments */
.comments { max-width: var(--measure); margin-top: clamp(3rem, 7vw, 5rem); }
.comments h2 {
  font-family: var(--serif); font-weight: 400; font-size: var(--step-1);
  margin: 0 0 1.5rem;
}
.comments ol { list-style: none; padding: 0; margin: 0; }
.comments ol ol { padding-left: 1.5rem; }
.comments article { padding-block: 1.5rem; border-top: 1px solid var(--rule); }
.comments .fn { font-style: normal; font-weight: 500; }
.comments .comment-metadata { font-size: var(--step--1); color: var(--ink-faint); }
.comments .comment-metadata a { text-decoration: none; }
.comment-form label { display: block; font-size: var(--step--1); color: var(--ink-faint); margin-bottom: 0.35rem; }
.comment-form input[type="text"],
.comment-form input[type="email"],
.comment-form input[type="url"],
.comment-form textarea {
  width: 100%; font: inherit; font-size: 1rem;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 3px;
  padding: 0.6rem 0.75rem;
}
.comment-form .submit {
  font: inherit; font-size: var(--step--1);
  letter-spacing: 0.08em; text-transform: uppercase;
  background: var(--ink); color: var(--paper);
  border: none; border-radius: 3px; padding: 0.8rem 1.6rem; cursor: pointer;
}
.comment-form .submit:hover { background: var(--accent); }

/* Search form */
.search-form { display: flex; gap: 0.5rem; max-width: 24rem; }
.search-form input[type="search"] {
  flex: 1; font: inherit; font-size: 1rem;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 3px; padding: 0.55rem 0.75rem;
}
.search-form button {
  font: inherit; font-size: var(--step--1);
  letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--ink); color: var(--paper);
  border: none; border-radius: 3px; padding: 0 1.1rem; cursor: pointer;
}

/* Empty state */
.empty { max-width: var(--measure); color: var(--ink-soft); }

/* --- Centred images ---
   img is display:block, so it needs auto inline margins to centre.
   Figures carrying an align* class are excluded so alignleft/alignright still float. */
.article-thumb,
.article-body figure:not([class*="align"]) {
  margin-inline: auto;
}
.article-thumb img,
.article-body figure:not([class*="align"]) img,
.article-body > img,
.wp-block-image:not([class*="align"]) img {
  margin-inline: auto;
}
.article-thumb figcaption,
.article-body figure:not([class*="align"]) figcaption,
.wp-caption-text {
  text-align: center;
}
