body#standaloneTheoryReader {
  height: 100vh;
  height: 100dvh;
  margin: 0;
}

#theoryReaderDialog {
  display: none;
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(96vw, 1060px);
  height: calc(100dvh - 28px);
  max-width: none;
  max-height: 960px;
  padding: 0;
  border: 0;
  border-radius: 16px;
  color: var(--ink, #111);
  background: var(--bg, #f0f4eb);
  overflow: hidden;
}
#theoryReaderDialog.theory-overlay-open {
  display: block;
  z-index: 2147483000;
  box-shadow: 0 0 0 100vmax #15231b80;
}


.theory-document, .theory-document * { box-sizing: border-box; }
.theory-document {
  --brand: #3f6b35;
  --soft: #e8f0dd;
  --line: #d9e1d2;
  --ink: #111111;
  display: flex;
  flex-direction: column;
  height: 100%;
  margin: 0;
  color: var(--ink);
  background: #f6f8f6;
  font: 15px/1.55 system-ui, "Noto Sans KR", sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
.theory-document [hidden] { display: none !important; }
.theory-document button, .theory-document input, .theory-document textarea, .theory-document select { font-family: inherit; }
.theory-document .plain-btn, .theory-document .link-btn {
  color: #111111;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.theory-document .plain-btn {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 8px;
  background: #fcfdf9;
}
.theory-document .plain-btn:hover:not(:disabled) { background: var(--soft); }
.theory-document .plain-btn:disabled { opacity: .55; cursor: default; }
.theory-document button.link-btn { border: 0; background: none; }
.theory-document :focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.theory-document-header {
  border-bottom: 1px solid var(--line);
  background: #fcfdf9;
}
.theory-document-bar {
  display: flex;
  align-items: center;
  gap: 5px 7px;
  padding: 5px 8px;
}
.theory-document-bar h2 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.theory-document-actions, .theory-zoom {
  display: flex;
  align-items: center;
  flex: none;
  gap: 4px;
}
.theory-document-actions .plain-btn { min-height: 36px; padding: 4px 6px; font-size: 12px; }
.theory-document-actions .plain-btn[aria-expanded="true"],
.theory-document-actions .plain-btn[aria-pressed="true"] { background: var(--soft); }
.theory-zoom .plain-btn { min-width: 30px; font-size: 16px; }
.theory-optional-tools {
  max-height: 38dvh;
  overflow: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--line);
}
.theory-document-viewport {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}
.theory-document .theory-sequence {
  --theory-paper-width: 794px;
  --theory-view-scale: 1;
  max-width: calc(var(--theory-paper-width) + 12px);
  margin-inline: auto;
  padding: 0 6px 20px;
}
.theory-document .theory-mark-toolbar {
  position: static;
  padding-inline: 8px;
  border-bottom: 0;
}
.theory-document .theory-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 6px 8px;
  scroll-margin-top: 8px;
}
.theory-document .theory-unit-title { margin: 0; padding: 4px 6px; }
.theory-document .theory-unit-body, .theory-document .theory-note[open] { grid-column: 1 / -1; min-width: 0; }
.theory-document .theory-note:not([open]) { margin: 0; padding: 0; background: transparent; }
.theory-document .theory-note > summary {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fcfdf9;
  font-size: 12px;
  list-style: none;
}
.theory-document .theory-note > summary::-webkit-details-marker { display: none; }
.theory-document .theory-note[open] > summary { margin: 6px 0; }
.theory-document-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-top: 1px solid var(--line);
  background: #fcfdf9;
}
.theory-document .theory-navigation {
  min-height: 40px;
  padding-inline: 12px;
  background: var(--soft);
}
.theory-position { min-width: 0; font-size: 14px; text-align: center; overflow-wrap: anywhere; }
.theory-navigation { flex: none; }
.theory-document .theory-page {
  width: calc(var(--theory-paper-width) * var(--theory-view-scale));
  margin-inline: auto;
  overflow: hidden;
  background: #fcfdf9;
  box-shadow: 0 0 0 1px var(--line);
}
.theory-document .theory-text {
  width: var(--theory-paper-width);
  padding: 24px 28px;
  transform: scale(var(--theory-view-scale));
  transform-origin: top left;
  font-size: 18px;
  line-height: 1.65;
  word-break: keep-all;
  background: #fcfdf9;
}
.theory-document .theory-text article h1 { font-size: 1.25em; margin: 1.2em 0 .45em; }
.theory-document .theory-text article h2 { font-size: 1.14em; margin: 1.2em 0 .45em; }
.theory-document .theory-text article [data-source-small] { font-size: .9em; }
.theory-document .theory-text :is(td, th) { padding: 5px 8px; }
.theory-document .theory-text > article > :first-child { margin-top: 0; }

@media (max-width: 700px) {
  #theoryReaderDialog {
  position: fixed;
  inset: 0;
  margin: auto;
    width: calc(100% - 8px);
    height: calc(100dvh - 8px);
    max-height: none;
    border-radius: 10px;
  }
  .theory-document-bar h2 { font-size: 14px; }
}
