* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; background: #1a1a1a; color: #e0e0e0; line-height: 1.6;   overflow-x: hidden;
}
.container { display: grid; grid-template-columns: 1fr 400px; gap: 20px; padding: 20px; max-width: 1800px; margin: 0 auto; }
@media (max-width: 1200px) { .container { grid-template-columns: 1fr; } }
.header { background: #242424; padding: 20px; border-bottom: 2px solid #333; }
.header h1 { color: #fff; font-size: 24px; margin-bottom: 15px; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr; gap: 10px; margin-bottom: 10px; }
@media (max-width: 768px) { .filters { grid-template-columns: 1fr; } }
input, select, button, textarea { padding: 10px; background: #2a2a2a; border: 1px solid #444; color: #e0e0e0; border-radius: 4px; font-size: 14px; }
input::placeholder { color: #666; }
button { cursor: pointer; background: #4a4a4a; transition: background 0.2s; }
button:hover { background: #555; }
button:active { background: #333; }
.btn-primary { background: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: #16a34a; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.library { background: #242424; border-radius: 8px; padding: 20px; max-height: calc(100vh - 200px); overflow-y: auto; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 15px; }
.card-item { background: #2a2a2a; border: 1px solid #444; border-radius: 6px; padding: 12px; transition: border-color 0.2s; }
.card-item:hover { border-color: #666; }
.card-header { display: flex; gap: 10px; margin-bottom: 10px; }
.card-image { width: 80px; height: 80px; object-fit: cover; border-radius: 4px; background: #1a1a1a; border: 1px solid #333; flex-shrink: 0; }
.card-info { flex: 1; min-width: 0; }
.card-name { font-weight: bold; font-size: 15px; color: #fff; margin-bottom: 4px; }
.card-meta { font-size: 12px; color: #999; margin-bottom: 2px; }
.card-text { font-size: 13px; color: #ccc; margin-top: 8px; white-space: pre-wrap; line-height: 1.4; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card-actions button { flex: 1; padding: 6px; font-size: 12px; }
.rarity-R { color: #fbbf24; }
.rarity-C { color: #9ca3af; }
.deck-panel { background: #242424; border-radius: 8px; padding: 15px; display: flex; flex-direction: column; position: sticky; top: 20px; max-height: calc(100vh - 40px); }
.deck-header input { width: 100%; margin-bottom: 15px; font-weight: bold; font-size: 16px; }
.deck-stats { background: #2a2a2a; padding: 12px; border-radius: 4px; margin-bottom: 15px; font-size: 14px; }
.deck-stats div { display: flex; justify-content: space-between; margin-bottom: 5px; }
.deck-stats div:last-child { margin-bottom: 0; }
.deck-list { flex: 1; overflow-y: auto; margin-bottom: 15px; background: #2a2a2a; border-radius: 8px; padding: 10px; min-height: 220px; }
.deck-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 10px; margin-bottom: 8px; background: #1a1a1a; border-radius: 8px; }
.deck-item-name { flex: 1; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deck-item-controls { display: flex; gap: 8px; align-items: center; }
.deck-item-controls button { padding: 8px 14px; font-size: 16px; min-width: 44px; min-height: 40px; border-radius: 8px; }
.deck-item-qty { font-weight: bold; min-width: 32px; text-align: center; font-size: 15px; }
.deck-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.export-section { margin-top: 15px; padding-top: 15px; border-top: 1px solid #333; }
.export-section h3 { font-size: 14px; margin-bottom: 10px; color: #999; text-transform: uppercase; }
textarea { width: 100%; min-height: 150px; resize: vertical; font-family: monospace; font-size: 12px; }
.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.8); z-index: 1000; align-items: center; justify-content: center; padding: 20px; }
.modal.active { display: flex; }
.modal-content { background: #242424; border-radius: 8px; padding: 24px; max-width: 600px; width: 100%; border: 1px solid #444; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.modal-header h2 { font-size: 18px; color: #fff; }
.modal-close { background: none; border: none; font-size: 24px; color: #999; cursor: pointer; padding: 0; width: 30px; height: 30px; }
.modal-close:hover { color: #fff; }
.modal-actions { display: flex; gap: 10px; margin-top: 15px; }
.modal-actions button { flex: 1; }
.empty-state { text-align: center; padding: 40px 20px; color: #666; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #1a1a1a; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #555; }
.toggle-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.toggle { display: flex; gap: 8px; align-items: center; font-size: 14px; color: #ddd; }
.toggle input { transform: scale(1.1); }
.card-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #2a2a2a; color: #ddd; }
.pill-leader { background: #2f3a55; }
.pill-token { background: #3a2f55; }
.btn-disabled { opacity: .6; cursor: not-allowed; }
#jsonFileInput { display: none; }
.info-banner { background: #2563eb; color: white; padding: 12px 20px; text-align: center; font-size: 14px; border-radius: 4px; margin-bottom: 15px; }

.deck-legal{
  margin: 10px 0 8px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.35;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  color: #111827;
  max-height: 130px;
  overflow: auto;
}
.deck-legal.legal{ background:#ecfdf5; border-color:#bbf7d0; color:#065f46; }
.deck-legal.illegal{ background:#fef2f2; border-color:#fecaca; color:#7f1d1d; }
.deck-legal strong{ font-weight: 700; }
.deck-legal ul{ margin: 6px 0 0 18px; padding:0; }

/* --- Légalité: badge compact + détails repliables --- */
.legality-badge{
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 700;
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap:10px;
}
.legality-badge.ok{
  background: rgba(34,197,94,0.18);
  border: 1px solid rgba(34,197,94,0.35);
  color: #bbf7d0;
}
.legality-badge.bad{
  background: rgba(239,68,68,0.18);
  border: 1px solid rgba(239,68,68,0.35);
  color: #fecaca;
}
.legality-details{
  margin-top: 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.10);
  padding: 6px 10px;
}
.legality-details summary{
  cursor:pointer;
  user-select:none;
  font-weight:600;
  opacity:0.9;
}
.legality-body{
  margin-top:8px;
  max-height: 160px;
  overflow:auto;
  padding-right:6px;
  line-height:1.35;
}



/* Top action buttons row (responsive) */
.top-actions{ display:flex; gap:10px; margin-top:10px; flex-wrap:wrap; }
.top-actions button{ flex:1 1 calc(50% - 10px); min-width:160px; }
@media (max-width: 420px){
  .top-actions button{ flex:1 1 100%; min-width:0; }
}

/* === Mobile navigation (Tabs: Cartes / Deck) === */
.mobile-tabs { display:none; }
@media (max-width: 768px){
  body { padding-bottom: 64px; overflow-x:hidden; }
  .container { padding: 12px !important; }
  /* show only one panel at a time */
  body.mobile-mode-cards #viewDeck { display:none; }
  body.mobile-mode-deck  #viewCards { display:none; }

  /* hide heavy controls when viewing deck */
  body.mobile-mode-deck .cards-only { display:none !important; }

  /* Make deck full width & comfortable */
  .container { grid-template-columns: 1fr !important; padding-bottom: 10px; }
  #viewDeck { max-height: none; overflow: visible; }
  /* Remove nested scrolling on mobile: let the page scroll naturally */
  #viewCards { max-height: none !important; overflow: visible !important; }
  .library { max-height: none !important; overflow: visible !important; }
  .deck-panel { position: static !important; max-height: none !important; }
  .deck-list { overflow: visible !important; }

  .mobile-tabs{
    display:flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 56px;
    background: #242424;
    border-top: 2px solid #333;
    z-index: 2000;
  }
  .mobile-tabs button{
    flex:1;
    border: none;
    background: transparent;
    color: #e0e0e0;
    font-size: 14px;
    display:flex;
    align-items:center;
    justify-content:center;
    gap: 8px;
  }
  .mobile-tabs button.active{
    background: #1f2937;
  }
  .tab-badge{
    min-width: 22px;
    padding: 2px 7px;
    border-radius: 999px;
    border: 1px solid #444;
    font-weight: 700;
    font-size: 12px;
    text-align:center;
  }
}



/* Controls menu (filters + actions) */
.controls-details {
  margin-top: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  overflow: hidden;
}
.controls-details > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.controls-details > summary::-webkit-details-marker { display: none; }
.controls-details[open] > summary { border-bottom: 1px solid rgba(255,255,255,0.08); }
.controls-details .filters { padding: 12px; }

/* Mobile: limit controls panel height so cards remain visible */
@media (max-width: 768px){
  .controls-details[open] .filters{
    max-height: 34vh; /* ~30-40% of screen */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}

/* Actions menu (mobile) */
.actions-details {
  margin-top: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  overflow: hidden;
}
.actions-details > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.actions-details > summary::-webkit-details-marker { display: none; }
.actions-details[open] > summary { border-bottom: 1px solid rgba(255,255,255,0.08); }
.actions-details .top-actions {
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.actions-details .top-actions button {
  width: 100%;
}
@media (min-width: 900px) {
  /* On desktop keep actions expanded automatically */
  .actions-details { background: transparent; border: 0; }
  .actions-details > summary { display:none; }
  .actions-details .top-actions { padding: 0; grid-template-columns: repeat(5, minmax(140px, 1fr)); }
}


/* Image preview modal (long press) */
#imageModal{position:fixed;inset:0;background:rgba(0,0,0,.72);display:none;align-items:center;justify-content:center;z-index:9999;padding:16px}
#imageModal.show{display:flex}
#imageModal .image-modal-content{width:min(92vw,520px);max-height:88vh;background:#1f1f1f;border:1px solid rgba(255,255,255,.12);border-radius:16px;overflow:hidden;display:flex;flex-direction:column}
#imageModal .modal-header{display:flex;align-items:center;justify-content:space-between;padding:12px 14px;border-bottom:1px solid rgba(255,255,255,.08)}
#imageModal .modal-header h2{margin:0;font-size:16px}
#imageModal .modal-close{position:absolute;right:16px;top:16px;width:44px;height:44px;border-radius:12px;border:1px solid #3a3a3a;background:#2a2a2a;color:#f2f2f2;font-size:28px;line-height:42px;text-align:center;cursor:pointer;z-index:10;touch-action:manipulation;}
#imageModal .image-modal-body{padding:12px;display:flex;align-items:center;justify-content:center;overflow:auto}
#imageModal .image-modal-body img{max-width:100%;height:auto;border-radius:10px;border:1px solid rgba(255,255,255,.10)}
#imageModal .image-modal-hint{padding:0 12px 12px 12px;color:#bdbdbd;font-size:12px}


/* --- Zoom modal: ensure close button clickable on mobile --- */
#imageModal .image-modal-header{position:sticky;top:0;z-index:10}
#imageModal .modal-close{position:relative;z-index:11;pointer-events:auto}
#imageModal .image-modal-content{position:relative}
