/* ============================================================
   Brayden Siew — personal site (REV P)
   Simple yet full with power. Reference: darioamodei.com.
   One column, book serif, cream paper, near-zero chrome.
   The substance carries the page; the design gets out of the way.
   ============================================================ */

:root {
  --paper:  #f3f1ea;
  --ink:    #20201d;
  --soft:   #6a665d;
  --rule:   #d8d3c6;
  --link:   #20201d;
  --accent: #9a3b1d;   /* a single warm rust, used only on hover */
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
}

[data-theme="dark"] {
  --paper:  #1a1a17;
  --ink:    #e9e5d8;
  --soft:   #9a958a;
  --rule:   #34332e;
  --link:   #e9e5d8;
  --accent: #d98a5c;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.18rem;
  line-height: 1.62;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 280ms ease, color 280ms ease;
}

/* living background: a faint cellular field, weighted to the margins.
   Kindred to web4.ai, tailored to our palette — see main.js. */
#bg {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 38rem;
  margin: 0 auto;
  padding: clamp(3.5rem, 9vh, 7rem) 1.5rem 5rem;
}

/* fade the whole page up once, gently */
.page > * {
  opacity: 0;
  transform: translateY(8px);
  animation: rise 600ms cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
.page > *:nth-child(2) { animation-delay: 70ms; }
.page > *:nth-child(3) { animation-delay: 140ms; }
.page > *:nth-child(4) { animation-delay: 210ms; }
.page > *:nth-child(5) { animation-delay: 280ms; }
.page > *:nth-child(6) { animation-delay: 350ms; }
@keyframes rise { to { opacity: 1; transform: none; } }

/* ---------- header ---------- */
.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}
h1 {
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* dark-mode toggle — the only piece of UI on the page */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  line-height: 0;
}
.tt-track {
  display: block;
  width: 34px;
  height: 18px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  position: relative;
  transition: border-color 280ms ease;
}
.tt-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 280ms cubic-bezier(0.4, 0.1, 0.2, 1), background 280ms ease;
}
[data-theme="dark"] .tt-thumb { transform: translateX(15px); }

/* epigraph — a quiet motto under the name */
.epigraph {
  font-style: italic;
  color: var(--soft);
  margin-bottom: 2.2rem;
  line-height: 1.5;
}
.epigraph-by { font-style: normal; font-size: 0.86rem; white-space: nowrap; }

/* ---------- prose ---------- */
.bio { margin-bottom: 3.5rem; }
.bio p { margin-bottom: 1.1rem; }
.bio p:last-child { margin-bottom: 0; }

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2.5px;
  text-decoration-color: var(--rule);
  transition: color 160ms ease, text-decoration-color 160ms ease;
}
a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

code {
  font-family: "Newsreader", serif;
  font-style: italic;
}

/* ---------- groups ---------- */
.group { margin-bottom: 3.5rem; }
h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.9rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--rule);
}

.list { list-style: none; }
.list li {
  margin-bottom: 0.75rem;
  line-height: 1.5;
}
.list li:last-child { margin-bottom: 0; }

.li-name { font-weight: 500; }
a.li-name { font-weight: 600; }
.li-desc { color: var(--soft); }

/* name → dash → description on one flow */
#work .list li .li-desc::before,
#into .list li .li-desc::before,
#writing .list li .li-desc::before { content: " — "; color: var(--soft); }

/* a touch more air between the richer entries */
#work .list li, #into .list li, #writing .list li { margin-bottom: 1rem; line-height: 1.55; }

/* writing index */
.writing-intro { color: var(--soft); margin-bottom: 1.3rem; }
.writing-label {
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 1.4rem 0 0.7rem;
}
#writing .list { margin-bottom: 0; }

.more {
  margin-top: 1rem;
  color: var(--soft);
  font-style: italic;
}

/* prose blocks inside sections (How I think / Right now) */
.prose { margin-bottom: 1rem; }
.prose:last-child { margin-bottom: 0; }
.prose em { font-style: italic; }

/* ---------- footer ---------- */
.foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 4rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.8rem;
  color: var(--soft);
}
.foot-sig { letter-spacing: 0.22em; font-size: 0.66rem; }

.mail-note.copied { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  .page > * { animation: none; opacity: 1; transform: none; }
  body, .tt-thumb, .tt-track, a { transition: none; }
}

/* ============================================================
   Essay / writing pages (writing/*.html)
   Same column, same paper, same living background.
   ============================================================ */
.backlink {
  display: inline-block;
  margin-bottom: 2.4rem;
  font-size: 0.92rem;
  color: var(--soft);
  text-decoration: none;
}
.backlink:hover { color: var(--accent); }
.backlink::before { content: "← "; }

.essay-head { margin-bottom: 2.2rem; }
.essay-head h1 {
  font-size: clamp(1.9rem, 3.6vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
}
.essay-head .date {
  display: block;
  margin-top: 0.7rem;
  font-size: 0.86rem;
  color: var(--soft);
}

.essay p {
  margin-bottom: 1.25rem;
  line-height: 1.7;
}
.essay p:last-child { margin-bottom: 0; }
.essay p.lede {
  font-size: 1.28rem;
  line-height: 1.55;
  color: var(--ink);
}
.essay em { font-style: italic; }
.essay h2 {
  border: none;
  padding: 0;
  margin: 2.2rem 0 0.6rem;
  font-size: 1.18rem;
  font-weight: 600;
}

.essay-foot {
  margin-top: 3rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.92rem;
}
.essay-foot a { color: var(--soft); text-decoration: none; }
.essay-foot a:hover { color: var(--accent); }

/* ============================================================
   Bilingual — English / 简体中文
   Each block exists twice (lang="en" / lang="zh"); the inactive
   language is hidden by CSS off the <html data-lang> state, so
   links and markup stay intact and there's no JS text-swapping.
   ============================================================ */
html[data-lang="en"] [lang="zh"] { display: none; }
html[data-lang="zh"] [lang="en"] { display: none; }

/* Chinese reads as a book serif too, just a different one, with a
   little more line-height to breathe. English stays Newsreader. */
[lang="zh"] {
  font-family: "Noto Serif SC", var(--serif);
  line-height: 1.85;
}
.essay p[lang="zh"] { line-height: 1.95; }
[lang="zh"] code { font-style: normal; }

/* the two controls (language + theme) sit together, top-right */
.controls { display: flex; align-items: center; gap: 0.95rem; }

/* language toggle — a quiet text button, sibling to the theme switch */
.lang-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--soft);
  padding: 2px 2px;
  line-height: 1;
  transition: color 160ms ease;
}
.lang-toggle:hover { color: var(--accent); }
.lang-toggle .lang-to-en { font-family: "Noto Serif SC", var(--serif); }
html[data-lang="en"] .lang-to-en { display: none; }
html[data-lang="zh"] .lang-to-zh { display: none; }

/* essay sub-header: backlink on the left, controls on the right */
.subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.4rem;
}
.subhead .backlink { margin-bottom: 0; }

/* ============================================================
   Competitions & awards page (awards/index.html)
   Text-first ledger rows; the certificate is a quiet framed
   thumbnail that opens full-size in a lightbox on click.
   ============================================================ */
.awards-intro {
  color: var(--soft);
  margin-bottom: 2.6rem;
  line-height: 1.6;
}
.award-group { margin-bottom: 2.8rem; }
.award-group:last-of-type { margin-bottom: 3.5rem; }

ul.awards { list-style: none; }
.awards .award {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.4rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule);
}
.awards .award:last-child { border-bottom: none; }

.award-text { min-width: 0; }
.award-name { font-weight: 600; display: block; }
.award-meta {
  display: block;
  color: var(--soft);
  font-size: 0.94rem;
  margin-top: 0.15rem;
  line-height: 1.45;
}

/* an "in progress" marker for entries not yet won */
.award--ongoing .award-name { color: var(--soft); }
.tag {
  display: inline-block;
  margin-left: 0.5rem;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  vertical-align: 0.12em;
  font-weight: 500;
}
[lang="zh"].tag { letter-spacing: 0.06em; }

/* certificate thumbnail — a small, consistent framed box */
.award-cert {
  flex: none;
  display: block;
  width: 116px;
  height: 78px;
  padding: 4px;
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: 0;
  transition: border-color 160ms ease, transform 160ms ease;
}
.award-cert img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.award-cert:hover { border-color: var(--accent); transform: translateY(-2px); }
.award-cert:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* an entry can carry more than one certificate (e.g. cert + score card) */
.award-certs { flex: none; display: flex; gap: 8px; }

/* ============================================================
   Front-page gate — one random riddle before the door opens.
   Hidden by default; shown only when <html> has .gated (set by
   an inline head script before paint, so the page never flashes).
   ============================================================ */
.gate-overlay { display: none; }
html.gated .page { display: none; }
html.gated body { overflow: hidden; }
html.gated .gate-overlay {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 5;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.5rem 4rem;
  background: var(--paper);
  transition: opacity 380ms ease;
}
.gate-overlay.lifting { opacity: 0; }
.gate-controls { position: fixed; top: 1.4rem; right: 1.6rem; z-index: 6; }
.gate { max-width: 33rem; width: 100%; }
.gate-mark {
  font-size: 0.7rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--soft);
  margin-bottom: 2.4rem;
}
.gate-intro {
  font-style: italic;
  color: var(--soft);
  margin-bottom: 2.8rem;
  line-height: 1.55;
}
.g-q {
  font-size: 1.42rem;
  line-height: 1.5;
  min-height: 4.2em;
  display: flex;
  align-items: center;
  justify-content: center;
}
[lang="zh"].g-q, .g-q [lang="zh"] { line-height: 1.7; }
#gate-form {
  margin-top: 1.4rem;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
}
#gate-input {
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--ink);
  background: none;
  border: none;
  border-bottom: 1.5px solid var(--rule);
  text-align: center;
  padding: 0.25rem 0.4rem;
  width: min(20rem, 70vw);
  outline: none;
  transition: border-color 200ms ease;
}
html[data-lang="zh"] #gate-input { font-family: "Noto Serif SC", var(--serif); }
#gate-input:focus { border-bottom-color: var(--accent); }
#gate-input::placeholder { color: var(--rule); }
.gate-enter {
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--serif);
  font-size: 1.4rem;
  line-height: 1;
  color: var(--soft);
  padding: 0 0.2rem;
  transition: color 160ms ease, transform 160ms ease;
}
.gate-enter:hover { color: var(--accent); transform: translateX(2px); }
.gate-msg {
  margin-top: 1.5rem;
  min-height: 1.4em;
  color: var(--soft);
  font-style: italic;
  line-height: 1.4;
}
.gate-msg.ok { color: var(--accent); font-style: normal; }
.gate-skip {
  margin-top: 2.2rem;
  font-size: 0.9rem;
  color: var(--soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms ease;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--serif);
}
.gate-skip.show { opacity: 0.7; pointer-events: auto; }
.gate-skip:hover { color: var(--accent); opacity: 1; }
@keyframes gate-shake {
  10%, 90% { transform: translateX(-2px); }
  30%, 70% { transform: translateX(4px); }
  50% { transform: translateX(-5px); }
}
#gate-form.wrong { animation: gate-shake 360ms cubic-bezier(.36,.07,.19,.97); }
#gate-form.wrong #gate-input { border-bottom-color: var(--accent); }
@media (prefers-reduced-motion: reduce) {
  #gate-form.wrong { animation: none; }
  .gate-overlay, .gate-skip, #gate-input, .gate-enter { transition: none; }
}

/* ---- awards page v2: rhythm & story ---- */

/* rust emphasis on the actual result/placement, used across the page */
.res { color: var(--accent); font-weight: 500; }

/* homepage → awards call-to-action: a clear outlined button, not a stray link */
.record-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.05rem;
  padding: 0.52rem 1.15rem;
  border: 1px solid var(--accent);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.98rem;
  transition: background 180ms ease, color 180ms ease, gap 160ms ease;
}
.record-btn:hover { background: var(--accent); color: var(--paper); gap: 0.72rem; }
.record-btn .arr { transition: transform 160ms ease; }
.record-btn:hover .arr { transform: translateX(2px); }

/* Campus leadership — bordered cards with a role, a title, and rust-marked points */
.lead-list { display: flex; flex-direction: column; gap: 1.1rem; }
.lead-item {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  border: 1px solid var(--rule);
  padding: 1.5rem 1.6rem;
}
.lead-main { flex: 1; min-width: 0; }
.lead-item > .award-cert { flex: none; margin-top: 0.2rem; }
.lead-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.55rem;
}
.lead-role {
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
  line-height: 1.35;
}
.lead-tag {
  flex: none;
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  color: var(--soft);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.14rem 0.55rem;
  white-space: nowrap;
}
.lead-title { font-size: 1.45rem; font-weight: 600; line-height: 1.2; }
.lead-desc { color: var(--soft); font-size: 0.94rem; line-height: 1.6; margin-top: 0.65rem; }
.lead-points { list-style: none; margin-top: 0.95rem; display: flex; flex-direction: column; gap: 0.5rem; }
.lead-points li { position: relative; padding-left: 1.5rem; font-size: 0.94rem; line-height: 1.45; }
.lead-points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.7em;
  width: 0.85rem;
  height: 1px;
  background: var(--accent);
}

/* groups reveal as you scroll (gated on .js-reveal so no-JS still shows all) */
.js-reveal .award-group {
  opacity: 0;
  transform: translateY(18px);
  animation: none;
  transition: opacity 0.6s cubic-bezier(0.2, 0.7, 0.2, 1),
              transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
  will-change: opacity, transform;
}
.js-reveal .award-group.in { opacity: 1; transform: none; }

/* Education — a vertical timeline, oldest at the top, "now" at the bottom */
.timeline { position: relative; margin-top: 0.5rem; }
.timeline::before {
  content: "";
  position: absolute;
  left: 5.35rem;
  top: 0.6rem;
  bottom: 0.6rem;
  width: 1px;
  background: var(--rule);
}
.tl-item {
  display: grid;
  grid-template-columns: 4.6rem 1fr;
  column-gap: 1.5rem;
  position: relative;
  padding-bottom: 2.2rem;
}
.tl-item:last-child { padding-bottom: 0.2rem; }
.tl-date {
  text-align: right;
  padding-top: 0.28rem;
  line-height: 1.3;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.tl-date span { display: block; color: var(--soft); }
.tl-body { position: relative; min-width: 0; }
.tl-body::before {
  content: "";
  position: absolute;
  left: -0.75rem;
  top: 0.55rem;
  transform: translateX(-50%);
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--paper);
  border: 1.6px solid var(--accent);
  transition: background 200ms ease;
}
.tl-item.now .tl-body::before { background: var(--accent); }
.tl-name { font-size: 1.16rem; font-weight: 600; line-height: 1.32; }
.tl-sub { color: var(--soft); font-size: 0.93rem; margin-top: 0.15rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.chip {
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--soft);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.12rem 0.55rem;
  white-space: nowrap;
}
.tl-hl { margin-top: 0.65rem; font-size: 0.9rem; color: var(--accent); line-height: 1.45; }
.tl-hl::before { content: "★ "; }

/* IELTS — a quiet stat under the timeline */
.ielts {
  margin: 1.8rem 0 0 6.1rem;
}
.ielts-top { display: flex; align-items: baseline; gap: 0.7rem; }
.ielts-fig { font-size: 2.15rem; font-weight: 600; line-height: 1; letter-spacing: -0.01em; }
.ielts-cap { color: var(--soft); font-size: 0.88rem; }
.ielts-break {
  display: flex; flex-wrap: wrap; gap: 0.3rem 1.3rem;
  margin-top: 0.6rem; color: var(--soft); font-size: 0.86rem;
}
.ielts-break b { color: var(--ink); font-weight: 600; }

/* Swimming — a rust chip + two big personal-best figures */
.athlete-chip {
  display: inline-block;
  font-size: 0.72rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.24rem 0.85rem;
  margin-bottom: 0.9rem;
}
.athlete-chip .zh { text-transform: none; letter-spacing: 0.02em; }
.swim-sub { color: var(--soft); font-size: 0.93rem; margin-bottom: 1.3rem; line-height: 1.5; }
.stats { display: flex; gap: 1rem; flex-wrap: wrap; }
.stat { flex: 1 1 12rem; border: 1px solid var(--rule); padding: 1.1rem 1.25rem; }
.stat-fig {
  display: block;
  font-size: 2.15rem; font-weight: 600; line-height: 1;
  letter-spacing: -0.01em; font-variant-numeric: tabular-nums;
}
.stat-cap {
  display: block; margin-top: 0.55rem;
  font-size: 0.72rem; letter-spacing: 0.11em; text-transform: uppercase; color: var(--soft);
}

/* Calligraphy — the 作品 as a featured piece, with a Lv.6 figure */
.calli { display: flex; gap: 1.7rem; align-items: flex-start; }
.calli-img {
  flex: none;
  display: block;
  width: 172px;
  border: 1px solid var(--rule);
  background: var(--paper);
  padding: 6px;
  transition: border-color 160ms ease, transform 160ms ease;
}
.calli-img img { display: block; width: 100%; height: auto; }
.calli-img:hover { border-color: var(--accent); transform: translateY(-2px); }
.calli-body { min-width: 0; }
.calli-fig { font-size: 2rem; font-weight: 600; line-height: 1; color: var(--accent); }
.calli-name { font-size: 1.16rem; font-weight: 600; margin-top: 0.3rem; }
.calli-detail { color: var(--soft); font-size: 0.94rem; line-height: 1.6; margin-top: 0.55rem; }
.calli-detail .zh-em { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .js-reveal .award-group { opacity: 1; transform: none; transition: none; }
  .calli-img, .tl-item::before { transition: none; }
}

/* lightbox — full certificate over a dimmed backdrop */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5vh 5vw;
  background: rgba(18, 18, 16, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}
.lightbox.open { opacity: 1; pointer-events: auto; }
.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  background: #fff;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.45);
}
.lightbox-close {
  position: fixed;
  top: 20px;
  right: 28px;
  background: none;
  border: none;
  color: #f3f1ea;
  font-size: 2.2rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  opacity: 0.8;
  transition: opacity 160ms ease;
}
.lightbox-close:hover { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .award-cert, .lightbox { transition: none; }
}
