/* The Bookshelf (shelf.js), in the dashboard: the shelf of books with their wax seals, and a book's details form.
   Loaded by dashboard.html after gilded.css. Uses the dashboard's own colours (--ink, --muted, --card, --edge…), so it
   follows light and dark, and Gilded Night's glass where it's there (--glass, --glass-2, --glass-line). */

/* ---------- Status: a wax seal (assets/art/wax-seal-blank.webp, tinted) with a mark, and the word beside it ---------- */
.sh-seal { position: relative; display: inline-grid; place-items: center; flex: none; width: 30px; height: 30px; }
.sh-seal img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; filter: var(--seal); }
.sh-seal svg { position: relative; width: 44%; height: 44%; color: rgba(255,246,228,.82); filter: drop-shadow(0 1px 0 rgba(0,0,0,.35)); }
.sh-seal--big { width: 64px; height: 64px; }
.sh-seal--draft { --seal: grayscale(1) sepia(.45) brightness(1.35) contrast(.9); }
.sh-seal--draft svg { color: rgba(60,44,22,.72); filter: drop-shadow(0 1px 0 rgba(255,255,255,.35)); }
.sh-seal--review { --seal: hue-rotate(28deg) saturate(1.5) brightness(1.3); }
.sh-seal--live { --seal: hue-rotate(118deg) saturate(.85) brightness(.95); }
.sh-seal--unpublished { --seal: grayscale(1) brightness(.62); }

.sh-state { display: inline-flex; align-items: center; gap: 6px; padding: 2px 12px 2px 2px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; color: var(--ink); background: var(--glass-2, var(--panel)); box-shadow: inset 0 0 0 1px var(--edge); }
.sh-state b { font-weight: 600; }
.sh-state--review b { color: #8a5a10; }
.sh-state--live b { color: #24613b; }
.sh-state--unpublished b { color: var(--muted); }
.dash-app.dark-ui .sh-state--review b { color: #f2c46d; }
.dash-app.dark-ui .sh-state--live b { color: #8fd8a7; }

/* ---------- The shelf ---------- */
.sh-bar .sh-owner { max-width: 210px; }
.sh-bar .sh-new { margin-left: 0; }
.sh-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 16px; }
.sh-card {
  position: relative; display: grid; grid-template-columns: 96px minmax(0, 1fr); grid-template-rows: 1fr auto; gap: 10px 18px;
  padding: 16px; border-radius: 22px; background: var(--glass, var(--card)); border: 1px solid var(--glass-line, var(--edge));
  box-shadow: var(--glass-shadow, none); color: var(--ink);
}
.sh-card .sh-cover-link { grid-row: 1 / 3; align-self: start; display: block; text-decoration: none; }
.sh-body { min-width: 0; display: grid; gap: 4px; align-content: start; }
.sh-body .sh-state { justify-self: start; margin-bottom: 4px; }
.sh-title { font: 600 23px/1.12 var(--serif); color: var(--ink); overflow-wrap: anywhere; }
.sh-title a { color: inherit; text-decoration: none; }
.sh-title a:hover { text-decoration: underline; text-decoration-color: var(--edge-strong); text-underline-offset: 4px; }
.sh-title a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; } /* the whole card opens the book */
.sh-sub { font: italic 500 16px/1.25 var(--serif); color: var(--muted); overflow-wrap: anywhere; }
.sh-by, .sh-facts, .sh-when { font-size: 13px; line-height: 1.4; color: var(--muted); overflow-wrap: anywhere; }
.sh-by { color: var(--ink); }
.sh-when { font-size: 12.5px; }
.sh-open { position: relative; z-index: 1; grid-column: 2; justify-self: start; min-height: 36px; }
.sh-none { grid-column: 1 / -1; }

/* A cover: the shop's picture, or cloth in a colour of its own with the title in gold */
.sh-cover { display: block; width: 100%; aspect-ratio: var(--book-ar, 2 / 3); border-radius: 3px 7px 7px 3px; overflow: hidden; box-shadow: 0 16px 26px -18px rgba(0,0,0,.85), inset 4px 0 0 rgba(0,0,0,.18); }
.sh-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sh-cloth {
  display: grid; align-content: center; justify-items: center; gap: 6px; padding: 12px 10px; text-align: center;
  background: var(--cloth, none), radial-gradient(120% 80% at 30% 20%, hsl(var(--h) 42% 34%), hsl(var(--h) 46% 15%));
  color: #f0d38c;
}
.sh-cloth b { font: 600 15px/1.1 var(--serif); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.sh-cloth small { font: italic 500 11px/1.2 var(--serif); color: rgba(240,211,140,.8); overflow-wrap: anywhere; }
.sh-cloth i { font: 600 8.5px/1.2 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: rgba(240,211,140,.7); font-style: normal; }
.sh-cloth::before { content: ""; width: 34%; height: 1px; background: rgba(240,211,140,.55); order: -1; }

/* An empty shelf */
.sh-empty { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, .7fr); gap: 28px; align-items: center; padding: clamp(22px, 4vw, 40px); border-radius: 28px; background: var(--glass, var(--card)); border: 1px solid var(--glass-line, var(--edge)); box-shadow: var(--glass-shadow, none); }
.sh-empty h2 { margin-top: 8px; font: 500 clamp(34px, 4.4vw, 54px)/1.02 var(--serif); color: var(--ink); }
.sh-empty p { max-width: 34em; margin-top: 12px; color: var(--muted); }
.sh-empty .sh-small { font-size: 13.5px; }
.sh-empty-art { display: flex; justify-content: center; gap: 10px; }
.sh-empty-art .sh-seal:nth-child(2) { transform: translateY(-14px) rotate(-8deg); }
.sh-empty-art .sh-seal:nth-child(3) { transform: rotate(10deg); }

/* ---------- One book ---------- */
.sh-edit { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.sh-head { margin-bottom: 14px; }
.sh-head .sh-h { margin-top: 4px; overflow-wrap: anywhere; }
.sh-fields { min-inline-size: 0; margin: 0; padding: 0; border: 0; display: grid; gap: 16px; }
.sh-fields[disabled] { opacity: .78; }
.sh-sec { padding: 22px 24px 8px; }
.sh-sec .dc-h { justify-content: flex-start; align-items: center; gap: 10px; margin-bottom: 18px; }
.sh-sec .dc-h small { margin-left: auto; }
.sh-n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font: 600 12.5px var(--sans); color: #2a1a06; background: linear-gradient(160deg, #f6dc94, #c49a45); }
.sh-narrow { max-width: 320px; }
.sh-row-series { grid-template-columns: minmax(0, 1fr) 120px; }
.sh-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sh-label { display: block; margin: 4px 0 8px; font-size: 12px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--kicker); }
.sh-label .opt { font-weight: 500; letter-spacing: .06em; text-transform: none; color: var(--muted); }
.sh-author { display: grid; gap: 2px; margin-bottom: 18px; }
.sh-author b { font: 600 20px/1.2 var(--serif); color: var(--ink); }
.sh-author small { font-size: 12.5px; color: var(--muted); }

/* Contributors */
.sh-people { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 8px; }
.sh-person { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 40px; gap: 8px; align-items: center; }
.sh-person :is(input, select) {
  width: 100%; min-height: 42px; padding: 0 12px; border-radius: 12px; font: inherit; font-size: 15px; color: var(--ink);
  background: var(--glass-2, var(--panel)); border: 1px solid var(--edge-strong);
}
.sh-person select { appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23a07a2c' stroke-width='1.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.sh-person select option { color: #1b140e; }
.sh-person :is(input, select):focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,162,74,.22); }
.sh-x { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--edge); background: transparent; color: var(--muted); cursor: pointer; }
.sh-x svg { width: 16px; height: 16px; }
.sh-x:hover { color: var(--accent); border-color: var(--edge-strong); }
.sh-add { margin-bottom: 16px; }

/* Keywords */
.sh-kw { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 0 8px; border-bottom: 1px solid rgba(90,64,30,.35); }
.dash-app.dark-ui .sh-kw { border-bottom-color: rgba(255,255,255,.28); }
.sh-kw:focus-within { border-bottom-color: var(--gold); }
.sh-kw-list { display: contents; list-style: none; }
.sh-kw-chip { display: inline-flex; align-items: center; gap: 2px; padding: 3px 3px 3px 12px; border-radius: 999px; font-size: 14px; color: var(--ink); background: rgba(201,162,74,.18); box-shadow: inset 0 0 0 1px rgba(201,162,74,.38); }
.sh-kw-chip button { display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.sh-kw-chip button svg { width: 13px; height: 13px; }
.sh-kw-chip button:hover { color: var(--accent); background: rgba(201,162,74,.18); }
.field .sh-kw input { flex: 1 1 180px; min-width: 0; border: 0; padding: 6px 2px; background: transparent; }
.field .sh-kw input:focus { background: transparent; }
.field .sh-kw input:disabled { display: none; }

/* Categories: tick-chips */
.sh-cats { min-inline-size: 0; margin: 0 0 20px; padding: 0; border: 0; }
.sh-cat-list { display: flex; flex-wrap: wrap; gap: 8px; }
.sh-cat { position: relative; display: inline-flex; cursor: pointer; }
.sh-cat input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: inherit; }
.sh-cat span { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 15px; border-radius: 999px; font-size: 14px; color: var(--ink); border: 1px solid var(--edge-strong); background: var(--glass-2, transparent); transition: background .2s, border-color .2s; }
.sh-cat input:checked + span { color: #2a1a06; font-weight: 600; border-color: #c49a45; background: linear-gradient(180deg, #f6dc94, #c49a45); }
.sh-cat input:checked + span::before { content: "✓"; font-size: 12px; }
.sh-cat input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }
.sh-cat input:disabled:not(:checked) + span { opacity: .45; cursor: not-allowed; }
.sh-cat:has(input:disabled) { cursor: not-allowed; }

.sh-count { text-align: right; font-size: 12.5px; }
.field-hint.is-bad { color: #b3261e; }
.dash-app.dark-ui .field-hint.is-bad { color: #f0a6a0; }
.field .sh-kw + .field-hint, .sh-sec .field-hint { margin-top: 6px; }
.sh-sec > .field-hint { margin: -10px 0 18px; }

/* The save bar: stays in sight at the bottom while the form is long */
.sh-actions {
  position: sticky; bottom: 10px; z-index: 3; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin-top: 16px;
  padding: 12px 14px; border-radius: 20px; background: var(--solid, var(--card)); border: 1px solid var(--glass-line, var(--edge)); box-shadow: 0 18px 40px -22px rgba(0,0,0,.7);
}
.sh-actions .form-status { flex: 1 1 200px; margin: 0; font-size: 14px; }
.sh-actions .form-status:empty { display: none; } /* nothing to say: the bar stays one line */
.sh-actions .dash-pill { min-height: 42px; }

.sh-lock { display: flex; gap: 12px; align-items: center; max-width: 46em; margin-top: 12px; padding: 12px 16px; border-radius: 16px; font-size: 14px; color: var(--ink); background: var(--glass-2, var(--panel)); box-shadow: inset 0 0 0 1px var(--edge-strong); }

/* The side: the book as it will look, and the road */
.sh-side { position: sticky; top: 18px; display: grid; gap: 16px; }
.sh-preview { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px; align-items: start; padding: 18px; border-radius: 24px; background: var(--glass, var(--card)); border: 1px solid var(--glass-line, var(--edge)); box-shadow: var(--glass-shadow, none); }
.sh-preview .sh-cloth b { font-size: 16px; }
.sh-pv-wrap { display: grid; gap: 10px; align-content: start; min-width: 0; }
.sh-cover-btn { justify-self: start; min-height: 42px; gap: 8px; }
.sh-cover-btn svg { width: 11px; height: 11px; }
.sh-pv-text { display: grid; gap: 8px; min-width: 0; align-content: start; }
.sh-pv-text .sh-state { justify-self: start; }
.sh-pv-by { font: 500 15px/1.3 var(--serif); color: var(--ink); overflow-wrap: anywhere; }
.sh-pv-by small { display: block; margin-top: 2px; font: 12.5px/1.35 var(--sans); color: var(--muted); }
.sh-road { padding: 18px 20px; border-radius: 24px; background: var(--glass, var(--card)); border: 1px solid var(--glass-line, var(--edge)); box-shadow: var(--glass-shadow, none); }
.sh-steps { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 4px; }
.sh-steps li { position: relative; display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 10px; padding: 6px 0; opacity: .55; }
.sh-steps li:not(:last-child)::after { content: ""; position: absolute; left: 14.5px; top: 36px; bottom: -6px; width: 1px; background: var(--edge-strong); }
.sh-steps li.is-done, .sh-steps li.is-now { opacity: 1; }
.sh-steps li.is-now b { color: var(--accent); }
.sh-steps b { display: block; font-size: 14px; font-weight: 600; color: var(--ink); }
.sh-steps small { display: block; font-size: 12.5px; line-height: 1.35; color: var(--muted); }
.sh-small { margin-top: 8px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.sh-small a { color: var(--accent); }

/* ---------- Narrower screens ---------- */
@media (max-width: 1100px) {
  .sh-edit { grid-template-columns: minmax(0, 1fr); }
  .sh-side { position: static; grid-row: 1; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .sh-actions { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); } /* above the phone's bottom bar */
}
@media (max-width: 640px) {
  .sh-card { grid-template-columns: 74px minmax(0, 1fr); padding: 14px; gap: 8px 14px; }
  .sh-card .sh-cloth { padding: 8px 6px; }
  .sh-card .sh-cloth b { font-size: 13px; -webkit-line-clamp: 4; }
  .sh-card .sh-cloth :is(small, i) { display: none; } /* a small cover keeps only its title */
  .sh-title { font-size: 20px; }
  .sh-empty { grid-template-columns: minmax(0, 1fr); }
  .sh-empty-art { justify-content: flex-start; order: -1; }
  .sh-side { grid-template-columns: minmax(0, 1fr); }
  .sh-preview { grid-template-columns: 92px minmax(0, 1fr); padding: 14px; }
  .sh-road { display: none; } /* the same words are on the shelf; the form comes first */
  .sh-sec { padding: 18px 16px 4px; }
  .sh-row-series { grid-template-columns: minmax(0, 1fr) 96px; gap: 0 14px; }
  .sh-row-3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 14px; }
  .sh-row-3 .field:last-child { grid-column: 1 / -1; }
  .sh-person { grid-template-columns: minmax(0, 1fr) 40px; }
  .sh-person select { grid-column: 1; }
  .sh-person .sh-x { grid-column: 2; grid-row: 1 / 3; }
  .sh-bar .sh-owner { max-width: none; flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .sh-cat span { transition: none; }
}
