/* Tier List Maker. Layout and colours build on the tokens/components in
   core/site.css; only the tier colours are specific to this module. */

/* On <body> (class set by the layout) so the media viewer and dialogs,
   which sit outside .tierlist-editor, get the tier colours too. */
.module-tierlist {
    --tier-s: #818cf8;
    --tier-a: #60a5fa;
    --tier-b: #5eead4;
    --tier-c: #86efac;
    --tier-d: #fde047;
}

/* ---- Shared page header row ---- */
.tierlist-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.tierlist-toolbar .page-title { margin: 0; }

/* ---- Login ---- */
.tierlist-login {
    max-width: 440px;
    margin: 0 auto;
    padding: 32px;
}

.tierlist-login .muted { margin: 0 0 24px; }

/* ---- Dashboard ---- */
.tierlist-dashboard .btn-row { margin-bottom: 24px; }

.lists-panel {
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lists-panel > p { margin: 0; }

.list-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.lists-panel .list-row .btn-row { margin: 0; }

.list-name { font-size: 1.05rem; font-weight: 500; }

/* ---- Tier rows ---- */
.tier-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 48px;
}

.tier-row {
    display: flex;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.tier-label {
    width: 88px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    color: var(--on-accent);
    flex-shrink: 0;
}

.tier-content {
    flex-grow: 1;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    min-height: 76px;
}

.tier-s .tier-label, .tier-btn.tier-s { background: var(--tier-s); }
.tier-a .tier-label, .tier-btn.tier-a { background: var(--tier-a); }
.tier-b .tier-label, .tier-btn.tier-b { background: var(--tier-b); }
.tier-c .tier-label, .tier-btn.tier-c { background: var(--tier-c); }
.tier-d .tier-label, .tier-btn.tier-d { background: var(--tier-d); }
.tier-btn.tier-l { background: var(--surface-2); color: var(--text); font-size: 1rem; }

.thumbnail {
    width: 80px;
    height: 80px;
    background: var(--surface-2);
    border-radius: 6px;
    object-fit: cover;
    cursor: pointer;
}

/* ---- Drag and drop ---- */
.dragging { opacity: 0.4; }
.tier-content.drag-over,
.image-grid-section.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -4px;
    background: var(--surface-2);
}

/* ---- Content (unranked) ---- */
.file-controls { margin-bottom: 20px; }
.file-controls #editModeTxt { margin: 0; }
.delete-mode-actions { margin-left: auto; }

.image-grid-section { padding: 24px; }

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

.grid-image {
    width: 100%;
    height: 180px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    object-fit: cover;
    cursor: pointer;
    border: 3px solid transparent;
}

.thumbnail { border: 3px solid transparent; box-sizing: border-box; }

.image-grid.delete-mode .grid-image:hover,
.tier-list.delete-mode .thumbnail:hover { border-color: var(--border); }
.grid-image.gi-delete-selected,
.thumbnail.gi-delete-selected,
.image-grid.delete-mode .grid-image.gi-delete-selected,
.tier-list.delete-mode .thumbnail.gi-delete-selected { border-color: var(--danger-strong); }

/* ---- Media viewer ---- */
.media-viewer {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000000e6;
}

/* Not positioned, so the nav buttons anchor to the fixed viewer and stay put
   however large the current media is. */
.media-viewer-content {
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Fixed height (the media's max height) so the tier buttons below don't move
   when photos of different sizes are shown. */
#modalMediaContainer {
    height: min(600px, 70vh);
    display: flex;
    align-items: center;
    justify-content: center;
}

#modalMediaContainer img,
#modalMediaContainer video {
    display: block;
    max-width: min(800px, 90vw);
    max-height: min(600px, 70vh);
    min-width: min(400px, 80vw);
    min-height: 300px;
    width: auto;
    height: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    object-fit: contain;
    background: #000;
    border: none;
    cursor: default;
}

.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    color: var(--text);
    background: #1a1e28b3;
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
}

.nav-btn:hover { background: var(--surface-2); }
.prev-btn { left: 24px; }
.next-btn { right: 24px; }

.tier-buttons {
    margin-top: 28px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.tier-btn {
    width: 60px;
    height: 60px;
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--on-accent);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.tier-btn:hover { transform: scale(1.08); }

@media (max-width: 768px) {
    .prev-btn { left: 10px; }
    .next-btn { right: 10px; }
    .nav-btn { width: 40px; height: 40px; font-size: 1.4rem; }
    .tier-label { width: 60px; font-size: 1.5rem; }
    #modalMediaContainer img,
    #modalMediaContainer video { min-height: 200px; }
}

/* .btn comes later in site.css and would win over .silver-shimmer, so re-assert it */
.btn.silver-shimmer {
    background: var(--silver-gradient);
    background-size: 250% 250%;
    animation: silver-shimmer 4s ease-in-out infinite;
    box-shadow: inset 0 1px 1px #ffffffaa, inset 0 -1px 2px #00000066;
}
.btn.silver-shimmer:hover {
    animation-duration: 1.5s;
    transform: scale(1.06);
    box-shadow: 0 0 12px 2px #dfe6f0aa, inset 0 1px 1px #ffffffcc, inset 0 -1px 2px #00000066;
}
@media (prefers-reduced-motion: reduce) {
    .btn.silver-shimmer, .btn.silver-shimmer:hover { animation: none; }
}

/* ---- Final Showdown ---- */
.showdown { display: grid; gap: 20px; }
.showdown .tierlist-toolbar { margin-bottom: 0; }
.showdown-heading { margin: 0 0 12px; font-size: 1.25rem; }
.showdown-subheading { margin: 24px 0 12px; font-size: 1rem; color: var(--text-dim); }

.showdown-code { text-align: center; }
.showdown-code .showdown-code-value {
    margin: 4px 0 12px;
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    font-weight: 800;
    letter-spacing: 0.25em;
    padding-left: 0.25em;   /* balances the trailing letter-spacing */
    background: var(--silver-gradient);
    background-size: 250% 250%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: silver-shimmer 4s ease-in-out infinite;
    user-select: all;
}
.showdown-code-input { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 700; }

.showdown-columns { display: grid; gap: 20px; grid-template-columns: minmax(220px, 1fr) 2fr; align-items: start; }
@media (max-width: 720px) { .showdown-columns { grid-template-columns: 1fr; } }

.showdown-voters { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.showdown-voters .is-done { color: var(--success); }
.showdown-voters .is-pending { color: var(--text-dim); }

.showdown-items { display: flex; flex-wrap: wrap; gap: 8px; }
.showdown-items .showdown-media { width: 96px; height: 96px; }
.showdown-media { object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-2); display: block; }

/* Voting */
.showdown-rank-list { list-style: none; margin: 16px 0; padding: 0; display: grid; gap: 10px; position: relative; }
.showdown-rank-item {
    display: flex; align-items: center; gap: 14px;
    padding: 8px 12px; background: var(--surface-2); border-radius: var(--radius-sm);
    border: 1px solid transparent;
    user-select: none; -webkit-user-select: none;
    will-change: transform;
}
.showdown-rank-item .showdown-media { -webkit-user-drag: none; }
.showdown-rank-handle {
    cursor: grab; color: var(--text-dim); font-size: 1.3rem; line-height: 1;
    padding: 14px 10px; margin: -14px -6px -14px -10px;   /* big touch target without growing the row */
    touch-action: none;   /* a finger on the handle drags instead of scrolling the page */
}
.showdown-rank-handle:hover { color: var(--text); }
.showdown-rank-item.is-dragging {
    position: relative; z-index: 10; cursor: grabbing;
    background: var(--surface); border-color: var(--accent);
    box-shadow: 0 14px 30px -10px #000000cc, 0 0 0 1px var(--accent);
}
.is-sorting, .is-sorting * { cursor: grabbing !important; }
.showdown-rank-item.just-moved { animation: rank-flash 0.9s ease-out; }
@keyframes rank-flash {
    0%   { background: #6ee7ff40; border-color: var(--accent); }
    100% { background: var(--surface-2); border-color: transparent; }
}
@media (prefers-reduced-motion: reduce) {
    .showdown-rank-item.just-moved { animation: none; }
}
.showdown-rank-num { font-weight: 800; font-size: 1.25rem; width: 1.5rem; text-align: center; color: var(--text-dim); }
.showdown-rank-item .showdown-media { width: 120px; height: 90px; }
.showdown-rank-btns { margin-left: auto; display: flex; gap: 6px; }

/* Results */
.showdown-results { margin: 0 0 28px; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.showdown-podium { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.showdown-place, .showdown-other { position: relative; margin: 0; text-align: center; }
.showdown-place .showdown-media { width: 100%; aspect-ratio: 1; border: 3px solid var(--border); }
.showdown-place figcaption, .showdown-other figcaption { margin-top: 6px; color: var(--text-dim); font-size: 0.9rem; }
.showdown-rank {
    position: absolute; top: 8px; left: 8px; z-index: 1;
    padding: 2px 10px; border-radius: var(--radius-pill);
    font-weight: 800; background: var(--bg); color: var(--text);
}
.showdown-place-gold .showdown-media { border-color: #f5c542; box-shadow: 0 0 18px -4px #f5c542aa; }
.showdown-place-silver .showdown-media { border-color: #c4c9d2; }
.showdown-place-bronze .showdown-media { border-color: #c98a55; }
.showdown-place-gold .showdown-rank { background: #f5c542; color: var(--on-accent); }
.showdown-place-silver .showdown-rank { background: #c4c9d2; color: var(--on-accent); }
.showdown-place-bronze .showdown-rank { background: #c98a55; color: var(--on-accent); }

.showdown-others { display: flex; flex-wrap: wrap; gap: 12px; }
.showdown-other { width: 110px; }
.showdown-other .showdown-media { width: 110px; height: 110px; }
.showdown-other .showdown-rank { font-size: 0.8rem; padding: 0 8px; }

/* QR code on the host page: always dark-on-white so scanners can read it */
.showdown-qr {
    width: min(220px, 60vw); margin: 4px auto 16px;
    padding: 0; background: #ffffff; border-radius: var(--radius-sm); overflow: hidden;
    box-shadow: var(--shadow);
}
.showdown-qr svg { display: block; width: 100%; height: auto; }

/* Click-to-expand items (lightbox.js) */
[data-lightbox-group] .showdown-media { cursor: zoom-in; transition: transform 0.15s ease, filter 0.15s ease; }
[data-lightbox-group] .showdown-media:hover { filter: brightness(1.12); }
.showdown-items .showdown-media:hover, .showdown-other .showdown-media:hover { transform: scale(1.04); }
[data-lightbox-group] .showdown-media:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.lightbox {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    background: #05070bee; padding: 56px 72px 32px;
    animation: lightbox-in 0.15s ease-out;
}
.lightbox[hidden] { display: none; }
.lightbox-stage { display: flex; align-items: center; justify-content: center; min-height: 0; flex: 1; width: 100%; }
.lightbox-media {
    width: 100%; height: 100%; object-fit: contain;   /* small images scale up to fill the screen */
    border-radius: var(--radius-sm);
}
.lightbox-caption { margin: 0; color: var(--text); font-weight: 600; }
.lightbox-btn {
    position: absolute; width: 48px; height: 48px; border: 0; border-radius: 50%;
    background: #ffffff1a; color: var(--text); font-size: 1.8rem; line-height: 1; cursor: pointer;
}
.lightbox-btn:hover { background: #ffffff33; }
.lightbox-close { top: 12px; right: 12px; }
.lightbox-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 12px; top: 50%; transform: translateY(-50%); }
body.lightbox-open { overflow: hidden; }
@keyframes lightbox-in { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 600px) { .lightbox { padding: 56px 12px 24px; } }
@media (prefers-reduced-motion: reduce) { .lightbox { animation: none; } }

.tierlist-login .auth-links { margin: 20px 0 0; text-align: center; line-height: 1.8; }
.tierlist-login .alert { margin-bottom: 16px; }
