/* Outil de création de liste (views/partials/deck-tool.ejs, public/deck-tool.js).
   Uniquement des tokens du design system (foundations.css) : couleurs, polices,
   rayons, cadres de cartes. Trois largeurs :
   - >= 900px : outil dans la page, recherche à gauche, liste fixe à droite ;
   - < 900px  : une colonne, recherche en mode focus plein écran au toucher du
                champ, liste en feuille plein écran, barre "Ma liste · Proxyfier" ;
   - < 640px  : la barre remonte au-dessus de la nav du bas du site. */

.deck-tool {
  --deck-chip: 44px;
  --deck-bar-h: 72px;
  margin-bottom: 1.75rem;
}

.deck-tool .visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* [hidden] doit toujours gagner, y compris sur .ds-btn (display: inline-block). */
.deck-tool [hidden] { display: none !important; }

/* manipulation : pas de double-tap-zoom sur mobile, qui avalait un toucher sur deux. */
.deck-tool button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
.deck-tool button:disabled { cursor: not-allowed; }
.deck-tool :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.deck-tool .deck-search-field input:focus-visible { outline: none; } /* la bordure du champ fait office de focus */

/* ---------- Méthodes (onglets du hero) ---------- */
.page-hero-cta.deck-methods { max-width: none; }
.deck-methods .deck-method {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.deck-methods .deck-method svg { width: 18px; height: 18px; flex-shrink: 0; }

@media (max-width: 639px) {
  .deck-methods {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    max-width: none;
  }
  .deck-methods .deck-method {
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-height: 68px;
    padding: 10px 6px;
    font-size: 12px;
    text-align: center;
  }
  .deck-methods .deck-method svg { width: 22px; height: 22px; }
}

/* ---------- Reprise ---------- */
.deck-resume {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 1rem;
  padding: 14px 16px;
  border-radius: var(--radius-card-sm);
  background: var(--card);
  border: 1px solid var(--accent);
}
.deck-resume[hidden] { display: none; }
.deck-resume p { margin: 0; color: var(--text); }
.deck-resume-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.deck-btn-sm { padding: 12px 18px; }

/* ---------- Mise en page ---------- */
.deck-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  align-items: start;
}
.deck-layout > .content-box { margin-bottom: 0; }
.deck-main { position: relative; min-width: 0; }
.deck-panel[hidden] { display: none; }

/* ---------- Recherche ---------- */
.deck-search-bar { display: flex; align-items: center; gap: 8px; }
.deck-search-field {
  flex: 1;
  min-width: 0;
  height: 52px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-radius: var(--radius-key);
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  transition: border-color 0.15s ease;
}
.deck-search-field:focus-within { border-color: var(--accent); }
.deck-search-field svg { width: 20px; height: 20px; flex-shrink: 0; }
.deck-search-field input {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px; /* >= 16px : pas de zoom automatique sur iOS */
}
.deck-search-field input::placeholder { color: var(--muted-2); }
.deck-search-field input::-webkit-search-cancel-button { filter: invert(0.7); }

.deck-name-lang {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 28px 0 12px;
  border: none;
  border-radius: 8px;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238A90A3' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M7 10l5 5l5-5'/%3E%3C/svg%3E") no-repeat right 8px center / 14px;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.deck-name-lang:hover { background-color: var(--raised); }

.deck-icon-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-key-sm);
  background: transparent;
  color: var(--text);
}
.deck-icon-btn:hover { background: var(--card); }
.deck-icon-btn svg { width: 22px; height: 22px; }
.deck-icon-btn[hidden] { display: none; }
.deck-focus-close, .deck-sheet-close { display: none; }

.deck-results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 6px;
}
.deck-results-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--text-eyebrow-weight);
  font-size: var(--text-eyebrow-size);
  letter-spacing: var(--text-eyebrow-tracking);
  text-transform: uppercase;
  color: var(--text-secondary);
}
/* Chargement : spinner + texte à côté du titre, résultats précédents grisés. */
.deck-results-title { display: inline-flex; align-items: center; gap: 10px; }
.deck-spinner, .deck-loading-text { display: none; }
.deck-tool.is-loading .deck-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--raised);
  border-top-color: var(--accent);
  animation: deck-spin 0.7s linear infinite;
}
.deck-tool.is-loading .deck-loading-text { display: inline; color: var(--accent); letter-spacing: var(--text-eyebrow-tracking); }
.deck-tool.is-loading #deckResultsTitle { display: none; }
.deck-tool.is-loading .deck-results, .deck-tool.is-loading .deck-archetypes { opacity: 0.45; transition: opacity 0.15s ease; }
@keyframes deck-spin { to { transform: rotate(360deg); } }

.deck-link-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  padding: 10px 0;
  min-height: 44px;
}
.deck-link-btn[hidden] { display: none; }

.deck-archetypes { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 10px; }
.deck-archetypes[hidden] { display: none; }
.deck-archetype {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 12px 14px;
  border-radius: var(--radius-card-sm);
  background: var(--card);
  border: 1px dashed var(--accent);
}
.deck-archetype[hidden] { display: none; }
.deck-archetype-label { margin: 0; font-weight: 600; color: var(--text); }
.deck-archetype-actions { display: flex; align-items: center; gap: 6px; }
.deck-archetype-add { font-size: 13px; color: var(--text-secondary); margin-right: 4px; }
.deck-archetype .deck-chip { width: auto; padding: 0 12px; }

/* padding-bottom : la place de la pastille "Annuler" sous le dernier résultat. */
.deck-results { list-style: none; margin: 0; padding: 0 0 72px; display: flex; flex-direction: column; gap: 2px; }
.deck-result {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius-key);
  outline: none;
}
.deck-result:hover, .deck-result:focus-within { background: var(--card); }
.deck-result:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.deck-thumb {
  width: 44px;
  height: 64px;
  padding: 0;
  border: none;
  border-radius: 4px;
  overflow: hidden;
  background: var(--frame-effect);
}
.deck-result[data-group="spell"] .deck-thumb { background: var(--frame-spell); }
.deck-result[data-group="trap"] .deck-thumb { background: var(--frame-trap); }
.deck-result[data-group="extra"] .deck-thumb { background: var(--frame-fusion); }
.deck-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.deck-result-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.deck-result-name { font-weight: 600; color: var(--text); line-height: 1.25; overflow-wrap: anywhere; }
.deck-result-meta { font-size: 13px; color: var(--text-secondary); line-height: 1.3; }
.deck-result-meta.is-in-list { color: var(--accent); font-weight: 600; }
.deck-results-empty { margin: 16px 8px; color: var(--text-secondary); }
.deck-results-empty[hidden] { display: none; }
.deck-more { display: block; width: 100%; margin-top: 10px; }
.deck-more[hidden] { display: none; }

/* ---------- Quantités ---------- */
.deck-qty { display: flex; align-items: center; gap: 4px; }
.deck-chip {
  width: var(--deck-chip);
  height: var(--deck-chip);
  border-radius: var(--radius-key-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.deck-chip:hover { background: var(--raised-hover); }
.deck-chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.deck-chip-plus { color: var(--accent); font-size: 20px; }
.deck-qty.is-stepper { gap: 0; border-radius: var(--radius-key-sm); background: var(--card); border: 1px solid var(--border); }
.deck-qty.is-stepper.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.deck-step {
  width: var(--deck-chip);
  height: var(--deck-chip);
  border: none;
  background: transparent;
  color: inherit;
  font-size: 20px;
  font-weight: 600;
}
.deck-qty.is-stepper:not(.is-active) .deck-step { color: var(--text); }
.deck-step-value {
  min-width: 30px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
}

/* ---------- Aperçu ---------- */
.deck-hover-preview { display: none; }
.deck-preview {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--text);
  max-width: min(92vw, 360px);
  text-align: center;
}
.deck-preview::backdrop { background: rgba(7, 8, 11, 0.8); }
.deck-preview img { display: block; width: 100%; border-radius: 10px; aspect-ratio: 421 / 614; background: var(--card); }
.deck-preview p { margin: 12px 0; font-weight: 600; }

@media (min-width: 1200px) {
  #deckPanel-search:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 190px;
    column-gap: 20px;
  }
  #deckPanel-search > * { grid-column: 1; }
  #deckPanel-search > .deck-hover-preview {
    display: block;
    grid-column: 2;
    grid-row: 1 / span 8;
    align-self: start;
    position: sticky;
    top: 24px;
    opacity: 0;
    transition: opacity 0.15s ease;
  }
  .deck-hover-preview.is-visible { opacity: 1; }
  .deck-hover-preview img { width: 100%; border-radius: 8px; aspect-ratio: 421 / 614; display: block; }
}

/* ---------- Import (YDKE / liste / fichier) ---------- */
.deck-label { display: block; margin-bottom: 10px; color: var(--text-secondary); font-size: 14px; }
.deck-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border-radius: var(--radius-key);
  background: var(--card);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  resize: vertical;
}
.deck-textarea:focus { outline: none; border-color: var(--accent); }
.deck-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.deck-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 150px;
  padding: 20px;
  border-radius: var(--radius-card-sm);
  border: 1.5px dashed rgba(255, 255, 255, 0.18);
  background: var(--card);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.deck-dropzone:hover, .deck-dropzone.is-drag, #deckFileInput:focus-visible + .deck-dropzone { border-color: var(--accent); }
.deck-dropzone svg { width: 30px; height: 30px; color: var(--accent); }
.deck-dropzone-title { font-family: var(--font-display); font-weight: 600; letter-spacing: var(--btn-tracking); text-transform: uppercase; color: var(--text); }
.deck-dropzone-hint { font-size: 13px; color: var(--text-secondary); }
.deck-report { margin-top: 14px; }
.deck-report:empty { display: none; }
.deck-report p { margin: 0 0 10px; }
.deck-report-source { color: var(--gain); font-weight: 600; }
.deck-report-status { color: var(--text-secondary); }
.deck-report-status.is-error, .deck-report-missing { color: var(--damage); }
.deck-report-choice {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding: 12px;
  border-radius: var(--radius-key);
  background: var(--card);
}
.deck-report-choice p { width: 100%; margin: 0 0 4px; }
.deck-report-missing { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.deck-report-details { margin-bottom: 10px; color: var(--damage); }
.deck-report-details summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.deck-candidate {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-key-sm);
  border: 1px solid var(--border);
  background: var(--raised);
  color: var(--text);
  text-align: left;
}
.deck-candidate[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.deck-candidate.is-skip { color: var(--text-secondary); }

/* ---------- Liste ---------- */
.deck-list {
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
  padding: 0;
  overflow: hidden;
}
.deck-list-head { display: flex; align-items: center; gap: 8px; padding: 20px 16px 12px 20px; }
.deck-list-titles { flex: 1; min-width: 0; }
.deck-list-head .deck-name-lang { min-height: 40px; }
.deck-list-count {
  margin: 8px 0 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  color: var(--text);
}
.deck-list-count:empty { display: none; }
.deck-list-body { flex: 1; overflow-y: auto; padding: 0 12px; overscroll-behavior: contain; }
.deck-group { margin-bottom: 8px; }
.deck-group-title {
  margin: 10px 8px 4px;
  padding: 0;
  background: none;
  font-family: var(--font-display);
  font-weight: var(--text-eyebrow-weight);
  font-size: var(--text-eyebrow-size);
  letter-spacing: var(--text-eyebrow-tracking);
  text-transform: uppercase;
  color: var(--frame-effect);
}
.deck-group[data-group="spell"] .deck-group-title { color: var(--frame-spell); }
.deck-group[data-group="trap"] .deck-group-title { color: var(--frame-trap); }
.deck-group[data-group="extra"] .deck-group-title { color: var(--frame-fusion); }
.deck-group-list { list-style: none; margin: 0; padding: 0; }
.deck-line {
  display: grid;
  grid-template-columns: 6px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 4px 4px 4px 8px;
  border-bottom: 1px solid var(--border);
}
.deck-line-frame { width: 6px; height: 28px; border-radius: 3px; background: var(--frame-effect); }
.deck-group[data-group="spell"] .deck-line-frame { background: var(--frame-spell); }
.deck-group[data-group="trap"] .deck-line-frame { background: var(--frame-trap); }
.deck-group[data-group="extra"] .deck-line-frame { background: var(--frame-fusion); }
.deck-line-name {
  min-width: 0;
  padding: 6px 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  text-align: left;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.deck-line-name:hover { color: var(--accent); }
.deck-line-name span { display: block; }
.deck-line-name .deck-line-tag { margin-top: 2px; font-size: 12px; color: var(--text-secondary); }
.deck-list .deck-qty.is-stepper { --deck-chip: 40px; }
.deck-list-empty { padding: 8px 20px 20px; color: var(--text-secondary); }
.deck-list-empty[hidden] { display: none; }
.deck-list-empty p { margin: 0 0 14px; }
.deck-list-foot {
  padding: 14px 20px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.deck-check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; color: var(--text-secondary); cursor: pointer; }
.deck-check input { width: 18px; height: 18px; accent-color: var(--accent); }
.deck-submit { width: 100%; }
.deck-submit:disabled { opacity: 0.5; filter: none; }

/* ---------- Barre, toast ---------- */
.deck-bar { display: none; }
.deck-toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 24px;
  width: fit-content;
  margin: 0 auto;
  z-index: 1300;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 480px;
  box-sizing: border-box;
  padding: 8px 8px 8px 16px;
  border-radius: var(--radius-key);
  background: var(--text);
  color: var(--surface);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  /* Laisse passer les touchers vers les résultats en dessous ; seul "Annuler" est cliquable. */
  pointer-events: none;
}
.deck-toast button { pointer-events: auto; }
.deck-toast[hidden] { display: none; }
.deck-toast span { flex: 1; font-size: 14px; }
.deck-toast button {
  min-height: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #A4460E; /* accent assombri : lisible sur le fond clair du toast (4.5:1) */
  font-weight: 700;
}
.deck-toast button[hidden] { display: none; }

/* ======================= Écran étroit ======================= */
@media (max-width: 899px) {
  .deck-layout { grid-template-columns: minmax(0, 1fr); }
  .deck-list { display: none; }

  .deck-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1001;
    display: flex;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .deck-bar[hidden] { display: none; }
  .deck-bar .ds-btn { flex: 1; padding: 0 12px; min-height: 52px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
  .deck-bar-count {
    padding: 2px 9px;
    border-radius: var(--radius-pill);
    background: var(--raised);
    letter-spacing: 0;
  }
  .deck-tool:has(.deck-bar:not([hidden])) { padding-bottom: var(--deck-bar-h); }
  .deck-toast { bottom: calc(var(--deck-bar-h) + 12px); }

  /* Mode focus : la recherche prend tout l'écran visible (au-dessus du clavier). */
  .deck-tool.is-focus #deckPanel-search {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--deck-vh, 100dvh);
    z-index: 1100;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 12px calc(var(--deck-bar-h) + 12px);
    background: var(--bg);
  }
  .deck-tool.is-focus .deck-search-bar {
    position: sticky;
    top: 0;
    z-index: 1;
    margin: 0 -12px;
    padding: 10px 12px 10px 6px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .deck-tool.is-focus .deck-focus-close { display: inline-flex; }
  .deck-tool.is-focus .deck-bar { z-index: 1200; bottom: var(--deck-kb, 0px); padding-bottom: 10px; }
  .deck-tool.is-focus .deck-toast { bottom: calc(var(--deck-kb, 0px) + var(--deck-bar-h) + 8px); }

  /* Feuille "Ma liste" plein écran. */
  .deck-tool.is-list .deck-list {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 1250;
    max-height: none;
    height: var(--deck-vh, 100dvh);
    border-radius: 0;
    border: none;
    background: var(--bg);
  }
  .deck-tool.is-list .deck-sheet-close { display: inline-flex; }
  .deck-tool.is-list .deck-list-head { padding: 10px 12px 10px 6px; border-bottom: 1px solid var(--border); }
  .deck-tool.is-list .deck-list-foot { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); background: var(--surface); }
  .deck-tool.is-list .deck-bar { display: none; }
  .deck-tool.is-list .deck-toast { bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }

  .deck-result { grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; padding: 6px 4px; }
  .deck-thumb { width: 40px; height: 58px; }
  .deck-tool { --deck-chip: 40px; }
  .deck-archetype { flex-direction: column; align-items: flex-start; }
}

html.deck-lock, html.deck-lock body { overflow: hidden; }

/* Téléphone : la nav du bas du site occupe 64px, la barre de l'outil se pose dessus. */
@media (max-width: 639px) {
  .deck-bar { bottom: calc(64px + env(safe-area-inset-bottom, 0px)); padding-bottom: 10px; }
  .deck-tool:has(.deck-bar:not([hidden])) { padding-bottom: calc(var(--deck-bar-h) + 8px); }
  .deck-toast { bottom: calc(64px + var(--deck-bar-h) + 12px + env(safe-area-inset-bottom, 0px)); }
  .deck-search-field { padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .deck-tool *, .deck-methods * { transition: none !important; }
  .deck-tool.is-loading .deck-spinner { animation-duration: 2s; }
}
