/* The white card is the point of the page: a cover and its title sit in one white rectangle, so it is always
   clear which goes with which. Colours are fixed, not theme-following, so that rectangle stays white in dark mode. */
:root {
  color-scheme: only light;
  --page: #16213e;
  --yellow: #ffd60a;
  --ink: #111827;
}
* { box-sizing: border-box; }
/* Without this, [hidden] loses to any explicit display rule. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--page);
  background-image: radial-gradient(rgba(255, 255, 255, .07) 1.5px, transparent 1.6px);
  background-size: 14px 14px;
  color: #fff;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; cursor: pointer; }

/* Header, with the add button always in reach */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  background: var(--page);
  border-bottom: 3px solid #000;
}
h1 {
  margin: 0;
  font-size: clamp(22px, 6.5vw, 34px);
  font-weight: 900;
  font-style: italic;
  line-height: 1.05;
  text-transform: uppercase;
  color: var(--yellow);
  text-shadow: 2px 2px 0 #000;
}
.count { margin: 2px 0 0; font-size: 13px; color: #cbd5e1; }
.count:empty { display: none; }
.add {
  min-height: 44px;
  padding: 0 14px;
  border: 3px solid #000;
  border-radius: 4px;
  background: var(--yellow);
  color: #000;
  font-weight: 800;
  box-shadow: 3px 3px 0 #000;
}
.add:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }
/* Search folds into a round magnifier at the end of the tools row; tapping it opens the field
   across the whole row (the other tools step aside) until it's closed or emptied.
   16px or iOS zooms the page when the field gets focus. */
.searchbox { flex: 0 0 44px; display: flex; gap: 6px; min-width: 0; }
.tool.round { flex: 0 0 44px; padding: 0; border-radius: 50%; background: #fff; display: grid; place-items: center; }
.tool.round.on { background: var(--yellow); }
.search, #searchClose { display: none; }
.search {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid #000;
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
.tools.searching > :not(.searchbox) { display: none; }
.tools.searching .searchbox { flex: 1 1 auto; }
.tools.searching .tool.round { display: none; }
.tools.searching .search, .tools.searching #searchClose { display: block; }
.tools.searching #searchClose { border-radius: 50%; }
button:disabled { opacity: .6; cursor: default; }
/* Series, sort and filters: a row of their own that shares the width, with long names cut short. */
.tools { flex: 1 0 100%; display: flex; gap: 6px; min-width: 0; }
.tool {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0 6px;
  overflow: hidden;
  border: 2px solid #000;
  border-radius: 4px;
  background: #e2e8f0;
  color: #000;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.15;
}
.tool.on { background: var(--yellow); }
.tool.clear { flex: 0 0 44px; padding: 0; background: #fff; font-size: 15px; }
.group {
  grid-column: 1 / -1;
  margin: 10px 0 -4px;
  font-size: 17px;
  font-weight: 900;
  font-style: italic;
  color: var(--yellow);
  text-shadow: 1px 1px 0 #000;
}
.group:first-child { margin-top: 0; }
.chooser-body { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.chooser h3 { margin: 8px 0 0; font-size: 14px; font-weight: 800; color: #334155; }
#chooserList { display: flex; flex-direction: column; gap: 6px; }
.option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid #cbd5e1;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  text-align: left;
}
.option small { color: #475569; font-size: 13px; }
.option.picked { border-color: #000; background: var(--yellow); }
.option.picked small { color: #000; }

/* The collection */
main { padding: 14px max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left)); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .45);
}
/* contain, not cover: a comic's cover is never cropped, and any spare room is more white card. */
.cover { display: block; width: 100%; aspect-ratio: 2 / 3; object-fit: contain; background: #fff; }
.cover.none {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: #f1f5f9;
  color: #64748b;
  font-size: 14px;
  text-align: center;
}
.title { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; white-space: pre-wrap; overflow-wrap: anywhere; }
/* A small pencil in a full-size tap target. margin-top: auto keeps the pencils in a row across cards with titles of
   different lengths; the negative side margins tuck the spare tap area into the card's padding. */
.edit {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  width: 44px;
  height: 44px;
  margin: auto -8px -8px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: #475569;
}
.edit:active { background: #f1f5f9; }
.status { margin: 0; padding: 48px 16px; color: #e2e8f0; text-align: center; }
.status.error { color: #fecaca; }
.version { padding: 8px 0 calc(16px + env(safe-area-inset-bottom)); color: rgba(255, 255, 255, .7); font-size: 12px; text-align: center; }
.version a { color: inherit; }
.footlink { padding: 0; border: 0; background: none; color: inherit; font-size: inherit; text-decoration: underline; }

/* The add form */
.sheet {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 3px solid #000;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
.sheet::backdrop { background: rgba(0, 0, 0, .65); }
.sheet form { display: flex; flex-direction: column; gap: 14px; padding: 16px; }
.sheet h2 { margin: 0; font-size: 20px; font-weight: 900; font-style: italic; text-transform: uppercase; outline: none; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 700; }
.field small { color: #475569; font-size: 13px; }
/* 16px or iOS zooms the page when the field gets focus. */
.field input:not([type=file]), .field select, .field textarea {
  width: 100%;
  padding: 10px;
  border: 2px solid #334155;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
.field textarea { min-height: 68px; resize: vertical; }
.field select { padding: 9px 6px; }
/* Issue, month and year on one line; they are short. min-width 0 lets the inputs shrink below their default size. */
.row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.row .field { min-width: 0; }
.provenance { margin: -4px 0 0; color: #475569; font-size: 13px; }

.suggest { display: flex; flex-direction: column; gap: 8px; margin-top: -6px; font-size: 14px; }
.suggest p { margin: 0; color: #334155; }
.suggest a { color: #475569; font-size: 12px; }
.suggest-list { display: flex; flex-direction: column; gap: 6px; }
.suggest-list:empty { display: none; }
.pick { min-height: 44px; padding: 6px 10px; border: 2px solid #334155; border-radius: 4px; background: #fff; color: var(--ink); font-size: 14px; font-weight: 600; text-align: left; white-space: pre-line; overflow-wrap: anywhere; }
/* A barcode shortlist can run to a dozen issues, too long to stack above the photo. */
.suggest-list.many { flex-direction: row; flex-wrap: wrap; }
.suggest-list.many .pick { flex: 1 1 45%; }
.pick.picked { border-color: #000; background: var(--yellow); }

.picker {
  position: relative;
  height: min(36vh, 280px);
  min-height: 150px;
  border: 2px solid #cbd5e1;
  border-radius: 4px;
  background: #f8fafc;
}
#preview { position: absolute; inset: 0; width: 100%; height: 100%; padding: 8px; object-fit: contain; }
.picker-text { margin: 0; color: #334155; font-size: 14px; }
/* Each file input lies over its whole button, invisible, so a tap lands on the real control. */
.photo-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.photo-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 6px 8px;
  overflow: hidden;
  border: 2px solid #334155;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  text-align: center;
}
.photo-btn.main { border: 3px solid #000; background: var(--yellow); color: #000; }
.photo-btn:active { transform: translate(1px, 1px); }
.photo-btn:focus-within { outline: 3px solid #2563eb; outline-offset: 2px; }
.photo-btn input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.link { align-self: flex-start; min-height: 44px; padding: 0; border: 0; background: none; color: #b91c1c; font-size: 14px; font-weight: 600; text-decoration: underline; }
.msg { margin: 0; padding: 8px 10px; border-radius: 4px; background: #fee2e2; color: #7f1d1d; font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.ghost { min-height: 44px; padding: 0 14px; border: 2px solid #334155; border-radius: 4px; background: #fff; color: var(--ink); font-weight: 700; }
.danger { min-height: 44px; margin-right: auto; padding: 0 12px; border: 2px solid #b91c1c; border-radius: 4px; background: #fff; color: #b91c1c; font-weight: 700; }

@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; }
  .title { font-size: 16px; }
}
/* The round ✕ beside the field closes and clears; the browser's own clear cross would be a second one. */
.search::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

/* Full-screen cover viewer */
.cover { cursor: zoom-in; }
.cover.none { cursor: default; }
.viewer { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: #000; color: #fff; overflow: hidden; }
.viewer::backdrop { background: #000; }
.viewer-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; touch-action: none; overflow: hidden; user-select: none; -webkit-user-select: none; }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center; will-change: transform; pointer-events: none; -webkit-touch-callout: none; }
.viewer-bar { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; gap: 8px; }
.viewer-bar button { min-width: 44px; height: 44px; padding: 0 12px; border: 0; border-radius: 22px; background: rgba(40, 40, 40, .85); color: #fff; font: inherit; font-size: 1.3rem; cursor: pointer; }
.viewer-bar button:focus-visible { outline: 2px solid #fff; }
