:root{
  --bg:#0b0f14; --fg:#e6eef7; --muted:#9fb3c8; --accent:#66e0ff; --chip:#1e2837; --line:#1b2a3d;
  --thumb:110px;
}
*{box-sizing:border-box}
.muted{color:var(--muted)} .small{font-size:12px}
.btn{background:#122035;border:1px solid #2a3b55;color:var(--fg);border-radius:10px;padding:8px 12px;cursor:pointer}
.btn.subtle{background:#0e1829}
/* Grouped toolbar rows */
.toolbar {
  display: grid;
  gap: 10px;
  align-items: start;
  justify-content: center;
  margin: 10px 0;
}
.chipRow {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;     /* neat, centered rows */
}
@media (min-width: 900px){
  .toolbar { gap: 12px; }
  .chipRow { justify-content: flex-start; } /* left-align on wider screens */
}

/* Grouped toolbar rows */
.toolbar {
  display: grid;
  gap: 10px;
  align-items: start;
  justify-content: center;
}
.chipRow {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;           /* centered on mobile */
}
@media (min-width: 900px){
  .chipRow { justify-content: flex-start; }  /* left-align on wider */
}

/* Sticky "Back to top" button (inside deck sidebar) */
/* --- Sticky "Back to top" inside the deck sidebar --- */
.toTopSticky{
  position: sticky;
  bottom: 12px;            /* stick to bottom of viewport */
  margin-top: 12px;
  z-index: 2;
  align-self: auto;        /* important: don't override flex alignment */
  width: 100%;
  justify-content: center;
  transition: opacity .2s ease;
}

/* When JS decides to pin it, we flip to fixed and anchor to the sidebar */
.toTopSticky.is-fixed {
  position: fixed;
  bottom: 16px;
  /* left is set by JS to keep it visually inside the deck sidebar */
}

/* --- Neon glow for cards currently in the deck --- */
@keyframes neonPulse {
  0%, 100% { box-shadow:
    0 0 0 2px #66e0ff44,
    0 0 18px #66e0ff33,
    0 10px 26px #66e0ff26,
    inset 0 0 18px #66e0ff1c; }
  50% { box-shadow:
    0 0 0 3px #66e0ff66,
    0 0 28px #66e0ff4d,
    0 16px 38px #66e0ff33,
    inset 0 0 26px #66e0ff28; }
}

.card.in-deck {
  outline: 2px solid #66e0ff88;               /* crisper outline */
  border-color: #66e0ff66;
  transform: translateY(-1px);
  animation: neonPulse 2.2s ease-in-out infinite;
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .card.in-deck { animation: none; }
}



/* Deck analytics: stack curves vertically and keep labels inside */
.analytics .curveWrap.stacked {
  display: grid;
  gap: 12px;
}
.analytics .curveBlock {
  overflow: hidden;                  /* keep labels/values inside */
}
.analytics .bars {
  padding: 6px 2px 18px;             /* room for x-axis labels */
  height: 128px;                     /* slight bump to avoid overflow */
}
.analytics .bar .val { top: -14px; } /* keep values within the box */


.toolbar{display:flex;gap:12px;align-items:center;justify-content:space-between;margin:10px 0}
.chip{background:var(--chip);border:1px solid #2a3b55;padding:8px 10px;border-radius:999px;display:inline-flex;align-items:center;gap:8px}

.layout{display:grid;grid-template-columns:1fr minmax(320px,380px);gap:16px}
@media (max-width:1100px){ .layout{grid-template-columns:1fr} .deckPane{order:-1} }

.grid{
  display:grid;
  grid-template-columns:repeat(auto-fill, minmax(var(--thumb), var(--thumb)));
  gap:12px; padding:16px; justify-content:center;
}
.section-title{grid-column:1/-1;margin-top:18px;font-weight:700;color:var(--accent);border-left:3px solid var(--accent);padding-left:10px}
.card{position:relative;width:100%;aspect-ratio:63/88;border-radius:12px;overflow:hidden;background:#0d1422;border:1px solid #26364f;cursor:pointer;transition:transform .12s ease}
.card:hover{transform:scale(1.03)}
.card img{width:100%;height:100%;object-fit:contain;display:block;background:#0d1422}
.card img { content-visibility: auto; contain-intrinsic-size: 840px 600px; }

.meta{position:absolute;inset:auto 6px 6px 6px;background:linear-gradient(180deg,transparent,#0009);padding:6px 8px;border-radius:8px;color:#dbe7f5;font-size:12px;display:flex;justify-content:space-between;gap:6px}
.empty{color:var(--muted);text-align:center;padding:20px}

.deckPane{background:linear-gradient(180deg,#0e1726,#0c1220);border:1px solid #2a3b55;border-radius:14px;padding:12px;display:flex;flex-direction:column;gap:12px}
.deckHeader .titleRow{display:flex;align-items:center;justify-content:space-between}
.badge{background:#132036;border:1px solid #29405f;color:#dbe7f5;padding:6px 10px;border-radius:999px;font-size:12px}
.errors{color:#ffc6c6;font-size:12px;line-height:1.3}
.deckGroup{border-top:1px solid #23344e;padding-top:8px}
.list{list-style:none;margin:6px 0 0 0;padding:0;display:flex;flex-direction:column;gap:6px}
.list li{display:flex;gap:8px;align-items:center;justify-content:space-between;background:#0f1a2b;border:1px solid #2a3b55;border-radius:10px;padding:6px 8px}
.list .left{display:flex;gap:8px;align-items:center}
.list .tag{font-size:11px;opacity:.8;background:#12233a;border:1px solid #23405e;border-radius:999px;padding:2px 6px}
.list .qty{display:flex;gap:6px;align-items:center}
.list input[type="number"]{width:56px;background:#0f1a2b;border:1px solid #2a3b55;color:var(--fg);border-radius:8px;padding:4px 6px}
.actions{display:flex;flex-wrap:wrap;gap:8px}
.saved, .loader{border-top:1px solid #23344e;padding-top:8px}
textarea#deckText{width:100%;background:#0f1a2b;border:1px solid #2a3b55;color:var(--fg);border-radius:10px;padding:8px}

/* Lightbox (reuses viewer look) */
.lightbox{position:fixed;inset:0;display:none;place-items:center;background:#000b;backdrop-filter:blur(2px);z-index:50;padding:16px}
.lightbox.open{display:grid}
.dialog{display:grid;grid-template-columns:minmax(280px,48vw) min(420px,40vw);gap:18px;align-items:center;max-width:96vw}
@media (max-width: 1000px){ .dialog{grid-template-columns:1fr;max-width:min(96vw,780px);} }
.zoom{position:relative;height:min(82vh,760px);aspect-ratio:63/88;width:auto;background:#0c1220;border:1px solid #345;border-radius:16px;overflow:hidden;box-shadow:0 30px 80px #000b;display:grid;place-items:center}
.zoom img{width:100%;height:100%;object-fit:contain;background:#0c1220}
.info{max-height:min(82vh,760px);overflow:auto;background:linear-gradient(180deg,#0e1726,#0c1220);border:1px solid #2a3b55;border-radius:16px;padding:14px;display:flex;flex-direction:column;gap:10px}
.info h3{margin:0;font-size:20px;color:#eaf2ff}
.info .desc{white-space:pre-wrap;color:#cfe1ff}
.row{display:flex;gap:8px;align-items:center;justify-content:space-between}
.close{background:#0b1628;border:1px solid #345;color:#cfe4ff;border-radius:10px;padding:6px 10px;cursor:pointer}
.badges{display:flex;flex-wrap:wrap;gap:8px}
.badge{background:#132036;border:1px solid #29405f;color:#dbe7f5;padding:6px 10px;border-radius:999px;font-size:12px}
.stats{display:flex;flex-wrap:wrap;gap:8px}
.stat{background:#0f1a2b;border:1px solid #2a3b55;color:#e6f2ff;padding:6px 10px;border-radius:10px;font-weight:600;font-size:13px}
.flavor{margin:4px 0 0 0;color:#b7c9e6;font-style:italic;opacity:.95}
.adder{display:flex;gap:8px;align-items:center;justify-content:flex-start}
.adder input{width:64px;background:#0f1a2b;border:1px solid #2a3b55;color:var(--fg);border-radius:8px;padding:6px}

/* ----- Mobile bottom sheet for card details ----- */
@media (max-width: 720px) {
  .lightbox {
    padding: 0;               /* use full viewport */
    align-items: end;         /* bottom sheet behavior */
    overscroll-behavior: contain;
  }

  .dialog {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100vw;
    max-width: 100vw;
    border-radius: 16px 16px 0 0;
    background: var(--bg, #0b0f14);
    box-shadow: 0 -8px 32px #000a;
  }

  .zoom {
    height: 42vh;             /* preview area */
    width: 100%;
    border-radius: 16px 16px 0 0;
  }

  .info {
    max-height: calc(58vh - env(safe-area-inset-bottom, 0px));
    border-radius: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); /* room for sticky adder */
  }

  /* Keep Close button reachable on tiny screens */
  .close {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
  }

  /* Make the "Add to Deck" bar always available */
  .adder {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    margin: 8px -14px -14px;  /* stretch to edges of panel padding */
    background: linear-gradient(180deg, transparent 0%, #0e1726 24%);
    border-top: 1px solid #2a3b55;
  }

  .adder input {
    height: 40px;
  }
  .adder .btn {
    min-height: 40px;
    flex: 1 1 auto;  /* big thumb-friendly target */
  }
}

/* Prevent page from scrolling behind the sheet */
body.body--lock {
  overflow: hidden;
  touch-action: none;
}


/* ===== Desktop: tighten dialog and equalize heights ===== */
@media (min-width: 1001px) {
  .dialog{
    align-items: stretch;                    /* was center -> stretch to same height */
    grid-template-columns: clamp(360px, 44vw, 600px) clamp(360px, 40vw, 560px);
    gap: 14px;
    height: min(82vh, 760px);                /* give the grid a reference height */
    max-width: 96vw;
  }
  .zoom{
    height: 100%;                            /* fill the grid row height */
    width: auto;
  }
  .zoom img{ object-fit: contain; }
  .info{
    height: 100%;                            /* match .zoom */
    max-height: none;                        /* let the grid control height */
    display: flex; flex-direction: column;
    overflow: hidden;                        /* clip internal scroll area below */
  }
  /* Make the scroll happen *inside* the content, not the whole pane */
  .info .desc, .info .badges, .info .stats, .info .flavor{
    overflow: auto;
  }
  /* Keep the action row visually anchored to the bottom */
  .adder{
    margin-top: auto;                        /* push to bottom in desktop */
    position: sticky; bottom: 0;             /* still nice if content exceeds */
    padding-top: 8px;
    background: linear-gradient(180deg, transparent 0%, #0e1726 60%);
    border-top: 1px solid #2a3b55;
  }
}


/* ----- Desktop: floating hover preview for deck list ----- */
@media (min-width: 1001px) {
  #hoverPreview {
    position: fixed;
    pointer-events: none;
    z-index: 60;
    display: none;
    width: clamp(180px, 18vw, 280px);
    aspect-ratio: 63 / 88;
    border-radius: 12px;
    overflow: hidden;
    background: #0c1220;
    border: 1px solid #2a3b55;
    box-shadow: 0 18px 40px #000a;
  }
  #hoverPreview img {
    width: 100%; height: 100%; object-fit: contain;
    display: block; background: #0c1220;
  }
}


/* ----- Deck analytics: tiny bar charts ----- */
.analytics .curveWrap { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (max-width: 1100px){ .analytics .curveWrap { grid-template-columns: 1fr; } }
.curveBlock{ background:#0f1a2b; border:1px solid #2a3b55; border-radius:10px; padding:10px; }
.curveTitle{ font-weight:700; color:var(--accent); margin-bottom:6px; }
.bars{ display:grid; grid-auto-flow:column; grid-auto-columns:1fr; gap:8px; align-items:end; height:120px; padding:6px 2px 0; }
.bar{ display:grid; grid-template-rows:1fr auto; gap:6px; justify-items:center; }
.bar .col{ width:100%; border-radius:8px 8px 4px 4px; background:linear-gradient(180deg,#2a88ff66,#29507a99); border:1px solid #2a3b55; box-shadow:0 4px 14px #0006 inset; min-height:4px; }
.bar .lab{ font-size:11px; color:var(--muted); }
.bar .val{ position:relative; top:-18px; font-size:12px; color:#dbe7f5; }
/* ----- Deck analytics: contain labels inside box ----- */
.analytics .curveBlock {
  overflow: hidden;                 /* keep labels/values inside */
}
.analytics .bars {
  /* was: padding: 6px 2px 0; height: 120px; */
  padding: 6px 2px 18px;           /* bottom room for "0,1,2..." labels */
  height: 128px;                   /* tiny bump so values don't push out */
}
.analytics .bar .val {
  /* keep the value overlay from pushing outside on short bars */
  top: -14px;                      /* was -18px */
}

/* Make highlighted cards more visible (still tasteful) */
.card.in-deck,
.card[style*="outline"] {
  outline-color: #66e0ff;                /* crisper */
  box-shadow:
    0 0 0 2px #66e0ff33,                 /* outer glow ring */
    0 10px 28px #66e0ff22,               /* soft drop glow */
    inset 0 0 22px #66e0ff1f;            /* subtle inner sheen */
  transform: translateY(-1px);           /* teeny lift */
}
