/* --- Definicje Zmiennych Kolorów (Nowa Paleta) --- */
:root {
    /* Kolory jasnego motywu */
    --background-color-light: #f4f7f9;
    --container-bg-light: #ffffff;
    --text-color-light: #1a202c;
    --border-color-light: #e2e8f0;
    --primary-color-light: #4c51bf;
    --hover-color-light: #667eea;
    --shadow-color-light: rgba(0, 0, 0, 0.05);
    --carousel-bg-light: #edf2f7;
    --nav-button-bg-light: #fff;
    --nav-button-color-light: #4c51bf;

    /* Kolory ciemnego motywu */
    --background-color-dark: #1a202c;
    --container-bg-dark: #2d3748;
    --text-color-dark: #e2e8f0;
    --border-color-dark: #4a5568;
    --primary-color-dark: #667eea;
    --hover-color-dark: #8093ff;
    --shadow-color-dark: rgba(255, 255, 255, 0.05);
    --carousel-bg-dark: #242c38;
    --nav-button-bg-dark: #2d3748;
    --nav-button-color-dark: #667eea;

    /* Kolory Koron */
    --gold: #FFD700;
    --silver: #C0C0C0;
    --bronze: #CD7F32;
}

/* Global styles */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--background-color-light);
    color: var(--text-color-light);
    margin: 0;
    padding: 20px;
    transition: background-color 0.3s, color 0.3s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    /* Remove mobile highlight on tap */
}

/* Ciemny motyw */
body.dark-mode {
    background-color: var(--background-color-dark);
    color: var(--text-color-dark);
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* --- Navigation and List Creation Section --- */
#nav-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    /* Ensure full width */
    gap: 15px;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color-light);
    transition: border-color 0.3s;
}

body.dark-mode #nav-container {
    border-bottom-color: var(--border-color-dark);
}

/* Input styling (used in form and modal) */
#new-list-name-modal,
input[type="text"] {
    padding: 12px;
    border: 1px solid var(--border-color-light);
    border-radius: 8px;
    font-size: 1em;
    background-color: var(--container-bg-light);
    color: var(--text-color-light);
    transition: border-color 0.3s, background-color 0.3s;
}

body.dark-mode #new-list-name-modal,
body.dark-mode input[type="text"] {
    border-color: var(--border-color-dark);
    background-color: var(--container-bg-dark);
    color: var(--text-color-dark);
}

/* --- Tierlist Carousel --- */
#carousel-wrapper {
    display: flex;
    align-items: flex-start;
    /* Zezwalamy na przesuwanie elementów na górę, gdy karuzela się zawija */
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    background-color: var(--carousel-bg-light);
    border: 1px solid var(--border-color-light);
    border-radius: 8px;
    transition: background-color 0.3s, box-shadow 0.3s, border-color 0.3s;
    gap: 5px;
    padding: 5px;
    /* Zewnętrzny padding, by dać miejsce na przyciski/margines */
}

body.dark-mode #carousel-wrapper {
    background-color: var(--carousel-bg-dark);
    border-color: var(--border-color-dark);
}

#tierlist-carousel {
    flex-grow: 1;
    overflow-x: hidden;
    /* Blokujemy przewijanie horyzontalne */
    white-space: normal;
    /* Zezwalamy na zawijanie wierszy */
    text-align: left;
    height: auto;
    /* Umożliwiamy rozszerzenie w pionie */
    min-height: 50px;
    padding: 0;
    scroll-snap-type: none;
    display: flex;
    flex-wrap: wrap;
    /* KLUCZOWA ZMIANA: Umożliwiamy zawijanie wierszy */
    align-items: center;
    gap: 5px;
    /* Odstęp między elementami */
}

/* Ukrycie paska przewijania (dla kompatybilności) */
#tierlist-carousel::-webkit-scrollbar {
    display: none;
}

#tierlist-carousel {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* Style for a single link in the carousel */
.tierlist-link {
    display: inline-block;
    padding: 8px 15px;
    margin: 0;
    border: 1px solid var(--border-color-light);
    text-decoration: none;
    color: var(--text-color-light);
    border-radius: 20px;
    transition: all 0.3s;
    background-color: var(--container-bg-light);
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}

body.dark-mode .tierlist-link {
    background-color: var(--container-bg-dark);
    color: var(--text-color-dark);
    border-color: var(--border-color-dark);
}

.tierlist-link:hover {
    box-shadow: 0 4px 6px -1px var(--shadow-color-light);
    transform: translateY(-1px);
}

body.dark-mode .tierlist-link:hover {
    box-shadow: 0 4px 6px -1px var(--shadow-color-dark);
}

/* Style for the '+' button */
.create-list-toggle-btn {
    border-style: dashed !important;
    color: var(--primary-color-light) !important;
}

body.dark-mode .create-list-toggle-btn {
    color: var(--primary-color-dark) !important;
    border-color: var(--primary-color-dark) !important;
}

/* Style for ACTIVE, selected list */
.tierlist-link.active {
    background-color: var(--primary-color-light);
    color: #ffffff;
    border-color: var(--primary-color-light);
    box-shadow: 0 4px 10px rgba(76, 81, 191, 0.4);
    transform: none;
}

body.dark-mode .tierlist-link.active {
    background-color: var(--primary-color-dark);
    border-color: var(--primary-color-dark);
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

/* Style for navigation buttons (arrows) */
.nav-button {
    background: var(--nav-button-bg-light);
    border: 2px solid var(--border-color-light);
    color: var(--nav-button-color-light);
    padding: 10px 15px;
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
    transition: all 0.2s;
    height: 50px;
    border-radius: 8px;
    flex-shrink: 0;
    align-self: flex-start;
    /* Przycisk pozostaje na górze, gdy karuzela się zawija */
}

body.dark-mode .nav-button {
    background: var(--nav-button-bg-dark);
    border-color: var(--border-color-dark);
    color: var(--nav-button-color-dark);
}

.nav-button:hover:not(:disabled) {
    background-color: var(--hover-color-light);
    color: #fff;
    border-color: var(--hover-color-light);
}

body.dark-mode .nav-button:hover:not(:disabled) {
    background-color: var(--hover-color-dark);
    color: #fff;
    border-color: var(--hover-color-dark);
}

.nav-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ZMIANA: Nowy styl dla przycisku motywu, który wygląda jak nav-button */
.theme-toggle-button {
    background: var(--nav-button-bg-light);
    border: 2px solid var(--border-color-light);
    color: var(--nav-button-color-light);
    padding: 10px;
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
    transition: all 0.2s;
    height: 50px;
    width: 50px;
    /* Kwadrat */
    border-radius: 8px;
    flex-shrink: 0;
    text-align: center;
    align-self: flex-start;
    /* Przycisk pozostaje na górze */
    margin-left: 5px;
    /* Mały odstęp od strzałek */
}

body.dark-mode .theme-toggle-button {
    background: var(--nav-button-bg-dark);
    border-color: var(--border-color-dark);
    color: var(--nav-button-color-dark);
}

.theme-toggle-button:hover {
    box-shadow: 0 2px 5px var(--shadow-color-light);
}

body.dark-mode .theme-toggle-button:hover {
    box-shadow: 0 2px 5px var(--shadow-color-dark);
}

/* --- Add Item Form --- */
.form-container {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    padding: 10px;
    border-radius: 12px;
    background-color: var(--container-bg-light);
    box-shadow: 0 2px 10px var(--shadow-color-light);
    transition: background-color 0.3s, box-shadow 0.3s;
}

body.dark-mode .form-container {
    background-color: var(--container-bg-dark);
    box-shadow: 0 2px 10px var(--shadow-color-dark);
}

.form-container input {
    flex-grow: 1;
}

.form-container button {
    padding: 12px 20px;
    background-color: var(--primary-color-light);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s, transform 0.1s;
}

body.dark-mode .form-container button {
    background-color: var(--primary-color-dark);
}

.form-container button:hover {
    background-color: var(--hover-color-light);
}

body.dark-mode .form-container button:hover {
    background-color: var(--hover-color-dark);
}

.form-container button:active {
    transform: translateY(1px);
}

/* --- Tierlist (Items) --- */
#tier-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

#tier-list li {
    display: flex;
    align-items: center;
    /* Center items vertically in the row */
    padding: 10px 15px;
    margin-bottom: 8px;
    background-color: var(--container-bg-light);
    border: 1px solid var(--border-color-light);
    border-radius: 12px;
    box-shadow: 0 1px 3px var(--shadow-color-light);
    cursor: grab;
    transition: background-color 0.3s, border-color 0.3s, transform 0.1s;
    /* Removed flex-wrap to keep delete button and content side-by-side */
}

body.dark-mode #tier-list li {
    background-color: var(--container-bg-dark);
    border-color: var(--border-color-dark);
    box-shadow: 0 1px 3px var(--shadow-color-dark);
}


/* Main Content Area */
.item-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Header Row: Rank + Name */
.item-top-row {
    display: flex;
    justify-content: flex-start;
    /* Align left */
    align-items: baseline;
    width: 100%;
    margin-bottom: 2px;
}

/* Rank Number on the Left */
.rank-number,
.crown {
    font-weight: 700;
    color: var(--primary-color-light);
    margin-left: 0;
    margin-right: 10px;
    /* Space to name */
    text-align: left;
    /* Align left */
    flex-shrink: 0;
}

.crown {
    font-size: 1.5em;
}

body.dark-mode .rank-number {
    color: var(--primary-color-dark);
}

.item-name {
    font-weight: 600;
    font-size: 1.1em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-description {
    font-size: 0.9em;
    color: var(--text-color-light);
    width: 100%;
    cursor: pointer;
    font-style: italic;
    word-wrap: break-word;
    padding-left: 0;
}

/* Improved Dark Mode Contrast for Description */
body.dark-mode .item-description {
    color: #cbd5e0;
}

/* DISABLE TEXT SELECTION GLOBALLY FOR ITEMS */
/* This ensures dragging doesn't select text on mobile */
.item-content,
.item-name,
.item-description,
.rank-number,
.crown {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.edit-icon {
    margin-left: 5px;
    font-size: 0.8em;
    opacity: 0.6;
    vertical-align: middle;
}

/* DELETE BUTTON HOLD ANIMATION */
.delete-button {
    position: relative;
    width: 40px;
    height: 40px;
    padding: 0;
    margin-left: 5px;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
    flex-shrink: 0;
    /* Remove default border radius if any, we use SVG for circle look or custom */
    border-radius: 50%;
}

.delete-button i {
    color: #ef4444;
    transition: color 0.2s;
    font-size: 1.1em;
    z-index: 2;
    /* Bring icon above SVG */
    pointer-events: none;
    /* Ensure clicks go to button */
}

.delete-button:hover i {
    color: #b91c1c;
}

/* SVG Progress Ring */
.delete-progress-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    /* Start from top */
    pointer-events: none;
    z-index: 1;
}

.delete-progress-circle {
    fill: none;
    stroke: #ef4444;
    /* Red stroke */
    stroke-width: 3;
    stroke-linecap: round;
    /* Calculated for r=18: 2 * PI * 18 ≈ 113 */
    stroke-dasharray: 113;
    stroke-dashoffset: 113;
    /* Start fully hidden */
    transition: stroke-dashoffset 0s linear;
    /* Default no transition */
    opacity: 0.3;
    /* Subtle background ring or hide it? */
}

/* Background Ring (Optional, creates a faint track) */
.delete-bg-circle {
    fill: none;
    stroke: rgba(239, 68, 68, 0.1);
    stroke-width: 3;
}

/* Trigger animation when class is added */
.delete-button.holding .delete-progress-circle {
    stroke-dashoffset: 0;
    /* Fill it */
    transition: stroke-dashoffset 1s linear;
    /* Match HOLD_DURATION */
    opacity: 1;
}


/* Shake effect for feedback when deletion is ready? Optional. */
.delete-button.ready {
    color: #b91c1c;
    transform: scale(1.1);
    transition: transform 0.1s;
}

/* ... (Drag/Sortable styles can stay) ... */
/* SortableJS placeholder styling */
.sortable-ghost {
    opacity: 0.4;
    border: 2px dashed var(--primary-color-light);
    background-color: var(--carousel-bg-light) !important;
}

body.dark-mode .sortable-ghost {
    border: 2px dashed var(--primary-color-dark);
    background-color: var(--carousel-bg-dark) !important;
}


/* --- Modal (Popup) Styles --- */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: var(--container-bg-light);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 400px;
    transform: scale(1);
    transition: background-color 0.3s;
}

body.dark-mode .modal-content {
    background-color: var(--container-bg-dark);
    box-shadow: 0 5px 15px rgba(255, 255, 255, 0.1);
}

.modal-content h2 {
    margin-top: 0;
    font-size: 1.5em;
    border-bottom: 1px solid var(--border-color-light);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

body.dark-mode .modal-content h2 {
    border-bottom-color: var(--border-color-dark);
}

#new-list-name-modal {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 20px;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-buttons button {
    padding: 10px 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s;
}

#cancel-create-list,
#cancel-delete,
#cancel-description {
    background-color: #e5e7eb;
    color: var(--text-color-light);
}

body.dark-mode #cancel-create-list,
body.dark-mode #cancel-delete,
body.dark-mode #cancel-description {
    background-color: #4a5568;
    color: var(--text-color-dark);
}

.create-button,
.delete-confirm-button {
    background-color: var(--primary-color-light);
    color: white;
}

body.dark-mode .create-button,
body.dark-mode .delete-confirm-button {
    background-color: var(--primary-color-dark);
}

.delete-confirm-button:hover {
    background-color: #dc2626;
    user-select: none;
    -webkit-user-select: none;
    /* Safari */
}

/* Description Modal Specifics */
#description-modal textarea {
    width: 100%;
    height: 100px;
    padding: 10px;
    border: 1px solid var(--border-color-light);
    border-radius: 8px;
    background-color: var(--container-bg-light);
    /* Or slightly different to distinguish inputs */
    color: var(--text-color-light);
    font-family: inherit;
    resize: vertical;
    margin-bottom: 20px;
    box-sizing: border-box;
    /* Ensure padding doesn't overflow width */
}

body.dark-mode #description-modal textarea {
    background-color: var(--container-bg-dark);
    color: var(--text-color-dark);
    border-color: var(--border-color-dark);
}

/* Responsywność */
@media (max-width: 600px) {

    body {
        padding: 2px;
        /* Reduce padding on mobile as requested */
    }

    .container {
        padding: 5px;
        width: 100%;
        /* Force full width as requested */
        max-width: 100%;
        margin: 0;
        /* Remove margin */
    }

    /* Disable text selection on mobile to prevent accidental highlighting during drag */
    #tier-list,
    .item-description,
    .item-name {
        user-select: none;
        -webkit-user-select: none;
        /* Safari */
    }

    .form-container {
        flex-direction: column;
    }

    .form-container button {
        width: 100%;
    }

    #carousel-wrapper {
        flex-wrap: nowrap;
        overflow: visible;
        padding: 5px;
        gap: 2px;
    }

    #tierlist-carousel {
        display: flex;
        flex-wrap: wrap;
        overflow-x: visible;
        justify-content: center;
        width: auto;
        min-width: 0;
        flex-grow: 1;
        height: auto;
    }

    .tierlist-link {
        padding: 6px 10px;
        margin: 2px;
        font-size: 0.85em;
        flex-grow: 1;
        text-align: center;
        white-space: nowrap;
    }

    #tier-list li {
        padding: 8px;
    }

    .delete-button {
        padding: 8px;
        margin-left: 2px;
    }

    .item-name {
        font-size: 1.05em;
    }

    .nav-button,
    .theme-toggle-button {
        padding: 5px;
        width: 35px;
        height: 35px;
        font-size: 0.9em;
        flex-shrink: 0;
    }

    .theme-toggle-button {
        padding: 8px;
    }
}

/* Dodatkowe poprawki dla urządzeń mobilnych - skalowanie czcionki */
@media (max-width: 480px) {
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 1.3rem;
    }

    .tierlist-link {
        font-size: 0.75em;
        padding: 5px 8px;
    }

    #tier-list li {
        padding: 10px;
    }

    .item-name {
        font-size: 1em;
    }

    .item-description {
        font-size: 0.8em;
    }
}

/* Dodatkowe poprawki dla urządzeń mobilnych - lepsze wyświetlanie listy */
@media screen and (max-width: 768px) {
    .tierlist-container {
        padding: 10px;
    }

    .tierlist-header {
        font-size: 1.5rem;
    }

    .item-name {
        font-size: 1.2rem;
    }

    .item-description {
        font-size: 0.9rem;
    }

    /* Dostosowanie rozmiaru listy do ekranu */
    #tier-list li {
        padding: 12px;
        flex-direction: row;
        align-items: center;
    }

    .item-content {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        flex-grow: 1;
        min-width: 0;
    }

    .rank-number {
        margin-bottom: 0;
        margin-right: 10px;
    }

    .item-name {
        font-size: 1.1em;
        margin-bottom: 2px;
    }

    .delete-button {
        align-self: center;
        padding: 8px;
        font-size: 1.2em;
    }
}