/* Mobile navigation and the Tools menu. Loaded after the app stylesheet. */

.nav-tools {
  position: relative;
}

.nav-tools-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 18;
  min-width: 232px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(28, 28, 28, 0.1);
}

.nav-tools-menu[hidden] {
  display: none;
}

.nav-tools-label {
  margin: 8px 12px 2px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--label);
}

.nav-tools-menu a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
}

.nav-tools-menu a:hover,
.nav-tools-menu a:focus-visible {
  background: var(--gray);
}

@media (min-width: 801px) {
  .header {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 8px;
  }
}

#app-tabbar,
#app-more,
#app-more-backdrop {
  display: none;
}

@media (max-width: 800px) {
  html.nav-ready .header {
    flex-wrap: nowrap;
    align-items: center;
  }

  html.nav-ready .brand {
    flex: 1;
    min-width: 0;
  }

  html.nav-ready .brand h1 {
    overflow: hidden;
    font-size: 24px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  html.nav-ready .header-actions {
    width: auto;
    justify-content: flex-end;
  }

  html.nav-ready .header-actions > .btn.ghost,
  html.nav-ready .header-actions > .nav-tools {
    display: none !important;
  }

  html.nav-ready .app {
    padding-bottom: calc(92px + env(safe-area-inset-bottom) + var(--keyboard-height));
  }

  html.nav-ready.nav-typing .app {
    padding-bottom: calc(28px + env(safe-area-inset-bottom) + var(--keyboard-height));
  }

  html.nav-ready #app-tabbar {
    display: flex;
  }

  html.nav-typing #app-tabbar {
    transform: translateY(120%);
  }

  html.nav-ready.more-open #app-more,
  html.nav-ready.more-open #app-more-backdrop {
    display: block;
  }
}

@media (max-width: 380px) {
  html.nav-ready .header {
    flex-wrap: wrap;
    row-gap: 10px;
  }

  html.nav-ready .header-actions {
    width: 100%;
  }

  html.nav-ready .brand h1 {
    overflow: visible;
    font-size: 26px;
    text-overflow: clip;
    white-space: normal;
  }
}

#app-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  align-items: stretch;
  justify-content: flex-start;
  gap: 2px;
  margin: 0;
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  transition: transform 0.18s ease;
  overflow-x: auto;
  scrollbar-width: none;
}

#app-tabbar::-webkit-scrollbar {
  display: none;
}

#app-tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1 0 auto;
  min-width: max-content;
  min-height: 52px;
  padding: 4px 8px 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.15;
}

#app-tabbar button span {
  display: block;
  white-space: nowrap;
}

#app-tabbar button svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#app-tabbar button[aria-current="page"] {
  color: var(--text);
  box-shadow: inset 0 2px 0 var(--text);
}

#app-tabbar button[aria-current="page"] svg {
  stroke-width: 2.1;
}

#app-more-backdrop {
  position: fixed;
  inset: 0;
  z-index: 16;
  background: rgba(28, 28, 28, 0.28);
}

#app-more {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 17;
  max-width: 520px;
  margin: 0 auto;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(28, 28, 28, 0.16);
}

#app-more button,
#app-more a {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
}

#app-more button.danger {
  color: var(--danger);
}

#app-more .nav-tools-label {
  margin-top: 4px;
}

#app-more a[aria-current="page"],
#app-more button:active {
  background: var(--gray);
}

html.essay-mode .app {
  min-height: 0 !important;
  padding-bottom: 8px !important;
}

html.essay-mode .app > :not(.header) {
  display: none !important;
}

html.essay-mode .header-actions > .btn:not(.ghost) {
  display: none !important;
}

#essay-panel {
  display: none;
  max-width: 880px;
  margin: 0 auto;
  padding: 4px 22px 48px;
}

html.essay-mode #essay-panel {
  display: block;
}

.essay-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 4px 0 6px;
}

.essay-lead {
  margin: 0;
  max-width: 40rem;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}

.essay-upload {
  position: relative;
  flex: none;
  padding: 8px 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.essay-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.essay-hint {
  margin: 0 0 16px;
  max-width: 40rem;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.essay-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.essay-card a {
  flex: 1;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.essay-remove {
  flex: none;
  margin-top: 4px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--danger);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.essay-list {
  display: grid;
  gap: 12px;
}

.essay-card {
  display: flex;
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: inherit;
}

.essay-card strong {
  display: block;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.essay-card span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.essay-card:hover,
.essay-card:focus-visible {
  border-color: var(--text);
}

@media (max-width: 800px) {
  html.essay-mode #essay-panel {
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }

  #app-tabbar button {
    font-size: 10px;
    letter-spacing: -0.03em;
  }

  #app-tabbar button span {
    display: block;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
  }

@media (max-width: 390px) {
  #app-tabbar button {
    font-size: 9px;
    letter-spacing: -0.04em;
    padding-left: 0;
    padding-right: 0;
  }
}

  #app-tabbar button svg {
    width: 20px;
    height: 20px;
  }
}

html.books-mode .app {
  min-height: 0 !important;
  padding-bottom: 8px !important;
}

html.books-mode .app > :not(.header) {
  display: none !important;
}

html.books-mode .header-actions > .btn:not(.ghost) {
  display: none !important;
}

#books-panel {
  display: none;
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 22px 64px;
}

html.books-mode #books-panel {
  display: block;
}

.books-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 6px;
}

.books-bar p,
.books-agent,
.books-hint,
.books-empty p,
.book-meta {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.books-add {
  flex: none;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.books-agent {
  margin-top: 28px;
}

.books-agent a,
.book-card h3 a {
  color: inherit;
}

#book-form[hidden],
.book-pop[hidden],
.books-msg[hidden] {
  display: none !important;
}

#book-form {
  display: grid;
  gap: 10px;
  margin: 12px 0 22px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

#book-form h2,
.book-card h3,
.books-empty h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 560;
  letter-spacing: -0.03em;
}

#book-form label {
  display: grid;
  gap: 6px;
  color: var(--label);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#book-form input[name="title"],
#book-form input[name="author"],
#book-form textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  font-size: 16px;
}

#book-form textarea {
  min-height: 76px;
  resize: vertical;
}

.book-pick input,
.book-more input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.book-pick {
  position: relative;
}

.book-pick .btn,
.book-pick em,
.book-more span {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 600;
  font-style: normal;
  font-size: 15px;
}

.book-pick em {
  color: var(--muted);
  font-weight: 500;
}

#book-form .btn {
  justify-self: start;
}

.books-msg {
  margin: 8px 0 0;
  color: var(--text);
  font-size: 14px;
}

.books-msg.is-error {
  color: var(--danger);
}

.books-empty {
  padding: 28px 0;
}

.books-empty h2 {
  font-size: 20px;
}

.books-empty p {
  margin-top: 6px;
}

#books-list {
  display: flex;
  flex-direction: column;
}

.book-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  align-items: start;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.book-card h3 a {
  text-decoration: none;
}

.book-card h3 a:hover,
.book-card h3 a:focus-visible {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.book-meta {
  margin-top: 4px;
}

.book-sums {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 8px 0 0;
}

.book-sums a {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.book-menu {
  position: relative;
}

.book-more-btn {
  width: 44px;
  height: 44px;
  margin-top: -6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  letter-spacing: 0;
  cursor: pointer;
}

.book-more-btn:hover,
.book-more-btn[aria-expanded="true"] {
  background: var(--gray);
}

.book-pop {
  position: absolute;
  top: calc(100% - 4px);
  right: 0;
  z-index: 30;
  min-width: 260px;
  max-width: min(360px, 80vw);
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 16px 40px rgba(28, 28, 28, 0.1);
}

.book-pop.is-up {
  top: auto;
  bottom: calc(100% - 4px);
}

.book-pop input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.book-link-form {
  display: grid;
  gap: 6px;
  padding: 8px 12px 10px;
}

.book-link-form input {
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.book-link-row {
  display: flex;
  align-items: center;
}

.book-link-row a {
  flex: 1;
  min-width: 0;
}

.book-link-row button {
  flex: none;
  width: auto;
  min-height: 40px;
  padding-left: 8px;
  color: var(--muted);
  font-size: 13px;
}

.book-pop a,
.book-pop button,
.book-pop label {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.book-pop a:hover,
.book-pop button:hover,
.book-pop label:hover,
.book-pop a:focus-visible,
.book-pop button:focus-visible {
  background: var(--gray);
}

.book-pop .danger {
  color: var(--danger);
}

.book-pop .book-link-row button {
  flex: none;
  width: auto;
  padding-right: 12px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 800px) {
  html.books-mode #books-panel {
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
  }
}
