:root {
  color-scheme: light dark;
  --bg: #f3f4f7;
  --paper: #ffffff;
  --text: #1a1f2a;
  --muted: #667085;
  --line: #d7dbe5;
  --accent: #0d4fa4;
  --ref-link: #07356f;
  --highlight: #fff2a3;
  --header-bg: #ebeff7;
  --shadow: 0 8px 30px rgba(17, 24, 39, 0.08);
}

:root[data-theme="dark"] {
  --bg: #11151c;
  --paper: #1a212c;
  --text: #e5e9f0;
  --muted: #a5b0c2;
  --line: #2b3647;
  --accent: #84b6ff;
  --ref-link: #7eaeea;
  --highlight: #294f62;
  --header-bg: #131923;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Source Sans Pro", "Noto Sans", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, color-mix(in srgb, var(--bg) 80%, #7fa2d8 20%) 100%);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--header-bg) 90%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1640px;
  margin: 0 auto;
  padding: 0.8rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.2rem;
  flex: 1 0 180px;
  transition: color 180ms ease;
}

.topbar h1.title-status-latest-bachelor {
  color: #2b8a68;
}

.topbar h1.title-status-latest-master {
  color: #ba6f00;
}

.topbar h1.title-status-other {
  color: #b23a3a;
}

:root[data-theme="dark"] .topbar h1.title-status-latest-bachelor {
  color: #65c9a4;
}

:root[data-theme="dark"] .topbar h1.title-status-latest-master {
  color: #ffb35b;
}

:root[data-theme="dark"] .topbar h1.title-status-other {
  color: #ff8f8f;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

button,
select {
  font: inherit;
  font-size: 0.92rem;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--text);
  border-radius: 8px;
  padding: 0.38rem 0.6rem;
}

button {
  cursor: pointer;
}

.theme-icon-btn {
  min-width: 2.2rem;
  padding: 0.35rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  text-align: center;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.layout {
  max-width: 1640px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 1rem;
}

.toc-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  align-self: start;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--line) 70%, var(--muted) 30%) transparent;
}

.toc-wrap::-webkit-scrollbar {
  width: 8px;
}

.toc-wrap::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--line) 72%, var(--muted) 28%);
  border-radius: 999px;
}

.toc-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.toc-wrap h2 {
  margin: 0 0 0.4rem 0;
  font-size: 1rem;
}

.toc-group {
  margin-bottom: 0.7rem;
}

.toc-entry {
  display: block;
  margin: 0.15rem 0;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0 0 0 0.7rem;
  text-indent: -0.7rem;
  line-height: 1.35;
  width: 100%;
  text-align: left;
}

.toc-entry.paragraph {
  margin-left: 0.7rem;
  margin-top: 1.2mm;
  padding-left: 0.9rem;
  text-indent: -0.9rem;
}

.paper-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.highlight-controls {
  margin-bottom: 0.7rem;
  position: sticky;
  top: 0;
  z-index: 2;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.highlight-controls label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.highlight-controls textarea {
  width: 100%;
  font: inherit;
  font-size: 0.92rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--text);
  padding: 0.45rem 0.6rem;
  resize: vertical;
  min-height: 2.4rem;
}

.highlight-controls textarea.invalid {
  border-color: #c63737;
  box-shadow: 0 0 0 1px color-mix(in srgb, #c63737 35%, transparent);
}

.paper {
  width: min(100%, 1048px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 1.3rem calc(1.1rem + 7mm) 1.3rem calc(1.1rem + 2mm);
}

.toast {
  position: fixed;
  top: 0.9rem;
  left: 50%;
  transform: translate(-50%, -120%);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--text);
  border-radius: 10px;
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
  z-index: 30;
  pointer-events: none;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.toast.error {
  border-color: #c63737;
  color: #c63737;
}

.section-heading {
  font-size: 1.45rem;
  margin: 2rem 0 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.35rem;
}

.document-title {
  font-size: 1.16rem;
  margin: 0.4rem 0 0.8rem;
  font-weight: 700;
}

.paragraph-heading {
  font-size: 1.16rem;
  margin: 1.35rem 0 0.35rem;
}

.row {
  display: grid;
  grid-template-columns: 45px minmax(0, 1fr);
  gap: 0.5rem;
  margin: 0.18rem 0;
}

.row-marker {
  color: var(--muted);
  text-align: right;
  padding-right: 0.2rem;
}

.row-content {
  line-height: 1.55;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
}

.list-inner {
  display: inline-grid;
  grid-template-columns: 2.2rem minmax(0, 1fr);
  column-gap: 0.45rem;
  margin-left: 1.05rem;
  align-items: start;
}

.list-marker {
  text-align: right;
  color: var(--muted);
}

.list-text {
  min-width: 0;
}

.clickable {
  color: var(--ref-link);
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: color-mix(in srgb, currentColor 50%, transparent);
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  cursor: pointer;
}

.sentence-no {
  font-size: 0.75em;
  vertical-align: super;
  margin-right: 0.1rem;
}

.highlight {
  background: var(--highlight);
  border-radius: 0.2rem;
  box-decoration-break: clone;
}

.error-box {
  border: 1px solid #c63737;
  color: #c63737;
  border-radius: 10px;
  padding: 0.8rem;
  white-space: pre-wrap;
  font-family: "JetBrains Mono", "Consolas", monospace;
}

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

  .toc-wrap {
    position: static;
    max-height: none;
  }
}

@media (max-width: 620px) {
  .row {
    grid-template-columns: 33px minmax(0, 1fr);
  }

  .paper {
    padding: 1rem 0.75rem;
  }
}
