/* Shared look, copied from ~/code/textmaxxing */
:root {
  --bg: #f7f7f5;
  --fg: #2e2e2c;
  --muted: #868682;
  --line: #e2e1dd;
  --button: #e6e5e1;
  --button-hover: #dcdbd6;
  --check: #e8551f;
  --error: #b3261e;
  --danger: #ecd3d0;       /* muted red, behind red icons */
  --danger-hover: #e3c0bc;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 6l5 5 5-5' fill='none' stroke='%232e2e2c' stroke-width='1.5'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e1d;
    --fg: #d9d9d5;
    --muted: #8c8c87;
    --line: #353533;
    --button: #2c2c2a;
    --button-hover: #363634;
    --check: #f0663a;
    --error: #f2b8b5;
    --danger: #3b2725;
    --danger-hover: #4a2f2c;
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 6l5 5 5-5' fill='none' stroke='%23d9d9d5' stroke-width='1.5'/%3E%3C/svg%3E");
  }
}

* { box-sizing: border-box; border-radius: 0; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.6;
}
a { color: inherit; }

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 14px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
  line-height: 1.45;
}
header.end { justify-content: flex-end; }
header .group { display: flex; align-items: center; gap: 4px; }

button, input[type=file]::file-selector-button {
  font: inherit;
  color: var(--fg);
  background: var(--button);
  border: 0;
  padding: 0.2em 0.7em;
  cursor: pointer;
}
button:hover, input[type=file]::file-selector-button:hover { background: var(--button-hover); }
input[type=file] { font: inherit; color: var(--muted); }
input[type=file]::file-selector-button { margin-right: 0.5em; }
input[type=text], input[type=number], input[type=email], input[type=password] {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 0.1em 0.3em;
}

.toggle { display: inline-flex; align-items: center; cursor: pointer; }
.toggle input {
  appearance: none;
  -webkit-appearance: none;
  width: 1.05em;
  height: 1.05em;
  margin: 0 0.3em 0 0;
  border: 1px solid var(--fg);
  background: var(--bg);
  cursor: pointer;
}
.toggle input:checked {
  background: var(--check);
  box-shadow: inset 0 0 0 2px var(--bg);
}
.toggle input:focus-visible { outline: 1px solid var(--fg); outline-offset: 2px; }

.muted { color: var(--muted); }
.error { color: var(--error); }

header form { margin: 0; }

/* Library */
.library { max-width: 680px; margin: 0 auto; padding: 32px 16px 96px; }
.library h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 16px; }
.library ul { list-style: none; padding: 0; margin: 0; }
.library li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border-top: 1px solid var(--line);
  padding: 12px 0;
}
.library .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.library .head h1 { margin: 0; }
#sort {
  font: inherit;
  font-size: 0.8rem;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 0 2em 0 0.6em;
  /* Buttons are 1.6em of text plus 0.2em padding top and bottom */
  height: 2em;
  /* Own chevron, matching the 1em line icons, instead of the browser's arrow */
  appearance: none;
  -webkit-appearance: none;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 0.5em center;
  background-size: 1em;
}
/* The direction button joins the dropdown as one bordered control */
.library .sort { display: flex; }
.library #direction {
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 0;
}
.library #direction:hover { background: var(--button); }
.library .head .title { display: flex; align-items: center; gap: 12px; }
.library #status { margin-top: 8px; }
.library #status:empty { display: none; }
/* Upload progress: a row like the list's above it, with a spinner for a
   thumbnail and a thin orange bar under the name */
#upload-progress {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
#upload-progress[hidden] { display: none; }
.upload-name { font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.upload-pct { font-variant-numeric: tabular-nums; }
.upload-track { height: 3px; margin-top: 6px; background: var(--line); }
.upload-fill { width: 0; height: 100%; background: var(--check); transition: width 0.2s linear; }
.library .info { flex: 1; min-width: 0; }
.library .thumb { flex: none; display: block; width: 48px; height: 64px; background: var(--line); }
.library .thumb:has(.spinner) { display: flex; align-items: center; justify-content: center; }
/* Three bars pulsing in turn */
.spinner { display: flex; align-items: center; gap: 3px; height: 14px; }
.spinner i { width: 3px; height: 100%; background: var(--muted); animation: pulse 0.9s ease-in-out infinite; }
.spinner i:nth-child(2) { animation-delay: 0.15s; }
.spinner i:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 100% { transform: scaleY(0.4); } 50% { transform: scaleY(1); } }
.library .thumb img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top; }
.library li:first-child { border-top: 0; }
.library .rename { display: block; width: 100%; font-weight: 600; }

/* Book suggestions under the name while renaming */
.library .rename-wrap { position: relative; }
.library .suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 20;
  width: max(100%, 22rem);
  max-height: 60vh;
  overflow-y: auto;
  margin-top: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.library .suggestion { display: flex; align-items: center; gap: 8px; padding: 6px 8px; cursor: pointer; }
.library .suggestion.active { background: var(--button); }
.library .suggestion .cover { flex: none; width: 24px; height: 36px; object-fit: cover; background: var(--line); }
.library .suggestion .title { font-weight: 600; font-size: 0.9rem; line-height: 1.3; }
.library li a { text-decoration: none; font-weight: 600; word-break: break-word; }
.library .meta { font-size: 0.8rem; }
.library li button, .library .head button { flex: none; font-size: 0.8rem; }
.library .delete { color: var(--error); background: var(--danger); }
.library .delete:hover { background: var(--danger-hover); }
/* Shown on hovering the PDF; space is kept so nothing shifts */
.library .delete { opacity: 0; }
.library li:hover .delete, .library .delete:focus-visible { opacity: 1; }
@media (hover: none) { .library .delete { opacity: 1; } }
/* In grid view, in the card's bottom-right corner beside the details,
   which leave room for it (the button is 2em at 0.8rem = 1.6rem) */
.library ul.grid li { position: relative; }
.library ul.grid li .delete { position: absolute; right: 0; bottom: 0; }
.library ul.grid .info { padding-right: calc(1.6rem + 4px); }
/* Icon buttons: square, as tall as the text buttons (1.6em line plus 0.2em padding each side) */
.library button.icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2em;
  height: 2em;
  padding: 0;
}
.library button.icon svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.5; }

/* Grid view */
.library ul.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 24px 16px;
  padding-top: 12px;
}
.library ul.grid li { flex-direction: column; align-items: stretch; gap: 6px; border-top: 0; padding: 0; }
.library ul.grid .thumb { width: 100%; height: auto; aspect-ratio: 3 / 4; border: 3px solid var(--line); }
.library ul.grid li button { align-self: flex-start; }

/* Details: one line in list view, stacked in grid view */
.library .meta > span + span::before { content: " · "; }
.library .progress { display: none; }
.library ul.grid .info a {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  line-height: 1.3;
}
.library ul.grid .meta > span { display: block; }
.library ul.grid .meta > span::before { content: none; }
.library ul.grid .meta .author { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--fg); }
/* Progress drawn over the thumbnail's 3px bottom border */
.library ul.grid .progress { display: block; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; }
.library ul.grid .progress[hidden] { display: none; }
.library ul.grid .progress > div { height: 100%; background: var(--check); }

/* Thumbnail edit button: over the thumbnail's corner, shown on hover */
.library .thumb-wrap { position: relative; flex: none; }
.library ul.grid .thumb-wrap { width: 100%; }
.library .thumb-edit {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 3px;
  line-height: 0;
  opacity: 0;
}
/* Grid thumbnails have a 3px border; keep the same 4px gap inside it. The
   button matches the trash button there: 1.6rem square with a 0.8rem icon. */
.library ul.grid .thumb-edit {
  right: 7px;
  bottom: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  padding: 0;
}
.library ul.grid .thumb-edit svg { width: 0.8rem; height: 0.8rem; }
.library .thumb-wrap:hover .thumb-edit, .library .thumb-edit:focus-visible { opacity: 1; }
@media (hover: none) { .library .thumb-edit { opacity: 1; } }
.library .thumb-edit svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; }

/* Dialogs, like cropping a thumbnail; layout from attentionmaxxing-3 */
.dialog {
  margin: auto;
  padding: 0;
  width: min(30rem, 92vw, 92vh);
  aspect-ratio: 1;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
}
.dialog::backdrop { background: rgb(0 0 0 / 50%); }
.dialog-form { display: flex; flex-direction: column; height: 100%; }
/* Title bar, like a native window's */
.dialog-titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: var(--button);
  border-bottom: 1px solid var(--line);
}
.dialog-titlebar h2 { font-size: 0.8rem; font-weight: 600; margin: 0; }
.dialog-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.dialog-body p { margin: 0; font-size: 0.85rem; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; font-size: 0.8rem; }
.dialog-actions button { white-space: nowrap; }
.dialog-actions .spacer { flex: 1; }
/* The 3:4 frame takes the height left over in the square dialog, centred */
.cropper-frame { flex: 1; min-height: 0; display: flex; justify-content: center; }
.cropper-canvas {
  height: 100%;
  width: auto;
  aspect-ratio: 3 / 4;
  background: var(--line);
  cursor: grab;
  touch-action: none; /* dragging moves the picture, not the page */
}
.cropper-canvas:active { cursor: grabbing; }
.cropper-zoom { accent-color: var(--fg); }

/* Login and signup */
.form-page { max-width: 320px; margin: 15vh auto 0; padding: 0 16px; }
.form-page h1 { font-size: 1.4rem; margin: 0 0 16px; }
.form-page form { display: flex; flex-direction: column; gap: 12px; }
.form-page input { padding: 0.3em 0.5em; }
.form-page input::placeholder { color: var(--muted); opacity: 1; }
.form-page button { padding: 0.4em 1em; }
.form-page p { font-size: 0.85rem; }
