* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f6f4ef;
  color: #171717;
}

header {
  height: 54px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 9px 14px;
  border-bottom: 1px solid #d5d0c6;
  background: #fffaf0;
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  font-weight: 900;
  letter-spacing: .04em;
  cursor: pointer;
  user-select: none;
  font-size: 22px;
}

.subtitle {
  color: #70675c;
  font-size: 13px;
}

main {
  display: grid;
  grid-template-columns: 390px 1fr;
  height: calc(100vh - 54px);
}

aside {
  overflow: auto;
  border-right: 1px solid #d5d0c6;
  background: #fbf8f1;
}

.sidebar-section {
  padding: 12px;
  border-bottom: 1px solid #e3ddd2;
}

aside h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: #6b6257;
  margin: 4px 0 8px;
}

#search {
  width: 100%;
  font-size: 15px;
  padding: 10px 11px;
  border: 1px solid #c8c1b4;
  border-radius: 8px;
  background: white;
  outline: none;
}

#search:focus {
  border-color: #8d806f;
  box-shadow: 0 0 0 2px rgba(141, 128, 111, .12);
}

#search-status {
  color: #70675c;
  font-size: 12px;
  margin: 7px 2px;
  min-height: 16px;
}

#results {
  max-height: 45vh;
  overflow: auto;
  padding-right: 2px;
}

#viewer {
  overflow: auto;
  padding: 28px 42px 80px;
  background: #fffdf8;
}

.book, .result {
  padding: 8px 9px;
  margin: 3px 0;
  border-radius: 6px;
  cursor: pointer;
}

.book:hover, .result:hover {
  background: #eee7dc;
}

.book.active {
  background: #e3d8c8;
}

.book .abbr, .result .abbr {
  font-weight: 800;
}

.book .path {
  display: block;
  color: #7c7266;
  font-size: 12px;
  margin-top: 2px;
}

.book-letter {
  margin-top: 10px;
  padding: 4px 7px;
  border-radius: 5px;
  background: #efe7da;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  color: #6b6257;
}

.result {
  border-left: 3px solid transparent;
}

.result:hover {
  border-left-color: #b7a889;
}

.result .title {
  font-weight: 650;
}

.result .snippet {
  color: #5b5248;
  font-size: 13px;
  margin-top: 3px;
  line-height: 1.35;
}

.result .meta {
  color: #85796a;
  font-size: 12px;
  margin-top: 3px;
}

.markdown {
  max-width: 980px;
  line-height: 1.55;
  font-size: 17px;
}

.markdown h1, .markdown h2, .markdown h3 {
  line-height: 1.2;
}

.markdown a {
  color: #0658a8;
  text-decoration: none;
}

.markdown a:hover {
  text-decoration: underline;
}

.markdown pre {
  white-space: pre-wrap;
  background: #f3eee5;
  padding: 12px;
  border-radius: 8px;
  overflow: auto;
}

.markdown code {
  background: #f3eee5;
  padding: 1px 4px;
  border-radius: 4px;
}

.oops {
  background: #fff1b8;
  color: #4b3900;
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 650;
}

.anchor-target {
  outline: 2px solid #efc94c;
  background: #fff8d8;
}

.welcome {
  max-width: 740px;
  margin: 10vh auto;
  text-align: center;
}

.loading, .error {
  max-width: 900px;
  padding: 18px;
  border-radius: 8px;
  background: #f3eee5;
}

.error {
  background: #ffe2d8;
  color: #64230d;
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }

  aside {
    max-height: 48vh;
    border-right: 0;
    border-bottom: 1px solid #d5d0c6;
  }

  #viewer { padding: 20px; }
  #results { max-height: 24vh; }
}


.search-hit {
  background: #ffd96a;
  color: #2e2100;
  border-radius: 3px;
  padding: 0 2px;
}

.result mark,
.markdown mark {
  background: #ffd96a;
  color: #2e2100;
  border-radius: 3px;
  padding: 0 2px;
}


.knowledge-item {
  padding: 6px 8px;
  margin: 4px 0;
  border-radius: 6px;
  background: #f4eee4;
  font-size: 13px;
}

.knowledge-item summary {
  cursor: pointer;
  font-weight: 800;
}

.knowledge-item div {
  color: #51483f;
  margin-top: 5px;
  line-height: 1.35;
}

.knowledge-empty {
  color: #70675c;
  font-size: 13px;
}

.knowledge-term {
  border-bottom: 1px dotted #7d6b4d;
  background: #fff7dc;
  cursor: help;
  border-radius: 3px;
  padding: 0 2px;
}

.knowledge-term:focus {
  outline: 2px solid #d7b65d;
  outline-offset: 1px;
}


.knowledge-panel {
  padding: 0;
  overflow: hidden;
}

.knowledge-panel-title {
  cursor: pointer;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .02em;
  user-select: none;
}

.knowledge-panel-title::marker {
  color: #7d6b4d;
}

.knowledge-panel #knowledge {
  padding: 0 12px 12px;
}

.knowledge-panel:not([open]) #knowledge {
  display: none;
}

.knowledge-panel:not([open]) {
  background: #f4eee4;
}

.knowledge-panel[open] .knowledge-panel-title {
  border-bottom: 1px solid #ded5c8;
  margin-bottom: 6px;
}


.spinner {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.15em;
  margin-right: 0.45em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  animation: lawking-spin 0.787s linear infinite;
}

.is-loading {
  color: #5e5448;
}

.loading.is-loading {
  display: flex;
  align-items: center;
  gap: 0.25em;
}

#search-status.is-loading {
  display: flex;
  align-items: center;
}

.app-initializing #viewer {
  cursor: wait;
}

@keyframes lawking-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-right-color: currentColor;
  }
}
