@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=DM+Sans:wght@400;500;700&display=swap');

:root {
  --bg:      #0a0a0e;
  --panel:   #111118;
  --card:    #18181f;
  --border:  #2a2a3a;
  --text:    #e8e8f0;
  --muted:   #5a5a7a;
  --accent:  #00e5ff;
  --accent2: #ff3d71;
  --accent3: #a259ff;
  --gold:    #ffd600;
  --s-plus:  #ff3d71;
  --s:       #ff6b3d;
  --a:       #ffaa00;
  --b:       #7ecb5a;
  --c:       #38d9a9;
  --d:       #4dabf7;
  --e:       #748ffc;
  --f:       #cc5de8;
  --g:       #a6a6a6;
  --nj:      #3d3d55;
  --ne:      #2a2a3a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Scanline overlay */
body::after {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,.08) 2px,
    rgba(0,0,0,.08) 4px
  );
  pointer-events: none; z-index: 0;
}

/* Glow blobs */
body::before {
  content: '';
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse 50% 40% at 10% 10%, rgba(0,229,255,.05) 0%, transparent 70%),
    radial-gradient(ellipse 40% 50% at 90% 80%, rgba(255,61,113,.05) 0%, transparent 70%),
    radial-gradient(ellipse 30% 30% at 50% 50%, rgba(162,89,255,.04) 0%, transparent 70%);
  pointer-events: none; z-index: 0;
}

/* ── HEADER ── */
header {
  position: relative; z-index: 10;
  text-align: center; padding: 2rem 1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(0,229,255,.04) 0%, transparent 100%);
}
header h1 {
  font-family: 'Bebas Neue', cursive;
  font-size: clamp(2.4rem, 6vw, 4rem);
  letter-spacing: .06em;
  background: linear-gradient(90deg, var(--accent), var(--accent3), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  line-height: 1;
}
header p {
  color: var(--muted);
  font-size: .8rem;
  margin-top: .4rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

/* ── LAYOUT ── */
.app {
  position: relative; z-index: 5;
  display: grid; grid-template-columns: 290px 1fr;
  gap: 1.2rem; max-width: 1640px; margin: 0 auto; padding: 1.2rem;
}
@media(max-width:880px) { .app { grid-template-columns: 1fr; } }

/* ── SIDEBAR ── */
.sidebar {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 1rem;
  height: fit-content; position: sticky; top: 1rem;
}
.sidebar-title {
  font-family: 'Bebas Neue', cursive; font-size: 1rem; letter-spacing: .1em;
  color: var(--accent); margin-bottom: .8rem;
}

/* Credentials box */
.cred-box {
  background: rgba(0,229,255,.05);
  border: 1px solid rgba(0,229,255,.15);
  border-radius: 10px; padding: .9rem; margin-bottom: .9rem;
}
.cred-box-title {
  font-size: .65rem; color: var(--accent);
  text-transform: uppercase; letter-spacing: .12em; margin-bottom: .6rem;
}
label { display: block; font-size: .68rem; color: var(--muted); margin: .5rem 0 .2rem; }
input[type=text], input[type=password] {
  width: 100%; background: var(--bg); border: 1px solid var(--border);
  border-radius: 7px; padding: .45rem .7rem; color: var(--text);
  font-family: inherit; font-size: .78rem; outline: none;
  transition: border-color .2s;
}
input:focus { border-color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  background: linear-gradient(135deg, var(--accent2), var(--accent3));
  border: none; border-radius: 8px; padding: .55rem .9rem;
  color: #fff; font-family: inherit; font-size: .78rem; font-weight: 700;
  cursor: pointer; transition: opacity .18s, transform .1s; white-space: nowrap;
}
.btn:hover { opacity: .82; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.btn-sm { padding: .3rem .6rem; font-size: .72rem; border-radius: 7px; }
.btn-ghost {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); opacity: 1; }

/* Search bar */
.search-row { display: flex; gap: .4rem; margin-bottom: .7rem; }
.search-row input {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 9px; padding: .55rem .8rem; color: var(--text);
  font-family: inherit; font-size: .82rem; outline: none;
  transition: border-color .2s;
}
.search-row input:focus { border-color: var(--accent2); }

#searchStatus {
  font-size: .7rem; color: var(--muted); text-align: center;
  padding: .3rem; font-style: italic; min-height: 1.4rem;
}
#searchStatus.err { color: #ff6b6b; font-style: normal; }
#searchStatus.ok  { color: #6bffb8; font-style: normal; }

/* ── SHOWCASE ── */
.showcase {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem; margin-top: .6rem;
  display: none; flex-direction: column; gap: .7rem;
}
.showcase.visible { display: flex; }

.showcase-nav {
  display: flex; align-items: center; gap: .5rem;
  justify-content: space-between;
}
.nav-counter { font-size: .7rem; color: var(--muted); text-align: center; flex: 1; }
.showcase-card { display: flex; gap: .9rem; align-items: flex-start; }
.showcase-cover {
  width: 90px; height: 120px; border-radius: 8px;
  object-fit: cover; flex-shrink: 0; background: var(--border);
}
.showcase-cover-ph {
  width: 90px; height: 120px; border-radius: 8px;
  background: var(--border); display: flex;
  align-items: center; justify-content: center;
  font-size: 2.2rem; flex-shrink: 0;
}
.showcase-info { flex: 1; min-width: 0; }
.showcase-name {
  font-family: 'Bebas Neue', cursive; font-size: 1rem; letter-spacing: .04em;
  line-height: 1.3; margin-bottom: .3rem;
}
.showcase-meta { font-size: .7rem; color: var(--muted); margin-bottom: .4rem; }
.showcase-rating { font-size: .72rem; color: var(--gold); }

/* Already-ranked badge */
.already-ranked {
  font-size: .65rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; padding: .2rem .5rem; border-radius: 4px;
  display: inline-block; margin-top: .3rem;
  background: rgba(255,214,0,.12); color: var(--gold); border: 1px solid rgba(255,214,0,.3);
}

/* ── DRAG CARD ── */
.drag-card {
  display: flex; align-items: center; gap: .6rem;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 9px; padding: .5rem .65rem;
  cursor: grab; user-select: none;
  transition: border-color .18s, box-shadow .18s;
}
.drag-card:hover { border-color: var(--accent); box-shadow: 0 0 12px rgba(0,229,255,.2); }
.drag-card.grabbing { opacity: .4; cursor: grabbing; }
.mini-img { width: 34px; height: 46px; border-radius: 5px; object-fit: cover; flex-shrink: 0; background: var(--border); }
.mini-ph  { width: 34px; height: 46px; border-radius: 5px; background: var(--border); display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.drag-label { font-size: .63rem; color: var(--muted); }
.drag-name  { font-size: .8rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }

/* ── QUICK-ADD GRID ── */
.add-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: .3rem;
}
.add-btn {
  padding: .35rem .4rem; font-size: .62rem; border-radius: 6px;
  cursor: pointer; border: 1px solid var(--border);
  background: rgba(255,255,255,.03); color: var(--text);
  font-family: inherit; font-weight: 700;
  transition: background .15s, border-color .15s, color .15s;
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.add-btn:hover { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.add-btn.tier-splus { border-color: var(--s-plus); color: var(--s-plus); }
.add-btn.tier-s     { border-color: var(--s); color: var(--s); }
.add-btn.tier-a     { border-color: var(--a); color: var(--a); }
.add-btn.tier-b     { border-color: var(--b); color: var(--b); }
.add-btn.tier-c     { border-color: var(--c); color: var(--c); }
.add-btn.tier-d     { border-color: var(--d); color: var(--d); }
.add-btn.tier-e     { border-color: var(--e); color: var(--e); }
.add-btn.tier-f     { border-color: var(--f); color: var(--f); }
.add-btn.tier-g     { border-color: var(--g); color: var(--g); }
.add-btn.tier-nj    { border-color: var(--nj); color: #aaa; }
.add-btn.tier-ne    { border-color: var(--ne); color: #888; }
.add-btn:hover      { background: var(--accent2) !important; border-color: var(--accent2) !important; color: #fff !important; }

/* ── RANDOM MODE ── */
.random-banner {
  background: linear-gradient(135deg, rgba(162,89,255,.12), rgba(0,229,255,.08));
  border: 1px solid rgba(162,89,255,.3);
  border-radius: 10px; padding: .7rem .9rem; margin-top: .6rem;
  font-size: .72rem; color: var(--accent3); line-height: 1.5;
  text-align: center;
}
.random-banner strong { color: var(--accent); font-size: .8rem; display: block; margin-bottom: .2rem; }
.progress-bar-wrap {
  background: rgba(255,255,255,.06); border-radius: 4px; height: 5px;
  margin-top: .5rem; overflow: hidden;
}
.progress-bar {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent2), var(--accent3));
  transition: width .4s ease;
}

/* ── TIERLIST PANEL ── */
.tierlist-panel { display: flex; flex-direction: column; gap: .9rem; }
.tierlist-top {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem;
}
.tierlist-top h2 { font-family: 'Bebas Neue', cursive; font-size: 1.1rem; letter-spacing: .08em; color: var(--accent3); }
.top-actions { display: flex; gap: .4rem; }

.tierlist { display: flex; flex-direction: column; gap: .35rem; }

/* ── TIER ROW ── */
.tier-row {
  display: flex; align-items: stretch;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); min-height: 86px;
  transition: border-color .18s;
}
.tier-row.dz-active { border-color: var(--accent); }
.tier-label {
  width: 110px; flex-shrink: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: .5rem .3rem; border-radius: 9px 0 0 9px;
  text-align: center; gap: 2px;
}
.tier-emoji { font-size: 1.2rem; line-height: 1; }
.tier-letter { font-family: 'Bebas Neue', cursive; font-size: 1.3rem; line-height: 1; }
.tier-name { font-size: .55rem; font-weight: 700; line-height: 1.25; opacity: .85; max-width: 95px; }

.tier-zone {
  flex: 1; display: flex; flex-wrap: wrap;
  gap: 5px; padding: 7px; align-content: flex-start;
  min-height: 72px; position: relative;
  border-radius: 0 9px 9px 0;
  transition: background .15s;
}
.tier-zone.dz-active { background: rgba(0,229,255,.04); }
.zone-empty {
  color: rgba(100,100,160,.35); font-size: .63rem;
  font-style: italic; display: flex; align-items: center; padding: 0 .4rem;
}

/* ── GAME CHIP ── */
.game-chip {
  position: relative; cursor: grab; flex-shrink: 0;
  border-radius: 6px; overflow: hidden;
  border: 2px solid transparent;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.game-chip:hover { transform: scale(1.1); box-shadow: 0 4px 18px rgba(0,0,0,.6); border-color: rgba(255,255,255,.3); z-index: 10; }
.game-chip.is-dragging { opacity: .35; transform: scale(.95); }
.chip-img { width: 52px; height: 70px; object-fit: cover; display: block; background: var(--border); }
.chip-ph  { width: 52px; height: 70px; background: var(--border); display: flex; align-items: center; justify-content: center; font-size: 1.5rem; }
.chip-rank {
  position: absolute; bottom: 2px; left: 2px;
  background: rgba(0,0,0,.82); color: #fff;
  font-size: .48rem; font-family: 'Bebas Neue', cursive; letter-spacing: .04em;
  padding: 1px 3px; border-radius: 3px;
}
.chip-remove {
  position: absolute; top: 2px; right: 2px;
  background: rgba(220,30,30,.88); border: none; color: #fff;
  width: 15px; height: 15px; border-radius: 50%; font-size: .55rem;
  cursor: pointer; display: none; align-items: center; justify-content: center;
  line-height: 1;
}
.game-chip:hover .chip-remove { display: flex; }
.chip-tip {
  position: absolute; bottom: calc(100% + 5px); left: 50%;
  transform: translateX(-50%);
  background: rgba(8,8,15,.97); border: 1px solid var(--border);
  border-radius: 5px; padding: .25rem .45rem; font-size: .62rem;
  white-space: nowrap; pointer-events: none; opacity: 0;
  transition: opacity .15s; z-index: 200;
}
.game-chip:hover .chip-tip { opacity: 1; }

/* ── DROP INDICATOR ── */
.drop-ind {
  width: 3px; height: 70px; background: var(--accent);
  border-radius: 2px; box-shadow: 0 0 8px var(--accent);
  flex-shrink: 0; animation: blink .6s ease-in-out infinite alternate;
}
@keyframes blink { from{opacity:.5} to{opacity:1} }

/* ── UNRANKED ── */
.unranked-wrap {
  background: var(--panel); border: 1px dashed var(--border);
  border-radius: 10px; padding: .7rem;
}
.unranked-title { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; margin-bottom: .5rem; }
.unranked-zone {
  display: flex; flex-wrap: wrap; gap: 5px; min-height: 54px;
  border-radius: 7px; transition: background .15s;
}
.unranked-zone.dz-active { background: rgba(0,229,255,.04); }

/* ── MISC ── */
.spin {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid rgba(255,255,255,.2); border-top-color: #fff;
  border-radius: 50%; animation: rot .7s linear infinite; vertical-align: middle;
}
@keyframes rot { to{transform:rotate(360deg)} }

.save-hint { font-size: .65rem; color: var(--accent); text-align: center; margin-top: .5rem; }
.sidebar-foot { margin-top: .8rem; border-top: 1px solid var(--border); padding-top: .7rem; display: flex; gap: .4rem; flex-wrap: wrap; }

/* ── MODAL ── */
.modal-bg {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.8); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.8rem; max-width: 420px; width: 92%;
  box-shadow: 0 20px 60px rgba(0,0,0,.9);
}
.modal h2 { font-family: 'Bebas Neue', cursive; letter-spacing: .06em; color: var(--accent2); margin-bottom: .35rem; font-size: 1.4rem; }
.modal p { color: var(--muted); font-size: .78rem; line-height: 1.55; margin-bottom: .4rem; }
.modal a { color: var(--accent); }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── NEXT GAME FLASH ── */
@keyframes flashIn {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.showcase.flash-in { animation: flashIn .3s ease; }

/* ── DETAIL MODAL ── */
.detail-modal {
  max-width: 640px; width: 95%; padding: 0; overflow: hidden; position: relative;
}
.detail-close {
  position: absolute; top: .7rem; right: .8rem; z-index: 10;
  background: rgba(255,255,255,.08); border: 1px solid var(--border);
  color: var(--muted); width: 28px; height: 28px; border-radius: 50%;
  cursor: pointer; font-size: .75rem; display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.detail-close:hover { background: var(--accent2); color: #fff; border-color: var(--accent2); }

.detail-inner {
  display: flex; gap: 0;
}
.detail-left {
  flex-shrink: 0; width: 180px;
}
.detail-cover {
  width: 180px; height: 240px; object-fit: cover; display: block;
}
.detail-cover-ph {
  width: 180px; height: 240px; background: var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 4rem;
}
.detail-right {
  flex: 1; padding: 1.4rem 1.3rem 1.2rem; display: flex; flex-direction: column; gap: .55rem; min-width: 0;
}
.detail-name {
  font-family: 'Bebas Neue', cursive; font-size: 1.6rem; letter-spacing: .04em;
  line-height: 1.15; color: var(--text);
}
.detail-meta { font-size: .75rem; color: var(--muted); }
.detail-rating { font-size: .9rem; }
.detail-tier  { margin-top: .1rem; }
.detail-tier-badge {
  display: inline-block; padding: .25rem .65rem; border-radius: 6px;
  font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.detail-section-label {
  font-size: .62rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em;
  margin-top: .3rem; border-top: 1px solid var(--border); padding-top: .6rem;
}
.detail-grid {
  grid-template-columns: 1fr 1fr;
  max-height: 180px; overflow-y: auto; gap: .25rem;
}
@media(max-width:520px) {
  .detail-inner { flex-direction: column; }
  .detail-left, .detail-cover, .detail-cover-ph { width: 100%; height: 180px; }
  .detail-cover { object-fit: cover; width:100%; }
}
