/**
 * Novellion Advance Cover Designer — Cover Builder styles.
 * Shared by two host modes: embedded as a modal dialog (e.g. on the theme's
 * Add Book page) and standalone as an inline block on this plugin's own
 * "Cover Designer" page (.nv-cover-builder--standalone below). Uses the
 * same --nv-* theme variables as the rest of the site, so it follows
 * light/dark mode automatically — no separate dark-mode block needed here.
 */

.nv-cover-builder__open {
  display: block;
  margin-top: 0.5rem;
  border: 0;
  font: inherit;
}

.nv-cover-builder[hidden] {
  display: none;
}

.nv-cover-builder {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.6);
  overflow-y: auto;
}

.nv-cover-builder__dialog {
  position: relative;
  width: min(100%, 920px);
  max-height: min(92vh, 900px);
  overflow-y: auto;
  background: var(--nv-surface);
  color: var(--nv-text);
  border: 1px solid var(--nv-border);
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
  padding: 1.75rem;
}

.nv-cover-builder__close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  border: 0;
  background: transparent;
  color: var(--nv-text-soft);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

.nv-cover-builder__body {
  display: flex;
  gap: 1.75rem;
  flex-wrap: wrap;
}

/* Two equal (50/50) columns — same flex-basis (0) and flex-grow (1) on both
   this and .nv-cover-builder__controls below. Switches to a single stacked
   column under 768px (see the media query near the end of this file). */
.nv-cover-builder__preview {
  flex: 1 1 0;
  min-width: 260px;
}

/* Exactly canvas-sized (it holds nothing else), unlike .nv-cover-builder__
   preview above it which also contains the upload button and hint text —
   the Advanced-mode selection overlay is positioned with percentages
   against THIS element so those percentages actually line up with the
   canvas instead of a taller box that includes the button/text below it. */
.nv-cover-builder__canvas-wrap {
  position: relative;
}

.nv-cover-builder__preview canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  border: 1px solid var(--nv-border);
  display: block;
  background: #000;
}

/* Advanced mode: a plain grab cursor over the whole cover hints that text
   can be dragged, even before anything is selected. */
.nv-cover-builder__canvas--advanced {
  cursor: grab;
}

/* Purely decorative — never drawn onto the canvas itself, so it can never
   leak into the exported cover image. Positioned in cover-builder.js with
   percentages (box-in-virtual-canvas-px / canvas-virtual-size), which keeps
   it aligned with the actual text without needing a resize observer, since
   the canvas itself always scales via CSS percentages too. */
.nv-cover-builder__selection {
  position: absolute;
  border: 2px dashed #ffd966;
  border-radius: 2px;
  pointer-events: none;
}

.nv-cover-builder__selection[hidden] {
  display: none;
}

.nv-cover-builder__selection::after {
  content: "";
  position: absolute;
  right: -9px;
  bottom: -9px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffd966;
  border: 2px solid #1a1a1a;
}

.nv-cover-builder__advanced-hint {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--nv-text-soft);
}

.nv-cover-builder__advanced-hint[hidden] {
  display: none;
}

.nv-cover-builder__preview .nv-book-form__upload-btn {
  margin-top: 0.6rem;
  width: 100%;
  text-align: center;
}

.nv-cover-builder__controls {
  flex: 1 1 0;
  min-width: 280px;
}

/* Top row: title/author on the left, the genre filter on the right — a
   deliberate exception to the rest of the panel's full-width fields, per
   the requested layout. */
.nv-cover-builder__top-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.nv-cover-builder__text-fields {
  flex: 1 1 60%;
}

.nv-cover-builder__genre-col {
  flex: 1 1 40%;
}

.nv-cover-builder__genre-field {
  margin-bottom: 0;
}

.nv-cover-builder__field {
  margin-bottom: 0.5rem;
}

.nv-cover-builder__field label {
  display: block;
  margin-bottom: 0.2rem;
  font-weight: 600;
}

/* Template-picker label + the Default/Advanced toggle, side by side above
   the template grid. */
.nv-cover-builder__mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.nv-cover-builder__mode-row label {
  margin-bottom: 0;
}

.nv-cover-builder__mode-toggle {
  display: inline-flex;
  border: 1px solid var(--nv-border);
  border-radius: 999px;
  overflow: hidden;
  flex: 0 0 auto;
}

.nv-cover-builder__mode-btn {
  border: 0;
  background: transparent;
  color: var(--nv-text-soft);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
}

.nv-cover-builder__mode-btn.is-active {
  background: var(--nv-action);
  color: var(--nv-cta-text);
}

/* Advanced per-block size field + its "Reset" button, side by side. */
.nv-cover-builder__size-with-reset {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.nv-cover-builder__size-with-reset input[type="number"] {
  flex: 1 1 auto;
  min-width: 0;
}

.nv-cover-builder__reset-btn {
  flex: 0 0 auto;
  border: 1px solid var(--nv-border);
  background: transparent;
  color: var(--nv-text-soft);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.nv-cover-builder__reset-btn:hover {
  background: var(--nv-bg-alt);
  color: var(--nv-text);
}

.nv-cover-builder__field input[type="text"],
.nv-cover-builder__field select {
  width: 100%;
}

.nv-cover-builder__field input[type="color"] {
  width: 3.5rem;
  height: 2.2rem;
  padding: 0;
  border: 1px solid var(--nv-border);
  border-radius: 4px;
  background: none;
  flex: 0 0 auto;
}

/* A color swatch plus its own hex text field, side by side. */
.nv-cover-builder__color-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nv-cover-builder__hex {
  width: 100px !important; /* overrides the generic 100%-width text-input rule above */
  font-family: monospace;
  text-transform: lowercase;
}

/* Effect / size pickers don't need the full width of the panel — a short,
   fixed width is easier to scan and matches the small set of choices in
   each one. Selectors are ID-based (highest specificity in this file) so
   this width always wins over the generic
   ".nv-cover-builder__field select { width: 100% }" rule above. */
#nv_cb_effect_title,
#nv_cb_effect_body,
#nv_cb_title_size,
#nv_cb_author_size,
#nv_cb_outline_width,
#nv_cb_shadow_strength {
  width: 150px;
  max-width: 100%;
}

/* The Advanced-mode size fields sit next to a Reset button (see
   .nv-cover-builder__size-with-reset above), so they get a narrower fixed
   width than the Default-mode ones above, which have the row to themselves. */
#nv_cb_adv_title_size,
#nv_cb_adv_subtitle_size,
#nv_cb_adv_author_size {
  width: 90px;
  max-width: 100%;
  /* Twice the height of a plain unstyled number input, per request — these
     three sit right next to their own "Reset" button, so make the reset
     button match this height too (below) rather than looking squashed next
     to a now much taller field. */
  padding: 0.7rem 0.5rem;
  border: 1px solid var(--nv-border);
  border-radius: 4px;
}

.nv-cover-builder__size-with-reset .nv-cover-builder__reset-btn {
  align-self: stretch;
}

/* Font-pair list — a scrollable listbox (not a native <select>) so its
   height can actually be capped with a real scrollbar, and so genre
   filtering can show/hide rows directly instead of juggling <option>
   elements. */
/* Font list on the left, effect + color on the right of it, side by side —
   the effect/color fields used to sit full-width further down the panel;
   moving them up next to the (now half-width) font list uses the space the
   narrower list frees up. */
.nv-cover-builder__fonts-row {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.nv-cover-builder__fonts-col {
  flex: 1 1 50%;
  min-width: 0;
}

.nv-cover-builder__fontlist {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--nv-border);
  border-radius: 4px;
  background: var(--nv-bg-alt);
}

.nv-cover-builder__fontlist-item {
  padding: 0.45rem 0.7rem;
  cursor: pointer;
}

.nv-cover-builder__fontlist-item:hover {
  background: var(--nv-surface);
}

.nv-cover-builder__fontlist-item.is-active {
  background: var(--nv-action);
  color: var(--nv-cta-text);
}

.nv-cover-builder__fontlist-empty {
  padding: 0.6rem 0.7rem;
  color: var(--nv-text-soft);
  font-style: italic;
}

.nv-cover-builder__row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.nv-cover-builder__row .nv-cover-builder__field {
  flex: 0 0 auto;
}

/* .nv-cover-builder__row sets display:flex above, which (same author-origin
   specificity as the browser's own `[hidden] { display: none }` rule) would
   otherwise win and keep a hidden row visible — toggling Default/Advanced's
   size-field rows via the native `hidden` attribute needs this explicit
   override, same as .nv-cover-builder__effect-extra[hidden] already has
   below. */
#nv_cb_default_size_fields[hidden],
#nv_cb_advanced_size_fields[hidden] {
  display: none;
}

.nv-cover-builder__effect-extra[hidden] {
  display: none;
}

/* Outline/shadow extra fields now live inside the narrow fonts-col (stacked
   vertically, not the wide horizontal row they used to be lower on the
   panel) — a little breathing room above them, separating them from the
   effect dropdown right above. */
.nv-cover-builder__fonts-col .nv-cover-builder__effect-extra {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--nv-border);
}

/* Template picker — a small grid of buttons, each drawing a tiny box with
   two bars standing in for the title/author blocks so the position reads
   at a glance without rendering an actual mini preview per template. */
.nv-cover-builder__templates {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
}

.nv-cover-builder__template {
  border: 2px solid var(--nv-border);
  border-radius: 6px;
  background: var(--nv-bg-alt);
  padding: 0.25rem;
  cursor: pointer;
}

.nv-cover-builder__template.is-active {
  border-color: var(--nv-text);
}

.nv-cover-builder__template-box {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: 3px;
  overflow: hidden;
}

.nv-cover-builder__template-bar {
  position: absolute;
  left: 12%;
  right: 12%;
  height: 14%;
  background: #fff;
  border-radius: 2px;
  /* Exact top/bottom offset is set inline per-template by cover-builder.js
     (buildTemplatePicker()), since it already knows each block's zone and
     stacking order — simpler and more reliable than a CSS sibling rule. */
}

.nv-cover-builder__template-bar--author {
  height: 9%;
  opacity: 0.85;
}

.nv-cover-builder__template-bar--subtitle {
  height: 7%;
  opacity: 0.65;
}

.nv-cover-builder__cancel-btn {
  border: 1px solid var(--nv-border);
  background: transparent;
  color: var(--nv-text-soft);
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font: inherit;
  cursor: pointer;
}

.nv-cover-builder__error {
  color: #c0392b;
  font-weight: 600;
}

.nv-cover-builder__actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
}

body.nv-cover-builder-open {
  overflow: hidden;
}

/* Standalone mode ([novellion_cover_designer] page): the builder is a
   normal block on the page, not a fixed full-screen overlay — no backdrop,
   no centering, no scroll-lock, and no close/cancel affordance (JS hides
   those buttons; this just removes their layout gap). */
.nv-cover-builder--standalone {
  position: static;
  inset: auto;
  z-index: auto;
  padding: 0;
  background: none;
  overflow: visible;
  display: block;
}

.nv-cover-builder--standalone .nv-cover-builder__dialog {
  width: 100%;
  max-height: none;
  overflow: visible;
  box-shadow: none;
}

.nv-cover-builder--standalone .nv-cover-builder__close {
  display: none;
}

@media (max-width: 768px) {
  .nv-cover-builder__body {
    flex-direction: column;
  }
  .nv-cover-builder__preview {
    flex: none;
    max-width: 320px;
    margin: 0 auto;
    position: static;
  }
  .nv-cover-builder__canvas-wrap,
  .nv-cover-builder__under {
    width: 100%;
  }
  .nv-cover-builder__top-row {
    flex-direction: column;
    gap: 0;
  }
  .nv-cover-builder__fonts-row {
    flex-direction: column;
    gap: 0;
  }
  .nv-cover-builder__templates {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Effects built from the registry (2.0.0). */
.nv-cover-builder__fx-group {
  margin-top: 0.4rem;
}

.nv-cover-builder__fx-heading {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
}

.nv-cover-builder__field input[type="range"] {
  width: 100%;
}

.nv-cover-builder__coverfx-list,
#nv_cb_cover_fx_list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
}

.nv-cover-builder__coverfx-item {
  flex: 1 1 11rem;
  min-width: 0;
}

.nv-cover-builder__coverfx-switch {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.nv-cover-builder__coverfx-item .nv-cover-builder__effect-extra:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
  margin-top: 0.3rem;
}


/* Layout (v2.0.1): the dialog fits the screen. On the left, the cover with
   the Use / Download / Cancel buttons right under it; on the right, ONE
   scrolling panel with every setting — so the cover and the buttons never
   leave the screen while settings are changed. Phones (below) keep the
   plain stacked, page-scrolling layout. */
.nv-cover-builder__under {
  margin-top: 0.5rem;
}

.nv-cover-builder__under .nv-cover-builder__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 0;
}

.nv-cover-builder__under .nv-cover-builder__actions button {
  flex: 1 1 auto;
  margin: 0;
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
}

.nv-cover-builder__under .nv-cover-builder__error {
  margin: 0.4rem 0 0;
}

.nv-cover-builder__coverfx-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.9rem;
}

.nv-cover-builder__coverfx-item {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.nv-cover-builder__coverfx-gear {
  border: 1px solid var(--nv-border);
  background: transparent;
  color: var(--nv-text-soft);
  border-radius: 4px;
  padding: 0 0.3rem;
  line-height: 1.3;
  cursor: pointer;
}

.nv-cover-builder__coverfx-gear[hidden] {
  display: none;
}

.nv-cover-builder__coverfx-gear.is-open {
  color: var(--nv-text);
  border-color: var(--nv-text-soft);
}

.nv-cover-builder__coverfx-settings .nv-cover-builder__effect-extra:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
  margin: 0.3rem 0 0.2rem;
}

@media (min-width: 769px) {
  .nv-cover-builder:not(.nv-cover-builder--standalone) .nv-cover-builder__dialog {
    --nv-cb-h: min(92vh, 900px);
    height: var(--nv-cb-h);
    max-height: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .nv-cover-builder:not(.nv-cover-builder--standalone) .nv-cover-builder__body {
    flex: 1 1 auto;
    min-height: 0;
    flex-wrap: nowrap;
  }

  /* The cover's width follows the available height (dialog height minus its
     padding, the upload button and the action buttons), so it is never cut. */
  .nv-cover-builder:not(.nv-cover-builder--standalone) .nv-cover-builder__preview {
    --nv-cb-cover-w: calc((var(--nv-cb-h) - 3.5rem - 11rem) * 0.75);
    flex: 0 0 auto;
    width: max(220px, min(46%, var(--nv-cb-cover-w)));
    min-width: 0;
  }

  .nv-cover-builder:not(.nv-cover-builder--standalone) .nv-cover-builder__controls {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    padding-right: 0.75rem;
    scrollbar-gutter: stable;
  }
}

.nv-cover-builder__field .nv-cover-builder__coverfx-switch {
  display: inline-flex;
  width: auto;
  margin: 0;
}

/* Ready styles (2.1.0) */
.nv-cover-builder__presets[hidden],
#nv_cb_plate_fields[hidden] { display: none; }
.nv-cover-builder__presets-list { display: flex; flex-wrap: wrap; gap: 6px; }
.nv-cover-builder__preset {
  padding: 5px 10px;
  border: 1px solid var(--nv-border, #d4d4d8);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.nv-cover-builder__preset:hover { border-color: currentColor; }

/* Plate size (2.2.0) */
.nv-cover-builder__plate-size[hidden] { display: none; }
.nv-cover-builder__plate-size { display: grid; gap: 4px; margin: -4px 0 10px; padding: 6px 8px; border: 1px solid var(--nv-border, #d4d4d8); border-radius: 6px; }
.nv-cover-builder__plate-size label { display: grid; grid-template-columns: 8.5em 1fr; align-items: center; gap: 8px; font-size: 13px; }
.nv-cover-builder__plate-size input[type="range"] { width: 100%; }
.nv-cover-builder__selection--plate { border-color: #5ad1ff; }
.nv-cover-builder__selection--plate::after { background: #5ad1ff; }
