/* ------------------------------------------------------------------
   Chuyện của ông · Grandpa's story
   Soft, paper-and-ink palette. Cormorant Garamond for display,
   EB Garamond for reading text (both carry full Vietnamese diacritics).
------------------------------------------------------------------- */

:root {
  --paper: #f6f1e6;
  --paper-2: #efe7d6;
  --paper-3: #e6dcc7;
  --ink: #2e2923;
  --ink-soft: #6a6056;
  --ink-faint: #9b9184;
  --line: #d9cdb6;
  --terracotta: #a8583c;
  --terracotta-soft: #c98a70;
  --moss: #5f6d4d;
  --gold: #b4924f;
  --shadow: 0 18px 50px -24px rgba(60, 40, 20, 0.45);
  --radius: 16px;
  --sidebar-w: 268px;
  --display: "Cormorant Garamond", "Times New Roman", serif;
  --body: "EB Garamond", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  background-image:
    radial-gradient(1200px 600px at 10% -10%, rgba(255, 255, 255, 0.55), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(180, 146, 79, 0.10), transparent 60%);
  color: var(--ink);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--terracotta); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

::selection { background: rgba(168, 88, 60, 0.18); }

/* ------------------------------ layout ------------------------------ */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 2.4rem 1.6rem 1.6rem;
  background: var(--paper-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.brand { display: block; color: var(--ink); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-vi {
  display: block;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.85rem;
  letter-spacing: 0.01em;
  line-height: 1.05;
}
.brand-en {
  display: block;
  margin-top: 0.35rem;
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1rem;
}
.brand-rule {
  width: 42px;
  height: 2px;
  background: var(--terracotta);
  margin-top: 1rem;
  border-radius: 2px;
}

.nav-label {
  margin: 0 0 0.6rem;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.nav-link {
  display: grid;
  grid-template-columns: 1.6rem 1fr;
  gap: 0.6rem;
  align-items: start;
  padding: 0.6rem 0.7rem;
  margin: 0 -0.7rem;
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease;
}
.nav-link:hover { background: rgba(168, 88, 60, 0.07); text-decoration: none; }
.nav-link.active { background: rgba(168, 88, 60, 0.11); }
.nav-link.active .num { color: var(--terracotta); }
.nav-link.disabled { opacity: 0.45; pointer-events: none; }
.nav-link .num {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--ink-faint);
  padding-top: 0.05rem;
}
.nav-link .vi { display: block; line-height: 1.25; }
.nav-link .en { display: block; font-style: italic; font-size: 0.9rem; color: var(--ink-soft); }

.nav-secondary { margin-top: auto; display: flex; flex-direction: column; gap: 0.2rem; }
.nav-secondary .nav-link { grid-template-columns: 1fr; font-size: 0.95rem; color: var(--ink-soft); }

/* ------------------------------ main ------------------------------ */

.main {
  padding: 3rem 3.2rem 4rem;
  max-width: 1380px;
  width: 100%;
}

.chapter-head { max-width: 760px; margin-bottom: 2rem; }
.eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.74rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--terracotta);
}
h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(2.3rem, 4vw, 3.4rem);
  line-height: 1.05;
  letter-spacing: -0.005em;
}
.subtitle {
  margin: 0.4rem 0 0;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.35rem;
  color: var(--ink-soft);
}
.lede { margin: 1.3rem 0 0; font-size: 1.12rem; color: var(--ink-soft); }
.lede .vi-lead { color: var(--ink); }

/* ------------------------------ stage ------------------------------ */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.4rem;
  align-items: start;
}

.viewer-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #cfd6cf;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  aspect-ratio: 16 / 10;
  min-height: 380px;
}
.viewer-card canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
.viewer-card canvas:active { cursor: grabbing; }
.viewer-card:fullscreen { aspect-ratio: auto; border-radius: 0; border: 0; }

.viewer-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--paper-2);
  color: var(--ink-soft);
  font-family: var(--display);
  font-style: italic;
  font-size: 1.3rem;
  transition: opacity 0.6s ease;
  z-index: 3;
}
.viewer-loading.hidden { opacity: 0; pointer-events: none; }

.viewer-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: rgba(46, 41, 35, 0.62);
  color: #f6f1e6;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(6px);
  transition: opacity 0.5s ease;
  z-index: 2;
}
.viewer-hint.faded { opacity: 0; }

.viewer-caption {
  position: absolute;
  left: 14px;
  top: 14px;
  max-width: 62%;
  padding: 0.55rem 0.9rem 0.6rem;
  border-radius: 12px;
  background: rgba(246, 241, 230, 0.86);
  border: 1px solid rgba(217, 205, 182, 0.7);
  backdrop-filter: blur(8px);
  z-index: 2;
  pointer-events: none;
}
.viewer-caption .cap-vi { font-family: var(--display); font-weight: 600; font-size: 1.15rem; line-height: 1.1; }
.viewer-caption .cap-en { font-style: italic; font-size: 0.9rem; color: var(--ink-soft); }

.viewer-tools {
  position: absolute;
  right: 12px;
  top: 12px;
  display: flex;
  gap: 6px;
  z-index: 2;
}
.tool-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(217, 205, 182, 0.8);
  background: rgba(246, 241, 230, 0.86);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.2s ease, transform 0.2s ease;
}
.tool-btn:hover { background: #fff; transform: translateY(-1px); }
.tool-btn svg { width: 18px; height: 18px; }

/* Touch D-pad (only on coarse pointers) */
.dpad {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: none;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(2, 44px);
  gap: 4px;
  z-index: 2;
}
.dpad button {
  border: 1px solid rgba(217, 205, 182, 0.8);
  background: rgba(246, 241, 230, 0.82);
  border-radius: 10px;
  font-size: 1.1rem;
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.dpad button:active { background: #fff; }
.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
@media (pointer: coarse) { .dpad { display: grid; } .viewer-hint { display: none; } }

/* ------------------------------ side panel ------------------------------ */

.panel { display: flex; flex-direction: column; gap: 1.1rem; }

.card {
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem 1.2rem;
}
.card-title {
  margin: 0 0 0.8rem;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.viewpoints { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.vp-btn {
  width: 100%;
  display: grid;
  grid-template-columns: 1.5rem 1fr;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.5rem 0.65rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease;
}
.vp-btn:hover { background: rgba(168, 88, 60, 0.07); }
.vp-btn.active { background: rgba(168, 88, 60, 0.12); }
.vp-btn .num { font-family: var(--display); font-weight: 600; color: var(--ink-faint); }
.vp-btn.active .num { color: var(--terracotta); }
.vp-btn .vi { display: block; line-height: 1.2; }
.vp-btn .en { display: block; font-style: italic; font-size: 0.88rem; color: var(--ink-soft); }

.viewer-col { display: flex; flex-direction: column; gap: 1.4rem; min-width: 0; }
.plan-card { display: grid; grid-template-columns: minmax(0, 380px) 1fr; gap: 1.4rem; align-items: start; }
.plan-wrap { position: relative; }
#plan { display: block; width: 100%; height: auto; border-radius: 10px; cursor: crosshair; border: 1px solid var(--line); }
.plan-note { margin: 0 0 0.6rem; font-size: 0.92rem; color: var(--ink-soft); }
.plan-note + .plan-note { font-style: italic; }

.spot-text .spot-vi { margin: 0; }
.spot-text .spot-en { margin: 0.6rem 0 0; font-style: italic; color: var(--ink-soft); font-size: 0.98rem; }

/* ------------------------------ excerpt ------------------------------ */

.excerpt {
  margin-top: 2.6rem;
  padding: 2rem 2.2rem 2.2rem;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.2)),
    var(--paper-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.excerpt-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.excerpt-head h2 { margin: 0; font-family: var(--display); font-weight: 500; font-size: 1.9rem; }
.excerpt-head .source { font-style: italic; color: var(--ink-soft); font-size: 0.95rem; }

.excerpt-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 2.4rem; }
.excerpt-cols h3 {
  margin: 0 0 0.6rem;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
}
.excerpt-cols p { margin: 0 0 1rem; text-align: justify; hyphens: auto; }
.excerpt-cols .vi-text p:first-of-type::first-letter {
  font-family: var(--display);
  font-size: 3.4em;
  float: left;
  line-height: 0.85;
  padding: 0.05em 0.12em 0 0;
  color: var(--terracotta);
}
.excerpt-cols .en-text { color: var(--ink-soft); }
.gap { color: var(--ink-faint); }

.notes { margin-top: 2.2rem; max-width: 760px; }
.notes h2 { font-family: var(--display); font-weight: 500; font-size: 1.7rem; margin: 0 0 0.6rem; }
.notes ul { margin: 0; padding-left: 1.2rem; color: var(--ink-soft); }
.notes li { margin-bottom: 0.4rem; }
.notes li b { color: var(--ink); font-weight: 600; }

.site-footer {
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
  color: var(--ink-faint);
  font-style: italic;
}

/* ------------------------------ prose page (about) ------------------------------ */

.prose { max-width: 720px; }
.prose p { margin: 0 0 1.1rem; }
.prose h2 { font-family: var(--display); font-weight: 500; font-size: 1.8rem; margin: 2rem 0 0.6rem; }
.prose .en { font-style: italic; color: var(--ink-soft); }

/* ------------------------------ responsive ------------------------------ */

@media (max-width: 1180px) {
  .stage { grid-template-columns: 1fr; }
  .panel { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 1.4rem 1.4rem 1rem;
    gap: 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand-vi { font-size: 1.5rem; }
  .brand-rule { display: none; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 0.2rem 0.8rem; align-items: center; }
  .nav-label { width: 100%; margin-bottom: 0.2rem; }
  .nav-link { margin: 0; padding: 0.4rem 0.6rem; }
  .nav-secondary { margin-top: 0; flex-direction: row; }
  .main { padding: 1.8rem 1.2rem 3rem; }
  .excerpt { padding: 1.4rem 1.2rem 1.6rem; }
  .excerpt-cols { grid-template-columns: 1fr; gap: 1.4rem; }
  .panel { grid-template-columns: 1fr; }
  .plan-card { grid-template-columns: 1fr; }
  .viewer-card { min-height: 300px; aspect-ratio: 4 / 3; }
  .viewer-caption { max-width: 70%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; }
}
