:root {
  /* ====== LIGHT MODE ====== */
  --bg: #f5fbfc;
  --bg-alt: #ffffff;
  --text: #0e2a31;
  --muted: #6b7280;
  --accent: #3AA8C1;
  --accent-soft: #d7eff3;
  --accent-strong: #2a8da5;
  --border: #cde4e8;
  --radius: 14px;
  --shadow-soft: 0 8px 20px rgba(15, 23, 42, 0.06);
  --font-main: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --max-width: 1120px;
  --transition-fast: 0.2s ease;
}

/* ====== DARK MODE ====== */
:root[data-theme="dark"] {
  --bg: #1f2a2e;
  --bg-alt: #2a3539;
  --text: #e3f2f4;
  --muted: #9ca3af;
  --accent: #3AA8C1;
  --accent-soft: #30464b;
  --accent-strong: #52bfd6;
  --border: #3a4b4f;
  --shadow-soft: 0 10px 26px rgba(0, 0, 0, 0.4);
}

/* ====== GLOBAL ====== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ====== ACCESSIBILITY ====== */
.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.skip-link:focus {
  position: fixed;
  left: 16px;
  top: 16px;
  width: auto;
  height: auto;
  padding: 8px 14px;
  background: var(--accent-strong);
  color: #fff;
  border-radius: 6px;
  z-index: 9999;
}

/* ====== HEADER / NAV ====== */
header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(245, 251, 252, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

:root[data-theme="dark"] header {
  background: rgba(31, 42, 46, 0.95);
}

.nav {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.logo-wrap {
  display: flex;
  flex-direction: column;
}

.site-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tagline {
  font-size: 0.8rem;
  color: var(--muted);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}

.nav-links a {
  padding: 6px 10px;
  border-radius: 999px;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.nav-links a:hover {
  background: var(--accent-strong);
  color: #f9fafb;
  text-decoration: none;
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.25);
}

/* ====== DARK MODE TOGGLE ====== */
#theme-toggle {
  border: none;
  background: var(--accent-soft);
  color: var(--accent-strong);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition:
    background var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    color var(--transition-fast);
}

#theme-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.16);
}

/* ====== MOBILE NAV ====== */
.menu-toggle {
  display: none;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--accent-strong);
}

/* ====== HERO SECTION ====== */
.hero {
  max-width: var(--max-width);
  margin: 18px auto 10px;
  padding: 18px;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 2.2fr) minmax(230px, 1.3fr);
}

.hero-main,
.card,
.content-section {
  background: var(--bg-alt);
  padding: 14px 14px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border);
}

.hero-main h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
}

.hero-main p {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 0.9rem;
}

.labels {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.label {
  font-size: 0.7rem;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ====== LAYOUT ====== */
.hero-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.content {
  max-width: var(--max-width);
  margin: 4px auto 24px;
  padding: 0 18px 4px;
  display: grid;
  grid-template-columns: minmax(0, 2.3fr) minmax(260px, 1.2fr);
  gap: 18px;
}

.content-section h2 {
  margin: 0 0 6px;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--accent-soft);
  padding-bottom: 4px;
}

.content-section h3 {
  margin: 8px 0 4px;
  font-size: 0.95rem;
}

/* ====== PROJECT LIST / TOC ====== */
.project-list {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
  font-size: 0.82rem;
}

.project-list li + li {
  margin-top: 4px;
}

.project-tagline {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

.toc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 4px 8px;
  margin-top: 4px;
  font-size: 0.78rem;
}

.toc-grid a {
  padding: 3px 6px;
  border-radius: 7px;
  background: var(--accent-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.toc-grid a:hover {
  background: var(--accent-strong);
  color: #f9fafb;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.25);
}

/* ====== KO-FI BUTTON ====== */
.kofi-card {
  text-align: center;
  margin: 1.5rem 0;
}

.kofi-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--accent-strong);
  color: #0f172a;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.25);
  transition:
    background 0.15s ease,
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.kofi-btn:hover {
  background: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(15, 23, 42, 0.3);
}

.kofi-icon {
  height: 20px;
  width: auto;
  display: inline-block;
}

:root[data-theme="dark"] .kofi-btn {
  background: #3AA8C1;
  color: #020817;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
}

/* ====== FOOTER ====== */
footer {
  max-width: var(--max-width);
  margin: 0 auto 18px;
  padding: 10px 18px 0;
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--border);
}

/* ====== BACK TO TOP ====== */
#back-to-top {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: none;
  background: var(--accent-strong);
  color: #f9fafb;
  font-size: 1.1rem;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.4);
  z-index: 50;
}

#back-to-top:hover {
  background: var(--bg-alt);
  color: var(--accent-strong);
}

/* ====== RESPONSIVE ====== */
.nav-links.open {
  display: flex;
}

.meta-line {
  font-size: 0.8rem;
  margin: 2px 0;
}

.start-reading-btn {
  margin-top: 16px;
  padding: 8px 18px;
  border-radius: 999px;
  border: none;
  background: var(--accent-strong);
  color: #f9fafb;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(15, 23, 42, 0.25);
  transition:
    background var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    color var(--transition-fast);
}

.start-reading-btn:hover {
  background: var(--accent);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 5px 12px rgba(15, 23, 42, 0.3);
}

@media (max-width: 768px) {
  .nav {
    padding: 9px 12px;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 54px;
    right: 10px;
    left: 10px;
    padding: 8px;
    flex-direction: column;
    align-items: flex-start;
    background: var(--bg-alt);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border);
  }

  .nav-links a {
    width: 100%;
    text-align: left;
    border-radius: 9px;
  }

  .menu-toggle {
    display: block;
  }

  .hero {
    grid-template-columns: 1fr;
    padding: 14px 12px 8px;
  }

  .content {
    grid-template-columns: 1fr;
    padding: 0 12px 10px;
  }
}

/* =========================
   TRANSLATION NOTES (POPUPS)
   ========================= */

.tl-note {
  position: relative;
  cursor: help;
  padding: 0 2px;
  border-bottom: 1px dashed var(--accent-strong);
  color: var(--accent-strong);
  font-weight: 500;
  transition: color 0.2s ease;
}

.tl-note:hover {
  color: var(--accent);
}

/* Bubble */
.tl-note::after {
  content: attr(data-note);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 8px);               /* default: above the word */
  max-width: 420px;                       /* nice and wide */
  min-width: 220px;
  padding: 8px 10px;
  font-size: 0.78rem;
  line-height: 1.5;
  background: var(--accent-strong);
  color: #ffffff;
  border-radius: 10px;
  text-align: left;
  white-space: normal;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  z-index: 99;
}

/* Arrow */
.tl-note::before {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 100%;
  border-width: 6px 6px 0 6px;
  border-style: solid;
  border-color: var(--accent-strong) transparent transparent transparent;
  opacity: 0;
  transition: opacity 0.18s ease;
  z-index: 98;
}

/* Show on hover */
.tl-note:hover::after,
.tl-note:hover::before {
  opacity: 1;
}

.tl-note:hover::after {
  transform: translateX(-50%) translateY(-2px);
}

/* Force bubble below when needed:
   <span class="tl-note" data-pos="below" ...> */
.tl-note[data-pos="below"]::after {
  top: calc(100% + 8px);
  bottom: auto;
}

.tl-note[data-pos="below"]::before {
  top: 100%;
  bottom: auto;
  border-width: 0 6px 6px 6px;
  border-color: transparent transparent var(--accent-strong) transparent;
}

/* Dark mode bubble */
:root[data-theme="dark"] .tl-note::after {
  background: #4b5563;
  color: #f9fafb;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.6);
}

:root[data-theme="dark"] .tl-note::before {
  border-color: #4b5563 transparent transparent transparent;
}

:root[data-theme="dark"] .tl-note[data-pos="below"]::before {
  border-color: transparent transparent #4b5563 transparent;
}

/* =========================
   COMMENTS STYLING
   ========================= */
.comments-section {
  margin: 32px auto 0;
  max-width: 960px;
  padding: 0 1.5rem 3rem;
}

.comments-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--muted);
}

.comments-card {
  padding: 14px 16px 18px;
  border-radius: 18px;
  background: #f9fafb;
  border: 1px solid rgba(148, 163, 253, 0.18);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Let Cusdis breathe — no tiny scrollable box */
#cusdis_thread {
  width: 100%;
}

/* Force the embedded iframe to be tall and full-width */
#cusdis_thread iframe {
  width: 100% !important;
  min-height: 700px !important;  /* make this bigger if you like */
  max-height: none !important;
  border: none !important;
}

/* Dark mode styling around the widget */
:root[data-theme="dark"] .comments-title {
  color: #e5e7eb;
}

:root[data-theme="dark"] .comments-card {
  background: #111827; /* dark, clean */
  border-color: rgba(129, 140, 248, 0.35);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.85);
  color: #e5e7eb;
}
