html,
body {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: hidden;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}

*, *::before, *::after {
  user-select: none;
  -webkit-user-select: none;
}

input,
textarea,
select,
[contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
}

body {
  margin: 0;
  height: 100dvh;
}

.app-shell {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  height: 100dvh;
}

.main-area {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 4;
  flex: 0 0 70px;
  min-width: 0;
}

.view {
  width: 100%;
  height: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  margin-inline: auto;
}

#library-view,
#cards-view,
#search-view {
  display: flex;
  flex-direction: column;
}

#library-view.hidden,
#cards-view.hidden,
#search-view.hidden {
  display: none;
}

.document-list,
.cards-list,
.search-results {
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
  align-content: start;
}

.reader-view {
  height: auto;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.reader-content,
.reader-column,
.pdf-stage {
  min-height: 0;
  overflow: hidden;
}

.pdf-stage {
  align-items: center;
  overflow: auto;
}

.reader-aside {
  min-height: 0;
  overflow: hidden;
}

#boot-error {
  position: fixed;
  z-index: 20;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  width: min(560px, calc(100% - 24px));
  padding: 12px 16px;
  transform: translateX(-50%);
  border: 1px solid #dfb6a9;
  border-radius: 6px;
  background: #fff4ef;
  color: #833d2b;
  font-size: 13px;
  line-height: 1.5;
}

.debug-toast {
  position: fixed;
  z-index: 19;
  right: 10px;
  bottom: max(10px, env(safe-area-inset-bottom));
  max-width: min(420px, calc(100% - 20px));
  padding: 8px 10px;
  border: 1px solid #9ab9ad;
  border-radius: 5px;
  background: #ecf7f2;
  color: #245e50;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace;
  opacity: 0;
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
  cursor: copy;
  transform: translateY(6px);
  transition: opacity .15s, transform .15s;
}

.debug-toast.visible {
  opacity: .96;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .page-intro {
    margin-bottom: 16px;
  }

  .reader-content {
    display: flex;
    flex-direction: column;
  }

  .reader-column {
    flex: 1 1 auto;
  }

  .pdf-stage {
    flex: 1 1 auto;
    padding: 8px;
  }

  .reader-aside {
    height: min(30%, 190px);
    flex: 0 0 min(30%, 190px);
    padding: 10px 14px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 650px) {
  .app-shell {
    display: block;
    padding: 0;
  }

  .main-area {
    height: calc(100% - 64px - env(safe-area-inset-bottom));
  }

  .sidebar {
    height: calc(64px + env(safe-area-inset-bottom));
    padding: 5px 12px env(safe-area-inset-bottom);
  }

  .main-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .topbar {
    flex-basis: 57px;
    padding-inline: 15px;
  }

  .view {
    padding: 16px 17px;
  }

  .reader-toolbar {
    height: 53px;
    padding-inline: 10px;
    gap: 7px;
  }
}
