@font-face {
  font-family: "Questrial";
  src: url("/assets/questrial-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --page: #050505;
  --panel: #0b0b0a;
  --panel-2: #11110f;
  --panel-3: #171713;
  --text: #f7f7f2;
  --body: #c8c5bb;
  --soft: #9a9a9a;
  --muted: #73736d;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --gold: #d8c35a;
  --green: #80cb23;
  --blue: #40a0e9;
  --paper: #f6f1e8;
  --paper-ink: #141412;
  font-family: Inter, Roboto, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--page);
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page);
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button {
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(128, 203, 35, 0.08), transparent 30%),
    linear-gradient(315deg, rgba(216, 195, 90, 0.08), transparent 34%),
    var(--page);
}

.login-panel {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(11, 11, 10, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
  padding: 32px;
}

.login-brand {
  margin-bottom: 26px;
}

.login-brand span,
.brand-block span,
.tree-meta,
.reader-head {
  color: var(--gold);
  font-size: 11px;
  line-height: 1.25;
  text-transform: uppercase;
  font-weight: 800;
}

.login-brand h1,
.topbar h1 {
  margin: 4px 0 0;
  color: var(--text);
  font-family: "Questrial", Inter, sans-serif;
  font-size: 28px;
  letter-spacing: 0;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  color: var(--body);
  font-size: 13px;
  font-weight: 800;
}

.login-form input,
.sidebar-tools input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 10px 12px;
}

.login-form input::placeholder,
.sidebar-tools input::placeholder {
  color: var(--muted);
}

.login-form button,
.secondary-button,
.icon-text-button,
.sidebar-tools button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
}

.login-form button {
  color: #050505;
  border-color: var(--green);
  background: var(--green);
  font-weight: 900;
  margin-top: 6px;
}

.secondary-button:hover,
.icon-text-button:hover,
.sidebar-tools button:hover {
  border-color: var(--gold);
}

.login-form button:disabled,
.secondary-button:disabled,
.icon-text-button:disabled,
.sidebar-tools button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

#loginMessage {
  min-height: 20px;
  color: #ffb4a8;
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  background:
    linear-gradient(135deg, rgba(128, 203, 35, 0.07), transparent 26%),
    linear-gradient(315deg, rgba(216, 195, 90, 0.08), transparent 30%),
    var(--page);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #050505;
  color: var(--text);
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  overflow: auto;
}

.brand-block {
  display: grid;
  gap: 4px;
  margin-bottom: 20px;
}

.brand-block strong {
  font-family: "Questrial", Inter, sans-serif;
  font-size: 20px;
}

.sidebar-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 12px;
}

.tree-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--soft);
  margin-bottom: 12px;
}

.file-tree {
  display: block;
  border-left: 1px solid var(--line);
  padding-left: 2px;
}

.tree-folder {
  margin: 1px 0;
  padding-left: calc(var(--level) * 10px);
}

.tree-folder summary {
  min-height: 28px;
  list-style: none;
  user-select: none;
  color: var(--soft);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 6px;
  border-radius: 6px;
  border: 1px solid transparent;
}

.tree-folder summary::-webkit-details-marker {
  display: none;
}

.tree-folder summary::before {
  content: ">";
  display: inline-block;
  width: 12px;
  margin-right: 5px;
  color: var(--gold);
  transition: transform 0.16s ease;
}

.tree-folder[open] summary::before {
  transform: rotate(90deg);
}

.tree-folder summary:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.07);
}

.tree-branch {
  display: grid;
  gap: 1px;
}

.file-tree button {
  position: relative;
  display: grid;
  gap: 1px;
  width: 100%;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--body);
  text-align: left;
  padding: 5px 7px 5px calc(12px + var(--level) * 12px);
  line-height: 1.22;
}

.file-tree button::before {
  content: "";
  position: absolute;
  left: calc(3px + var(--level) * 12px);
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 999px;
  background: transparent;
}

.file-tree button:hover {
  color: #ffffff;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.07);
}

.file-tree button.active {
  color: #ffffff;
  border-color: rgba(128, 203, 35, 0.32);
  background: rgba(128, 203, 35, 0.13);
}

.file-tree button.active::before {
  background: var(--green);
}

.file-tree span {
  display: block;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-tree small {
  display: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-tree button:hover small,
.file-tree button.active small {
  display: block;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 82px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 0 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 5, 5, 0.86);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  min-width: 0;
}

.topbar-title span {
  display: block;
  color: var(--soft);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar h1 {
  font-size: 24px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.session-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 800;
  color: #ffffff;
  background: rgba(128, 203, 35, 0.13);
  border: 1px solid rgba(128, 203, 35, 0.32);
}

.reader {
  min-width: 0;
  flex: 1;
  overflow: auto;
  padding: 26px 36px 58px;
}

.reader-head {
  max-width: 980px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--soft);
  margin-bottom: 14px;
}

.markdown-body,
.raw-markdown {
  max-width: 980px;
  min-height: calc(100vh - 190px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--paper-ink);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.26);
}

.markdown-body {
  padding: 30px 34px;
  line-height: 1.68;
  overflow-wrap: anywhere;
}

.raw-markdown {
  margin: 0;
  padding: 24px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  line-height: 1.55;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  line-height: 1.25;
  letter-spacing: 0;
}

.markdown-body h1 {
  border-bottom: 1px solid rgba(20, 20, 18, 0.14);
  padding-bottom: 12px;
}

.markdown-body a {
  color: #1f6f1f;
  font-weight: 800;
  text-decoration-color: rgba(31, 111, 31, 0.32);
}

.markdown-body code {
  background: rgba(20, 20, 18, 0.08);
  border-radius: 5px;
  padding: 2px 5px;
}

.markdown-body pre {
  overflow: auto;
  background: #141412;
  color: #f7f7f2;
  border-radius: 8px;
  padding: 16px;
}

.markdown-body blockquote {
  margin-left: 0;
  border-left: 4px solid var(--gold);
  padding-left: 16px;
  color: #4b473c;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  display: block;
  overflow-x: auto;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid rgba(20, 20, 18, 0.16);
  padding: 8px 10px;
}

.missing-wikilink {
  color: #9b271f;
  font-weight: 800;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 290px minmax(0, 1fr);
  }
  .topbar {
    padding: 0 18px;
  }
  .reader {
    padding: 22px;
  }
  .markdown-body {
    padding: 24px;
  }
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }
  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(330px, 88vw);
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    box-shadow: 24px 0 80px rgba(0, 0, 0, 0.38);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    min-height: 78px;
  }
  .topbar-actions {
    grid-column: 1 / -1;
    justify-content: space-between;
    padding-bottom: 12px;
  }
  .reader {
    padding: 16px;
  }
  .markdown-body,
  .raw-markdown {
    min-height: calc(100vh - 210px);
  }
}
