/* ============================================================
   Predicting the Next Words - GitHub Pages Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* --- Custom Properties (Light Theme) --- */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --bg-code: #f4f4f8;
  --bg-nav: rgba(255, 255, 255, 0.95);
  --bg-table-stripe: #f8f9fa;
  --text-primary: #1a1a2e;
  --text-secondary: #4a4a6a;
  --text-muted: #6c757d;
  --accent: #16213e;
  --accent-light: #1a2744;
  --accent-hover: #0f3460;
  --border: #dee2e6;
  --border-light: #e9ecef;
  --shadow: rgba(0, 0, 0, 0.08);
  --shadow-hover: rgba(0, 0, 0, 0.14);
  --table-rule: #2c2c54;
  --table-rule-light: #b0b0c0;
  --link: #16213e;
  --link-hover: #0f3460;
  --toggle-bg: #e0e0e0;
  --toggle-fg: #1a1a2e;

  /* Part colors */
  --part-i: #2e7d32;
  --part-ii: #1565c0;
  --part-iii: #e65100;
  --part-iv: #6a1b9a;

  /* Depth badges */
  --depth-deep: #c62828;
  --depth-moderate: #1565c0;
  --depth-survey: #2e7d32;

  /* Progress */
  --progress-complete: #2e7d32;
  --progress-active: #1565c0;
  --progress-pending: #9e9e9e;

  /* UI font */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a35;
  --bg-card: #161630;
  --bg-code: #1a1a35;
  --bg-nav: rgba(15, 15, 35, 0.95);
  --bg-table-stripe: #1a1a35;
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0c8;
  --text-muted: #8888a8;
  --accent: #4fc3f7;
  --accent-light: #29b6f6;
  --accent-hover: #81d4fa;
  --border: #2a2a50;
  --border-light: #22223a;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-hover: rgba(0, 0, 0, 0.45);
  --table-rule: #4fc3f7;
  --table-rule-light: #3a3a6a;
  --link: #4fc3f7;
  --link-hover: #81d4fa;
  --toggle-bg: #2a2a50;
  --toggle-fg: #e0e0e0;

  /* Part colors */
  --part-i: #66bb6a;
  --part-ii: #42a5f5;
  --part-iii: #ff9800;
  --part-iv: #ce93d8;

  /* Depth badges */
  --depth-deep: #ef5350;
  --depth-moderate: #42a5f5;
  --depth-survey: #66bb6a;

  /* Progress */
  --progress-complete: #66bb6a;
  --progress-active: #42a5f5;
  --progress-pending: #757575;

  /* UI font */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

body {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

h1 { font-size: 2.2rem; }
h2 { font-size: 1.7rem; border-bottom: 2px solid var(--border-light); padding-bottom: 0.4rem; }
h3 { font-size: 1.35rem; }
h4 { font-size: 1.15rem; }

p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

strong { color: var(--text-primary); }

/* --- Layout --- */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.content {
  padding-top: 5rem;
  padding-bottom: 3rem;
}

/* --- Navigation --- */
.nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg-nav);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.nav-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 3.5rem;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
}

.nav-brand:hover {
  color: var(--accent);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
}

.nav-link {
  display: inline-block;
  padding: 0.5rem 0.75rem;
  font-size: 0.92rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 3px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.nav-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.nav-link.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* Theme toggle button */
.theme-toggle {
  background: var(--toggle-bg);
  border: 1px solid var(--border);
  color: var(--toggle-fg);
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  margin-left: 0.75rem;
  flex-shrink: 0;
}

.theme-toggle:hover {
  transform: scale(1.1);
}

/* --- Hamburger (CSS-only checkbox hack) --- */
.nav-toggle {
  display: none;
}

.nav-toggle-label {
  display: none;
  cursor: pointer;
  width: 2.2rem;
  height: 2.2rem;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  order: 1;
}

.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 1.4rem;
  height: 2px;
  background-color: var(--text-primary);
  border-radius: 1px;
  transition: transform 0.3s ease, opacity 0.3s ease;
  position: relative;
}

.hamburger::before,
.hamburger::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
}

.hamburger::before { top: -6px; }
.hamburger::after  { top: 6px; }

/* Animate to X when open */
.nav-toggle:checked ~ .nav-toggle-label .hamburger {
  background-color: transparent;
}

.nav-toggle:checked ~ .nav-toggle-label .hamburger::before {
  top: 0;
  transform: rotate(45deg);
}

.nav-toggle:checked ~ .nav-toggle-label .hamburger::after {
  top: 0;
  transform: rotate(-45deg);
}

/* --- Cards / Content Sections --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 8px var(--shadow);
  transition: box-shadow 0.2s ease, background-color 0.3s ease, border-color 0.3s ease;
}

.card:hover {
  box-shadow: 0 4px 16px var(--shadow-hover);
}

.card h2:first-child,
.card h3:first-child {
  margin-top: 0;
}

/* --- Tables (Booktabs Style) --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}

thead {
  border-top: 2px solid var(--table-rule);
  border-bottom: 1px solid var(--table-rule);
}

thead th {
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-weight: 700;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background-color 0.15s ease;
}

tbody tr:nth-child(even) {
  background-color: var(--bg-table-stripe);
}

tbody tr:hover {
  background-color: var(--bg-secondary);
}

tbody td {
  padding: 0.55rem 0.75rem;
  color: var(--text-secondary);
}

tbody tr:last-child {
  border-bottom: 2px solid var(--table-rule);
}

/* Remove all vertical borders */
th, td {
  border-left: none;
  border-right: none;
}

/* --- Code --- */
code, kbd, samp {
  font-family: 'Source Code Pro', 'Fira Code', 'Consolas', monospace;
  font-size: 0.88em;
}

:not(pre) > code {
  background: var(--bg-code);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: var(--accent);
  border: 1px solid var(--border-light);
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 1.25rem;
  margin: 1.25rem 0;
  overflow-x: auto;
  line-height: 1.55;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: 0.88rem;
  color: var(--text-primary);
}

/* --- Mermaid Diagrams --- */
.mermaid-container {
  text-align: center;
  margin: 1.5rem 0;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.mermaid {
  display: inline-block;
  max-width: 100%;
}

.mermaid svg {
  max-width: 100%;
  height: auto;
}

/* --- Collapsible Sections (details/summary) --- */
details {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  margin: 1rem 0;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

details[open] {
  box-shadow: 0 2px 8px var(--shadow);
}

summary {
  padding: 0.85rem 1.25rem;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 1rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
  transition: color 0.2s ease;
  border-radius: 8px;
}

summary::-webkit-details-marker {
  display: none;
}

summary::before {
  content: '\25B6';
  font-size: 0.7em;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

details[open] > summary::before {
  transform: rotate(90deg);
}

summary:hover {
  color: var(--accent);
}

details > *:not(summary) {
  padding: 0 1.25rem;
}

details > *:last-child {
  padding-bottom: 1rem;
}

/* --- Blockquote --- */
blockquote {
  border-left: 4px solid var(--accent);
  margin: 1.25rem 0;
  padding: 0.75rem 1.25rem;
  background: var(--bg-secondary);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
  font-style: italic;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* --- Lists --- */
ul, ol {
  margin: 0.75rem 0 1rem 1.5rem;
  color: var(--text-secondary);
}

li {
  margin-bottom: 0.35rem;
}

li > ul, li > ol {
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

/* --- Images & Figures --- */
img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}

figure {
  margin: 1.5rem 0;
  text-align: center;
}

figcaption {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-style: italic;
}

/* --- Horizontal Rule --- */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* --- Footer --- */
.footer {
  padding: 2rem 0;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  transition: border-color 0.3s ease;
}

/* ============================================================
   Responsive: Tablet (<= 768px)
   ============================================================ */
@media (max-width: 768px) {
  .nav-toggle-label {
    display: flex;
  }

  .nav-inner {
    flex-wrap: wrap;
  }

  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    padding: 0.5rem 0 1rem;
    gap: 0;
    order: 2;
  }

  .nav-toggle:checked ~ .nav-links {
    display: flex;
  }

  .nav-link {
    width: 100%;
    padding: 0.65rem 0;
    border-bottom: none;
  }

  .nav-link.active {
    border-bottom: none;
    border-left: 3px solid var(--accent);
    padding-left: 0.75rem;
  }

  .theme-toggle {
    margin-left: auto;
    margin-right: 0.5rem;
  }

  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.4rem; }
  h3 { font-size: 1.2rem; }

  .card {
    padding: 1.25rem;
  }

  table {
    font-size: 0.88rem;
  }

  thead th,
  tbody td {
    padding: 0.4rem 0.5rem;
  }
}

/* ============================================================
   Responsive: Phone (<= 480px)
   ============================================================ */
@media (max-width: 480px) {
  body {
    font-size: 1rem;
  }

  .container {
    padding: 0 1rem;
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }

  .card {
    padding: 1rem;
    border-radius: 6px;
  }

  pre {
    padding: 0.85rem;
    font-size: 0.82rem;
    border-radius: 6px;
  }

  /* Stack table on very small screens */
  table, thead, tbody, th, td, tr {
    display: block;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
  }

  tbody tr {
    margin-bottom: 0.75rem;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 0.5rem;
  }

  tbody td {
    padding: 0.3rem 0.5rem;
    text-align: right;
    position: relative;
    padding-left: 45%;
  }

  tbody td::before {
    content: attr(data-label);
    position: absolute;
    left: 0.5rem;
    width: 40%;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.85rem;
  }
}

/* ============================================================
   Print
   ============================================================ */
@media print {
  .nav,
  .theme-toggle,
  .nav-toggle-label {
    display: none !important;
  }

  .content {
    padding-top: 0;
  }

  body {
    font-size: 11pt;
    color: #000;
    background: #fff;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  a[href]::after {
    content: ' (' attr(href) ')';
    font-size: 0.85em;
    color: #555;
  }

  .nav-link[href]::after,
  .nav-brand[href]::after {
    content: none;
  }

  pre {
    white-space: pre-wrap;
    border: 1px solid #ccc;
  }

  table {
    page-break-inside: avoid;
  }
}
