*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font: 16px/1.5 system-ui, sans-serif;
  color: #111827;
  background: #fff;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
p {
  margin: 0;
}

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 380px);
}

.login-card h1 {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.login-card .lead {
  margin: 8px 0 24px;
  color: #4b5563;
}

.login-card label {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
}

.login-card input,
.search-input,
.sort select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
}

.login-card button,
.notice-actions button {
  border: 0;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  padding: 10px 12px;
  cursor: pointer;
}

.login-card button[type="submit"] {
  width: 100%;
  margin-top: 8px;
}

.form-error,
.form-ok {
  min-height: 1.4em;
  margin: 0 0 8px;
  font-size: 14px;
}

.form-error {
  color: #b91c1c;
}

.form-ok {
  color: #047857;
}

.settings-form {
  max-width: 420px;
}

.settings-form h2 {
  font-size: 20px;
  font-weight: 500;
  margin: 0 0 8px;
}

.settings-form .lead {
  margin: 0 0 20px;
  color: #4b5563;
}

.settings-form label {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
}

.settings-form input {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
}

.settings-form button {
  border: 0;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  cursor: pointer;
}

.settings-form button:disabled {
  opacity: 0.6;
  cursor: default;
}

.notice-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 256px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 16px 12px;
  background: #fafafa;
  border-right: 1px solid #e5e7eb;
}

.nav {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav > button,
.list-button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 12px;
}

.nav > button:hover,
.list-button:hover,
.section-row button:hover {
  background: #f3f4f6;
}

.nav > button.active,
.list-button.active {
  background: #e5e7eb;
  font-weight: 600;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding: 4px 12px;
  color: #6b7280;
  font-size: 13px;
}

.section-row button {
  border: 0;
  background: transparent;
  color: #111827;
  border-radius: 6px;
  padding: 4px 8px;
}

.list-button {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.userbox {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
  padding: 12px 12px 4px;
  border-top: 1px solid #e5e7eb;
}

.user-name {
  font-weight: 600;
  word-break: break-word;
}

.userbox button {
  align-self: flex-start;
  border: 0;
  background: transparent;
  color: #4b5563;
  padding: 4px 0;
}

.backdrop {
  display: none;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 24px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.toolbar h1 {
  font-size: 24px;
  font-weight: 600;
}

.menu-button {
  display: none;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
}

.sort {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.sort label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.sort select {
  width: auto;
  margin-top: 0;
}

.sort button {
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
}

.search-input {
  flex: 1;
  min-width: 12rem;
  max-width: 33rem;
  margin-top: 0;
}

.rows {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.rows h2 {
  margin-bottom: 12px;
  font-size: 20px;
  font-weight: 500;
}

.scroller,
.grid {
  display: flex;
  gap: 16px;
}

.scroller {
  overflow-x: auto;
  padding-bottom: 8px;
}

.grid {
  flex-wrap: wrap;
}

.card {
  width: 190px;
  height: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  text-align: left;
}

.card:hover {
  border-color: #9ca3af;
}

.cover {
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  background: #e7e1d6;
  color: #1f2937;
  font-size: 18px;
  line-height: 1.4;
  text-align: center;
}

.progress {
  display: block;
  height: 4px;
  flex-shrink: 0;
  background: #e5e7eb;
}

.progress > span {
  display: block;
  height: 100%;
  background: #111827;
}

.card-title {
  padding: 8px 10px 0;
  overflow: hidden;
  color: #374151;
  font-size: 13px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.empty {
  color: #6b7280;
}

.reader {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #111;
  color: #fff;
  user-select: none;
  overscroll-behavior: none;
}

.reader-top,
.reader-bottom,
.settings {
  background: #1a1a1a;
}

.reader-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}

.bookmarks {
  flex: 1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  min-width: 0;
}

.bookmark,
.reader-actions button {
  border: 1px solid #4b5563;
  background: transparent;
  color: #fff;
  border-radius: 999px;
  padding: 4px 10px;
}

.reader-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.reader-actions button {
  border-radius: 8px;
  padding: 6px 10px;
}

.settings {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 4px 16px 12px;
}

.settings[hidden] {
  display: none;
}

.setting-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.setting-group > span {
  color: #9ca3af;
  font-size: 13px;
}

.settings label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

.spread {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
}

.spread img {
  max-width: calc(50% - 8px);
  max-height: 100%;
  object-fit: contain;
}

.spread.one img {
  max-width: 100%;
}

.hits {
  position: absolute;
  inset: 0;
  display: flex;
}

.hits button {
  flex: 1;
  border: 0;
  background: transparent;
}

.hits button:focus {
  outline: none;
}

.reader-bottom {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 14px;
}

.reader-bottom input[type="range"] {
  flex: 1;
}

.page-label {
  min-width: 5.5em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pdf-frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #fff;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

@media (max-width: 800px) {
  .menu-button {
    display: inline-flex;
  }

  .sidebar {
    display: none;
  }

  .shell.nav-open .sidebar {
    display: flex;
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    width: min(280px, 86vw);
    height: 100vh;
  }

  .shell.nav-open .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.4);
  }

  .sort {
    margin-left: 0;
    width: 100%;
  }
}
