:root {
  /* BanG Dream! band colors, used as accents on a light page */
  --pink: #ff3377;      /* Poppin'Party */
  --red: #e23344;       /* Afterglow */
  --mint: #33ddaa;      /* Pastel*Palettes */
  --yellow: #ffcc11;    /* Hello, Happy World! */
  --blue: #3344aa;      /* Roselia */
  --sky: #33aaff;       /* Morfonica */
  --teal: #22cccc;      /* RAISE A SUILEN */

  --bg: #fff8fb;
  --panel: #ffffff;
  --panel-2: #fff0f6;
  --line: #f3d6e3;
  --text: #2a2347;
  --muted: #7a7298;
  --gold: #f5b400;
  --silver: #aab4cc;
  --bronze: #e0925a;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(51, 68, 170, 0.1);
  --font: "Space Grotesk", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 420px at 0% -80px, rgba(255, 51, 119, 0.12), transparent 70%),
    radial-gradient(900px 420px at 100% -80px, rgba(51, 170, 255, 0.14), transparent 70%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- masthead ---------- */
.masthead { background: rgba(255, 255, 255, 0.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.masthead-inner { max-width: 1280px; margin: 0 auto; padding: 14px 20px; display: flex; align-items: center; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 13px; background: linear-gradient(140deg, var(--pink), #ff7a59); color: #fff; font-weight: 700; font-size: 20px; letter-spacing: -0.04em; box-shadow: 0 6px 16px rgba(255, 51, 119, 0.35); }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.stripe { height: 5px; background: linear-gradient(90deg, var(--pink) 0 20%, var(--red) 20% 30%, var(--yellow) 30% 50%, var(--mint) 50% 65%, var(--teal) 65% 78%, var(--sky) 78% 90%, var(--blue) 90%); }

/* ---------- mode tabs ---------- */
.modebar { max-width: 1280px; margin: 0 auto; padding: 16px 20px 0; }
.modebar-inner { display: inline-flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); }
.mode { border: 0; background: transparent; border-radius: 999px; padding: 9px 20px; font-weight: 700; font-size: 14px; color: var(--muted); transition: background 0.12s, color 0.12s; }
.mode:hover { color: var(--text); }
.mode[aria-pressed="true"] { background: var(--pink); color: #fff; box-shadow: 0 6px 14px rgba(255, 51, 119, 0.3); }
.mode:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- layout: library 75% | ranking 25% ---------- */
.layout { max-width: 1280px; margin: 0 auto; padding: 24px 20px 48px; display: grid; grid-template-columns: 3fr 1fr; gap: 24px; align-items: start; }
.library { min-width: 0; }
.ranking { min-width: 0; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; scrollbar-width: thin; border-radius: 20px; }

h2 { margin: 0; font-size: 20px; }
h2 small { color: var(--muted); font-weight: 500; font-size: 14px; margin-left: 8px; }

/* ---------- ranking panel ---------- */
.ranking-card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 16px 14px 16px; box-shadow: var(--shadow); border-top: 5px solid var(--pink); }
.ranking-head { display: flex; align-items: baseline; justify-content: space-between; }
.ranking-head small { color: var(--muted); font-weight: 700; font-size: 13px; background: var(--panel-2); border-radius: 999px; padding: 3px 10px; }
.nick { display: block; margin: 12px 0 0; font-size: 12px; color: var(--muted); }
.nick input { display: block; width: 100%; margin-top: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; color: var(--text); }
.nick input:focus, .search input:focus { outline: 2px solid var(--pink); outline-offset: 1px; }
.target { margin: 12px 0 10px; font-size: 12px; line-height: 1.4; color: var(--muted); min-height: 1.4em; }
.target b { color: var(--pink); }

.actions { display: grid; gap: 8px; margin-top: 14px; }
.btn { border-radius: 10px; padding: 9px 14px; border: 1px solid var(--line); background: var(--panel); font-size: 14px; font-weight: 700; transition: transform 0.12s, border-color 0.12s, background 0.12s; }
.btn:hover:not(:disabled) { border-color: var(--pink); transform: translateY(-1px); }
.btn.primary { background: var(--pink); color: #fff; border-color: var(--pink); box-shadow: 0 6px 14px rgba(255, 51, 119, 0.3); }
.btn.ghost { background: transparent; color: var(--muted); font-weight: 500; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

/* pyramid: sizes follow the column width, first place is always biggest */
.board { container-type: inline-size; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.row { display: flex; justify-content: center; gap: 6px; width: 100%; }
.row-1 { --s: min(100cqw, 330px); }
.row-2 { --s: min(calc((100cqw - 6px) / 2), 190px); }
.row-3 { --s: min(calc((100cqw - 12px) / 3), 140px); }
.row-4 { --s: min(calc((100cqw - 18px) / 4), 104px); }

.slot { width: var(--s); position: relative; }
.slot .cover { position: relative; width: var(--s); height: var(--s); border-radius: 10px; overflow: hidden; background: var(--panel-2); border: 2px dashed #e8bfd2; display: grid; place-items: center; transition: transform 0.12s; }
.slot.filled .cover { border: 2px solid var(--rank-color); box-shadow: 0 6px 16px rgba(42, 35, 71, 0.18); }
.slot.r1.filled .cover { border-width: 3px; box-shadow: 0 0 0 4px rgba(255, 204, 17, 0.28), 0 14px 30px rgba(245, 180, 0, 0.3); }
.slot .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.slot:hover .cover { transform: translateY(-2px); }
.slot.selected .cover { outline: 3px solid var(--pink); outline-offset: 2px; }
.slot.drag-over .cover { outline: 3px dashed var(--blue); outline-offset: 2px; }
.slot[draggable="true"] { cursor: grab; }
.slot.dragging { opacity: 0.4; }
.slot:focus-visible { outline: none; }
.slot:focus-visible .cover { outline: 3px solid var(--blue); outline-offset: 2px; }

.slot .empty-label { color: #c9a7ba; font-size: 11px; text-align: center; line-height: 1.1; }
.slot .empty-label b { display: block; font-size: calc(var(--s) * 0.42); line-height: 1; color: #f0cfdf; letter-spacing: -0.04em; }
.slot.r1 .empty-label { font-size: 14px; }

.slot .badge { position: absolute; left: 5px; top: 5px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: grid; place-items: center; background: var(--rank-color); color: #2a2347; font-weight: 700; font-size: 12px; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25); }
.slot.r1 .badge { min-width: 40px; height: 40px; font-size: 22px; left: 10px; top: 10px; }
.slot.r2 .badge, .slot.r3 .badge { min-width: 28px; height: 28px; font-size: 15px; }

.slot .meta { margin-top: 5px; text-align: center; }
.slot .t { font-weight: 700; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.slot .b { margin-top: 2px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.slot.r1 .t { font-size: 18px; }
.slot.r1 .b { font-size: 12px; }
.slot.r2 .t, .slot.r3 .t { font-size: 12px; }
.slot.r2 .b, .slot.r3 .b { font-size: 10px; }
/* the smaller ranks show only the cover; their titles are in the list below */
.slot.r4 .meta, .slot.r5 .meta, .slot.r6 .meta, .slot.r7 .meta, .slot.r8 .meta, .slot.r9 .meta, .slot.r10 .meta { display: none; }

.r1 { --rank-color: var(--gold); }
.r2 { --rank-color: var(--silver); }
.r3 { --rank-color: var(--bronze); }
.r4, .r5, .r6 { --rank-color: var(--sky); }
.r7, .r8, .r9, .r10 { --rank-color: #a9a3e8; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); display: inline-block; flex: none; }

/* compact list with the move / remove controls */
.rank-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; }
.rank-list li { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 6px; padding: 4px 4px 4px 0; border-radius: 8px; font-size: 12px; }
.rank-list li.is-selected { background: var(--panel-2); }
.rank-list .n { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: #2a2347; font-weight: 700; font-size: 11px; }
.rank-list .lt { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.rank-list .lt.none { color: #c9a7ba; font-weight: 500; }
.rank-list .lt button { all: unset; cursor: pointer; display: block; overflow: hidden; text-overflow: ellipsis; }
.rank-list .lt button:focus-visible { outline: 2px solid var(--blue); border-radius: 4px; }
.rank-list .ctl { display: flex; gap: 2px; }
.rank-list .ctl button { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); font-size: 11px; line-height: 1; padding: 0; }
.rank-list .ctl button:hover:not(:disabled) { background: var(--pink); border-color: var(--pink); color: #fff; }
.rank-list .ctl button:disabled { opacity: 0.3; cursor: default; }
.rank-list li:nth-child(1) { --c: var(--gold); }
.rank-list li:nth-child(2) { --c: var(--silver); }
.rank-list li:nth-child(3) { --c: var(--bronze); }
.rank-list li:nth-child(n+4):nth-child(-n+6) { --c: var(--sky); }
.rank-list li:nth-child(n+7) { --c: #a9a3e8; }

/* best song per band: one tile per band, then a compact list */
.band-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.band-board[hidden], .band-list[hidden], .board[hidden], .rank-list[hidden] { display: none; }
.band-tile { position: relative; aspect-ratio: 1; padding: 0; border-radius: 10px; overflow: hidden; background: var(--panel-2); border: 2px dashed #e8bfd2; display: grid; place-items: center; transition: transform 0.12s; }
.band-tile:hover { transform: translateY(-2px); }
.band-tile:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.band-tile.picked { border: 2px solid var(--c); box-shadow: 0 6px 14px rgba(42, 35, 71, 0.18); }
.band-tile.active { outline: 3px solid var(--pink); outline-offset: 2px; }
.band-tile img.cv { width: 100%; height: 100%; object-fit: cover; display: block; }
.band-tile .empty-ico { width: 58%; height: 58%; object-fit: contain; opacity: 0.4; }
.band-tile .empty-mono { font-weight: 700; font-size: 15px; color: var(--c); opacity: 0.55; }
.band-tile .corner { position: absolute; left: 3px; bottom: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.band-tile .corner img { width: 82%; height: 82%; object-fit: contain; }
.band-tile .corner b { font-size: 8px; color: var(--c); }

.band-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; }
.band-list li { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; padding: 4px 4px 4px 0; border-radius: 8px; }
.band-list li.is-active { background: var(--panel-2); }
.band-list .bico { width: 28px; height: 28px; border-radius: 50%; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.band-list .bico img { width: 82%; height: 82%; object-fit: contain; }
.band-list .bico b { font-size: 9px; color: var(--c); }
.band-list button.open { all: unset; cursor: pointer; display: block; min-width: 0; }
.band-list button.open:focus-visible { outline: 2px solid var(--blue); border-radius: 4px; }
.band-list .bn { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.band-list .bt { font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.band-list .bt.none { color: #c9a7ba; font-weight: 500; }
.band-list .rm { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); font-size: 11px; line-height: 1; padding: 0; }
.band-list .rm:hover { background: var(--pink); border-color: var(--pink); color: #fff; }

/* ---------- library ---------- */
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.search input { width: min(320px, 82vw); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.lib-hint { margin: 6px 0 14px; color: var(--muted); font-size: 13px; }
.crumb { display: flex; align-items: center; gap: 12px; margin: 14px 0; padding: 8px 10px; background: var(--panel); border: 1px solid var(--line); border-left: 6px solid var(--c, var(--pink)); border-radius: 12px; }
.crumb[hidden], .folders[hidden], .grid[hidden] { display: none; }
.crumb-name { font-weight: 700; font-size: 16px; }

/* band folders */
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 22px 16px; padding-top: 12px; }
.folder { position: relative; display: flex; flex-direction: column; gap: 8px; text-align: left; min-height: 170px; padding: 58px 14px 14px; background: var(--panel); border: 1px solid var(--line); border-top: 5px solid var(--c); border-radius: 4px 14px 14px 14px; box-shadow: var(--shadow); transition: transform 0.14s, box-shadow 0.14s; }
.folder::before { content: ""; position: absolute; left: -1px; top: -17px; width: 46%; height: 13px; background: var(--c); border-radius: 8px 8px 0 0; }
.folder:hover { transform: translateY(-4px); box-shadow: 0 14px 28px rgba(42, 35, 71, 0.16); }
.folder:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.folder-stack { position: absolute; right: 12px; top: -14px; width: 92px; height: 70px; pointer-events: none; }
.folder-stack img { position: absolute; bottom: 0; width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 2px solid #fff; box-shadow: 0 4px 10px rgba(42, 35, 71, 0.25); background: var(--panel-2); transform-origin: bottom center; transition: transform 0.18s; }
.folder-stack img:nth-child(1) { left: 0; transform: rotate(-9deg); }
.folder-stack img:nth-child(2) { left: 18px; transform: rotate(0deg); z-index: 1; }
.folder-stack img:nth-child(3) { left: 36px; transform: rotate(9deg); z-index: 2; }
.folder:hover .folder-stack img:nth-child(1) { transform: rotate(-15deg) translateY(-6px); }
.folder:hover .folder-stack img:nth-child(2) { transform: translateY(-9px); }
.folder:hover .folder-stack img:nth-child(3) { transform: rotate(15deg) translateY(-6px); }
.folder-head { display: flex; align-items: center; gap: 8px; margin-top: auto; }
.folder-head .ico { width: 30px; height: 30px; object-fit: contain; border-radius: 50%; background: #fff; padding: 3px; border: 1px solid var(--line); flex: none; }
.folder-head .mono { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 700; background: var(--c); color: #fff; flex: none; }
.folder-name { font-weight: 700; font-size: 15px; line-height: 1.2; overflow-wrap: anywhere; }
.folder-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.folder-meta b { background: var(--c); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 11px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); gap: 12px; }
.card { position: relative; text-align: left; background: var(--panel); border: 1px solid var(--line); border-top: 4px solid var(--c, var(--pink)); border-radius: 12px; padding: 8px; transition: transform 0.12s, box-shadow 0.12s; }
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.card:focus-visible { outline: 2px solid var(--blue); }
.card img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; background: var(--panel-2); }
.card .t { margin-top: 8px; font-size: 12.5px; font-weight: 700; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.card .b { margin-top: 4px; font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.card .pick { position: absolute; right: 12px; top: 16px; min-width: 28px; height: 28px; padding: 0 8px; border-radius: 999px; display: none; place-items: center; font-weight: 700; font-size: 13px; background: var(--pink); color: #fff; box-shadow: 0 3px 10px rgba(255, 51, 119, 0.5); }
.card.chosen { background: var(--panel-2); }
.card.chosen .pick { display: grid; }
.card.chosen img { opacity: 0.55; }
.empty { color: var(--muted); text-align: center; padding: 30px; }

.foot { max-width: 1280px; margin: 0 auto; padding: 0 20px 40px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500; box-shadow: 0 10px 30px rgba(42, 35, 71, 0.35); z-index: 50; max-width: 90vw; }

/* ---------- narrow screens: ranking first, full width ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px 16px 40px; }
  .ranking { position: static; max-height: none; overflow: visible; order: -1; }
  .row-1 { --s: min(100cqw, 320px); }
  .row-2 { --s: min(calc((100cqw - 6px) / 2), 200px); }
  .row-3 { --s: min(calc((100cqw - 12px) / 3), 150px); }
  .row-4 { --s: min(calc((100cqw - 18px) / 4), 110px); }
  .brand p { display: none; }
  .modebar { padding: 12px 16px 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
