* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background: #ffffff;
  color: #000000;
  font-family: "Monaco", "Menlo", "Ubuntu Mono", "Consolas", monospace;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

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

.boot-screen {
  min-height: 100vh;
  background: #ffffff;
}

.boot-brand {
  display: flex;
  align-items: center;
  min-height: 63px;
  padding: 8px 64px;
  border-bottom: 3px solid #000000;
  font-weight: 700;
}

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: min(280px, 100%);
  border: 3px solid #000000;
  padding: 20px;
  background: #ffffff;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-form label {
  font-weight: 700;
}

.login-form input,
.control-select {
  border: 2px solid #000000;
  background: #ffffff;
  color: #000000;
  font: inherit;
  padding: 8px 10px;
}

.login-form button,
.nav-btn,
.sidebar-btn {
  border: 2px solid #000000;
  background: #ffffff;
  color: #000000;
  font: inherit;
  cursor: pointer;
}

.login-form button {
  padding: 10px 12px;
  font-weight: 700;
}

.inline-error {
  margin-top: 12px;
  border: 2px solid #000000;
  padding: 10px 12px;
  background: #f4f4f4;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 12px;
  border-bottom: 3px solid #000000;
  flex-shrink: 0;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-status {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-status[data-tone="error"] {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 1 auto;
  flex-wrap: nowrap;
  justify-content: flex-end;
  min-width: 0;
}

.settings-menu {
  position: relative;
}

.settings-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 5;
  display: none;
  width: min(280px, calc(100vw - 24px));
  border: 2px solid #000000;
  background: #ffffff;
}

.settings-menu.open .settings-panel {
  display: block;
}

.settings-content {
  max-height: calc(100vh - 84px);
  overflow-y: auto;
}

.settings-section,
.settings-row,
.settings-action {
  width: 100%;
  border: none;
  border-bottom: 1px solid #000000;
  background: #ffffff;
  color: #000000;
  font: inherit;
}

.settings-section {
  padding: 10px 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
  padding: 8px 12px;
}

.settings-action {
  cursor: pointer;
  text-align: left;
}

.settings-action {
  display: block;
  box-sizing: border-box;
  min-height: 44px;
  padding: 9px 12px;
  border-bottom: 1px solid #000000;
  text-decoration: none;
}

.settings-content > :last-child {
  border-bottom: none;
}

.settings-action:hover {
  background: #f4f4f4;
}

.settings-action:disabled,
.settings-action[aria-disabled="true"] {
  cursor: not-allowed;
  color: #000000;
  background: #ffffff;
  text-decoration: line-through;
}

.settings-action[aria-disabled="true"] {
  pointer-events: none;
}

.settings-label {
  margin-bottom: 2px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.settings-value {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.control-select {
  min-width: 0;
}

.nav-btn {
  min-height: 44px;
  padding: 8px 12px;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
  line-height: 1;
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.sidebar-controls .icon-btn svg {
  width: 26px;
  height: 26px;
}

.nav-btn:disabled {
  opacity: 1;
  border-style: dashed;
  cursor: default;
}

.nav-btn.active {
  background: #000000;
  color: #ffffff;
}

.workspace {
  display: flex;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: 218px;
  border-right: 3px solid #000000;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #ffffff;
}

.sidebar.collapsed {
  width: 0;
  border-right: none;
  overflow: hidden;
}

.sidebar-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px;
  flex-shrink: 0;
  border-top: 2px solid #000000;
}

.sidebar-btn {
  min-height: 44px;
  padding: 8px 10px;
  width: 100%;
}

.sidebar-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.sidebar-controls .sidebar-btn {
  width: auto;
  min-width: 0;
}

.sidebar-btn[aria-busy="true"] {
  box-shadow: inset 0 0 0 2px currentColor;
}

.library-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.library-list::-webkit-scrollbar {
  width: 4px;
}

.library-item {
  width: 100%;
  text-align: left;
  padding: 12px;
  border: none;
  border-bottom: 1px solid #000000;
  background: #ffffff;
  color: #000000;
  cursor: pointer;
  font: inherit;
}

.library-item.active {
  background: #000000;
  color: #ffffff;
}

.library-item.pending {
  box-shadow: inset 0 0 0 2px currentColor;
}

.library-item-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.library-item-title {
  flex: 1;
  min-width: 0;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-item-status {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 20px;
  width: 20px;
  font-size: 13px;
  font-weight: 700;
}

.library-item-status[data-state="unread"]::before {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

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

.shared-view #toggleSidebar,
.shared-view #shareBtn,
.shared-view .account-section {
  display: none !important;
}

.shared-view .sidebar {
  display: none;
}

.reader-body {
  flex: 1;
  min-height: 0;
}

.reader-container {
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
  padding: 20px 24px 40px;
  font-size: 16px;
  scroll-behavior: auto;
  font-family: "Noto Sans", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
}

.reader-content.empty-state {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-style: italic;
}

.reader-content[data-render-mode="image"] {
  min-height: 100%;
}

.nav-btn:focus-visible,
.sidebar-btn:focus-visible,
.library-item:focus-visible,
.settings-row:focus-visible,
.settings-action:focus-visible,
.control-select:focus-visible {
  outline: 3px solid #000000;
  outline-offset: -4px;
}

.md-content h1,
.md-content h2,
.md-content h3 {
  border-bottom: 2px solid #000000;
  padding-bottom: 4px;
  margin: 18px 0 10px;
}

.md-content p,
.md-content ul,
.md-content ol,
.md-content blockquote,
.md-content table {
  margin-bottom: 14px;
}

@media (max-width: 720px) {
  .topbar {
    gap: 10px;
    padding: 6px 8px;
  }

  .topbar-controls {
    justify-content: flex-end;
    gap: 8px;
  }

  .brand-title {
    font-size: 15px;
  }

  .login-form input,
  .control-select,
  .nav-btn,
  .sidebar-btn {
    padding: 7px 9px;
  }

  .reader-container {
    padding: 16px 18px 36px;
  }

}

@media (max-width: 640px) {
  .workspace {
    position: static;
  }

  .sidebar {
    position: static;
    width: 100%;
    border-right: 0;
  }

  .sidebar.collapsed {
    width: 100%;
    border-right: 0;
    overflow: visible;
  }

  .reader {
    width: 100%;
  }

  .app-shell[data-view="library"] .reader {
    display: none;
  }

  .app-shell[data-view="reader"] .sidebar {
    display: none;
  }

  .app-shell[data-view="library"] #toggleSidebar {
    visibility: hidden;
  }

}

.md-content ul,
.md-content ol {
  padding-left: 24px;
}

.md-content blockquote {
  border-left: 4px solid #000000;
  padding-left: 12px;
}

.md-content table {
  width: 100%;
  border-collapse: collapse;
}

.md-content th,
.md-content td {
  border: 2px solid #000000;
  padding: 6px 8px;
  text-align: left;
}

.md-content code {
  border: 1px solid #000000;
  padding: 2px 4px;
  font-family: "Noto Sans Mono", "Monaco", "Menlo", "Ubuntu Mono", monospace;
}

.md-content .mermaid-block {
  margin: 16px 0;
  padding: 12px 14px;
  border: 2px solid #000000;
  background: #ffffff;
}

.md-content .mermaid-block::before,
.md-content .math-block::before {
  content: attr(data-language);
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.md-content .mermaid-diagram {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
}

.md-content .mermaid-source {
  margin: 0;
  white-space: pre;
  overflow-x: auto;
}

.md-content .mermaid-block svg {
  display: block;
  height: auto;
}

.md-content .mermaid-block--error {
  border-style: dashed;
}

.md-content .mermaid-error,
.md-content .math-error {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #000000;
  font-size: 0.92em;
  font-style: italic;
}

.md-content .math-inline {
  display: inline-flex;
  max-width: 100%;
  align-items: baseline;
  vertical-align: middle;
}

.md-content .math-inline .math-render {
  display: inline-flex;
  max-width: 100%;
  align-items: baseline;
}

.md-content .math-inline .katex {
  max-width: 100%;
}

.md-content .math-block {
  display: block;
  margin: 16px 0;
  padding: 12px 14px;
  border: 2px solid #000000;
  background: #ffffff;
  overflow-x: auto;
}

.md-content .math-block .math-render {
  display: block;
  min-width: fit-content;
}

.md-content .math-block .katex-display {
  margin: 0;
}

.md-content .math-source {
  display: none;
  border: 1px solid #000000;
  font-family: "Noto Sans Mono", "Monaco", "Menlo", "Ubuntu Mono", monospace;
}

.md-content .math-inline .math-error {
  display: inline;
  margin: 0 0 0 8px;
  padding: 0;
  border-top: none;
}

.md-content .math-inline .math-source {
  padding: 2px 4px;
}

.md-content .math-block .math-source {
  margin: 0;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-x: auto;
}

.md-content .math--error .math-source {
  display: inline-block;
}

.md-content .math-block.math--error .math-source {
  display: block;
}

.md-content .math-block.math--error {
  border-style: dashed;
}

.code-container {
  border: 2px solid #000000;
  padding: 10px 20px 16px;
  margin: 14px 0;
  font-family: "Noto Sans Mono", "Monaco", "Menlo", "Ubuntu Mono", monospace;
}

.code-container::before {
  content: attr(data-language);
  display: block;
  margin: 0 0 8px;
  border-bottom: 1px solid #000000;
  padding: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  text-align: right;
}

.code-line {
  display: flex;
  gap: 12px;
  counter-increment: line-number;
}

.code-container {
  counter-reset: line-number;
}

.code-line::before {
  content: counter(line-number);
  width: 4ch;
  flex-shrink: 0;
  text-align: right;
  border-right: 2px solid #000000;
  padding-right: 8px;
  font-weight: 700;
}

.line-code {
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1;
}

.md-content .code-container,
.md-content .mermaid-source,
.md-content .math-source {
  font-family: "Noto Sans Mono", "Monaco", "Menlo", "Ubuntu Mono", monospace;
}

.image-content {
  min-height: calc(100vh - 220px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-frame {
  width: min(100%, 1120px);
  margin: 0 auto;
  border: 2px solid #000000;
  background: #ffffff;
  padding: 18px;
}

.image-frame img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: calc(100vh - 300px);
  margin: 0 auto;
  object-fit: contain;
}

.image-caption {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #000000;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #ffffff;
}

::-webkit-scrollbar-thumb {
  background: #000000;
}

@media (max-width: 860px) {
  .sidebar {
    width: 218px;
  }

  .reader-container {
    padding: 16px 18px 36px;
    font-size: 15px;
  }

  .image-frame {
    padding: 14px;
  }

  .image-frame img {
    max-height: calc(100vh - 260px);
  }
}

@media (max-width: 640px) {
  .image-content {
    min-height: auto;
  }

  .sidebar,
  .sidebar.collapsed {
    width: 100%;
  }

  .app-shell[data-view="library"] #shareBtn {
    visibility: hidden;
  }

  .image-frame {
    padding: 12px;
  }

  .image-frame img {
    max-height: calc(100vh - 240px);
  }
}
