*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f4f0e9;
  --bg-strong: #ece6da;
  --panel: #ffffff;
  --ink: #2d241a;
  --muted: #6c6257;
  --accent: #c47a1f;
  --border: rgba(0, 0, 0, 0.08);
  --col-nav: 280px;
  --col-paper: 760px;
  --col-proof: 400px;
  --divider: 6px;
  --proof-top: 75%;
  --proof-bottom: 25%;
  --divider-row: 6px;
}

body {
  margin: 0;
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  color: var(--ink);
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: var(--accent);
  color: #fffaf2;
  letter-spacing: 0.02em;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-link {
  color: inherit;
  text-decoration: none;
}
.brand-link:hover {
  text-decoration: none;
}

.brand-subtitle {
  font-size: 13px;
  color: rgba(231, 237, 246, 0.85);
}

.status-pill {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.04);
  color: var(--ink);
  font-size: 13px;
  border: 1px solid var(--border);
}

.layout {
  display: grid;
  grid-template-columns:
    minmax(220px, 20%)
    var(--divider)
    minmax(500px, 60%)
    var(--divider)
    minmax(320px, 25%);
  gap: 0;
  column-gap: 8px;
  padding: 18px 24px 28px;
  align-items: stretch;
}

.nav-panel,
.paper-panel,
.proof-panel {
  border-radius: 18px;
  height: calc(100vh - 120px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.divider {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

.divider-vertical {
  width: var(--divider);
  cursor: default;
  pointer-events: none;
  margin: 0 8px;
}

.divider-horizontal {
  height: var(--divider-row);
  cursor: row-resize;
}

.nav-panel {
  background: #f9f6ef;
  border: 1px solid var(--border);
  color: var(--ink);
}

.paper-panel {
  background: var(--panel);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border);
  overflow-y: auto;
}

.proof-panel {
  background: #f9f6ef;
  border: 1px solid var(--border);
  color: var(--ink);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 12px;
  border-bottom: 1px solid rgba(12, 18, 30, 0.08);
}

.panel-title {
  font-weight: 700;
  font-size: 18px;
}

.panel-title.clickable {
  cursor: pointer;
}

.panel-subtitle {
  font-size: 13px;
  color: var(--muted);
}

.panel-links {
  display: flex;
  gap: 8px;
}

.paper-content {
  padding: 0 24px 28px;
  overflow-y: visible;
  flex: 1 1 auto;
  width: 100%;
  max-width: 80%;
  margin: 0 auto;
}

.paper-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px 24px 8px;
  border-bottom: 1px solid var(--border);
}

.link-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(196, 122, 31, 0.1);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  border: 1px solid rgba(196, 122, 31, 0.3);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, color 120ms ease;
}

.link-pill .icon {
  font-size: 14px;
  display: inline-flex;
}

.link-pill:hover {
  background: rgba(196, 122, 31, 0.16);
  box-shadow: none;
  transform: translateY(-1px);
  color: #1a140f;
}

.link-pill .icon svg {
  width: 16px;
  height: 16px;
}

.paper-content h1,
.paper-content h2,
.paper-content h3,
.paper-content h4 {
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  color: #2d241a;
  margin-bottom: 8px;
}

.paper-content h2 {
  margin-top: 28px;
}

.paper-content h3 {
  margin-top: 20px;
}

.paper-content p {
  line-height: 1.64;
  color: #3a3127;
  margin: 12px 0;
}

.paper-content ul {
  padding-left: 20px;
  margin: 10px 0 18px;
  color: #3a3127;
  line-height: 1.6;
}

.paper-content a {
  color: var(--accent);
}

.paper-content blockquote {
  margin: 14px 0;
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  background: rgba(216, 140, 43, 0.12);
  color: #f3ede0;
}

.paper-content code {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 13px;
  color: #2d241a;
}

.paper-content pre code {
  display: block;
  background: #f1efe7;
  color: #2d241a;
  padding: 14px;
  border-radius: 12px;
  overflow-x: auto;
}

.muted {
  color: var(--muted);
}

.proof-placeholder {
  padding: 18px 22px;
  line-height: 1.6;
  color: #2d241a;
}

.proof-placeholder p {
  margin: 10px 0;
  color: #2d241a;
}

.proof-split {
  display: grid;
  grid-template-rows: var(--proof-top) var(--divider-row) var(--proof-bottom);
  height: 100%;
  min-height: 0;
}

.proof-section {
  padding: 12px 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.proof-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.compile-btn {
  background: var(--accent);
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: #1b1208;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.compile-btn:hover {
  transform: translateY(-1px);
  box-shadow: none;
}

.subheading {
  font-weight: 700;
  color: #2d241a;
  margin-bottom: 6px;
}

.reference-detail {
  padding: 8px 0 8px;
  color: #e7ecf7;
  line-height: 1.6;
  overflow: auto;
  max-height: none;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.reference-detail .ref-label {
  color: #93a2b7;
}

.reference-detail .ref-title {
  color: #fff;
  display: block;
  margin: 6px 0 4px;
  font-weight: 700;
}

.reference-detail .ref-authors {
  color: #cfd8e8;
  margin: 6px 0;
}

.reference-detail .ref-venue {
  color: #a7b4c8;
}

.reference-detail a {
  color: #f6f1e8;
}

.reference-detail pre {
  background: #0f1828;
  border-radius: 12px;
  padding: 12px 14px;
  color: #e5edff;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.lean-editor {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  background: #0f1218;
  color: #eae9e6;
  border: 1px solid rgba(216, 140, 43, 0.28);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: 'JetBrains Mono', 'SFMono-Regular', ui-monospace, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 13px;
  resize: none;
}

.lean-output {
  padding: 12px 14px;
  background: #f4f0e9;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  color: #2d241a;
  min-height: 80px;
  overflow-y: auto;
  font-family: 'DM Sans', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
}

.lean-output.pending {
  color: #6c6257;
}

.lean-output.success {
  color: #0f5132;
}

.lean-output.error {
  color: #8c1c1c;
}

.cite-popover {
  position: absolute;
  background: #1b1d23;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  color: #e7ecf7;
  padding: 12px 14px;
  border-radius: 12px;
  max-width: 360px;
  min-width: 240px;
  z-index: 9999;
  line-height: 1.5;
}

.cite-popover .cite-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  color: #93a2b7;
  font-size: 16px;
  cursor: pointer;
}

.cite-popover .cite-close:hover {
  color: #dbe4f3;
}

.cite-popover a {
  color: #fff;
}

.cross-ref {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.cross-ref:hover {
  text-decoration: underline;
}

.figure-block {
  margin: 18px 0;
  text-align: center;
}

.figure-block img {
  max-width: 100%;
  border-radius: 0;
  box-shadow: none;
}

.figure-block figcaption {
  margin-top: 8px;
  color: #c9c6be;
  font-size: 14px;
}

.inline-graphic {
  max-width: 100%;
}

.equation-block {
  text-align: center;
  margin: 18px auto;
  position: relative;
  scroll-margin-top: 80px;
}

.toc-block {
  border: 1px solid rgba(196, 122, 31, 0.35);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 12px 0 18px;
  background: #f9f6ef;
}

.toc-title {
  font-weight: 700;
  margin-bottom: 8px;
  color: #f6f1e8;
}

.toc-block ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.toc-block li {
  margin: 6px 0;
}

.toc-block li.toc-sub {
  padding-left: 12px;
}

.toc-block a {
  color: var(--accent);
  text-decoration: none;
}

.video-embed {
  margin: 18px 0;
}

.video-frame {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
}

.video-frame iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 12px;
}

.toc-block a:hover {
  text-decoration: underline;
}

.eq-number {
  margin-left: 10px;
  font-weight: 600;
  color: #d88c2b;
}

.lemma-block,
.theorem-block,
.corollary-block,
.proof-block {
  border: 1px solid rgba(196, 122, 31, 0.35);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 18px 0;
  background: #f9f4eb;
  color: #2d241a;
}

.theorem-block,
.corollary-block {
  background: #f7efe1;
}

.proof-block {
  background: #f4efe7;
  border-color: rgba(0, 0, 0, 0.08);
}

.env-heading {
  font-weight: 700;
  margin-bottom: 6px;
}

.env-body {
  line-height: 1.6;
}

.algorithm-block {
  margin: 18px 0;
  padding: 12px 14px;
  border: 1px solid rgba(196, 122, 31, 0.28);
  border-radius: 12px;
  background: #f9f6ef;
}

.algorithm-block .algo-caption {
  font-weight: 700;
  margin-bottom: 8px;
}

.algorithm-block ol {
  padding-left: 20px;
  margin: 0;
  color: #2d241a;
  line-height: 1.6;
}

.algorithm-block .algo-indent {
  display: block;
  padding-left: 12px;
}

.error {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fca5a5;
  padding: 12px 14px;
  border-radius: 10px;
}

.references {
  margin-top: 32px;
  padding-top: 12px;
  border-top: 1px solid rgba(196, 122, 31, 0.25);
}

.references ol {
  list-style: none;
  padding-left: 0;
  margin: 12px 0 0;
  color: #2d241a;
  line-height: 1.6;
}

.references a {
  color: var(--accent);
}

.ref-title {
  font-weight: 600;
}

.ref-label {
  display: inline-block;
  min-width: 36px;
  font-weight: 600;
  color: #d88c2b;
}

.paper-list {
  padding: 12px 12px 18px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.paper-group {
  margin-bottom: 10px;
}

.paper-entry {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: #f9f6ef;
  border: 1px solid rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  color: #2d241a;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.paper-entry:hover {
  background: #f2ecdf;
  border-color: rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.paper-entry.active {
  background: var(--accent);
  border-color: transparent;
  color: #fffaf2;
  box-shadow: none;
}

.paper-list .bullet {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: inline-block;
  background: transparent;
  flex-shrink: 0;
}

.paper-entry.active .bullet {
  background: #0b1623;
  border-color: #0b1623;
}

.paper-accordion {
  margin-top: -4px;
  padding: 10px 12px;
  border: 1px solid rgba(196, 122, 31, 0.25);
  border-radius: 12px;
  background: #f9f6ef;
}

.paper-accordion .accordion-title {
  font-weight: 700;
  font-size: 13px;
  color: #d8deea;
  margin-bottom: 6px;
}

.paper-accordion ul {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.paper-accordion li {
  margin: 6px 0;
}

.paper-accordion li.toc-sub {
  padding-left: 12px;
}

.paper-accordion a {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
}

.paper-accordion a:hover {
  text-decoration: underline;
}

.entry-icons {
  display: inline-flex;
  gap: 8px;
  justify-content: flex-end;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #f2ecdf;
  border: 1px solid rgba(0, 0, 0, 0.12);
  color: #2d241a;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.icon-link:hover {
  background: #e8dfcb;
  border-color: rgba(196, 122, 31, 0.35);
  transform: translateY(-1px);
}

.icon-link svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .nav-panel,
  .paper-panel,
  .proof-panel {
    height: auto;
    min-height: 320px;
  }
}
