:root {
  --line: #dee2e6;
  --light: #f8f9fa;
  --muted: #6c757d;
  --primary: #0d6efd;
  --header-height: 50px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { scroll-behavior: smooth; }
body { margin: 0; color: #212529; background: #fff; }
button, input { font: inherit; }
a { color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: 4px; left: 4px; z-index: 100; padding: 8px 12px;
  transform: translateY(-150%); color: #fff; background: #212529;
}
.skip-link:focus { transform: translateY(0); }

.site-header {
  position: fixed; inset: 0 0 auto; z-index: 50; min-height: var(--header-height);
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid #eee; background: var(--light);
}
.primary-nav { display: flex; align-items: center; justify-content: center; list-style: none; }
.primary-nav a {
  display: block; padding: 13px 10px; color: rgba(0,0,0,.55);
  font-size: 1rem; text-decoration: none;
}
.primary-nav a:hover { color: rgba(0,0,0,.7); }
.primary-nav a.active { color: rgba(0,0,0,.9); font-weight: 700; }
.menu-button { display: none; }

#app { min-height: 100%; padding-top: var(--header-height); }
.loading-view, .document-state {
  display: grid; place-content: center; min-height: 180px; color: var(--muted); text-align: center;
}
.loading-dot {
  width: 18px; height: 18px; margin: auto; border: 3px solid var(--line);
  border-top-color: #6c757d; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Original contact page */
.contact-main { margin-top: 20px; }
.character-wrap { display: flex; justify-content: center; }
.contact-email { text-align: center; }
.contact-email h2 { padding-top: 20px; margin: 0; font-size: 1.5rem; }
.character-face { position: relative; width: 247px; height: 250px; }
.character-face img { display: block; width: 247px; height: 250px; }
.mainline {
  position: absolute; top: 200px; left: calc(50% - 3px); z-index: 2;
  width: 40px; height: 3px; margin-left: -20px; background: #000;
  transform-origin: 20px 1.5px; will-change: transform;
}

/* Original lecture layout */
.lecture-layout {
  display: grid; grid-template-columns: 290px minmax(0, 1fr) 265px;
  height: calc(100vh - var(--header-height)); background: #fff;
}
.lecture-sidebar {
  height: 100%; overflow-y: auto; padding: 14px 10px 24px;
  background: var(--light);
}
.sidebar-top { margin-bottom: 12px; }
.sidebar-top h1 { display: none; }
.lang-switch { display: flex; width: 100%; margin-bottom: 1rem; }
.lang-switch button {
  flex: 1; padding: .25rem .5rem; border: 1px solid var(--primary);
  color: var(--primary); background: #fff; font-size: .875rem; cursor: pointer;
}
.lang-switch button:first-child { border-radius: .25rem 0 0 .25rem; }
.lang-switch button:last-child { margin-left: -1px; border-radius: 0 .25rem .25rem 0; }
.lang-switch button.active { z-index: 1; color: #fff; background: var(--primary); }
.subject { margin-bottom: 10px; }
.subject-toggle {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 6px; color: #212529;
  background: #e9ecef; font-size: .85rem; font-weight: 600; text-align: left; cursor: pointer;
}
.subject-toggle:hover { background: #dfe3e6; }
.subject-toggle::after { content: "▾"; font-size: .7rem; transition: transform .2s ease; }
.subject-toggle[aria-expanded="false"]::after { transform: rotate(-90deg); }
.document-list { margin-top: 6px; padding-left: 2px; }
.document-list[hidden] { display: none; }
.document-link {
  display: block; padding: 8px 10px; border-radius: 6px; color: var(--muted);
  font-size: .8rem; line-height: 1.35; text-decoration: none;
  white-space: normal; overflow-wrap: break-word;
}
.document-link:hover { background: #ededed; }
.document-link.active { color: var(--primary); background: #e9ecef; font-weight: 700; }
.chapter-number { display: none; }
.lecture-main { min-width: 0; height: 100%; overflow-y: auto; padding: 28px 36px 60px; }
.document-meta { display: none; }
.right-rail { height: 100%; padding: 24px 17px; }
.rail-card {
  width: 230px; margin-bottom: 18px; padding: 18px;
  border: 1px solid #e6e6e6; border-radius: 8px; background: #fff;
}
.rail-label {
  display: block; margin-bottom: 12px; color: #aaa; font-size: .65rem;
  letter-spacing: .12em; text-transform: uppercase;
}
.rail-card h2 { padding: 0; margin: 0 0 12px; font-size: 1rem; }
.rail-card p {
  margin: 0 0 16px; color: #555; font-size: .84rem;
  line-height: 1.65; word-break: keep-all;
}
.rail-card a {
  color: #444; font-size: .78rem; line-height: 1.5;
  text-decoration: none; overflow-wrap: anywhere;
}
.rail-card a:hover { color: #000; text-decoration: underline; }
.ad-slot {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 220px;
  border: 1px dashed #ddd; color: #aaa; background: #fafafa;
  font-size: .68rem; line-height: 1.7; letter-spacing: .12em;
  text-align: center; text-transform: uppercase;
}

/* Original Markdown presentation */
.md-content {
  max-width: 860px; padding-bottom: 60px; color: #2c2c2c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px; line-height: 1.75;
}
.md-content > :first-child { margin-top: 0; }
.md-content h1, .md-content h2, .md-content h3, .md-content h4,
.md-content h5, .md-content h6 {
  margin-top: 2em; margin-bottom: .6em; color: #1a1a2e;
  font-weight: 700; line-height: 1.3;
}
.md-content h1 { padding-bottom: .3em; border-bottom: 2px solid #e0e0e0; font-size: 2rem; }
.md-content h2 { padding: 0 0 .25em; border-bottom: 1px solid #ebebeb; font-size: 1.5rem; }
.md-content h3 { font-size: 1.2rem; }
.md-content h4 { font-size: 1rem; }
.md-content p { margin-bottom: 1.1em; }
.md-content a { color: #4a6fa5; text-decoration: none; }
.md-content a:hover { color: #2d4f8a; text-decoration: underline; }
.md-content code {
  padding: .15em .45em; border: 1px solid #ddd; border-radius: 4px;
  color: #c0392b; background: #f3f3f3;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; font-size: .88em;
}
.md-content pre {
  margin-bottom: 1.2em; padding: 1em 1.2em; overflow-x: auto;
  border: 1px solid #cfcfcf; border-radius: 6px; background: #f7f7f7; line-height: 1.5;
}
.md-content pre code { padding: 0; border: 0; color: inherit; background: none; font-size: .9em; }
.md-content blockquote {
  margin: 1.2em 0; padding: .5em 1.2em; border-left: 4px solid #4a6fa5;
  border-radius: 0 4px 4px 0; color: #555; background: #f8f9fc;
}
.md-content blockquote p { margin: 0; }
.md-content table { width: 100%; margin-bottom: 1.2em; border-collapse: collapse; font-size: .95em; }
.md-content th, .md-content td { padding: .5em .9em; border: 1px solid #ddd; text-align: left; }
.md-content th { color: #1a1a2e; background: #f0f3f8; font-weight: 600; }
.md-content tr:nth-child(even) td { background: #fafafa; }
.md-content ul, .md-content ol { margin-bottom: 1em; padding-left: 1.8em; }
.md-content li { margin-bottom: .3em; }
.md-content hr { margin: 2em 0; border: 0; border-top: 1px solid #e0e0e0; }
.md-content img { max-width: 100%; margin: 1em 0; border-radius: 4px; }

/* Original portfolio presentation */
.portfolio-shell {
  min-height: calc(100vh - var(--header-height));
  display: flex; justify-content: center; align-items: flex-start; padding-top: 50px;
}
.login-card { margin: 0; }
.password-row { display: flex; gap: 4px; align-items: flex-start; }
.password-row input {
  display: block; width: 220px; padding: .375rem .75rem;
  border: 1px solid #ced4da; border-radius: .375rem; color: #212529; background: #fff;
  font-size: 1rem; line-height: 1.5;
}
.password-row input:focus {
  border-color: #86b7fe; outline: 0; box-shadow: 0 0 0 .25rem rgba(13,110,253,.25);
}
.button {
  padding: .375rem .75rem; border: 1px solid #6c757d; border-radius: .375rem;
  color: #fff; background: #6c757d; line-height: 1.5; cursor: pointer;
}
.form-error { min-height: 1.25em; margin: 6px 0 0; color: #dc3545; font-size: .875rem; }
.portfolio-layout {
  display: grid; grid-template-columns: 200px minmax(0, 1fr);
  height: calc(100vh - var(--header-height));
}
.portfolio-sidebar { height: 100%; overflow-y: auto; padding-top: 5px; background: var(--light); }
.portfolio-sidebar h2 { display: none; }
.portfolio-sidebar nav { display: flex; flex-direction: column; }
.portfolio-sidebar a {
  display: block; padding: .5rem 1rem; color: var(--muted);
  font-size: 1rem; text-decoration: none;
}
.portfolio-sidebar a.active { color: #212529; font-weight: 700; }
.logout-button {
  margin-left: 1rem; padding: .25rem .5rem; border: 1px solid #6c757d;
  border-radius: .25rem; color: #fff; background: #6c757d;
  font-size: .875rem; cursor: pointer;
}
.portfolio-content { height: 100%; overflow-y: auto; padding-top: 20px; }
.portfolio-content > p { margin-left: 16px; }
.resume-header {
  display: flex; justify-content: center; width: calc(100% - 24px); margin: 0 12px;
  border: 1px solid #000;
}
.resume-header > img {
  width: auto; max-height: 220px; padding: 8px; border: 1px solid #000;
}
.resume-header > div { flex: 1; padding: 8px 28px; border: 1px solid #000; }
.resume-header h3 { margin: 1rem 0 .5rem; font-size: 1.75rem; }

@media (max-width: 992px) {
  .lecture-layout { display: block; height: auto; }
  .lecture-sidebar, .lecture-main, .right-rail { width: 100%; height: auto; }
  .right-rail { display: none; }
}

@media (max-width: 576px) {
  .site-header { justify-content: flex-end; padding: 5px 12px; }
  .menu-button {
    display: block; width: 42px; height: 38px; padding: 7px;
    border: 1px solid rgba(0,0,0,.15); border-radius: 4px; background: transparent;
  }
  .menu-button span:not(.sr-only) { display: block; width: 100%; height: 2px; margin: 5px 0; background: rgba(0,0,0,.55); }
  .primary-nav {
    position: absolute; inset: var(--header-height) 0 auto; display: none;
    flex-direction: column; align-items: stretch; padding: 8px 12px; background: var(--light);
  }
  .primary-nav.open { display: flex; }
  .primary-nav a { padding: 8px 0; }
  .portfolio-layout { display: block; height: auto; }
  .portfolio-sidebar, .portfolio-content { height: auto; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
