/* 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; }
button:disabled { opacity: .6; cursor: default; }

/* 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; }
/* margin-top: auto keeps the Edit buttons in a row across cards with titles of different lengths. */
.edit {
  width: 100%;
  min-height: 44px;
  margin-top: auto;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}
.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, .55); font-size: 12px; text-align: center; }

/* 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[type=password], .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; }

/* The file input lies over the whole box, invisible, so a tap anywhere lands on the real control. */
.picker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: min(36vh, 280px);
  min-height: 150px;
  padding: 10px;
  border: 2px dashed #64748b;
  border-radius: 4px;
  background: #f8fafc;
  color: #334155;
  text-align: center;
}
.picker:focus-within { outline: 3px solid #2563eb; outline-offset: 2px; }
.picker input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
#preview { position: absolute; inset: 0; width: 100%; height: 100%; padding: 8px; object-fit: contain; }
.picker.has-photo #pickerText {
  position: absolute;
  bottom: 8px;
  padding: 2px 10px;
  border-radius: 99px;
  background: rgba(0, 0, 0, .75);
  color: #fff;
  font-size: 13px;
}
.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; }
}
